]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
bgpd: the neighbor as are displayed with as-notation mode
[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"
8079a413 42#include "asn.h"
718e3744 43
44#include "bgpd/bgpd.h"
48ecf8f5 45#include "bgpd/bgp_attr_evpn.h"
4bf6a362 46#include "bgpd/bgp_advertise.h"
718e3744 47#include "bgpd/bgp_attr.h"
48#include "bgpd/bgp_aspath.h"
49#include "bgpd/bgp_community.h"
ed0e57e3 50#include "bgpd/bgp_community_alias.h"
4bf6a362 51#include "bgpd/bgp_ecommunity.h"
57d187bc 52#include "bgpd/bgp_lcommunity.h"
4bf6a362 53#include "bgpd/bgp_damp.h"
718e3744 54#include "bgpd/bgp_debug.h"
14454c9f 55#include "bgpd/bgp_errors.h"
e0701b79 56#include "bgpd/bgp_fsm.h"
4cd690ae 57#include "bgpd/bgp_nht.h"
4bf6a362 58#include "bgpd/bgp_nexthop.h"
4122b697 59#include "bgpd/bgp_network.h"
718e3744 60#include "bgpd/bgp_open.h"
4bf6a362 61#include "bgpd/bgp_regex.h"
718e3744 62#include "bgpd/bgp_route.h"
c016b6c7 63#include "bgpd/bgp_mplsvpn.h"
718e3744 64#include "bgpd/bgp_zebra.h"
fee0f4c6 65#include "bgpd/bgp_table.h"
94f2b392 66#include "bgpd/bgp_vty.h"
165b5fff 67#include "bgpd/bgp_mpath.h"
cb1faec9 68#include "bgpd/bgp_packet.h"
3f9c7369 69#include "bgpd/bgp_updgrp.h"
c43ed2e4 70#include "bgpd/bgp_bfd.h"
555e09d4 71#include "bgpd/bgp_io.h"
94c2f693 72#include "bgpd/bgp_evpn.h"
dd65f45e 73#include "bgpd/bgp_evpn_vty.h"
b5e140c8 74#include "bgpd/bgp_evpn_mh.h"
dcc68b5e 75#include "bgpd/bgp_addpath.h"
48ecf8f5 76#include "bgpd/bgp_mac.h"
dd65f45e 77#include "bgpd/bgp_flowspec.h"
389e4f92 78#include "bgpd/bgp_conditional_adv.h"
49e5a4a0 79#ifdef ENABLE_BGP_VNC
dd65f45e
DL
80#include "bgpd/rfapi/bgp_rfapi_cfg.h"
81#endif
82
5d5393b9 83FRR_CFG_DEFAULT_BOOL(BGP_IMPORT_CHECK,
62282e83
DS
84 {
85 .val_bool = false,
86 .match_profile = "traditional",
87 .match_version = "< 7.4",
88 },
89 { .val_bool = true },
67b0f40c 90);
5d5393b9 91FRR_CFG_DEFAULT_BOOL(BGP_SHOW_HOSTNAME,
4c1458b5
DL
92 { .val_bool = true, .match_profile = "datacenter", },
93 { .val_bool = false },
67b0f40c 94);
aef999a2
DA
95FRR_CFG_DEFAULT_BOOL(BGP_SHOW_NEXTHOP_HOSTNAME,
96 { .val_bool = true, .match_profile = "datacenter", },
97 { .val_bool = false },
67b0f40c 98);
5d5393b9 99FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
4c1458b5
DL
100 { .val_bool = true, .match_profile = "datacenter", },
101 { .val_bool = false },
67b0f40c 102);
5d5393b9 103FRR_CFG_DEFAULT_BOOL(BGP_DETERMINISTIC_MED,
4c1458b5
DL
104 { .val_bool = true, .match_profile = "datacenter", },
105 { .val_bool = false },
67b0f40c 106);
5d5393b9
DL
107FRR_CFG_DEFAULT_ULONG(BGP_CONNECT_RETRY,
108 { .val_ulong = 10, .match_profile = "datacenter", },
109 { .val_ulong = 120 },
67b0f40c 110);
5d5393b9
DL
111FRR_CFG_DEFAULT_ULONG(BGP_HOLDTIME,
112 { .val_ulong = 9, .match_profile = "datacenter", },
113 { .val_ulong = 180 },
67b0f40c 114);
5d5393b9
DL
115FRR_CFG_DEFAULT_ULONG(BGP_KEEPALIVE,
116 { .val_ulong = 3, .match_profile = "datacenter", },
117 { .val_ulong = 60 },
67b0f40c 118);
1d3fdccf
DA
119FRR_CFG_DEFAULT_BOOL(BGP_EBGP_REQUIRES_POLICY,
120 { .val_bool = false, .match_profile = "datacenter", },
121 { .val_bool = false, .match_version = "< 7.4", },
122 { .val_bool = true },
67b0f40c 123);
2adac256
DA
124FRR_CFG_DEFAULT_BOOL(BGP_SUPPRESS_DUPLICATES,
125 { .val_bool = false, .match_version = "< 7.6", },
126 { .val_bool = true },
67b0f40c 127);
f2ca5c5b
DA
128FRR_CFG_DEFAULT_BOOL(BGP_GRACEFUL_NOTIFICATION,
129 { .val_bool = false, .match_version = "< 8.3", },
130 { .val_bool = true },
131);
1ae314be
DA
132FRR_CFG_DEFAULT_BOOL(BGP_HARD_ADMIN_RESET,
133 { .val_bool = false, .match_version = "< 8.3", },
134 { .val_bool = true },
135);
5d5393b9 136
dd65f45e
DL
137DEFINE_HOOK(bgp_inst_config_write,
138 (struct bgp *bgp, struct vty *vty),
8451921b
DL
139 (bgp, vty));
140DEFINE_HOOK(bgp_snmp_update_last_changed, (struct bgp *bgp), (bgp));
1ca2fd11 141DEFINE_HOOK(bgp_snmp_init_stats, (struct bgp *bgp), (bgp));
718e3744 142
d62a17ae 143static struct peer_group *listen_range_exists(struct bgp *bgp,
144 struct prefix *range, int exact);
145
055679e9 146/* Show BGP peer's information. */
147enum show_type {
148 show_all,
149 show_peer,
150 show_ipv4_all,
151 show_ipv6_all,
152 show_ipv4_peer,
153 show_ipv6_peer
154};
155
36235319
QY
156static struct peer_group *listen_range_exists(struct bgp *bgp,
157 struct prefix *range, int exact);
2986cac2 158
36235319 159static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
403e64f8 160 struct bgp *bgp);
2986cac2 161
36235319
QY
162static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
163 enum show_type type,
164 const char *ip_str,
165 afi_t afi, bool use_json);
2986cac2 166
d62a17ae 167static enum node_type bgp_node_type(afi_t afi, safi_t safi)
168{
169 switch (afi) {
170 case AFI_IP:
171 switch (safi) {
172 case SAFI_UNICAST:
173 return BGP_IPV4_NODE;
d62a17ae 174 case SAFI_MULTICAST:
175 return BGP_IPV4M_NODE;
d62a17ae 176 case SAFI_LABELED_UNICAST:
177 return BGP_IPV4L_NODE;
d62a17ae 178 case SAFI_MPLS_VPN:
179 return BGP_VPNV4_NODE;
7c40bf39 180 case SAFI_FLOWSPEC:
181 return BGP_FLOWSPECV4_NODE;
58cf0823
DS
182 case SAFI_UNSPEC:
183 case SAFI_ENCAP:
184 case SAFI_EVPN:
185 case SAFI_MAX:
5c525538
RW
186 /* not expected */
187 return BGP_IPV4_NODE;
d62a17ae 188 }
58cf0823 189 break;
d62a17ae 190 case AFI_IP6:
191 switch (safi) {
192 case SAFI_UNICAST:
193 return BGP_IPV6_NODE;
d62a17ae 194 case SAFI_MULTICAST:
195 return BGP_IPV6M_NODE;
d62a17ae 196 case SAFI_LABELED_UNICAST:
197 return BGP_IPV6L_NODE;
d62a17ae 198 case SAFI_MPLS_VPN:
199 return BGP_VPNV6_NODE;
7c40bf39 200 case SAFI_FLOWSPEC:
201 return BGP_FLOWSPECV6_NODE;
58cf0823
DS
202 case SAFI_UNSPEC:
203 case SAFI_ENCAP:
204 case SAFI_EVPN:
205 case SAFI_MAX:
206 /* not expected and the return value seems wrong */
5c525538 207 return BGP_IPV4_NODE;
d62a17ae 208 }
58cf0823 209 break;
d62a17ae 210 case AFI_L2VPN:
211 return BGP_EVPN_NODE;
b26f891d 212 case AFI_UNSPEC:
d62a17ae 213 case AFI_MAX:
214 // We should never be here but to clarify the switch statement..
215 return BGP_IPV4_NODE;
d62a17ae 216 }
217
218 // Impossible to happen
219 return BGP_IPV4_NODE;
f51bae9c 220}
20eb8864 221
5cb5f4d0
DD
222static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
223{
7d0d37de
DS
224 if (afi == AFI_IP) {
225 if (safi == SAFI_UNICAST)
226 return "IPv4 Unicast";
227 if (safi == SAFI_MULTICAST)
228 return "IPv4 Multicast";
229 if (safi == SAFI_LABELED_UNICAST)
230 return "IPv4 Labeled Unicast";
231 if (safi == SAFI_MPLS_VPN)
232 return "IPv4 VPN";
233 if (safi == SAFI_ENCAP)
234 return "IPv4 Encap";
235 if (safi == SAFI_FLOWSPEC)
236 return "IPv4 Flowspec";
237 } else if (afi == AFI_IP6) {
238 if (safi == SAFI_UNICAST)
239 return "IPv6 Unicast";
240 if (safi == SAFI_MULTICAST)
241 return "IPv6 Multicast";
242 if (safi == SAFI_LABELED_UNICAST)
243 return "IPv6 Labeled Unicast";
244 if (safi == SAFI_MPLS_VPN)
245 return "IPv6 VPN";
246 if (safi == SAFI_ENCAP)
247 return "IPv6 Encap";
248 if (safi == SAFI_FLOWSPEC)
249 return "IPv6 Flowspec";
250 } else if (afi == AFI_L2VPN) {
251 if (safi == SAFI_EVPN)
252 return "L2VPN EVPN";
253 }
254
255 return "Unknown";
5cb5f4d0
DD
256}
257
258/*
259 * Please note that we have intentionally camelCased
260 * the return strings here. So if you want
261 * to use this function, please ensure you
262 * are doing this within json output
263 */
264static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
265{
7d0d37de
DS
266 if (afi == AFI_IP) {
267 if (safi == SAFI_UNICAST)
268 return "ipv4Unicast";
269 if (safi == SAFI_MULTICAST)
270 return "ipv4Multicast";
271 if (safi == SAFI_LABELED_UNICAST)
272 return "ipv4LabeledUnicast";
273 if (safi == SAFI_MPLS_VPN)
274 return "ipv4Vpn";
275 if (safi == SAFI_ENCAP)
276 return "ipv4Encap";
277 if (safi == SAFI_FLOWSPEC)
278 return "ipv4Flowspec";
279 } else if (afi == AFI_IP6) {
280 if (safi == SAFI_UNICAST)
281 return "ipv6Unicast";
282 if (safi == SAFI_MULTICAST)
283 return "ipv6Multicast";
284 if (safi == SAFI_LABELED_UNICAST)
285 return "ipv6LabeledUnicast";
286 if (safi == SAFI_MPLS_VPN)
287 return "ipv6Vpn";
288 if (safi == SAFI_ENCAP)
289 return "ipv6Encap";
290 if (safi == SAFI_FLOWSPEC)
291 return "ipv6Flowspec";
292 } else if (afi == AFI_L2VPN) {
293 if (safi == SAFI_EVPN)
294 return "l2VpnEvpn";
295 }
296
297 return "Unknown";
5cb5f4d0
DD
298}
299
0249b8b6
HS
300/* unset srv6 locator */
301static int bgp_srv6_locator_unset(struct bgp *bgp)
302{
303 int ret;
304 struct listnode *node, *nnode;
efae8c26 305 struct srv6_locator_chunk *chunk;
0249b8b6
HS
306 struct bgp_srv6_function *func;
307 struct bgp *bgp_vrf;
0249b8b6
HS
308
309 /* release chunk notification via ZAPI */
310 ret = bgp_zebra_srv6_manager_release_locator_chunk(
311 bgp->srv6_locator_name);
312 if (ret < 0)
313 return -1;
314
315 /* refresh chunks */
03852f67 316 for (ALL_LIST_ELEMENTS(bgp->srv6_locator_chunks, node, nnode, chunk)) {
0249b8b6 317 listnode_delete(bgp->srv6_locator_chunks, chunk);
69467313 318 srv6_locator_chunk_free(&chunk);
03852f67 319 }
0249b8b6
HS
320
321 /* refresh functions */
bda15542 322 for (ALL_LIST_ELEMENTS(bgp->srv6_functions, node, nnode, func)) {
0249b8b6 323 listnode_delete(bgp->srv6_functions, func);
bda15542
CS
324 XFREE(MTYPE_BGP_SRV6_FUNCTION, func);
325 }
0249b8b6
HS
326
327 /* refresh tovpn_sid */
328 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
329 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
330 continue;
331
332 /* refresh vpnv4 tovpn_sid */
944909f4
CS
333 XFREE(MTYPE_BGP_SRV6_SID,
334 bgp_vrf->vpn_policy[AFI_IP].tovpn_sid);
0249b8b6
HS
335
336 /* refresh vpnv6 tovpn_sid */
944909f4
CS
337 XFREE(MTYPE_BGP_SRV6_SID,
338 bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid);
527588aa
CS
339
340 /* refresh per-vrf tovpn_sid */
341 XFREE(MTYPE_BGP_SRV6_SID, bgp_vrf->tovpn_sid);
0249b8b6
HS
342 }
343
344 /* update vpn bgp processes */
345 vpn_leak_postchange_all();
346
f8e9c702
CS
347 /* refresh tovpn_sid_locator */
348 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
349 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
350 continue;
351
352 /* refresh vpnv4 tovpn_sid_locator */
efae8c26
CS
353 srv6_locator_chunk_free(
354 &bgp_vrf->vpn_policy[AFI_IP].tovpn_sid_locator);
f8e9c702
CS
355
356 /* refresh vpnv6 tovpn_sid_locator */
efae8c26
CS
357 srv6_locator_chunk_free(
358 &bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid_locator);
527588aa
CS
359
360 /* refresh per-vrf tovpn_sid_locator */
69467313 361 srv6_locator_chunk_free(&bgp_vrf->tovpn_sid_locator);
f8e9c702
CS
362 }
363
0249b8b6
HS
364 /* clear locator name */
365 memset(bgp->srv6_locator_name, 0, sizeof(bgp->srv6_locator_name));
366
367 return 0;
368}
369
718e3744 370/* Utility function to get address family from current node. */
d62a17ae 371afi_t bgp_node_afi(struct vty *vty)
372{
373 afi_t afi;
374 switch (vty->node) {
375 case BGP_IPV6_NODE:
376 case BGP_IPV6M_NODE:
377 case BGP_IPV6L_NODE:
378 case BGP_VPNV6_NODE:
7c40bf39 379 case BGP_FLOWSPECV6_NODE:
d62a17ae 380 afi = AFI_IP6;
381 break;
382 case BGP_EVPN_NODE:
383 afi = AFI_L2VPN;
384 break;
385 default:
386 afi = AFI_IP;
387 break;
388 }
389 return afi;
718e3744 390}
391
392/* Utility function to get subsequent address family from current
393 node. */
d62a17ae 394safi_t bgp_node_safi(struct vty *vty)
395{
396 safi_t safi;
397 switch (vty->node) {
398 case BGP_VPNV4_NODE:
399 case BGP_VPNV6_NODE:
400 safi = SAFI_MPLS_VPN;
401 break;
402 case BGP_IPV4M_NODE:
403 case BGP_IPV6M_NODE:
404 safi = SAFI_MULTICAST;
405 break;
406 case BGP_EVPN_NODE:
407 safi = SAFI_EVPN;
408 break;
409 case BGP_IPV4L_NODE:
410 case BGP_IPV6L_NODE:
411 safi = SAFI_LABELED_UNICAST;
412 break;
7c40bf39 413 case BGP_FLOWSPECV4_NODE:
414 case BGP_FLOWSPECV6_NODE:
415 safi = SAFI_FLOWSPEC;
416 break;
d62a17ae 417 default:
418 safi = SAFI_UNICAST;
419 break;
420 }
421 return safi;
718e3744 422}
423
55f91488
QY
424/**
425 * Converts an AFI in string form to afi_t
426 *
427 * @param afi string, one of
428 * - "ipv4"
429 * - "ipv6"
81cf0de5 430 * - "l2vpn"
55f91488
QY
431 * @return the corresponding afi_t
432 */
d62a17ae 433afi_t bgp_vty_afi_from_str(const char *afi_str)
434{
435 afi_t afi = AFI_MAX; /* unknown */
436 if (strmatch(afi_str, "ipv4"))
437 afi = AFI_IP;
438 else if (strmatch(afi_str, "ipv6"))
439 afi = AFI_IP6;
81cf0de5
CS
440 else if (strmatch(afi_str, "l2vpn"))
441 afi = AFI_L2VPN;
d62a17ae 442 return afi;
443}
444
445int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
446 afi_t *afi)
447{
448 int ret = 0;
449 if (argv_find(argv, argc, "ipv4", index)) {
450 ret = 1;
451 if (afi)
452 *afi = AFI_IP;
453 } else if (argv_find(argv, argc, "ipv6", index)) {
454 ret = 1;
455 if (afi)
456 *afi = AFI_IP6;
8688b3e7
DS
457 } else if (argv_find(argv, argc, "l2vpn", index)) {
458 ret = 1;
459 if (afi)
460 *afi = AFI_L2VPN;
d62a17ae 461 }
462 return ret;
46f296b4
LB
463}
464
375a2e67 465/* supports <unicast|multicast|vpn|labeled-unicast> */
d62a17ae 466safi_t bgp_vty_safi_from_str(const char *safi_str)
467{
468 safi_t safi = SAFI_MAX; /* unknown */
469 if (strmatch(safi_str, "multicast"))
470 safi = SAFI_MULTICAST;
471 else if (strmatch(safi_str, "unicast"))
472 safi = SAFI_UNICAST;
473 else if (strmatch(safi_str, "vpn"))
474 safi = SAFI_MPLS_VPN;
81cf0de5
CS
475 else if (strmatch(safi_str, "evpn"))
476 safi = SAFI_EVPN;
d62a17ae 477 else if (strmatch(safi_str, "labeled-unicast"))
478 safi = SAFI_LABELED_UNICAST;
7c40bf39 479 else if (strmatch(safi_str, "flowspec"))
480 safi = SAFI_FLOWSPEC;
d62a17ae 481 return safi;
482}
483
484int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
485 safi_t *safi)
486{
487 int ret = 0;
488 if (argv_find(argv, argc, "unicast", index)) {
489 ret = 1;
490 if (safi)
491 *safi = SAFI_UNICAST;
492 } else if (argv_find(argv, argc, "multicast", index)) {
493 ret = 1;
494 if (safi)
495 *safi = SAFI_MULTICAST;
496 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
497 ret = 1;
498 if (safi)
499 *safi = SAFI_LABELED_UNICAST;
500 } else if (argv_find(argv, argc, "vpn", index)) {
501 ret = 1;
502 if (safi)
503 *safi = SAFI_MPLS_VPN;
8688b3e7
DS
504 } else if (argv_find(argv, argc, "evpn", index)) {
505 ret = 1;
506 if (safi)
507 *safi = SAFI_EVPN;
7c40bf39 508 } else if (argv_find(argv, argc, "flowspec", index)) {
509 ret = 1;
510 if (safi)
511 *safi = SAFI_FLOWSPEC;
d62a17ae 512 }
513 return ret;
46f296b4
LB
514}
515
b16bcbba
TA
516/*
517 * Convert an afi_t/safi_t pair to matching BGP_DEFAULT_AF* flag.
518 *
519 * afi
520 * address-family identifier
521 *
522 * safi
523 * subsequent address-family identifier
524 *
525 * Returns:
526 * default_af string corresponding to the supplied afi/safi pair.
527 * If afi/safi is invalid or if flag for afi/safi doesn't exist,
528 * return -1.
529 */
530static const char *get_bgp_default_af_flag(afi_t afi, safi_t safi)
531{
532 switch (afi) {
533 case AFI_IP:
534 switch (safi) {
535 case SAFI_UNICAST:
536 return "ipv4-unicast";
537 case SAFI_MULTICAST:
538 return "ipv4-multicast";
539 case SAFI_MPLS_VPN:
540 return "ipv4-vpn";
541 case SAFI_ENCAP:
542 return "ipv4-encap";
543 case SAFI_LABELED_UNICAST:
544 return "ipv4-labeled-unicast";
545 case SAFI_FLOWSPEC:
546 return "ipv4-flowspec";
58cf0823
DS
547 case SAFI_UNSPEC:
548 case SAFI_EVPN:
549 case SAFI_MAX:
b16bcbba
TA
550 return "unknown-afi/safi";
551 }
552 break;
553 case AFI_IP6:
554 switch (safi) {
555 case SAFI_UNICAST:
556 return "ipv6-unicast";
557 case SAFI_MULTICAST:
558 return "ipv6-multicast";
559 case SAFI_MPLS_VPN:
560 return "ipv6-vpn";
561 case SAFI_ENCAP:
562 return "ipv6-encap";
563 case SAFI_LABELED_UNICAST:
564 return "ipv6-labeled-unicast";
565 case SAFI_FLOWSPEC:
566 return "ipv6-flowspec";
58cf0823
DS
567 case SAFI_UNSPEC:
568 case SAFI_EVPN:
569 case SAFI_MAX:
b16bcbba
TA
570 return "unknown-afi/safi";
571 }
572 break;
573 case AFI_L2VPN:
574 switch (safi) {
575 case SAFI_EVPN:
576 return "l2vpn-evpn";
58cf0823
DS
577 case SAFI_UNICAST:
578 case SAFI_MULTICAST:
579 case SAFI_MPLS_VPN:
580 case SAFI_ENCAP:
581 case SAFI_LABELED_UNICAST:
582 case SAFI_FLOWSPEC:
583 case SAFI_UNSPEC:
584 case SAFI_MAX:
b16bcbba
TA
585 return "unknown-afi/safi";
586 }
58cf0823 587 break;
b16bcbba
TA
588 case AFI_UNSPEC:
589 case AFI_MAX:
590 return "unknown-afi/safi";
591 }
592 /* all AFIs are accounted for above, so this shouldn't happen */
58cf0823
DS
593
594 assert(!"Reached end of function where we did not expect to");
b16bcbba
TA
595}
596
5d5393b9 597int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
e55b0883
PG
598 enum bgp_instance_type inst_type, const char *as_pretty,
599 enum asnotation_mode asnotation)
5d5393b9 600{
e55b0883 601 int ret = bgp_get(bgp, as, name, inst_type, as_pretty, asnotation);
5d5393b9
DL
602
603 if (ret == BGP_CREATED) {
604 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
d43114f3 605 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
5d5393b9
DL
606
607 if (DFLT_BGP_IMPORT_CHECK)
892fedb6 608 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
5d5393b9 609 if (DFLT_BGP_SHOW_HOSTNAME)
892fedb6 610 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
aef999a2
DA
611 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
612 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
5d5393b9 613 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
892fedb6 614 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
5d5393b9 615 if (DFLT_BGP_DETERMINISTIC_MED)
892fedb6 616 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
1d3fdccf
DA
617 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
618 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2adac256
DA
619 if (DFLT_BGP_SUPPRESS_DUPLICATES)
620 SET_FLAG((*bgp)->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
f2ca5c5b
DA
621 if (DFLT_BGP_GRACEFUL_NOTIFICATION)
622 SET_FLAG((*bgp)->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
1ae314be
DA
623 if (DFLT_BGP_HARD_ADMIN_RESET)
624 SET_FLAG((*bgp)->flags, BGP_FLAG_HARD_ADMIN_RESET);
5d5393b9
DL
625
626 ret = BGP_SUCCESS;
627 }
628 return ret;
629}
630
7eeee51e 631/*
f212a857 632 * bgp_vty_find_and_parse_afi_safi_bgp
7eeee51e 633 *
f212a857
DS
634 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
635 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
7eeee51e
DS
636 * to appropriate values for the calling function. This is to allow the
637 * calling function to make decisions appropriate for the show command
638 * that is being parsed.
639 *
640 * The show commands are generally of the form:
d62a17ae 641 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
642 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
7eeee51e
DS
643 *
644 * Since we use argv_find if the show command in particular doesn't have:
645 * [ip]
18c57037 646 * [<view|vrf> VIEWVRFNAME]
375a2e67 647 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
7eeee51e
DS
648 * The command parsing should still be ok.
649 *
650 * vty -> The vty for the command so we can output some useful data in
651 * the event of a parse error in the vrf.
652 * argv -> The command tokens
653 * argc -> How many command tokens we have
d62a17ae 654 * idx -> The current place in the command, generally should be 0 for this
655 * function
7eeee51e
DS
656 * afi -> The parsed afi if it was included in the show command, returned here
657 * safi -> The parsed safi if it was included in the show command, returned here
f212a857 658 * bgp -> Pointer to the bgp data structure we need to fill in.
52e5b8c4 659 * use_json -> json is configured or not
7eeee51e
DS
660 *
661 * The function returns the correct location in the parse tree for the
662 * last token found.
0e37c258
DS
663 *
664 * Returns 0 for failure to parse correctly, else the idx position of where
665 * it found the last token.
7eeee51e 666 */
d62a17ae 667int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
668 struct cmd_token **argv, int argc,
669 int *idx, afi_t *afi, safi_t *safi,
9f049418 670 struct bgp **bgp, bool use_json)
d62a17ae 671{
672 char *vrf_name = NULL;
673
674 assert(afi);
675 assert(safi);
676 assert(bgp);
677
678 if (argv_find(argv, argc, "ip", idx))
679 *afi = AFI_IP;
680
9a8bdf1c 681 if (argv_find(argv, argc, "view", idx))
d62a17ae 682 vrf_name = argv[*idx + 1]->arg;
9a8bdf1c
PG
683 else if (argv_find(argv, argc, "vrf", idx)) {
684 vrf_name = argv[*idx + 1]->arg;
685 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
686 vrf_name = NULL;
687 }
688 if (vrf_name) {
d62a17ae 689 if (strmatch(vrf_name, "all"))
690 *bgp = NULL;
691 else {
692 *bgp = bgp_lookup_by_name(vrf_name);
693 if (!*bgp) {
52e5b8c4
SP
694 if (use_json) {
695 json_object *json = NULL;
696 json = json_object_new_object();
697 json_object_string_add(
698 json, "warning",
699 "View/Vrf is unknown");
75eeda93 700 vty_json(vty, json);
52e5b8c4 701 }
ca61fd25
DS
702 else
703 vty_out(vty, "View/Vrf %s is unknown\n",
704 vrf_name);
d62a17ae 705 *idx = 0;
706 return 0;
707 }
708 }
709 } else {
710 *bgp = bgp_get_default();
711 if (!*bgp) {
52e5b8c4
SP
712 if (use_json) {
713 json_object *json = NULL;
714 json = json_object_new_object();
715 json_object_string_add(
716 json, "warning",
717 "Default BGP instance not found");
75eeda93 718 vty_json(vty, json);
52e5b8c4 719 }
ca61fd25
DS
720 else
721 vty_out(vty,
722 "Default BGP instance not found\n");
d62a17ae 723 *idx = 0;
724 return 0;
725 }
726 }
727
728 if (argv_find_and_parse_afi(argv, argc, idx, afi))
729 argv_find_and_parse_safi(argv, argc, idx, safi);
730
731 *idx += 1;
732 return *idx;
733}
734
28c6e247 735static bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
d62a17ae 736{
737 struct interface *ifp = NULL;
4122b697
DA
738 struct listnode *node;
739 struct bgp_listener *listener;
740 union sockunion all_su;
d62a17ae 741
4122b697 742 if (su->sa.sa_family == AF_INET) {
3d2a2725 743 (void)str2sockunion("0.0.0.0", &all_su);
d62a17ae 744 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
4122b697 745 } else if (su->sa.sa_family == AF_INET6) {
3d2a2725 746 (void)str2sockunion("::", &all_su);
d62a17ae 747 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
748 su->sin6.sin6_scope_id,
749 bgp->vrf_id);
4122b697 750 }
d62a17ae 751
4122b697
DA
752 if (ifp) {
753 for (ALL_LIST_ELEMENTS_RO(bm->listen_sockets, node, listener)) {
754 if (sockunion_family(su) !=
755 sockunion_family(&listener->su))
756 continue;
757
758 /* If 0.0.0.0/:: is a listener, then treat as self and
759 * reject.
760 */
761 if (!sockunion_cmp(&listener->su, su) ||
762 !sockunion_cmp(&listener->su, &all_su))
763 return true;
764 }
765 }
d62a17ae 766
3dc339cd 767 return false;
718e3744 768}
769
28c6e247
IR
770/* Utility function for looking up peer from VTY. */
771/* This is used only for configuration, so disallow if attempted on
772 * a dynamic neighbor.
773 */
774static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
775{
776 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
777 int ret;
778 union sockunion su;
779 struct peer *peer;
780
781 if (!bgp) {
782 return NULL;
783 }
784
785 ret = str2sockunion(ip_str, &su);
786 if (ret < 0) {
787 peer = peer_lookup_by_conf_if(bgp, ip_str);
788 if (!peer) {
789 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
790 == NULL) {
791 vty_out(vty,
792 "%% Malformed address or name: %s\n",
793 ip_str);
794 return NULL;
795 }
796 }
797 } else {
798 peer = peer_lookup(bgp, &su);
799 if (!peer) {
800 vty_out(vty,
801 "%% Specify remote-as or peer-group commands first\n");
802 return NULL;
803 }
804 if (peer_dynamic_neighbor(peer)) {
805 vty_out(vty,
806 "%% Operation not allowed on a dynamic neighbor\n");
807 return NULL;
808 }
809 }
810 return peer;
811}
812
718e3744 813/* Utility function for looking up peer or peer group. */
f14e6fdb
DS
814/* This is used only for configuration, so disallow if attempted on
815 * a dynamic neighbor.
816 */
d62a17ae 817struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
818{
819 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
820 int ret;
821 union sockunion su;
822 struct peer *peer = NULL;
823 struct peer_group *group = NULL;
824
825 if (!bgp) {
826 return NULL;
827 }
828
829 ret = str2sockunion(peer_str, &su);
830 if (ret == 0) {
831 /* IP address, locate peer. */
832 peer = peer_lookup(bgp, &su);
833 } else {
834 /* Not IP, could match either peer configured on interface or a
835 * group. */
836 peer = peer_lookup_by_conf_if(bgp, peer_str);
837 if (!peer)
838 group = peer_group_lookup(bgp, peer_str);
839 }
840
841 if (peer) {
842 if (peer_dynamic_neighbor(peer)) {
3b56a646
DA
843 zlog_warn(
844 "%pBP: Operation not allowed on a dynamic neighbor",
845 peer);
d62a17ae 846 vty_out(vty,
847 "%% Operation not allowed on a dynamic neighbor\n");
848 return NULL;
849 }
850
851 return peer;
852 }
853
854 if (group)
855 return group->conf;
856
3b56a646
DA
857 zlog_warn("Specify remote-as or peer-group commands first before: %s",
858 vty->buf);
d62a17ae 859 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
860
861 return NULL;
862}
863
4b7e23e9 864int bgp_vty_return(struct vty *vty, enum bgp_create_error_code ret)
d62a17ae 865{
866 const char *str = NULL;
867
868 switch (ret) {
4b7e23e9
DS
869 case BGP_SUCCESS:
870 case BGP_CREATED:
871 case BGP_GR_NO_OPERATION:
872 break;
d62a17ae 873 case BGP_ERR_INVALID_VALUE:
874 str = "Invalid value";
875 break;
876 case BGP_ERR_INVALID_FLAG:
877 str = "Invalid flag";
878 break;
879 case BGP_ERR_PEER_GROUP_SHUTDOWN:
880 str = "Peer-group has been shutdown. Activate the peer-group first";
881 break;
882 case BGP_ERR_PEER_FLAG_CONFLICT:
883 str = "Can't set override-capability and strict-capability-match at the same time";
884 break;
885 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
886 str = "Specify remote-as or peer-group remote AS first";
887 break;
888 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
889 str = "Cannot change the peer-group. Deconfigure first";
890 break;
891 case BGP_ERR_PEER_GROUP_MISMATCH:
892 str = "Peer is not a member of this peer-group";
893 break;
894 case BGP_ERR_PEER_FILTER_CONFLICT:
895 str = "Prefix/distribute list can not co-exist";
896 break;
897 case BGP_ERR_NOT_INTERNAL_PEER:
898 str = "Invalid command. Not an internal neighbor";
899 break;
900 case BGP_ERR_REMOVE_PRIVATE_AS:
901 str = "remove-private-AS cannot be configured for IBGP peers";
902 break;
d62a17ae 903 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
904 str = "Cannot have local-as same as BGP AS number";
905 break;
906 case BGP_ERR_TCPSIG_FAILED:
907 str = "Error while applying TCP-Sig to session(s)";
908 break;
909 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
910 str = "ebgp-multihop and ttl-security cannot be configured together";
911 break;
912 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
913 str = "ttl-security only allowed for EBGP peers";
914 break;
915 case BGP_ERR_AS_OVERRIDE:
916 str = "as-override cannot be configured for IBGP peers";
917 break;
918 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
919 str = "Invalid limit for number of dynamic neighbors";
920 break;
921 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
922 str = "Dynamic neighbor listen range already exists";
923 break;
924 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
925 str = "Operation not allowed on a dynamic neighbor";
926 break;
927 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
928 str = "Operation not allowed on a directly connected neighbor";
929 break;
930 case BGP_ERR_PEER_SAFI_CONFLICT:
a59803d0 931 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
055679e9 932 break;
933 case BGP_ERR_GR_INVALID_CMD:
934 str = "The Graceful Restart command used is not valid at this moment.";
935 break;
936 case BGP_ERR_GR_OPERATION_FAILED:
937 str = "The Graceful Restart Operation failed due to an err.";
938 break;
6dcea6fe
DS
939 case BGP_ERR_PEER_GROUP_MEMBER:
940 str = "Peer-group member cannot override remote-as of peer-group.";
941 break;
942 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
943 str = "Peer-group members must be all internal or all external.";
944 break;
4b7e23e9
DS
945 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_NOT_FOUND:
946 str = "Range specified cannot be deleted because it is not part of current config.";
947 break;
948 case BGP_ERR_INSTANCE_MISMATCH:
949 str = "Instance specified does not match the current instance.";
950 break;
951 case BGP_ERR_NO_INTERFACE_CONFIG:
952 str = "Interface specified is not being used for interface based peer.";
953 break;
954 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
955 str = "No configuration already specified for soft reconfiguration.";
956 break;
957 case BGP_ERR_AS_MISMATCH:
958 str = "BGP is already running.";
959 break;
960 case BGP_ERR_AF_UNCONFIGURED:
961 str = "AFI/SAFI specified is not currently configured.";
962 break;
4b7e23e9
DS
963 case BGP_ERR_INVALID_AS:
964 str = "Confederation AS specified is the same AS as our AS.";
965 break;
d864dd9e
EB
966 case BGP_ERR_INVALID_ROLE_NAME:
967 str = "Invalid role name";
968 break;
969 case BGP_ERR_INVALID_INTERNAL_ROLE:
8f2d6021 970 str = "External roles can be set only on eBGP session";
d864dd9e 971 break;
d62a17ae 972 }
973 if (str) {
974 vty_out(vty, "%% %s\n", str);
975 return CMD_WARNING_CONFIG_FAILED;
976 }
977 return CMD_SUCCESS;
718e3744 978}
979
7aafcaca 980/* BGP clear sort. */
d62a17ae 981enum clear_sort {
982 clear_all,
983 clear_peer,
984 clear_group,
985 clear_external,
986 clear_as
7aafcaca
DS
987};
988
1ca2fd11
IR
989static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
990 safi_t safi, int error)
d62a17ae 991{
992 switch (error) {
993 case BGP_ERR_AF_UNCONFIGURED:
a486300b
PG
994 if (vty)
995 vty_out(vty,
996 "%% BGP: Enable %s address family for the neighbor %s\n",
997 get_afi_safi_str(afi, safi, false), peer->host);
998 else
999 zlog_warn(
1af6e82b 1000 "%% BGP: Enable %s address family for the neighbor %s",
a486300b 1001 get_afi_safi_str(afi, safi, false), peer->host);
d62a17ae 1002 break;
1003 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
a486300b
PG
1004 if (vty)
1005 vty_out(vty,
1006 "%% BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
1007 peer->host);
1008 else
1009 zlog_warn(
1af6e82b 1010 "%% BGP: Inbound soft reconfig for %s not possible as it has neither refresh capability, nor inbound soft reconfig",
a486300b 1011 peer->host);
d62a17ae 1012 break;
1013 default:
1014 break;
1015 }
7aafcaca
DS
1016}
1017
dc912615 1018static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
c368171c 1019 struct listnode **nnode, enum bgp_clear_type stype)
dc912615
DS
1020{
1021 int ret = 0;
2adac256 1022 struct peer_af *paf;
dc912615
DS
1023
1024 /* if afi/.safi not specified, spin thru all of them */
1025 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
1026 afi_t tmp_afi;
1027 safi_t tmp_safi;
0e5cdd59
DS
1028 enum bgp_af_index index;
1029
1030 for (index = BGP_AF_START; index < BGP_AF_MAX; index++) {
1031 paf = peer->peer_af_array[index];
1032 if (!paf)
1033 continue;
dc912615 1034
2adac256
DA
1035 if (paf && paf->subgroup)
1036 SET_FLAG(paf->subgroup->sflags,
1037 SUBGRP_STATUS_FORCE_UPDATES);
1038
0e5cdd59
DS
1039 tmp_afi = paf->afi;
1040 tmp_safi = paf->safi;
dc912615
DS
1041 if (!peer->afc[tmp_afi][tmp_safi])
1042 continue;
1043
1044 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 1045 ret = peer_clear(peer, nnode);
dc912615
DS
1046 else
1047 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
1048 stype);
1049 }
1050 /* if afi specified and safi not, spin thru safis on this afi */
1051 } else if (safi == SAFI_UNSPEC) {
1052 safi_t tmp_safi;
1053
1054 for (tmp_safi = SAFI_UNICAST;
1055 tmp_safi < SAFI_MAX; tmp_safi++) {
1056 if (!peer->afc[afi][tmp_safi])
1057 continue;
1058
2adac256
DA
1059 paf = peer_af_find(peer, afi, tmp_safi);
1060 if (paf && paf->subgroup)
1061 SET_FLAG(paf->subgroup->sflags,
1062 SUBGRP_STATUS_FORCE_UPDATES);
1063
dc912615 1064 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 1065 ret = peer_clear(peer, nnode);
dc912615
DS
1066 else
1067 ret = peer_clear_soft(peer, afi,
1068 tmp_safi, stype);
1069 }
1070 /* both afi/safi specified, let the caller know if not defined */
1071 } else {
1072 if (!peer->afc[afi][safi])
1073 return 1;
1074
2adac256
DA
1075 paf = peer_af_find(peer, afi, safi);
1076 if (paf && paf->subgroup)
1077 SET_FLAG(paf->subgroup->sflags,
1078 SUBGRP_STATUS_FORCE_UPDATES);
1079
dc912615 1080 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 1081 ret = peer_clear(peer, nnode);
dc912615
DS
1082 else
1083 ret = peer_clear_soft(peer, afi, safi, stype);
1084 }
1085
1086 return ret;
1087}
1088
7aafcaca 1089/* `clear ip bgp' functions. */
1ca2fd11 1090static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
d62a17ae 1091 enum clear_sort sort, enum bgp_clear_type stype,
1ca2fd11 1092 const char *arg)
d62a17ae 1093{
dc912615 1094 int ret = 0;
3ae8bfa5 1095 bool found = false;
d62a17ae 1096 struct peer *peer;
dc95985f 1097
1098 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
d62a17ae 1099
1100 /* Clear all neighbors. */
1101 /*
1102 * Pass along pointer to next node to peer_clear() when walking all
3ae8bfa5
PM
1103 * nodes on the BGP instance as that may get freed if it is a
1104 * doppelganger
d62a17ae 1105 */
1106 if (sort == clear_all) {
1107 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dc95985f 1108
1109 bgp_peer_gr_flags_update(peer);
1110
36235319 1111 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
dc95985f 1112 gr_router_detected = true;
1113
c368171c 1114 ret = bgp_peer_clear(peer, afi, safi, &nnode,
dc912615 1115 stype);
d62a17ae 1116
1117 if (ret < 0)
1ca2fd11 1118 bgp_clear_vty_error(vty, peer, afi, safi, ret);
dc95985f 1119 }
1120
36235319
QY
1121 if (gr_router_detected
1122 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1123 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1124 } else if (!gr_router_detected
1125 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1126 bgp_zebra_send_capabilities(bgp, true);
04b6bdc0 1127 }
d62a17ae 1128
1129 /* This is to apply read-only mode on this clear. */
1130 if (stype == BGP_CLEAR_SOFT_NONE)
1131 bgp->update_delay_over = 0;
1132
1133 return CMD_SUCCESS;
7aafcaca
DS
1134 }
1135
3ae8bfa5 1136 /* Clear specified neighbor. */
d62a17ae 1137 if (sort == clear_peer) {
1138 union sockunion su;
d62a17ae 1139
1140 /* Make sockunion for lookup. */
1141 ret = str2sockunion(arg, &su);
1142 if (ret < 0) {
1143 peer = peer_lookup_by_conf_if(bgp, arg);
1144 if (!peer) {
1145 peer = peer_lookup_by_hostname(bgp, arg);
1146 if (!peer) {
1ca2fd11
IR
1147 vty_out(vty,
1148 "Malformed address or name: %s\n",
d62a17ae 1149 arg);
1150 return CMD_WARNING;
1151 }
1152 }
1153 } else {
1154 peer = peer_lookup(bgp, &su);
1155 if (!peer) {
1ca2fd11 1156 vty_out(vty,
664b6f18 1157 "%% BGP: Unknown neighbor - \"%s\"\n",
1ca2fd11 1158 arg);
d62a17ae 1159 return CMD_WARNING;
1160 }
1161 }
7aafcaca 1162
dc95985f 1163 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1164 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1165
dc912615
DS
1166 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1167
1168 /* if afi/safi not defined for this peer, let caller know */
1169 if (ret == 1)
3ae8bfa5 1170 ret = BGP_ERR_AF_UNCONFIGURED;
7aafcaca 1171
d62a17ae 1172 if (ret < 0)
1ca2fd11 1173 bgp_clear_vty_error(vty, peer, afi, safi, ret);
7aafcaca 1174
d62a17ae 1175 return CMD_SUCCESS;
7aafcaca 1176 }
7aafcaca 1177
3ae8bfa5 1178 /* Clear all neighbors belonging to a specific peer-group. */
d62a17ae 1179 if (sort == clear_group) {
1180 struct peer_group *group;
7aafcaca 1181
d62a17ae 1182 group = peer_group_lookup(bgp, arg);
1183 if (!group) {
664b6f18 1184 vty_out(vty, "%% BGP: No such peer-group %s\n", arg);
d62a17ae 1185 return CMD_WARNING;
1186 }
1187
1188 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
c368171c 1189 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 1190
d62a17ae 1191 if (ret < 0)
1ca2fd11 1192 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
1193 else
1194 found = true;
d62a17ae 1195 }
3ae8bfa5
PM
1196
1197 if (!found)
1ca2fd11 1198 vty_out(vty,
664b6f18 1199 "%% BGP: No %s peer belonging to peer-group %s is configured\n",
5cb5f4d0 1200 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1201
d62a17ae 1202 return CMD_SUCCESS;
7aafcaca 1203 }
7aafcaca 1204
3ae8bfa5 1205 /* Clear all external (eBGP) neighbors. */
d62a17ae 1206 if (sort == clear_external) {
1207 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1208 if (peer->sort == BGP_PEER_IBGP)
1209 continue;
7aafcaca 1210
dc95985f 1211 bgp_peer_gr_flags_update(peer);
1212
36235319 1213 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 1214 gr_router_detected = true;
dc95985f 1215
c368171c 1216 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 1217
d62a17ae 1218 if (ret < 0)
1ca2fd11 1219 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
1220 else
1221 found = true;
d62a17ae 1222 }
3ae8bfa5 1223
36235319
QY
1224 if (gr_router_detected
1225 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1226 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1227 } else if (!gr_router_detected
1228 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1229 bgp_zebra_send_capabilities(bgp, true);
1230 }
1231
3ae8bfa5 1232 if (!found)
1ca2fd11 1233 vty_out(vty,
664b6f18 1234 "%% BGP: No external %s peer is configured\n",
1ca2fd11 1235 get_afi_safi_str(afi, safi, false));
3ae8bfa5 1236
d62a17ae 1237 return CMD_SUCCESS;
1238 }
1239
3ae8bfa5 1240 /* Clear all neighbors belonging to a specific AS. */
d62a17ae 1241 if (sort == clear_as) {
8079a413
PG
1242 as_t as;
1243
1244 if (!asn_str2asn(arg, &as)) {
1245 vty_out(vty, "%% BGP: No such AS %s\n", arg);
1246 return CMD_WARNING;
1247 }
d62a17ae 1248
1249 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1250 if (peer->as != as)
1251 continue;
1252
dc95985f 1253 bgp_peer_gr_flags_update(peer);
1254
36235319 1255 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 1256 gr_router_detected = true;
dc95985f 1257
c368171c 1258 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
d62a17ae 1259
1260 if (ret < 0)
1ca2fd11 1261 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
1262 else
1263 found = true;
d62a17ae 1264 }
3ae8bfa5 1265
36235319
QY
1266 if (gr_router_detected
1267 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1268 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1269 } else if (!gr_router_detected
1270 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1271 bgp_zebra_send_capabilities(bgp, true);
1272 }
1273
3ae8bfa5 1274 if (!found)
1ca2fd11 1275 vty_out(vty,
664b6f18 1276 "%% BGP: No %s peer is configured with AS %s\n",
1ca2fd11 1277 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1278
d62a17ae 1279 return CMD_SUCCESS;
1280 }
1281
1282 return CMD_SUCCESS;
1283}
1284
1ca2fd11
IR
1285static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
1286 safi_t safi, enum clear_sort sort,
1287 enum bgp_clear_type stype, const char *arg)
d62a17ae 1288{
1289 struct bgp *bgp;
1290
1291 /* BGP structure lookup. */
1292 if (name) {
1293 bgp = bgp_lookup_by_name(name);
1294 if (bgp == NULL) {
1ca2fd11 1295 vty_out(vty, "Can't find BGP instance %s\n", name);
d62a17ae 1296 return CMD_WARNING;
1297 }
1298 } else {
1299 bgp = bgp_get_default();
1300 if (bgp == NULL) {
1ca2fd11 1301 vty_out(vty, "No BGP process is configured\n");
d62a17ae 1302 return CMD_WARNING;
1303 }
1304 }
1305
1ca2fd11 1306 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
7aafcaca
DS
1307}
1308
1309/* clear soft inbound */
1ca2fd11 1310static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
7aafcaca 1311{
99b3ebd3
NS
1312 afi_t afi;
1313 safi_t safi;
1314
1ca2fd11
IR
1315 FOREACH_AFI_SAFI (afi, safi)
1316 bgp_clear_vty(vty, name, afi, safi, clear_all,
1317 BGP_CLEAR_SOFT_IN, NULL);
7aafcaca
DS
1318}
1319
1320/* clear soft outbound */
1ca2fd11 1321static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
7aafcaca 1322{
99b3ebd3
NS
1323 afi_t afi;
1324 safi_t safi;
1325
1ca2fd11
IR
1326 FOREACH_AFI_SAFI (afi, safi)
1327 bgp_clear_vty(vty, name, afi, safi, clear_all,
1328 BGP_CLEAR_SOFT_OUT, NULL);
7aafcaca
DS
1329}
1330
1331
a486300b
PG
1332void bgp_clear_soft_in(struct bgp *bgp, afi_t afi, safi_t safi)
1333{
1334 bgp_clear(NULL, bgp, afi, safi, clear_all, BGP_CLEAR_SOFT_IN, NULL);
1335}
1336
4f770cf1
DA
1337static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
1338 uint64_t flag, int set)
1339{
1340 int ret;
1341 struct peer *peer;
1342
1343 peer = peer_and_group_lookup_vty(vty, ip_str);
1344 if (!peer)
1345 return CMD_WARNING_CONFIG_FAILED;
1346
1347 /*
1348 * If 'neighbor <interface>', then this is for directly connected peers,
1349 * we should not accept disable-connected-check.
1350 */
1351 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
1352 vty_out(vty,
1353 "%s is directly connected peer, cannot accept disable-connected-check\n",
1354 ip_str);
1355 return CMD_WARNING_CONFIG_FAILED;
1356 }
1357
1358 if (!set && flag == PEER_FLAG_SHUTDOWN)
1359 peer_tx_shutdown_message_unset(peer);
1360
1361 if (set)
1362 ret = peer_flag_set(peer, flag);
1363 else
1364 ret = peer_flag_unset(peer, flag);
1365
1366 return bgp_vty_return(vty, ret);
1367}
1368
1369static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint64_t flag)
1370{
1371 return peer_flag_modify_vty(vty, ip_str, flag, 1);
1372}
1373
1374static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
1375 uint64_t flag)
1376{
1377 return peer_flag_modify_vty(vty, ip_str, flag, 0);
1378}
1379
2e4c2296 1380#include "bgpd/bgp_vty_clippy.c"
f787d7a0 1381
8029b216
AK
1382DEFUN_HIDDEN (bgp_local_mac,
1383 bgp_local_mac_cmd,
093e3f23 1384 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
8029b216
AK
1385 BGP_STR
1386 "Local MAC config\n"
1387 "VxLAN Network Identifier\n"
1388 "VNI number\n"
1389 "local mac\n"
1390 "mac address\n"
1391 "mac-mobility sequence\n"
1392 "seq number\n")
1393{
1394 int rv;
1395 vni_t vni;
1396 struct ethaddr mac;
1397 struct ipaddr ip;
1398 uint32_t seq;
1399 struct bgp *bgp;
1400
1401 vni = strtoul(argv[3]->arg, NULL, 10);
1402 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1403 vty_out(vty, "%% Malformed MAC address\n");
1404 return CMD_WARNING;
1405 }
1406 memset(&ip, 0, sizeof(ip));
1407 seq = strtoul(argv[7]->arg, NULL, 10);
1408
1409 bgp = bgp_get_default();
1410 if (!bgp) {
1411 vty_out(vty, "Default BGP instance is not there\n");
1412 return CMD_WARNING;
1413 }
1414
b5e140c8
AK
1415 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1416 zero_esi);
8029b216
AK
1417 if (rv < 0) {
1418 vty_out(vty, "Internal error\n");
1419 return CMD_WARNING;
1420 }
1421
1422 return CMD_SUCCESS;
1423}
1424
1425DEFUN_HIDDEN (no_bgp_local_mac,
1426 no_bgp_local_mac_cmd,
093e3f23 1427 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
8029b216
AK
1428 NO_STR
1429 BGP_STR
1430 "Local MAC config\n"
1431 "VxLAN Network Identifier\n"
1432 "VNI number\n"
1433 "local mac\n"
1434 "mac address\n")
1435{
1436 int rv;
1437 vni_t vni;
1438 struct ethaddr mac;
1439 struct ipaddr ip;
1440 struct bgp *bgp;
1441
1442 vni = strtoul(argv[4]->arg, NULL, 10);
1443 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1444 vty_out(vty, "%% Malformed MAC address\n");
1445 return CMD_WARNING;
1446 }
1447 memset(&ip, 0, sizeof(ip));
1448
1449 bgp = bgp_get_default();
1450 if (!bgp) {
1451 vty_out(vty, "Default BGP instance is not there\n");
1452 return CMD_WARNING;
1453 }
1454
ec0ab544 1455 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
8029b216
AK
1456 if (rv < 0) {
1457 vty_out(vty, "Internal error\n");
1458 return CMD_WARNING;
1459 }
1460
1461 return CMD_SUCCESS;
1462}
1463
718e3744 1464DEFUN (no_synchronization,
1465 no_synchronization_cmd,
1466 "no synchronization",
1467 NO_STR
1468 "Perform IGP synchronization\n")
1469{
d62a17ae 1470 return CMD_SUCCESS;
718e3744 1471}
1472
1473DEFUN (no_auto_summary,
1474 no_auto_summary_cmd,
1475 "no auto-summary",
1476 NO_STR
1477 "Enable automatic network number summarization\n")
1478{
d62a17ae 1479 return CMD_SUCCESS;
718e3744 1480}
3d515fd9 1481
718e3744 1482/* "router bgp" commands. */
1ca2fd11
IR
1483DEFUN_NOSH (router_bgp,
1484 router_bgp_cmd,
e55b0883 1485 "router bgp [ASNUM$instasn [<view|vrf> VIEWVRFNAME] [as-notation <dot|dot+|plain>]]",
1ca2fd11
IR
1486 ROUTER_STR
1487 BGP_STR
1488 AS_STR
e55b0883
PG
1489 BGP_INSTANCE_HELP_STR
1490 "Force the AS notation output\n"
1491 "use 'AA.BB' format for AS 4 byte values\n"
1492 "use 'AA.BB' format for all AS values\n"
1493 "use plain format for all AS values\n")
718e3744 1494{
d62a17ae 1495 int idx_asn = 2;
1496 int idx_view_vrf = 3;
1497 int idx_vrf = 4;
1ca2fd11 1498 int is_new_bgp = 0;
e55b0883
PG
1499 int idx_asnotation = 3;
1500 int idx_asnotation_kind = 4;
1501 enum asnotation_mode asnotation = ASNOTATION_UNDEFINED;
1ca2fd11 1502 int ret;
d62a17ae 1503 as_t as;
1504 struct bgp *bgp;
1505 const char *name = NULL;
1506 enum bgp_instance_type inst_type;
1507
1508 // "router bgp" without an ASN
1509 if (argc == 2) {
1510 // Pending: Make VRF option available for ASN less config
1abef40f 1511 bgp = bgp_get_default();
d62a17ae 1512
1abef40f 1513 if (bgp == NULL) {
d62a17ae 1514 vty_out(vty, "%% No BGP process is configured\n");
1515 return CMD_WARNING_CONFIG_FAILED;
1516 }
1517
1518 if (listcount(bm->bgp) > 1) {
996c9314 1519 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1520 return CMD_WARNING_CONFIG_FAILED;
1521 }
1522 }
1523
1524 // "router bgp X"
1525 else {
8079a413
PG
1526 if (!asn_str2asn(argv[idx_asn]->arg, &as)) {
1527 vty_out(vty, "%% BGP: No such AS %s\n",
1528 argv[idx_asn]->arg);
1529 return CMD_WARNING_CONFIG_FAILED;
1530 }
1ca2fd11 1531
cc413e2a
DA
1532 if (as == BGP_PRIVATE_AS_MAX || as == BGP_AS4_MAX)
1533 vty_out(vty, "Reserved AS used (%u|%u); AS is %u\n",
1534 BGP_PRIVATE_AS_MAX, BGP_AS4_MAX, as);
1535
d62a17ae 1536 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
d62a17ae 1537
e55b0883
PG
1538 if (argv_find(argv, argc, "VIEWVRFNAME", &idx_vrf)) {
1539 idx_view_vrf = idx_vrf - 1;
1540 if (argv[idx_view_vrf]->text) {
1541 name = argv[idx_vrf]->arg;
1542
1543 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1544 if (strmatch(name, VRF_DEFAULT_NAME))
1545 name = NULL;
1546 else
1547 inst_type =
1548 BGP_INSTANCE_TYPE_VRF;
1549 } else if (!strcmp(argv[idx_view_vrf]->text,
1550 "view"))
1551 inst_type = BGP_INSTANCE_TYPE_VIEW;
1552 }
1553 }
1554 if (argv_find(argv, argc, "as-notation", &idx_asnotation)) {
1555 idx_asnotation_kind = idx_asnotation + 1;
1556 if (strmatch(argv[idx_asnotation_kind]->text, "dot+"))
1557 asnotation = ASNOTATION_DOTPLUS;
1558 else if (strmatch(argv[idx_asnotation_kind]->text,
1559 "dot"))
1560 asnotation = ASNOTATION_DOT;
1561 else if (strmatch(argv[idx_asnotation_kind]->text,
1562 "plain"))
1563 asnotation = ASNOTATION_PLAIN;
d62a17ae 1564 }
1565
1ca2fd11
IR
1566 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1567 is_new_bgp = (bgp_lookup(as, name) == NULL);
3bd70bf8 1568
9eb11997 1569 ret = bgp_get_vty(&bgp, &as, name, inst_type,
e55b0883 1570 argv[idx_asn]->arg, asnotation);
1ca2fd11
IR
1571 switch (ret) {
1572 case BGP_ERR_AS_MISMATCH:
9eb11997
PG
1573 vty_out(vty, "BGP is already running; AS is %s\n",
1574 bgp->as_pretty);
1ca2fd11
IR
1575 return CMD_WARNING_CONFIG_FAILED;
1576 case BGP_ERR_INSTANCE_MISMATCH:
1577 vty_out(vty,
1578 "BGP instance name and AS number mismatch\n");
1579 vty_out(vty,
9eb11997
PG
1580 "BGP instance is already running; AS is %s\n",
1581 bgp->as_pretty);
1ca2fd11 1582 return CMD_WARNING_CONFIG_FAILED;
ff8a8a7a 1583 }
1ca2fd11
IR
1584
1585 /*
1586 * If we just instantiated the default instance, complete
1587 * any pending VRF-VPN leaking that was configured via
1588 * earlier "router bgp X vrf FOO" blocks.
1589 */
1590 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1591 vpn_leak_postchange_all();
1592
1593 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1594 bgp_vpn_leak_export(bgp);
1595 /* Pending: handle when user tries to change a view to vrf n vv.
1596 */
e55b0883
PG
1597 /* for pre-existing bgp instance,
1598 * - update as_pretty
1599 * - update asnotation if explicitly mentioned
1600 */
1601 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO)) {
1602 XFREE(MTYPE_BGP, bgp->as_pretty);
1603 bgp->as_pretty = XSTRDUP(MTYPE_BGP, argv[idx_asn]->arg);
1604 if (!CHECK_FLAG(bgp->config, BGP_CONFIG_ASNOTATION) &&
1605 asnotation != ASNOTATION_UNDEFINED) {
1606 SET_FLAG(bgp->config, BGP_CONFIG_ASNOTATION);
1607 bgp->asnotation = asnotation;
1608 }
1609 }
d62a17ae 1610 }
1611
1ca2fd11
IR
1612 /* unset the auto created flag as the user config is now present */
1613 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1614 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1615
1616 return CMD_SUCCESS;
718e3744 1617}
1618
718e3744 1619/* "no router bgp" commands. */
1ca2fd11
IR
1620DEFUN (no_router_bgp,
1621 no_router_bgp_cmd,
e55b0883 1622 "no router bgp [ASNUM$instasn [<view|vrf> VIEWVRFNAME] [as-notation <dot|dot+|plain>]]",
1ca2fd11
IR
1623 NO_STR
1624 ROUTER_STR
1625 BGP_STR
1626 AS_STR
e55b0883
PG
1627 BGP_INSTANCE_HELP_STR
1628 "Force the AS notation output\n"
1629 "use 'AA.BB' format for AS 4 byte values\n"
1630 "use 'AA.BB' format for all AS values\n"
1631 "use plain format for all AS values\n")
718e3744 1632{
4fd9919e 1633 int idx_asn = 3;
d62a17ae 1634 int idx_vrf = 5;
1ca2fd11 1635 as_t as;
4fd9919e 1636 struct bgp *bgp;
d62a17ae 1637 const char *name = NULL;
718e3744 1638
d62a17ae 1639 // "no router bgp" without an ASN
1640 if (argc == 3) {
1641 // Pending: Make VRF option available for ASN less config
8382083a 1642 bgp = bgp_get_default();
718e3744 1643
8382083a 1644 if (bgp == NULL) {
d62a17ae 1645 vty_out(vty, "%% No BGP process is configured\n");
1646 return CMD_WARNING_CONFIG_FAILED;
1647 }
7fb21a9f 1648
d62a17ae 1649 if (listcount(bm->bgp) > 1) {
996c9314 1650 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1651 return CMD_WARNING_CONFIG_FAILED;
1652 }
4fd9919e 1653
4fd9919e 1654 if (bgp->l3vni) {
be125e6f 1655 vty_out(vty, "%% Please unconfigure l3vni %u\n",
4fd9919e
IR
1656 bgp->l3vni);
1657 return CMD_WARNING_CONFIG_FAILED;
1658 }
d62a17ae 1659 } else {
8079a413
PG
1660 if (!asn_str2asn(argv[idx_asn]->arg, &as)) {
1661 vty_out(vty, "%% BGP: No such AS %s\n",
1662 argv[idx_asn]->arg);
1663 return CMD_WARNING_CONFIG_FAILED;
1664 }
1ca42c8d 1665 if (argc > 4) {
d62a17ae 1666 name = argv[idx_vrf]->arg;
1ca42c8d
IR
1667 if (strmatch(argv[idx_vrf - 1]->text, "vrf")
1668 && strmatch(name, VRF_DEFAULT_NAME))
1669 name = NULL;
1670 }
7fb21a9f 1671
4fd9919e
IR
1672 /* Lookup bgp structure. */
1673 bgp = bgp_lookup(as, name);
1674 if (!bgp) {
1675 vty_out(vty, "%% Can't find BGP instance\n");
1676 return CMD_WARNING_CONFIG_FAILED;
1677 }
1678
1679 if (bgp->l3vni) {
1680 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1681 bgp->l3vni);
1682 return CMD_WARNING_CONFIG_FAILED;
1683 }
1684
1685 /* Cannot delete default instance if vrf instances exist */
1686 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1687 struct listnode *node;
1688 struct bgp *tmp_bgp;
1689
1690 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1691 if (tmp_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
1692 continue;
1693 if (CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1694 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1695 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1696 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1697 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1698 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1699 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1700 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1701 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1702 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1703 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1704 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1705 (bgp == bgp_get_evpn() &&
1706 (CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1707 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST) ||
1708 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1709 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP) ||
1710 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1711 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST) ||
1712 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1713 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))) ||
f33bf7c0 1714 (hashcount(tmp_bgp->vnihash))) {
4fd9919e
IR
1715 vty_out(vty,
1716 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1717 return CMD_WARNING_CONFIG_FAILED;
1718 }
1719 }
1720 }
d62a17ae 1721 }
718e3744 1722
1ca2fd11 1723 bgp_delete(bgp);
718e3744 1724
1ca2fd11 1725 return CMD_SUCCESS;
718e3744 1726}
1727
425bd64b
PS
1728/* bgp session-dscp */
1729
1730DEFPY (bgp_session_dscp,
1731 bgp_session_dscp_cmd,
1732 "bgp session-dscp (0-63)$dscp",
1733 BGP_STR
1734 "Override default (C6) bgp TCP session DSCP value\n"
1735 "Manually configured dscp parameter\n")
1736{
1737 bm->tcp_dscp = dscp << 2;
1738
1739 return CMD_SUCCESS;
1740}
1741
1742DEFPY (no_bgp_session_dscp,
1743 no_bgp_session_dscp_cmd,
1744 "no bgp session-dscp [(0-63)]",
1745 NO_STR
1746 BGP_STR
1747 "Override default (C6) bgp TCP session DSCP value\n"
1748 "Manually configured dscp parameter\n")
1749{
1750 bm->tcp_dscp = IPTOS_PREC_INTERNETCONTROL;
1751
1752 return CMD_SUCCESS;
1753}
718e3744 1754
ff8a8a7a
CS
1755/* BGP router-id. */
1756
1ca2fd11
IR
1757DEFPY (bgp_router_id,
1758 bgp_router_id_cmd,
1759 "bgp router-id A.B.C.D",
1760 BGP_STR
1761 "Override configured router identifier\n"
1762 "Manually configured router identifier\n")
718e3744 1763{
1ca2fd11
IR
1764 VTY_DECLVAR_CONTEXT(bgp, bgp);
1765 bgp_router_id_static_set(bgp, router_id);
1766 return CMD_SUCCESS;
ff8a8a7a 1767}
718e3744 1768
1ca2fd11
IR
1769DEFPY (no_bgp_router_id,
1770 no_bgp_router_id_cmd,
1771 "no bgp router-id [A.B.C.D]",
1772 NO_STR
1773 BGP_STR
1774 "Override configured router identifier\n"
1775 "Manually configured router identifier\n")
ff8a8a7a 1776{
1ca2fd11 1777 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1778
1ca2fd11
IR
1779 if (router_id_str) {
1780 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1781 vty_out(vty, "%% BGP router-id doesn't match\n");
1782 return CMD_WARNING_CONFIG_FAILED;
1783 }
1784 }
718e3744 1785
1ca2fd11
IR
1786 router_id.s_addr = 0;
1787 bgp_router_id_static_set(bgp, router_id);
1788
1789 return CMD_SUCCESS;
ff8a8a7a 1790}
6b0655a2 1791
ed0e57e3 1792DEFPY(bgp_community_alias, bgp_community_alias_cmd,
b4ad2fae 1793 "[no$no] bgp community alias WORD$community ALIAS_NAME$alias_name",
ed0e57e3
DA
1794 NO_STR BGP_STR
1795 "Add community specific parameters\n"
1796 "Create an alias for a community\n"
1797 "Community (AA:BB or AA:BB:CC)\n"
1798 "Alias name\n")
1799{
8cfa1e78 1800 struct community_alias ca = {};
ed0e57e3
DA
1801 struct community_alias *lookup_community;
1802 struct community_alias *lookup_alias;
d13d137a
DA
1803 struct community *comm;
1804 struct lcommunity *lcomm;
1805 uint8_t invalid = 0;
ed0e57e3 1806
d13d137a
DA
1807 comm = community_str2com(community);
1808 if (!comm)
1809 invalid++;
1810 community_free(&comm);
1811
1812 lcomm = lcommunity_str2com(community);
1813 if (!lcomm)
1814 invalid++;
1815 lcommunity_free(&lcomm);
1816
1817 if (invalid > 1) {
ed0e57e3
DA
1818 vty_out(vty, "Invalid community format\n");
1819 return CMD_WARNING;
1820 }
1821
8cfa1e78
DA
1822 strlcpy(ca.community, community, sizeof(ca.community));
1823 strlcpy(ca.alias, alias_name, sizeof(ca.alias));
ed0e57e3 1824
8cfa1e78
DA
1825 lookup_community = bgp_ca_community_lookup(&ca);
1826 lookup_alias = bgp_ca_alias_lookup(&ca);
ed0e57e3
DA
1827
1828 if (no) {
8cfa1e78
DA
1829 bgp_ca_alias_delete(&ca);
1830 bgp_ca_community_delete(&ca);
ed0e57e3
DA
1831 } else {
1832 if (lookup_alias) {
1833 /* Lookup if community hash table has an item
1834 * with the same alias name.
1835 */
8cfa1e78
DA
1836 strlcpy(ca.community, lookup_alias->community,
1837 sizeof(ca.community));
1838 if (bgp_ca_community_lookup(&ca)) {
ed0e57e3
DA
1839 vty_out(vty,
1840 "community (%s) already has this alias (%s)\n",
1841 lookup_alias->community,
1842 lookup_alias->alias);
1843 return CMD_WARNING;
1844 }
8cfa1e78 1845 bgp_ca_alias_delete(&ca);
ed0e57e3
DA
1846 }
1847
8cfa1e78
DA
1848 if (lookup_community) {
1849 /* Lookup if alias hash table has an item
1850 * with the same community.
1851 */
1852 strlcpy(ca.alias, lookup_community->alias,
1853 sizeof(ca.alias));
1854 if (bgp_ca_alias_lookup(&ca)) {
1855 vty_out(vty,
1856 "alias (%s) already has this community (%s)\n",
1857 lookup_community->alias,
1858 lookup_community->community);
1859 return CMD_WARNING;
1860 }
1861 bgp_ca_community_delete(&ca);
1862 }
ed0e57e3 1863
8cfa1e78
DA
1864 bgp_ca_alias_insert(&ca);
1865 bgp_ca_community_insert(&ca);
ed0e57e3
DA
1866 }
1867
1868 return CMD_SUCCESS;
1869}
1870
9acb67cb
DS
1871DEFPY (bgp_global_suppress_fib_pending,
1872 bgp_global_suppress_fib_pending_cmd,
1873 "[no] bgp suppress-fib-pending",
1874 NO_STR
1875 BGP_STR
1876 "Advertise only routes that are programmed in kernel to peers globally\n")
1877{
1878 bm_wait_for_fib_set(!no);
1879
1880 return CMD_SUCCESS;
1881}
1882
c208c586
S
1883DEFPY (bgp_suppress_fib_pending,
1884 bgp_suppress_fib_pending_cmd,
1885 "[no] bgp suppress-fib-pending",
1886 NO_STR
1887 BGP_STR
1888 "Advertise only routes that are programmed in kernel to peers\n")
1889{
1890 VTY_DECLVAR_CONTEXT(bgp, bgp);
1891
1892 bgp_suppress_fib_pending_set(bgp, !no);
1893 return CMD_SUCCESS;
1894}
1895
718e3744 1896/* BGP Cluster ID. */
1ca2fd11
IR
1897DEFUN (bgp_cluster_id,
1898 bgp_cluster_id_cmd,
1899 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1900 BGP_STR
1901 "Configure Route-Reflector Cluster-id\n"
1902 "Route-Reflector Cluster-id in IP address format\n"
1903 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1904{
1ca2fd11 1905 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1906 int idx_ipv4 = 2;
1ca2fd11
IR
1907 int ret;
1908 struct in_addr cluster;
1909
1910 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1911 if (!ret) {
1912 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1913 return CMD_WARNING_CONFIG_FAILED;
1914 }
718e3744 1915
1ca2fd11
IR
1916 bgp_cluster_id_set(bgp, &cluster);
1917 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1918
1ca2fd11 1919 return CMD_SUCCESS;
718e3744 1920}
1921
1ca2fd11
IR
1922DEFUN (no_bgp_cluster_id,
1923 no_bgp_cluster_id_cmd,
1924 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1925 NO_STR
1926 BGP_STR
1927 "Configure Route-Reflector Cluster-id\n"
1928 "Route-Reflector Cluster-id in IP address format\n"
1929 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1930{
1ca2fd11
IR
1931 VTY_DECLVAR_CONTEXT(bgp, bgp);
1932 bgp_cluster_id_unset(bgp);
1933 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1934
1ca2fd11 1935 return CMD_SUCCESS;
718e3744 1936}
1937
c163f297
DS
1938DEFPY (bgp_norib,
1939 bgp_norib_cmd,
1940 "bgp no-rib",
1941 BGP_STR
1942 "Disable BGP route installation to RIB (Zebra)\n")
1943{
1944 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1945 vty_out(vty,
1946 "%% No-RIB option is already set, nothing to do here.\n");
1947 return CMD_SUCCESS;
1948 }
1949
1950 bgp_option_norib_set_runtime();
1951
1952 return CMD_SUCCESS;
1953}
1954
1955DEFPY (no_bgp_norib,
1956 no_bgp_norib_cmd,
1957 "no bgp no-rib",
1958 NO_STR
1959 BGP_STR
1960 "Disable BGP route installation to RIB (Zebra)\n")
1961{
1962 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1963 vty_out(vty,
1964 "%% No-RIB option is not set, nothing to do here.\n");
1965 return CMD_SUCCESS;
1966 }
1967
1968 bgp_option_norib_unset_runtime();
1969
1970 return CMD_SUCCESS;
1971}
1972
e46723a5
DS
1973DEFPY (no_bgp_send_extra_data,
1974 no_bgp_send_extra_data_cmd,
1975 "[no] bgp send-extra-data zebra",
1976 NO_STR
1977 BGP_STR
1978 "Extra data to Zebra for display/use\n"
1979 "To zebra\n")
1980{
ec0acb80
DA
1981 if (no)
1982 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1983 else
1984 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
e46723a5
DS
1985
1986 return CMD_SUCCESS;
1987}
1988
1ca2fd11
IR
1989DEFUN (bgp_confederation_identifier,
1990 bgp_confederation_identifier_cmd,
8079a413 1991 "bgp confederation identifier ASNUM",
e9273987 1992 BGP_STR
1ca2fd11 1993 "AS confederation parameters\n"
8079a413 1994 AS_STR
1ca2fd11 1995 "Set routing domain confederation AS\n")
718e3744 1996{
1ca2fd11 1997 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1998 int idx_number = 3;
1ca2fd11 1999 as_t as;
718e3744 2000
8079a413
PG
2001 if (!asn_str2asn(argv[idx_number]->arg, &as)) {
2002 vty_out(vty, "%% BGP: No such AS %s\n", argv[idx_number]->arg);
2003 return CMD_WARNING_CONFIG_FAILED;
2004 }
718e3744 2005
7e14d0fa 2006 bgp_confederation_id_set(bgp, as, argv[idx_number]->arg);
718e3744 2007
1ca2fd11 2008 return CMD_SUCCESS;
718e3744 2009}
2010
1ca2fd11
IR
2011DEFUN (no_bgp_confederation_identifier,
2012 no_bgp_confederation_identifier_cmd,
8079a413 2013 "no bgp confederation identifier [ASNUM]",
1ca2fd11 2014 NO_STR
e9273987 2015 BGP_STR
1ca2fd11 2016 "AS confederation parameters\n"
8079a413 2017 AS_STR
1ca2fd11 2018 "Set routing domain confederation AS\n")
ff8a8a7a 2019{
1ca2fd11
IR
2020 VTY_DECLVAR_CONTEXT(bgp, bgp);
2021 bgp_confederation_id_unset(bgp);
2022
2023 return CMD_SUCCESS;
ff8a8a7a
CS
2024}
2025
1ca2fd11
IR
2026DEFUN (bgp_confederation_peers,
2027 bgp_confederation_peers_cmd,
8079a413 2028 "bgp confederation peers ASNUM...",
e9273987 2029 BGP_STR
1ca2fd11
IR
2030 "AS confederation parameters\n"
2031 "Peer ASs in BGP confederation\n"
2032 AS_STR)
718e3744 2033{
1ca2fd11 2034 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 2035 int idx_asn = 3;
1ca2fd11 2036 as_t as;
d62a17ae 2037 int i;
718e3744 2038
1ca2fd11 2039 for (i = idx_asn; i < argc; i++) {
8079a413
PG
2040 if (!asn_str2asn(argv[i]->arg, &as)) {
2041 vty_out(vty, "%% Invalid confed peer AS value: %s\n",
2042 argv[i]->arg);
2043 continue;
2044 }
2045
7e14d0fa 2046 bgp_confederation_peers_add(bgp, as, argv[i]->arg);
1ca2fd11
IR
2047 }
2048 return CMD_SUCCESS;
718e3744 2049}
2050
1ca2fd11
IR
2051DEFUN (no_bgp_confederation_peers,
2052 no_bgp_confederation_peers_cmd,
8079a413 2053 "no bgp confederation peers ASNUM...",
1ca2fd11 2054 NO_STR
e9273987 2055 BGP_STR
1ca2fd11
IR
2056 "AS confederation parameters\n"
2057 "Peer ASs in BGP confederation\n"
2058 AS_STR)
718e3744 2059{
1ca2fd11 2060 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 2061 int idx_asn = 4;
1ca2fd11 2062 as_t as;
d62a17ae 2063 int i;
718e3744 2064
1ca2fd11 2065 for (i = idx_asn; i < argc; i++) {
8079a413
PG
2066 if (!asn_str2asn(argv[i]->arg, &as)) {
2067 vty_out(vty, "%% Invalid confed peer AS value: %s\n",
2068 argv[i]->arg);
2069 continue;
2070 }
1ca2fd11
IR
2071 bgp_confederation_peers_remove(bgp, as);
2072 }
2073 return CMD_SUCCESS;
718e3744 2074}
6b0655a2 2075
5e242b0d
DS
2076/**
2077 * Central routine for maximum-paths configuration.
2078 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
2079 * @set: 1 for setting values, 0 for removing the max-paths config.
2080 */
585f1adc
IR
2081static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
2082 const char *mpaths, uint16_t options,
2083 int set)
d62a17ae 2084{
585f1adc
IR
2085 VTY_DECLVAR_CONTEXT(bgp, bgp);
2086 uint16_t maxpaths = 0;
d62a17ae 2087 int ret;
585f1adc
IR
2088 afi_t afi;
2089 safi_t safi;
2090
2091 afi = bgp_node_afi(vty);
2092 safi = bgp_node_safi(vty);
d62a17ae 2093
2094 if (set) {
585f1adc 2095 maxpaths = strtol(mpaths, NULL, 10);
d62a17ae 2096 if (maxpaths > multipath_num) {
585f1adc 2097 vty_out(vty,
d62a17ae 2098 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
2099 maxpaths, multipath_num);
2100 return CMD_WARNING_CONFIG_FAILED;
2101 }
2102 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
2103 options);
2104 } else
2105 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
2106
2107 if (ret < 0) {
585f1adc 2108 vty_out(vty,
d62a17ae 2109 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
2110 (set == 1) ? "" : "un",
2111 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
2112 maxpaths, afi, safi);
2113 return CMD_WARNING_CONFIG_FAILED;
2114 }
2115
2116 bgp_recalculate_all_bestpaths(bgp);
2117
2118 return CMD_SUCCESS;
165b5fff
JB
2119}
2120
1ca2fd11
IR
2121DEFUN (bgp_maxmed_admin,
2122 bgp_maxmed_admin_cmd,
2123 "bgp max-med administrative ",
2124 BGP_STR
2125 "Advertise routes with max-med\n"
2126 "Administratively applied, for an indefinite period\n")
abc920f8 2127{
1ca2fd11 2128 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 2129
1ca2fd11
IR
2130 bgp->v_maxmed_admin = 1;
2131 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
ff8a8a7a 2132
1ca2fd11 2133 bgp_maxmed_update(bgp);
abc920f8 2134
1ca2fd11 2135 return CMD_SUCCESS;
ff8a8a7a
CS
2136}
2137
1ca2fd11
IR
2138DEFUN (bgp_maxmed_admin_medv,
2139 bgp_maxmed_admin_medv_cmd,
2140 "bgp max-med administrative (0-4294967295)",
2141 BGP_STR
2142 "Advertise routes with max-med\n"
2143 "Administratively applied, for an indefinite period\n"
2144 "Max MED value to be used\n")
abc920f8 2145{
1ca2fd11 2146 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 2147 int idx_number = 3;
abc920f8 2148
1ca2fd11
IR
2149 bgp->v_maxmed_admin = 1;
2150 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
abc920f8 2151
1ca2fd11 2152 bgp_maxmed_update(bgp);
abc920f8 2153
1ca2fd11 2154 return CMD_SUCCESS;
abc920f8
DS
2155}
2156
1ca2fd11
IR
2157DEFUN (no_bgp_maxmed_admin,
2158 no_bgp_maxmed_admin_cmd,
2159 "no bgp max-med administrative [(0-4294967295)]",
2160 NO_STR
2161 BGP_STR
2162 "Advertise routes with max-med\n"
2163 "Administratively applied, for an indefinite period\n"
2164 "Max MED value to be used\n")
abc920f8 2165{
1ca2fd11
IR
2166 VTY_DECLVAR_CONTEXT(bgp, bgp);
2167 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
2168 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
2169 bgp_maxmed_update(bgp);
ff8a8a7a 2170
1ca2fd11 2171 return CMD_SUCCESS;
abc920f8
DS
2172}
2173
1ca2fd11
IR
2174DEFUN (bgp_maxmed_onstartup,
2175 bgp_maxmed_onstartup_cmd,
2176 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
2177 BGP_STR
2178 "Advertise routes with max-med\n"
2179 "Effective on a startup\n"
2180 "Time (seconds) period for max-med\n"
2181 "Max MED value to be used\n")
abc920f8 2182{
1ca2fd11 2183 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 2184 int idx = 0;
4668a151 2185
9b01d289
DA
2186 if (argv_find(argv, argc, "(5-86400)", &idx))
2187 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
d62a17ae 2188 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1ca2fd11 2189 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
d62a17ae 2190 else
1ca2fd11 2191 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 2192
1ca2fd11
IR
2193 bgp_maxmed_update(bgp);
2194
2195 return CMD_SUCCESS;
abc920f8
DS
2196}
2197
1ca2fd11
IR
2198DEFUN (no_bgp_maxmed_onstartup,
2199 no_bgp_maxmed_onstartup_cmd,
2200 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
2201 NO_STR
2202 BGP_STR
2203 "Advertise routes with max-med\n"
2204 "Effective on a startup\n"
2205 "Time (seconds) period for max-med\n"
2206 "Max MED value to be used\n")
abc920f8 2207{
1ca2fd11
IR
2208 VTY_DECLVAR_CONTEXT(bgp, bgp);
2209
2210 /* Cancel max-med onstartup if its on */
2211 if (bgp->t_maxmed_onstartup) {
c3aaa89a 2212 THREAD_OFF(bgp->t_maxmed_onstartup);
1ca2fd11
IR
2213 bgp->maxmed_onstartup_over = 1;
2214 }
abc920f8 2215
1ca2fd11
IR
2216 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
2217 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 2218
1ca2fd11
IR
2219 bgp_maxmed_update(bgp);
2220
2221 return CMD_SUCCESS;
abc920f8
DS
2222}
2223
d70583f7
D
2224static int bgp_global_update_delay_config_vty(struct vty *vty,
2225 uint16_t update_delay,
2226 uint16_t establish_wait)
2227{
2228 struct listnode *node, *nnode;
2229 struct bgp *bgp;
2230 bool vrf_cfg = false;
2231
2232 /*
2233 * See if update-delay is set per-vrf and warn user to delete it
2234 * Note that we only need to check this if this is the first time
2235 * setting the global config.
2236 */
2237 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
2238 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2239 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
2240 vty_out(vty,
2241 "%% update-delay configuration found in vrf %s\n",
2242 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
2243 ? VRF_DEFAULT_NAME
2244 : bgp->name);
2245 vrf_cfg = true;
2246 }
2247 }
2248 }
2249
2250 if (vrf_cfg) {
2251 vty_out(vty,
2252 "%%Failed: global update-delay config not permitted\n");
2253 return CMD_WARNING;
2254 }
2255
2256 if (!establish_wait) { /* update-delay <delay> */
2257 bm->v_update_delay = update_delay;
2258 bm->v_establish_wait = bm->v_update_delay;
2259 } else {
2260 /* update-delay <delay> <establish-wait> */
2261 if (update_delay < establish_wait) {
2262 vty_out(vty,
2263 "%%Failed: update-delay less than the establish-wait!\n");
2264 return CMD_WARNING_CONFIG_FAILED;
2265 }
2266
2267 bm->v_update_delay = update_delay;
2268 bm->v_establish_wait = establish_wait;
2269 }
2270
2271 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2272 bgp->v_update_delay = bm->v_update_delay;
2273 bgp->v_establish_wait = bm->v_establish_wait;
2274 }
2275
2276 return CMD_SUCCESS;
2277}
2278
2279static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
2280{
2281 struct listnode *node, *nnode;
2282 struct bgp *bgp;
2283
2284 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
2285 bm->v_establish_wait = bm->v_update_delay;
2286
2287 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2288 bgp->v_update_delay = bm->v_update_delay;
2289 bgp->v_establish_wait = bm->v_establish_wait;
2290 }
2291
2292 return CMD_SUCCESS;
2293}
2294
2295static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
2296 uint16_t establish_wait)
f188f2c4 2297{
d62a17ae 2298 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 2299
d70583f7
D
2300 /* if configured globally, per-instance config is not allowed */
2301 if (bm->v_update_delay) {
2302 vty_out(vty,
2303 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
2304 return CMD_WARNING_CONFIG_FAILED;
2305 }
2306
f188f2c4 2307
d70583f7 2308 if (!establish_wait) /* update-delay <delay> */
d62a17ae 2309 {
2310 bgp->v_update_delay = update_delay;
2311 bgp->v_establish_wait = bgp->v_update_delay;
2312 return CMD_SUCCESS;
2313 }
f188f2c4 2314
d62a17ae 2315 /* update-delay <delay> <establish-wait> */
d62a17ae 2316 if (update_delay < establish_wait) {
2317 vty_out(vty,
2318 "%%Failed: update-delay less than the establish-wait!\n");
2319 return CMD_WARNING_CONFIG_FAILED;
2320 }
f188f2c4 2321
d62a17ae 2322 bgp->v_update_delay = update_delay;
2323 bgp->v_establish_wait = establish_wait;
f188f2c4 2324
d62a17ae 2325 return CMD_SUCCESS;
f188f2c4
DS
2326}
2327
d62a17ae 2328static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 2329{
d62a17ae 2330 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 2331
d70583f7
D
2332 /* If configured globally, cannot remove from one bgp instance */
2333 if (bm->v_update_delay) {
2334 vty_out(vty,
2335 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2336 return CMD_WARNING_CONFIG_FAILED;
2337 }
d62a17ae 2338 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2339 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 2340
d62a17ae 2341 return CMD_SUCCESS;
f188f2c4
DS
2342}
2343
2b791107 2344void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 2345{
d70583f7
D
2346 /* If configured globally, no need to display per-instance value */
2347 if (bgp->v_update_delay != bm->v_update_delay) {
d62a17ae 2348 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2349 if (bgp->v_update_delay != bgp->v_establish_wait)
2350 vty_out(vty, " %d", bgp->v_establish_wait);
2351 vty_out(vty, "\n");
2352 }
f188f2c4
DS
2353}
2354
d70583f7
D
2355/* Global update-delay configuration */
2356DEFPY (bgp_global_update_delay,
2357 bgp_global_update_delay_cmd,
2358 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2359 BGP_STR
2360 "Force initial delay for best-path and updates for all bgp instances\n"
2361 "Max delay in seconds\n"
2362 "Establish wait in seconds\n")
2363{
2364 return bgp_global_update_delay_config_vty(vty, delay, wait);
2365}
f188f2c4 2366
d70583f7
D
2367/* Global update-delay deconfiguration */
2368DEFPY (no_bgp_global_update_delay,
2369 no_bgp_global_update_delay_cmd,
2370 "no bgp update-delay [(0-3600) [(1-3600)]]",
2371 NO_STR
2372 BGP_STR
f188f2c4 2373 "Force initial delay for best-path and updates\n"
d70583f7
D
2374 "Max delay in seconds\n"
2375 "Establish wait in seconds\n")
f188f2c4 2376{
d70583f7 2377 return bgp_global_update_delay_deconfig_vty(vty);
f188f2c4
DS
2378}
2379
d70583f7
D
2380/* Update-delay configuration */
2381
2382DEFPY (bgp_update_delay,
2383 bgp_update_delay_cmd,
2384 "update-delay (0-3600)$delay [(1-3600)$wait]",
f188f2c4 2385 "Force initial delay for best-path and updates\n"
d70583f7
D
2386 "Max delay in seconds\n"
2387 "Establish wait in seconds\n")
f188f2c4 2388{
d70583f7 2389 return bgp_update_delay_config_vty(vty, delay, wait);
f188f2c4
DS
2390}
2391
2392/* Update-delay deconfiguration */
d70583f7 2393DEFPY (no_bgp_update_delay,
f188f2c4 2394 no_bgp_update_delay_cmd,
838758ac
DW
2395 "no update-delay [(0-3600) [(1-3600)]]",
2396 NO_STR
f188f2c4 2397 "Force initial delay for best-path and updates\n"
d70583f7
D
2398 "Max delay in seconds\n"
2399 "Establish wait in seconds\n")
f188f2c4 2400{
d62a17ae 2401 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
2402}
2403
5e242b0d 2404
1ca2fd11
IR
2405static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2406 bool set)
cb1faec9 2407{
1ca2fd11
IR
2408 VTY_DECLVAR_CONTEXT(bgp, bgp);
2409
8fa7732f
QY
2410 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2411 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
555e09d4
QY
2412
2413 return CMD_SUCCESS;
2414}
2415
1ca2fd11
IR
2416static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2417 bool set)
555e09d4 2418{
1ca2fd11
IR
2419 VTY_DECLVAR_CONTEXT(bgp, bgp);
2420
8fa7732f
QY
2421 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2422 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
cb1faec9 2423
d62a17ae 2424 return CMD_SUCCESS;
cb1faec9
DS
2425}
2426
2b791107 2427void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 2428{
555e09d4
QY
2429 uint32_t quanta =
2430 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2431 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 2432 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
2433}
2434
555e09d4
QY
2435void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2436{
2437 uint32_t quanta =
2438 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2439 if (quanta != BGP_READ_PACKET_MAX)
152456fe 2440 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 2441}
cb1faec9 2442
8fa7732f
QY
2443/* Packet quanta configuration
2444 *
2445 * XXX: The value set here controls the size of a stack buffer in the IO
2446 * thread. When changing these limits be careful to prevent stack overflow.
2447 *
2448 * Furthermore, the maximums used here should correspond to
2449 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2450 */
1ca2fd11
IR
2451DEFPY (bgp_wpkt_quanta,
2452 bgp_wpkt_quanta_cmd,
2453 "[no] write-quanta (1-64)$quanta",
2454 NO_STR
2455 "How many packets to write to peer socket per run\n"
2456 "Number of packets\n")
2457{
2458 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
2459}
cb1faec9 2460
1ca2fd11
IR
2461DEFPY (bgp_rpkt_quanta,
2462 bgp_rpkt_quanta_cmd,
2463 "[no] read-quanta (1-10)$quanta",
2464 NO_STR
2465 "How many packets to read from peer socket per I/O cycle\n"
2466 "Number of packets\n")
2467{
2468 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
555e09d4
QY
2469}
2470
2b791107 2471void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 2472{
37a333fe 2473 if (!bgp->heuristic_coalesce)
d62a17ae 2474 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
2475}
2476
d1adb448
PG
2477/* BGP TCP keepalive */
2478static void bgp_config_tcp_keepalive(struct vty *vty, struct bgp *bgp)
2479{
2480 if (bgp->tcp_keepalive_idle) {
2481 vty_out(vty, " bgp tcp-keepalive %u %u %u\n",
2482 bgp->tcp_keepalive_idle, bgp->tcp_keepalive_intvl,
2483 bgp->tcp_keepalive_probes);
2484 }
2485}
4668a151 2486
1ca2fd11
IR
2487DEFUN (bgp_coalesce_time,
2488 bgp_coalesce_time_cmd,
2489 "coalesce-time (0-4294967295)",
2490 "Subgroup coalesce timer\n"
2491 "Subgroup coalesce timer value (in ms)\n")
ff8a8a7a 2492{
1ca2fd11 2493 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 2494
1ca2fd11 2495 int idx = 0;
9b01d289 2496
1ca2fd11 2497 bgp->heuristic_coalesce = false;
9b01d289
DA
2498
2499 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2500 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
2501
1ca2fd11 2502 return CMD_SUCCESS;
3f9c7369
DS
2503}
2504
1ca2fd11
IR
2505DEFUN (no_bgp_coalesce_time,
2506 no_bgp_coalesce_time_cmd,
2507 "no coalesce-time (0-4294967295)",
2508 NO_STR
2509 "Subgroup coalesce timer\n"
2510 "Subgroup coalesce timer value (in ms)\n")
3f9c7369 2511{
1ca2fd11 2512 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 2513
1ca2fd11
IR
2514 bgp->heuristic_coalesce = true;
2515 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
2516 return CMD_SUCCESS;
3f9c7369
DS
2517}
2518
5e242b0d 2519/* Maximum-paths configuration */
585f1adc
IR
2520DEFUN (bgp_maxpaths,
2521 bgp_maxpaths_cmd,
2522 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2523 "Forward packets over multiple paths\n"
2524 "Number of paths\n")
5e242b0d 2525{
d62a17ae 2526 int idx_number = 1;
585f1adc
IR
2527 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
2528 argv[idx_number]->arg, 0, 1);
5e242b0d
DS
2529}
2530
d62a17ae 2531ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2532 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2533 "Forward packets over multiple paths\n"
2534 "Number of paths\n")
596c17ba 2535
585f1adc
IR
2536DEFUN (bgp_maxpaths_ibgp,
2537 bgp_maxpaths_ibgp_cmd,
2538 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2539 "Forward packets over multiple paths\n"
2540 "iBGP-multipath\n"
2541 "Number of paths\n")
165b5fff 2542{
d62a17ae 2543 int idx_number = 2;
585f1adc
IR
2544 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2545 argv[idx_number]->arg, 0, 1);
5e242b0d 2546}
165b5fff 2547
d62a17ae 2548ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2549 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2550 "Forward packets over multiple paths\n"
2551 "iBGP-multipath\n"
2552 "Number of paths\n")
596c17ba 2553
585f1adc
IR
2554DEFUN (bgp_maxpaths_ibgp_cluster,
2555 bgp_maxpaths_ibgp_cluster_cmd,
2556 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2557 "Forward packets over multiple paths\n"
2558 "iBGP-multipath\n"
2559 "Number of paths\n"
2560 "Match the cluster length\n")
5e242b0d 2561{
d62a17ae 2562 int idx_number = 2;
aa53c036
DS
2563 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2564 argv[idx_number]->arg, true, 1);
165b5fff
JB
2565}
2566
d62a17ae 2567ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2568 "maximum-paths ibgp " CMD_RANGE_STR(
2569 1, MULTIPATH_NUM) " equal-cluster-length",
2570 "Forward packets over multiple paths\n"
2571 "iBGP-multipath\n"
2572 "Number of paths\n"
2573 "Match the cluster length\n")
596c17ba 2574
585f1adc
IR
2575DEFUN (no_bgp_maxpaths,
2576 no_bgp_maxpaths_cmd,
2577 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2578 NO_STR
2579 "Forward packets over multiple paths\n"
2580 "Number of paths\n")
165b5fff 2581{
585f1adc 2582 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
165b5fff
JB
2583}
2584
d62a17ae 2585ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 2586 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 2587 "Forward packets over multiple paths\n"
2588 "Number of paths\n")
596c17ba 2589
585f1adc
IR
2590DEFUN (no_bgp_maxpaths_ibgp,
2591 no_bgp_maxpaths_ibgp_cmd,
2592 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2593 NO_STR
2594 "Forward packets over multiple paths\n"
2595 "iBGP-multipath\n"
2596 "Number of paths\n"
2597 "Match the cluster length\n")
165b5fff 2598{
585f1adc 2599 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
2600}
2601
d62a17ae 2602ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2603 "no maximum-paths ibgp [" CMD_RANGE_STR(
2604 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2605 NO_STR
2606 "Forward packets over multiple paths\n"
2607 "iBGP-multipath\n"
2608 "Number of paths\n"
2609 "Match the cluster length\n")
596c17ba 2610
dd65f45e
DL
2611static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2612 afi_t afi, safi_t safi)
165b5fff 2613{
00908b7a 2614 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
d62a17ae 2615 vty_out(vty, " maximum-paths %d\n",
2616 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2617 }
165b5fff 2618
00908b7a 2619 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
d62a17ae 2620 vty_out(vty, " maximum-paths ibgp %d",
2621 bgp->maxpaths[afi][safi].maxpaths_ibgp);
aa53c036 2622 if (bgp->maxpaths[afi][safi].same_clusterlen)
d62a17ae 2623 vty_out(vty, " equal-cluster-length");
2624 vty_out(vty, "\n");
2625 }
165b5fff 2626}
6b0655a2 2627
718e3744 2628/* BGP timers. */
2629
1ca2fd11
IR
2630DEFUN (bgp_timers,
2631 bgp_timers_cmd,
2632 "timers bgp (0-65535) (0-65535)",
2633 "Adjust routing timers\n"
2634 "BGP timers\n"
2635 "Keepalive interval\n"
2636 "Holdtime\n")
718e3744 2637{
1ca2fd11 2638 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 2639 int idx_number = 2;
2640 int idx_number_2 = 3;
1ca2fd11
IR
2641 unsigned long keepalive = 0;
2642 unsigned long holdtime = 0;
718e3744 2643
1ca2fd11
IR
2644 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
2645 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
718e3744 2646
1ca2fd11
IR
2647 /* Holdtime value check. */
2648 if (holdtime < 3 && holdtime != 0) {
2649 vty_out(vty,
2650 "%% hold time value must be either 0 or greater than 3\n");
2651 return CMD_WARNING_CONFIG_FAILED;
2652 }
718e3744 2653
1ca2fd11
IR
2654 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY,
2655 BGP_DEFAULT_DELAYOPEN);
718e3744 2656
1ca2fd11 2657 return CMD_SUCCESS;
718e3744 2658}
2659
1ca2fd11
IR
2660DEFUN (no_bgp_timers,
2661 no_bgp_timers_cmd,
2662 "no timers bgp [(0-65535) (0-65535)]",
2663 NO_STR
2664 "Adjust routing timers\n"
2665 "BGP timers\n"
2666 "Keepalive interval\n"
2667 "Holdtime\n")
718e3744 2668{
1ca2fd11
IR
2669 VTY_DECLVAR_CONTEXT(bgp, bgp);
2670 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
2671 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
ff8a8a7a 2672
1ca2fd11 2673 return CMD_SUCCESS;
718e3744 2674}
2675
b042667a
TI
2676/* BGP minimum holdtime. */
2677
2678DEFUN(bgp_minimum_holdtime, bgp_minimum_holdtime_cmd,
2679 "bgp minimum-holdtime (1-65535)",
2680 "BGP specific commands\n"
2681 "BGP minimum holdtime\n"
2682 "Seconds\n")
2683{
2684 VTY_DECLVAR_CONTEXT(bgp, bgp);
2685 int idx_number = 2;
2686 unsigned long min_holdtime;
2687
2688 min_holdtime = strtoul(argv[idx_number]->arg, NULL, 10);
2689
2690 bgp->default_min_holdtime = min_holdtime;
2691
2692 return CMD_SUCCESS;
2693}
2694
2695DEFUN(no_bgp_minimum_holdtime, no_bgp_minimum_holdtime_cmd,
2696 "no bgp minimum-holdtime [(1-65535)]",
2697 NO_STR
2698 "BGP specific commands\n"
2699 "BGP minimum holdtime\n"
2700 "Seconds\n")
2701{
2702 VTY_DECLVAR_CONTEXT(bgp, bgp);
2703
2704 bgp->default_min_holdtime = 0;
2705
2706 return CMD_SUCCESS;
2707}
ff8a8a7a 2708
d1adb448
PG
2709DEFPY(bgp_tcp_keepalive, bgp_tcp_keepalive_cmd,
2710 "bgp tcp-keepalive (1-65535)$idle (1-65535)$intvl (1-30)$probes",
2711 BGP_STR
2712 "TCP keepalive parameters\n"
2713 "TCP keepalive idle time (seconds)\n"
2714 "TCP keepalive interval (seconds)\n"
2715 "TCP keepalive maximum probes\n")
2716{
2717 VTY_DECLVAR_CONTEXT(bgp, bgp);
2718
2719 bgp_tcp_keepalive_set(bgp, (uint16_t)idle, (uint16_t)intvl,
2720 (uint16_t)probes);
2721
2722 return CMD_SUCCESS;
2723}
2724
2725DEFPY(no_bgp_tcp_keepalive, no_bgp_tcp_keepalive_cmd,
2726 "no bgp tcp-keepalive [(1-65535) (1-65535) (1-30)]",
2727 NO_STR
2728 BGP_STR
2729 "TCP keepalive parameters\n"
2730 "TCP keepalive idle time (seconds)\n"
2731 "TCP keepalive interval (seconds)\n"
2732 "TCP keepalive maximum probes\n")
2733{
2734 VTY_DECLVAR_CONTEXT(bgp, bgp);
2735
2736 bgp_tcp_keepalive_unset(bgp);
2737
2738 return CMD_SUCCESS;
2739}
2740
1ca2fd11
IR
2741DEFUN (bgp_client_to_client_reflection,
2742 bgp_client_to_client_reflection_cmd,
2743 "bgp client-to-client reflection",
e9273987 2744 BGP_STR
1ca2fd11
IR
2745 "Configure client to client route reflection\n"
2746 "reflection of routes allowed\n")
718e3744 2747{
1ca2fd11
IR
2748 VTY_DECLVAR_CONTEXT(bgp, bgp);
2749 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2750 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 2751
1ca2fd11 2752 return CMD_SUCCESS;
718e3744 2753}
2754
1ca2fd11
IR
2755DEFUN (no_bgp_client_to_client_reflection,
2756 no_bgp_client_to_client_reflection_cmd,
2757 "no bgp client-to-client reflection",
2758 NO_STR
e9273987 2759 BGP_STR
1ca2fd11
IR
2760 "Configure client to client route reflection\n"
2761 "reflection of routes allowed\n")
718e3744 2762{
1ca2fd11
IR
2763 VTY_DECLVAR_CONTEXT(bgp, bgp);
2764 SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2765 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 2766
1ca2fd11 2767 return CMD_SUCCESS;
718e3744 2768}
2769
2770/* "bgp always-compare-med" configuration. */
1ca2fd11
IR
2771DEFUN (bgp_always_compare_med,
2772 bgp_always_compare_med_cmd,
2773 "bgp always-compare-med",
e9273987 2774 BGP_STR
1ca2fd11 2775 "Allow comparing MED from different neighbors\n")
718e3744 2776{
1ca2fd11
IR
2777 VTY_DECLVAR_CONTEXT(bgp, bgp);
2778 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2779 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2780
1ca2fd11 2781 return CMD_SUCCESS;
718e3744 2782}
2783
1ca2fd11
IR
2784DEFUN (no_bgp_always_compare_med,
2785 no_bgp_always_compare_med_cmd,
2786 "no bgp always-compare-med",
2787 NO_STR
e9273987 2788 BGP_STR
1ca2fd11 2789 "Allow comparing MED from different neighbors\n")
718e3744 2790{
1ca2fd11
IR
2791 VTY_DECLVAR_CONTEXT(bgp, bgp);
2792 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2793 bgp_recalculate_all_bestpaths(bgp);
6b0655a2 2794
1ca2fd11 2795 return CMD_SUCCESS;
2adac256
DA
2796}
2797
2adac256 2798
1ca2fd11
IR
2799DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2800 "bgp ebgp-requires-policy",
e9273987 2801 BGP_STR
1ca2fd11 2802 "Require in and out policy for eBGP peers (RFC8212)\n")
2adac256 2803{
1ca2fd11
IR
2804 VTY_DECLVAR_CONTEXT(bgp, bgp);
2805 SET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2806 return CMD_SUCCESS;
2adac256
DA
2807}
2808
1ca2fd11
IR
2809DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2810 "no bgp ebgp-requires-policy",
2811 NO_STR
e9273987 2812 BGP_STR
1ca2fd11 2813 "Require in and out policy for eBGP peers (RFC8212)\n")
ff8a8a7a 2814{
1ca2fd11
IR
2815 VTY_DECLVAR_CONTEXT(bgp, bgp);
2816 UNSET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2817 return CMD_SUCCESS;
ff8a8a7a 2818}
9dac9fc8 2819
1ca2fd11
IR
2820DEFUN(bgp_suppress_duplicates, bgp_suppress_duplicates_cmd,
2821 "bgp suppress-duplicates",
e9273987 2822 BGP_STR
1ca2fd11 2823 "Suppress duplicate updates if the route actually not changed\n")
9dac9fc8 2824{
1ca2fd11
IR
2825 VTY_DECLVAR_CONTEXT(bgp, bgp);
2826 SET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2827 return CMD_SUCCESS;
9dac9fc8
DA
2828}
2829
1ca2fd11
IR
2830DEFUN(no_bgp_suppress_duplicates, no_bgp_suppress_duplicates_cmd,
2831 "no bgp suppress-duplicates",
2832 NO_STR
e9273987 2833 BGP_STR
1ca2fd11 2834 "Suppress duplicate updates if the route actually not changed\n")
9dac9fc8 2835{
1ca2fd11
IR
2836 VTY_DECLVAR_CONTEXT(bgp, bgp);
2837 UNSET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2838 return CMD_SUCCESS;
9dac9fc8
DA
2839}
2840
fb29348a
DA
2841DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2842 "bgp reject-as-sets",
e9273987 2843 BGP_STR
fb29348a
DA
2844 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2845{
2846 VTY_DECLVAR_CONTEXT(bgp, bgp);
2847 struct listnode *node, *nnode;
2848 struct peer *peer;
2849
7f972cd8 2850 bgp->reject_as_sets = true;
fb29348a
DA
2851
2852 /* Reset existing BGP sessions to reject routes
2853 * with aspath containing AS_SET or AS_CONFED_SET.
2854 */
2855 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2856 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2857 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2858 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2859 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2860 }
2861 }
2862
2863 return CMD_SUCCESS;
2864}
2865
2866DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2867 "no bgp reject-as-sets",
2868 NO_STR
e9273987 2869 BGP_STR
fb29348a
DA
2870 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2871{
2872 VTY_DECLVAR_CONTEXT(bgp, bgp);
2873 struct listnode *node, *nnode;
2874 struct peer *peer;
2875
7f972cd8 2876 bgp->reject_as_sets = false;
fb29348a
DA
2877
2878 /* Reset existing BGP sessions to reject routes
2879 * with aspath containing AS_SET or AS_CONFED_SET.
2880 */
2881 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2882 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2883 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2884 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2885 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2886 }
2887 }
2888
2889 return CMD_SUCCESS;
2890}
9dac9fc8 2891
718e3744 2892/* "bgp deterministic-med" configuration. */
1ca2fd11 2893DEFUN (bgp_deterministic_med,
718e3744 2894 bgp_deterministic_med_cmd,
2895 "bgp deterministic-med",
e9273987 2896 BGP_STR
718e3744 2897 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2898{
1ca2fd11
IR
2899 VTY_DECLVAR_CONTEXT(bgp, bgp);
2900
2901 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2902 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2903 bgp_recalculate_all_bestpaths(bgp);
2904 }
7aafcaca 2905
1ca2fd11 2906 return CMD_SUCCESS;
718e3744 2907}
2908
1ca2fd11 2909DEFUN (no_bgp_deterministic_med,
718e3744 2910 no_bgp_deterministic_med_cmd,
2911 "no bgp deterministic-med",
2912 NO_STR
e9273987 2913 BGP_STR
718e3744 2914 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2915{
1ca2fd11
IR
2916 VTY_DECLVAR_CONTEXT(bgp, bgp);
2917 int bestpath_per_as_used;
2918 afi_t afi;
2919 safi_t safi;
2920 struct peer *peer;
2921 struct listnode *node, *nnode;
2922
2923 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2924 bestpath_per_as_used = 0;
2925
2926 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2927 FOREACH_AFI_SAFI (afi, safi)
2928 if (bgp_addpath_dmed_required(
2929 peer->addpath_type[afi][safi])) {
2930 bestpath_per_as_used = 1;
2931 break;
2932 }
2933
2934 if (bestpath_per_as_used)
2935 break;
2936 }
2937
2938 if (bestpath_per_as_used) {
2939 vty_out(vty,
2940 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2941 return CMD_WARNING_CONFIG_FAILED;
2942 } else {
2943 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2944 bgp_recalculate_all_bestpaths(bgp);
2945 }
2946 }
d62a17ae 2947
1ca2fd11 2948 return CMD_SUCCESS;
718e3744 2949}
538621f2 2950
055679e9 2951/* "bgp graceful-restart mode" configuration. */
538621f2 2952DEFUN (bgp_graceful_restart,
2ba1fe69 2953 bgp_graceful_restart_cmd,
2954 "bgp graceful-restart",
e9273987 2955 BGP_STR
2ba1fe69 2956 GR_CMD
055679e9 2957 )
538621f2 2958{
055679e9 2959 int ret = BGP_GR_FAILURE;
2960
2961 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2962 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
dc95985f 2963
d62a17ae 2964 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2965
2966 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2967
36235319
QY
2968 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2969 ret);
5cce3f05 2970
055679e9 2971 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2972 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
dc95985f 2973 vty_out(vty,
2974 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2975 return bgp_vty_return(vty, ret);
538621f2 2976}
2977
2978DEFUN (no_bgp_graceful_restart,
2ba1fe69 2979 no_bgp_graceful_restart_cmd,
2980 "no bgp graceful-restart",
2981 NO_STR
e9273987 2982 BGP_STR
2ba1fe69 2983 NO_GR_CMD
055679e9 2984 )
538621f2 2985{
d62a17ae 2986 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2987
2988 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2989 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
055679e9 2990
2991 int ret = BGP_GR_FAILURE;
2992
2993 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2994
36235319
QY
2995 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2996 ret);
5cce3f05 2997
055679e9 2998 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2999 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
dc95985f 3000 vty_out(vty,
3001 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 3002
3003 return bgp_vty_return(vty, ret);
538621f2 3004}
3005
93406d87 3006DEFUN (bgp_graceful_restart_stalepath_time,
2ba1fe69 3007 bgp_graceful_restart_stalepath_time_cmd,
3008 "bgp graceful-restart stalepath-time (1-4095)",
e9273987 3009 BGP_STR
2ba1fe69 3010 "Graceful restart capability parameters\n"
3011 "Set the max time to hold onto restarting peer's stale paths\n"
3012 "Delay value (seconds)\n")
93406d87 3013{
d62a17ae 3014 VTY_DECLVAR_CONTEXT(bgp, bgp);
3015 int idx_number = 3;
d7c0a89a 3016 uint32_t stalepath;
93406d87 3017
d62a17ae 3018 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
3019 bgp->stalepath_time = stalepath;
3020 return CMD_SUCCESS;
93406d87 3021}
3022
eb6f1b41 3023DEFUN (bgp_graceful_restart_restart_time,
2ba1fe69 3024 bgp_graceful_restart_restart_time_cmd,
dcbebfd3 3025 "bgp graceful-restart restart-time (0-4095)",
e9273987 3026 BGP_STR
2ba1fe69 3027 "Graceful restart capability parameters\n"
3028 "Set the time to wait to delete stale routes before a BGP open message is received\n"
3029 "Delay value (seconds)\n")
eb6f1b41 3030{
d62a17ae 3031 VTY_DECLVAR_CONTEXT(bgp, bgp);
3032 int idx_number = 3;
d7c0a89a 3033 uint32_t restart;
eb6f1b41 3034
d62a17ae 3035 restart = strtoul(argv[idx_number]->arg, NULL, 10);
3036 bgp->restart_time = restart;
3037 return CMD_SUCCESS;
eb6f1b41
PG
3038}
3039
cfd47646 3040DEFUN (bgp_graceful_restart_select_defer_time,
3041 bgp_graceful_restart_select_defer_time_cmd,
3042 "bgp graceful-restart select-defer-time (0-3600)",
e9273987 3043 BGP_STR
cfd47646 3044 "Graceful restart capability parameters\n"
3045 "Set the time to defer the BGP route selection after restart\n"
3046 "Delay value (seconds, 0 - disable)\n")
3047{
3048 VTY_DECLVAR_CONTEXT(bgp, bgp);
3049 int idx_number = 3;
3050 uint32_t defer_time;
3051
3052 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
3053 bgp->select_defer_time = defer_time;
3054 if (defer_time == 0)
892fedb6 3055 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 3056 else
892fedb6 3057 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 3058
3059 return CMD_SUCCESS;
3060}
3061
93406d87 3062DEFUN (no_bgp_graceful_restart_stalepath_time,
2ba1fe69 3063 no_bgp_graceful_restart_stalepath_time_cmd,
3064 "no bgp graceful-restart stalepath-time [(1-4095)]",
3065 NO_STR
e9273987 3066 BGP_STR
2ba1fe69 3067 "Graceful restart capability parameters\n"
3068 "Set the max time to hold onto restarting peer's stale paths\n"
3069 "Delay value (seconds)\n")
93406d87 3070{
d62a17ae 3071 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 3072
d62a17ae 3073 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
3074 return CMD_SUCCESS;
93406d87 3075}
3076
eb6f1b41 3077DEFUN (no_bgp_graceful_restart_restart_time,
2ba1fe69 3078 no_bgp_graceful_restart_restart_time_cmd,
dcbebfd3 3079 "no bgp graceful-restart restart-time [(0-4095)]",
2ba1fe69 3080 NO_STR
e9273987 3081 BGP_STR
2ba1fe69 3082 "Graceful restart capability parameters\n"
3083 "Set the time to wait to delete stale routes before a BGP open message is received\n"
3084 "Delay value (seconds)\n")
eb6f1b41 3085{
d62a17ae 3086 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 3087
d62a17ae 3088 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
3089 return CMD_SUCCESS;
eb6f1b41
PG
3090}
3091
cfd47646 3092DEFUN (no_bgp_graceful_restart_select_defer_time,
3093 no_bgp_graceful_restart_select_defer_time_cmd,
3094 "no bgp graceful-restart select-defer-time [(0-3600)]",
3095 NO_STR
e9273987 3096 BGP_STR
cfd47646 3097 "Graceful restart capability parameters\n"
3098 "Set the time to defer the BGP route selection after restart\n"
3099 "Delay value (seconds)\n")
3100{
3101 VTY_DECLVAR_CONTEXT(bgp, bgp);
3102
3103 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
892fedb6 3104 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 3105
3106 return CMD_SUCCESS;
3107}
3108
43fc21b3 3109DEFUN (bgp_graceful_restart_preserve_fw,
2ba1fe69 3110 bgp_graceful_restart_preserve_fw_cmd,
3111 "bgp graceful-restart preserve-fw-state",
e9273987 3112 BGP_STR
2ba1fe69 3113 "Graceful restart capability parameters\n"
3114 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 3115{
d62a17ae 3116 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3117 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 3118 return CMD_SUCCESS;
43fc21b3
JC
3119}
3120
3121DEFUN (no_bgp_graceful_restart_preserve_fw,
2ba1fe69 3122 no_bgp_graceful_restart_preserve_fw_cmd,
3123 "no bgp graceful-restart preserve-fw-state",
3124 NO_STR
e9273987 3125 BGP_STR
2ba1fe69 3126 "Graceful restart capability parameters\n"
3127 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 3128{
d62a17ae 3129 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3130 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 3131 return CMD_SUCCESS;
43fc21b3
JC
3132}
3133
f2ca5c5b
DA
3134DEFPY (bgp_graceful_restart_notification,
3135 bgp_graceful_restart_notification_cmd,
3136 "[no$no] bgp graceful-restart notification",
3137 NO_STR
3138 BGP_STR
3139 "Graceful restart capability parameters\n"
3140 "Indicate Graceful Restart support for BGP NOTIFICATION messages\n")
3141{
3142 VTY_DECLVAR_CONTEXT(bgp, bgp);
3143
3144 if (no)
3145 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
3146 else
3147 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
3148
3149 return CMD_SUCCESS;
3150}
3151
1ae314be
DA
3152DEFPY (bgp_administrative_reset,
3153 bgp_administrative_reset_cmd,
3154 "[no$no] bgp hard-administrative-reset",
3155 NO_STR
3156 BGP_STR
3157 "Send Hard Reset CEASE Notification for 'Administrative Reset'\n")
3158{
3159 VTY_DECLVAR_CONTEXT(bgp, bgp);
3160
3161 if (no)
3162 UNSET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3163 else
3164 SET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3165
3166 return CMD_SUCCESS;
3167}
3168
055679e9 3169DEFUN (bgp_graceful_restart_disable,
2ba1fe69 3170 bgp_graceful_restart_disable_cmd,
3171 "bgp graceful-restart-disable",
e9273987 3172 BGP_STR
2ba1fe69 3173 GR_DISABLE)
055679e9 3174{
3175 int ret = BGP_GR_FAILURE;
3176
3177 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3178 zlog_debug(
2ba1fe69 3179 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
dc95985f 3180
055679e9 3181 VTY_DECLVAR_CONTEXT(bgp, bgp);
3182
3183 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
3184
dc95985f 3185 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
3186 bgp->peer, ret);
5cce3f05 3187
055679e9 3188 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3189 zlog_debug(
2ba1fe69 3190 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
dc95985f 3191 vty_out(vty,
3192 "Graceful restart configuration changed, reset all peers to take effect\n");
3193
055679e9 3194 return bgp_vty_return(vty, ret);
3195}
3196
3197DEFUN (no_bgp_graceful_restart_disable,
2ba1fe69 3198 no_bgp_graceful_restart_disable_cmd,
3199 "no bgp graceful-restart-disable",
3200 NO_STR
e9273987 3201 BGP_STR
2ba1fe69 3202 NO_GR_DISABLE
055679e9 3203 )
3204{
3205 VTY_DECLVAR_CONTEXT(bgp, bgp);
3206
3207 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3208 zlog_debug(
2ba1fe69 3209 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
055679e9 3210
3211 int ret = BGP_GR_FAILURE;
3212
3213 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
3214
36235319
QY
3215 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
3216 ret);
5cce3f05 3217
055679e9 3218 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3219 zlog_debug(
2ba1fe69 3220 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
dc95985f 3221 vty_out(vty,
3222 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 3223
3224 return bgp_vty_return(vty, ret);
3225}
3226
3227DEFUN (bgp_neighbor_graceful_restart_set,
2ba1fe69 3228 bgp_neighbor_graceful_restart_set_cmd,
3229 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3230 NEIGHBOR_STR
3231 NEIGHBOR_ADDR_STR2
3232 GR_NEIGHBOR_CMD
055679e9 3233 )
3234{
3235 int idx_peer = 1;
3236 struct peer *peer;
3237 int ret = BGP_GR_FAILURE;
3238
dc95985f 3239 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3240
055679e9 3241 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3242 zlog_debug(
2ba1fe69 3243 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
dc95985f 3244
055679e9 3245 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3246 if (!peer)
3247 return CMD_WARNING_CONFIG_FAILED;
3248
3249 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
3250
dc95985f 3251 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3252 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3253
3254 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3255 zlog_debug(
2ba1fe69 3256 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 3257 vty_out(vty,
3258 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3259
3260 return bgp_vty_return(vty, ret);
3261}
3262
3263DEFUN (no_bgp_neighbor_graceful_restart,
2ba1fe69 3264 no_bgp_neighbor_graceful_restart_set_cmd,
3265 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3266 NO_STR
3267 NEIGHBOR_STR
3268 NEIGHBOR_ADDR_STR2
3269 NO_GR_NEIGHBOR_CMD
055679e9 3270 )
3271{
3272 int idx_peer = 2;
3273 int ret = BGP_GR_FAILURE;
3274 struct peer *peer;
3275
dc95985f 3276 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3277
055679e9 3278 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3279 if (!peer)
3280 return CMD_WARNING_CONFIG_FAILED;
3281
3282 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3283 zlog_debug(
2ba1fe69 3284 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
055679e9 3285
3286 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
3287
dc95985f 3288 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3289 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3290
3291 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3292 zlog_debug(
2ba1fe69 3293 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 3294 vty_out(vty,
3295 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3296
3297 return bgp_vty_return(vty, ret);
3298}
3299
3300DEFUN (bgp_neighbor_graceful_restart_helper_set,
2ba1fe69 3301 bgp_neighbor_graceful_restart_helper_set_cmd,
3302 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3303 NEIGHBOR_STR
3304 NEIGHBOR_ADDR_STR2
3305 GR_NEIGHBOR_HELPER_CMD
055679e9 3306 )
3307{
3308 int idx_peer = 1;
3309 struct peer *peer;
3310 int ret = BGP_GR_FAILURE;
3311
dc95985f 3312 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3313
055679e9 3314 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3315 zlog_debug(
2ba1fe69 3316 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
dc95985f 3317
055679e9 3318 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3319
055679e9 3320 if (!peer)
3321 return CMD_WARNING_CONFIG_FAILED;
3322
3323
3324 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
5cce3f05 3325
dc95985f 3326 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3327 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
5cce3f05 3328
055679e9 3329 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3330 zlog_debug(
2ba1fe69 3331 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 3332 vty_out(vty,
3333 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3334
3335 return bgp_vty_return(vty, ret);
3336}
3337
3338DEFUN (no_bgp_neighbor_graceful_restart_helper,
2ba1fe69 3339 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3340 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3341 NO_STR
3342 NEIGHBOR_STR
3343 NEIGHBOR_ADDR_STR2
3344 NO_GR_NEIGHBOR_HELPER_CMD
055679e9 3345 )
3346{
3347 int idx_peer = 2;
3348 int ret = BGP_GR_FAILURE;
3349 struct peer *peer;
3350
dc95985f 3351 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3352
055679e9 3353 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3354 if (!peer)
3355 return CMD_WARNING_CONFIG_FAILED;
3356
3357 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3358 zlog_debug(
2ba1fe69 3359 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
055679e9 3360
36235319 3361 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
055679e9 3362
dc95985f 3363 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3364 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3365
3366 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3367 zlog_debug(
2ba1fe69 3368 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 3369 vty_out(vty,
3370 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3371
3372 return bgp_vty_return(vty, ret);
3373}
3374
3375DEFUN (bgp_neighbor_graceful_restart_disable_set,
2ba1fe69 3376 bgp_neighbor_graceful_restart_disable_set_cmd,
3377 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3378 NEIGHBOR_STR
3379 NEIGHBOR_ADDR_STR2
3380 GR_NEIGHBOR_DISABLE_CMD
055679e9 3381 )
3382{
3383 int idx_peer = 1;
3384 struct peer *peer;
3385 int ret = BGP_GR_FAILURE;
3386
dc95985f 3387 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3388
055679e9 3389 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3390 zlog_debug(
2ba1fe69 3391 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 3392
3393 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3394 if (!peer)
3395 return CMD_WARNING_CONFIG_FAILED;
3396
36235319 3397 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
055679e9 3398
3399 if (peer->bgp->t_startup)
3400 bgp_peer_gr_flags_update(peer);
3401
dc95985f 3402 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3403 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3404
055679e9 3405 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3406 zlog_debug(
2ba1fe69 3407 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3408 vty_out(vty,
3409 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3410
3411 return bgp_vty_return(vty, ret);
3412}
3413
3414DEFUN (no_bgp_neighbor_graceful_restart_disable,
2ba1fe69 3415 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3416 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3417 NO_STR
3418 NEIGHBOR_STR
3419 NEIGHBOR_ADDR_STR2
3420 NO_GR_NEIGHBOR_DISABLE_CMD
055679e9 3421 )
3422{
3423 int idx_peer = 2;
3424 int ret = BGP_GR_FAILURE;
3425 struct peer *peer;
3426
dc95985f 3427 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3428
055679e9 3429 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3430 if (!peer)
3431 return CMD_WARNING_CONFIG_FAILED;
3432
3433 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3434 zlog_debug(
2ba1fe69 3435 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 3436
3437 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3438
dc95985f 3439 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3440 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3441
3442 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3443 zlog_debug(
2ba1fe69 3444 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3445 vty_out(vty,
3446 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3447
3448 return bgp_vty_return(vty, ret);
3449}
3450
4f770cf1
DA
3451DEFPY (neighbor_graceful_shutdown,
3452 neighbor_graceful_shutdown_cmd,
3453 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor graceful-shutdown",
3454 NO_STR
3455 NEIGHBOR_STR
3456 NEIGHBOR_ADDR_STR2
3457 "Graceful shutdown\n")
3458{
3459 afi_t afi;
3460 safi_t safi;
3461 struct peer *peer;
3462 VTY_DECLVAR_CONTEXT(bgp, bgp);
3463 int ret;
3464
3465 peer = peer_and_group_lookup_vty(vty, neighbor);
3466 if (!peer)
3467 return CMD_WARNING_CONFIG_FAILED;
3468
3469 if (no)
3470 ret = peer_flag_unset_vty(vty, neighbor,
3471 PEER_FLAG_GRACEFUL_SHUTDOWN);
3472 else
3473 ret = peer_flag_set_vty(vty, neighbor,
3474 PEER_FLAG_GRACEFUL_SHUTDOWN);
3475
3476 FOREACH_AFI_SAFI (afi, safi) {
3477 if (!peer->afc[afi][safi])
3478 continue;
3479
3480 bgp_clear(vty, bgp, afi, safi, clear_peer, BGP_CLEAR_SOFT_IN,
3481 neighbor);
3482 }
3483
3484 return ret;
3485}
3486
d6e3c15b 3487DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3488 bgp_graceful_restart_disable_eor_cmd,
3489 "bgp graceful-restart disable-eor",
e9273987 3490 BGP_STR
d6e3c15b 3491 "Graceful restart configuration parameters\n"
3492 "Disable EOR Check\n")
3493{
3494 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3495 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3496
d6e3c15b 3497 return CMD_SUCCESS;
3498}
3499
3500DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3501 no_bgp_graceful_restart_disable_eor_cmd,
3502 "no bgp graceful-restart disable-eor",
3503 NO_STR
e9273987 3504 BGP_STR
d6e3c15b 3505 "Graceful restart configuration parameters\n"
3506 "Disable EOR Check\n")
3507{
3508 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3509 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3510
3511 return CMD_SUCCESS;
3512}
3513
3514DEFUN (bgp_graceful_restart_rib_stale_time,
3515 bgp_graceful_restart_rib_stale_time_cmd,
3516 "bgp graceful-restart rib-stale-time (1-3600)",
e9273987 3517 BGP_STR
dc95985f 3518 "Graceful restart configuration parameters\n"
3519 "Specify the stale route removal timer in rib\n"
3520 "Delay value (seconds)\n")
3521{
3522 VTY_DECLVAR_CONTEXT(bgp, bgp);
3523 int idx_number = 3;
3524 uint32_t stale_time;
3525
3526 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3527 bgp->rib_stale_time = stale_time;
3528 /* Send the stale timer update message to RIB */
3529 if (bgp_zebra_stale_timer_update(bgp))
3530 return CMD_WARNING;
3531
3532 return CMD_SUCCESS;
3533}
3534
3535DEFUN (no_bgp_graceful_restart_rib_stale_time,
3536 no_bgp_graceful_restart_rib_stale_time_cmd,
3537 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3538 NO_STR
e9273987 3539 BGP_STR
dc95985f 3540 "Graceful restart configuration parameters\n"
3541 "Specify the stale route removal timer in rib\n"
3542 "Delay value (seconds)\n")
3543{
3544 VTY_DECLVAR_CONTEXT(bgp, bgp);
3545
3546 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3547 /* Send the stale timer update message to RIB */
3548 if (bgp_zebra_stale_timer_update(bgp))
3549 return CMD_WARNING;
3550
d6e3c15b 3551 return CMD_SUCCESS;
3552}
3553
8606be87 3554DEFUN(bgp_llgr_stalepath_time, bgp_llgr_stalepath_time_cmd,
5970204c 3555 "bgp long-lived-graceful-restart stale-time (1-16777215)",
7f8a9a24 3556 BGP_STR
8606be87
DA
3557 "Enable Long-lived Graceful Restart\n"
3558 "Specifies maximum time to wait before purging long-lived stale routes\n"
3559 "Stale time value (seconds)\n")
3560{
3561 VTY_DECLVAR_CONTEXT(bgp, bgp);
3562
3563 uint32_t llgr_stale_time;
3564
3565 llgr_stale_time = strtoul(argv[3]->arg, NULL, 10);
3566 bgp->llgr_stale_time = llgr_stale_time;
3567
3568 return CMD_SUCCESS;
3569}
3570
3571DEFUN(no_bgp_llgr_stalepath_time, no_bgp_llgr_stalepath_time_cmd,
5970204c 3572 "no bgp long-lived-graceful-restart stale-time [(1-16777215)]",
8606be87
DA
3573 NO_STR BGP_STR
3574 "Enable Long-lived Graceful Restart\n"
3575 "Specifies maximum time to wait before purging long-lived stale routes\n"
3576 "Stale time value (seconds)\n")
3577{
3578 VTY_DECLVAR_CONTEXT(bgp, bgp);
3579
3580 bgp->llgr_stale_time = BGP_DEFAULT_LLGR_STALE_TIME;
3581
3582 return CMD_SUCCESS;
3583}
3584
1ca2fd11
IR
3585static inline void bgp_initiate_graceful_shut_unshut(struct vty *vty,
3586 struct bgp *bgp)
05bd726c 3587{
3588 bgp_static_redo_import_check(bgp);
3589 bgp_redistribute_redo(bgp);
1ca2fd11
IR
3590 bgp_clear_star_soft_out(vty, bgp->name);
3591 bgp_clear_star_soft_in(vty, bgp->name);
05bd726c 3592}
3593
3594static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3595{
3596 struct listnode *node, *nnode;
3597 struct bgp *bgp;
3598 bool vrf_cfg = false;
3599
3600 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3601 return CMD_SUCCESS;
3602
3603 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3604 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3605 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3606 vty_out(vty,
3607 "%% graceful-shutdown configuration found in vrf %s\n",
3608 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3609 VRF_DEFAULT_NAME : bgp->name);
3610 vrf_cfg = true;
3611 }
3612 }
3613
3614 if (vrf_cfg) {
3615 vty_out(vty,
3616 "%%Failed: global graceful-shutdown not permitted\n");
3617 return CMD_WARNING;
3618 }
3619
3620 /* Set flag globally */
3621 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3622
3623 /* Initiate processing for all BGP instances. */
1ca2fd11
IR
3624 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3625 bgp_initiate_graceful_shut_unshut(vty, bgp);
05bd726c 3626
3627 return CMD_SUCCESS;
3628}
3629
3630static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3631{
3632 struct listnode *node, *nnode;
3633 struct bgp *bgp;
3634
3635 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3636 return CMD_SUCCESS;
3637
3638 /* Unset flag globally */
3639 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3640
3641 /* Initiate processing for all BGP instances. */
1ca2fd11
IR
3642 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3643 bgp_initiate_graceful_shut_unshut(vty, bgp);
05bd726c 3644
3645 return CMD_SUCCESS;
3646}
3647
7f323236
DW
3648/* "bgp graceful-shutdown" configuration */
3649DEFUN (bgp_graceful_shutdown,
3650 bgp_graceful_shutdown_cmd,
3651 "bgp graceful-shutdown",
3652 BGP_STR
3653 "Graceful shutdown parameters\n")
3654{
05bd726c 3655 if (vty->node == CONFIG_NODE)
3656 return bgp_global_graceful_shutdown_config_vty(vty);
3657
1ca2fd11 3658 VTY_DECLVAR_CONTEXT(bgp, bgp);
7f323236 3659
1ca2fd11
IR
3660 /* if configured globally, per-instance config is not allowed */
3661 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3662 vty_out(vty,
3663 "%%Failed: per-vrf graceful-shutdown config not permitted with global graceful-shutdown\n");
3664 return CMD_WARNING_CONFIG_FAILED;
3665 }
3666
3667 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3668 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3669 bgp_initiate_graceful_shut_unshut(vty, bgp);
3670 }
3671
3672 return CMD_SUCCESS;
7f323236
DW
3673}
3674
1ca2fd11 3675DEFUN (no_bgp_graceful_shutdown,
7f323236
DW
3676 no_bgp_graceful_shutdown_cmd,
3677 "no bgp graceful-shutdown",
3678 NO_STR
3679 BGP_STR
3680 "Graceful shutdown parameters\n")
3681{
05bd726c 3682 if (vty->node == CONFIG_NODE)
3683 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3684
1ca2fd11 3685 VTY_DECLVAR_CONTEXT(bgp, bgp);
05bd726c 3686
1ca2fd11
IR
3687 /* If configured globally, cannot remove from one bgp instance */
3688 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3689 vty_out(vty,
3690 "%%Failed: bgp graceful-shutdown configured globally. Delete per-vrf not permitted\n");
3691 return CMD_WARNING_CONFIG_FAILED;
3692 }
7f323236 3693
1ca2fd11
IR
3694 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3695 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3696 bgp_initiate_graceful_shut_unshut(vty, bgp);
3697 }
3698
3699 return CMD_SUCCESS;
7f323236
DW
3700}
3701
718e3744 3702/* "bgp fast-external-failover" configuration. */
1ca2fd11 3703DEFUN (bgp_fast_external_failover,
718e3744 3704 bgp_fast_external_failover_cmd,
3705 "bgp fast-external-failover",
3706 BGP_STR
3707 "Immediately reset session if a link to a directly connected external peer goes down\n")
3708{
1ca2fd11
IR
3709 VTY_DECLVAR_CONTEXT(bgp, bgp);
3710 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3711 return CMD_SUCCESS;
718e3744 3712}
3713
1ca2fd11 3714DEFUN (no_bgp_fast_external_failover,
718e3744 3715 no_bgp_fast_external_failover_cmd,
3716 "no bgp fast-external-failover",
3717 NO_STR
3718 BGP_STR
3719 "Immediately reset session if a link to a directly connected external peer goes down\n")
3720{
1ca2fd11
IR
3721 VTY_DECLVAR_CONTEXT(bgp, bgp);
3722 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3723 return CMD_SUCCESS;
718e3744 3724}
6b0655a2 3725
97a52c82
DA
3726DEFPY (bgp_bestpath_aigp,
3727 bgp_bestpath_aigp_cmd,
3728 "[no$no] bgp bestpath aigp",
3729 NO_STR
3730 BGP_STR
3731 "Change the default bestpath selection\n"
3732 "Evaluate the AIGP attribute during the best path selection process\n")
3733{
3734 VTY_DECLVAR_CONTEXT(bgp, bgp);
3735
3736 if (no)
3737 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_AIGP);
3738 else
3739 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_AIGP);
3740
3741 bgp_recalculate_all_bestpaths(bgp);
3742
3743 return CMD_SUCCESS;
3744}
3745
718e3744 3746/* "bgp bestpath compare-routerid" configuration. */
1ca2fd11
IR
3747DEFUN (bgp_bestpath_compare_router_id,
3748 bgp_bestpath_compare_router_id_cmd,
3749 "bgp bestpath compare-routerid",
e9273987 3750 BGP_STR
1ca2fd11
IR
3751 "Change the default bestpath selection\n"
3752 "Compare router-id for identical EBGP paths\n")
718e3744 3753{
1ca2fd11
IR
3754 VTY_DECLVAR_CONTEXT(bgp, bgp);
3755 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3756 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3757
1ca2fd11 3758 return CMD_SUCCESS;
718e3744 3759}
3760
1ca2fd11
IR
3761DEFUN (no_bgp_bestpath_compare_router_id,
3762 no_bgp_bestpath_compare_router_id_cmd,
3763 "no bgp bestpath compare-routerid",
3764 NO_STR
e9273987 3765 BGP_STR
1ca2fd11
IR
3766 "Change the default bestpath selection\n"
3767 "Compare router-id for identical EBGP paths\n")
718e3744 3768{
1ca2fd11
IR
3769 VTY_DECLVAR_CONTEXT(bgp, bgp);
3770 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3771 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3772
1ca2fd11 3773 return CMD_SUCCESS;
718e3744 3774}
6b0655a2 3775
718e3744 3776/* "bgp bestpath as-path ignore" configuration. */
1ca2fd11
IR
3777DEFUN (bgp_bestpath_aspath_ignore,
3778 bgp_bestpath_aspath_ignore_cmd,
3779 "bgp bestpath as-path ignore",
e9273987 3780 BGP_STR
1ca2fd11
IR
3781 "Change the default bestpath selection\n"
3782 "AS-path attribute\n"
3783 "Ignore as-path length in selecting a route\n")
718e3744 3784{
1ca2fd11
IR
3785 VTY_DECLVAR_CONTEXT(bgp, bgp);
3786 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3787 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3788
1ca2fd11 3789 return CMD_SUCCESS;
718e3744 3790}
3791
1ca2fd11
IR
3792DEFUN (no_bgp_bestpath_aspath_ignore,
3793 no_bgp_bestpath_aspath_ignore_cmd,
3794 "no bgp bestpath as-path ignore",
3795 NO_STR
e9273987 3796 BGP_STR
1ca2fd11
IR
3797 "Change the default bestpath selection\n"
3798 "AS-path attribute\n"
3799 "Ignore as-path length in selecting a route\n")
718e3744 3800{
1ca2fd11
IR
3801 VTY_DECLVAR_CONTEXT(bgp, bgp);
3802 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3803 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3804
1ca2fd11 3805 return CMD_SUCCESS;
718e3744 3806}
6b0655a2 3807
6811845b 3808/* "bgp bestpath as-path confed" configuration. */
1ca2fd11 3809DEFUN (bgp_bestpath_aspath_confed,
6811845b 3810 bgp_bestpath_aspath_confed_cmd,
3811 "bgp bestpath as-path confed",
e9273987 3812 BGP_STR
6811845b 3813 "Change the default bestpath selection\n"
3814 "AS-path attribute\n"
3815 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3816{
1ca2fd11
IR
3817 VTY_DECLVAR_CONTEXT(bgp, bgp);
3818 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3819 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3820
1ca2fd11 3821 return CMD_SUCCESS;
6811845b 3822}
3823
1ca2fd11 3824DEFUN (no_bgp_bestpath_aspath_confed,
6811845b 3825 no_bgp_bestpath_aspath_confed_cmd,
3826 "no bgp bestpath as-path confed",
3827 NO_STR
e9273987 3828 BGP_STR
6811845b 3829 "Change the default bestpath selection\n"
3830 "AS-path attribute\n"
3831 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3832{
1ca2fd11
IR
3833 VTY_DECLVAR_CONTEXT(bgp, bgp);
3834 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3835 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3836
1ca2fd11 3837 return CMD_SUCCESS;
6811845b 3838}
6b0655a2 3839
2fdd455c 3840/* "bgp bestpath as-path multipath-relax" configuration. */
1ca2fd11 3841DEFUN (bgp_bestpath_aspath_multipath_relax,
2fdd455c 3842 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3843 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
e9273987 3844 BGP_STR
16fc1eec
DS
3845 "Change the default bestpath selection\n"
3846 "AS-path attribute\n"
3847 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3848 "Generate an AS_SET\n"
16fc1eec
DS
3849 "Do not generate an AS_SET\n")
3850{
1ca2fd11 3851 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 3852 int idx = 0;
1ca2fd11 3853 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6 3854
1ca2fd11
IR
3855 /* no-as-set is now the default behavior so we can silently
3856 * ignore it */
d62a17ae 3857 if (argv_find(argv, argc, "as-set", &idx))
1ca2fd11 3858 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
d62a17ae 3859 else
1ca2fd11 3860 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
7aafcaca 3861
1ca2fd11
IR
3862 bgp_recalculate_all_bestpaths(bgp);
3863
3864 return CMD_SUCCESS;
16fc1eec
DS
3865}
3866
1ca2fd11 3867DEFUN (no_bgp_bestpath_aspath_multipath_relax,
219178b6 3868 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3869 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec 3870 NO_STR
e9273987 3871 BGP_STR
16fc1eec
DS
3872 "Change the default bestpath selection\n"
3873 "AS-path attribute\n"
3874 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3875 "Generate an AS_SET\n"
16fc1eec
DS
3876 "Do not generate an AS_SET\n")
3877{
1ca2fd11
IR
3878 VTY_DECLVAR_CONTEXT(bgp, bgp);
3879 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3880 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3881 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3882
1ca2fd11 3883 return CMD_SUCCESS;
2fdd455c 3884}
6b0655a2 3885
ee88563a
JM
3886/* "bgp bestpath peer-type multipath-relax" configuration. */
3887DEFUN(bgp_bestpath_peer_type_multipath_relax,
3888 bgp_bestpath_peer_type_multipath_relax_cmd,
3889 "bgp bestpath peer-type multipath-relax",
3890 BGP_STR
3891 "Change the default bestpath selection\n"
3892 "Peer type\n"
3893 "Allow load sharing across routes learned from different peer types\n")
3894{
3895 VTY_DECLVAR_CONTEXT(bgp, bgp);
3896 SET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3897 bgp_recalculate_all_bestpaths(bgp);
3898
3899 return CMD_SUCCESS;
3900}
3901
3902DEFUN(no_bgp_bestpath_peer_type_multipath_relax,
3903 no_bgp_bestpath_peer_type_multipath_relax_cmd,
3904 "no bgp bestpath peer-type multipath-relax",
3905 NO_STR BGP_STR
3906 "Change the default bestpath selection\n"
3907 "Peer type\n"
3908 "Allow load sharing across routes learned from different peer types\n")
3909{
3910 VTY_DECLVAR_CONTEXT(bgp, bgp);
3911 UNSET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3912 bgp_recalculate_all_bestpaths(bgp);
3913
3914 return CMD_SUCCESS;
3915}
3916
848973c7 3917/* "bgp log-neighbor-changes" configuration. */
1ca2fd11
IR
3918DEFUN (bgp_log_neighbor_changes,
3919 bgp_log_neighbor_changes_cmd,
3920 "bgp log-neighbor-changes",
e9273987 3921 BGP_STR
1ca2fd11 3922 "Log neighbor up/down and reset reason\n")
848973c7 3923{
1ca2fd11
IR
3924 VTY_DECLVAR_CONTEXT(bgp, bgp);
3925 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3926 return CMD_SUCCESS;
848973c7 3927}
3928
1ca2fd11
IR
3929DEFUN (no_bgp_log_neighbor_changes,
3930 no_bgp_log_neighbor_changes_cmd,
3931 "no bgp log-neighbor-changes",
3932 NO_STR
e9273987 3933 BGP_STR
1ca2fd11 3934 "Log neighbor up/down and reset reason\n")
848973c7 3935{
1ca2fd11
IR
3936 VTY_DECLVAR_CONTEXT(bgp, bgp);
3937 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3938 return CMD_SUCCESS;
848973c7 3939}
6b0655a2 3940
718e3744 3941/* "bgp bestpath med" configuration. */
1ca2fd11 3942DEFUN (bgp_bestpath_med,
718e3744 3943 bgp_bestpath_med_cmd,
2d8c1a4d 3944 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
e9273987 3945 BGP_STR
718e3744 3946 "Change the default bestpath selection\n"
3947 "MED attribute\n"
3948 "Compare MED among confederation paths\n"
838758ac
DW
3949 "Treat missing MED as the least preferred one\n"
3950 "Treat missing MED as the least preferred one\n"
3951 "Compare MED among confederation paths\n")
718e3744 3952{
1ca2fd11 3953 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 3954
1ca2fd11 3955 int idx = 0;
d62a17ae 3956 if (argv_find(argv, argc, "confed", &idx))
1ca2fd11 3957 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
d62a17ae 3958 idx = 0;
3959 if (argv_find(argv, argc, "missing-as-worst", &idx))
1ca2fd11 3960 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
e52702f2 3961
1ca2fd11 3962 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3963
1ca2fd11 3964 return CMD_SUCCESS;
718e3744 3965}
3966
1ca2fd11 3967DEFUN (no_bgp_bestpath_med,
718e3744 3968 no_bgp_bestpath_med_cmd,
2d8c1a4d 3969 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 3970 NO_STR
e9273987 3971 BGP_STR
718e3744 3972 "Change the default bestpath selection\n"
3973 "MED attribute\n"
3974 "Compare MED among confederation paths\n"
3a2d747c
QY
3975 "Treat missing MED as the least preferred one\n"
3976 "Treat missing MED as the least preferred one\n"
3977 "Compare MED among confederation paths\n")
718e3744 3978{
1ca2fd11 3979 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 3980
1ca2fd11 3981 int idx = 0;
d62a17ae 3982 if (argv_find(argv, argc, "confed", &idx))
1ca2fd11 3983 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
d62a17ae 3984 idx = 0;
3985 if (argv_find(argv, argc, "missing-as-worst", &idx))
1ca2fd11
IR
3986 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3987
3988 bgp_recalculate_all_bestpaths(bgp);
718e3744 3989
1ca2fd11 3990 return CMD_SUCCESS;
718e3744 3991}
3992
f7e1c681 3993/* "bgp bestpath bandwidth" configuration. */
3994DEFPY (bgp_bestpath_bw,
3995 bgp_bestpath_bw_cmd,
ad36d216 3996 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
e9273987 3997 BGP_STR
f7e1c681 3998 "Change the default bestpath selection\n"
3999 "Link Bandwidth attribute\n"
4000 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
4001 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
4002 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
4003{
4004 VTY_DECLVAR_CONTEXT(bgp, bgp);
4005 afi_t afi;
4006 safi_t safi;
4007
ad36d216
DS
4008 if (!bw_cfg) {
4009 vty_out(vty, "%% Bandwidth configuration must be specified\n");
4010 return CMD_ERR_INCOMPLETE;
f7e1c681 4011 }
ad36d216
DS
4012 if (!strcmp(bw_cfg, "ignore"))
4013 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
4014 else if (!strcmp(bw_cfg, "skip-missing"))
4015 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
4016 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
4017 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
4018 else
4019 return CMD_ERR_NO_MATCH;
f7e1c681 4020
4021 /* This config is used in route install, so redo that. */
4022 FOREACH_AFI_SAFI (afi, safi) {
4023 if (!bgp_fibupd_safi(safi))
4024 continue;
4025 bgp_zebra_announce_table(bgp, afi, safi);
4026 }
4027
4028 return CMD_SUCCESS;
4029}
4030
ad36d216
DS
4031DEFPY (no_bgp_bestpath_bw,
4032 no_bgp_bestpath_bw_cmd,
4033 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
4034 NO_STR
e9273987 4035 BGP_STR
ad36d216
DS
4036 "Change the default bestpath selection\n"
4037 "Link Bandwidth attribute\n"
4038 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
4039 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
4040 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
4041{
4042 VTY_DECLVAR_CONTEXT(bgp, bgp);
4043 afi_t afi;
4044 safi_t safi;
4045
4046 bgp->lb_handling = BGP_LINK_BW_ECMP;
4047
4048 /* This config is used in route install, so redo that. */
4049 FOREACH_AFI_SAFI (afi, safi) {
4050 if (!bgp_fibupd_safi(safi))
4051 continue;
4052 bgp_zebra_announce_table(bgp, afi, safi);
4053 }
4054 return CMD_SUCCESS;
4055}
4056
b16bcbba 4057DEFPY(bgp_default_afi_safi, bgp_default_afi_safi_cmd,
38d11af5
TA
4058 "[no] bgp default <ipv4-unicast|"
4059 "ipv4-multicast|"
4060 "ipv4-vpn|"
4061 "ipv4-labeled-unicast|"
4062 "ipv4-flowspec|"
4063 "ipv6-unicast|"
4064 "ipv6-multicast|"
4065 "ipv6-vpn|"
4066 "ipv6-labeled-unicast|"
4067 "ipv6-flowspec|"
4068 "l2vpn-evpn>$afi_safi",
b16bcbba 4069 NO_STR
e9273987 4070 BGP_STR
e84c59af 4071 "Configure BGP defaults\n"
b16bcbba 4072 "Activate ipv4-unicast for a peer by default\n"
38d11af5
TA
4073 "Activate ipv4-multicast for a peer by default\n"
4074 "Activate ipv4-vpn for a peer by default\n"
4075 "Activate ipv4-labeled-unicast for a peer by default\n"
4076 "Activate ipv4-flowspec for a peer by default\n"
4077 "Activate ipv6-unicast for a peer by default\n"
4078 "Activate ipv6-multicast for a peer by default\n"
4079 "Activate ipv6-vpn for a peer by default\n"
4080 "Activate ipv6-labeled-unicast for a peer by default\n"
4081 "Activate ipv6-flowspec for a peer by default\n"
4082 "Activate l2vpn-evpn for a peer by default\n")
e84c59af
DA
4083{
4084 VTY_DECLVAR_CONTEXT(bgp, bgp);
b16bcbba
TA
4085 char afi_safi_str[strlen(afi_safi) + 1];
4086 char *afi_safi_str_tok;
e84c59af 4087
b16bcbba
TA
4088 strlcpy(afi_safi_str, afi_safi, sizeof(afi_safi_str));
4089 char *afi_str = strtok_r(afi_safi_str, "-", &afi_safi_str_tok);
4090 char *safi_str = strtok_r(NULL, "-", &afi_safi_str_tok);
4091 afi_t afi = bgp_vty_afi_from_str(afi_str);
38d11af5 4092 safi_t safi;
e84c59af 4093
d880a643
DS
4094 /*
4095 * Impossible situation but making coverity happy
4096 */
4097 assert(afi != AFI_MAX);
4098
38d11af5
TA
4099 if (strmatch(safi_str, "labeled"))
4100 safi = bgp_vty_safi_from_str("labeled-unicast");
4101 else
4102 safi = bgp_vty_safi_from_str(safi_str);
b16bcbba 4103
f609bcd6 4104 assert(safi != SAFI_MAX);
b16bcbba
TA
4105 if (no)
4106 bgp->default_af[afi][safi] = false;
38d11af5
TA
4107 else {
4108 if ((safi == SAFI_LABELED_UNICAST
4109 && bgp->default_af[afi][SAFI_UNICAST])
4110 || (safi == SAFI_UNICAST
4111 && bgp->default_af[afi][SAFI_LABELED_UNICAST]))
4112 bgp_vty_return(vty, BGP_ERR_PEER_SAFI_CONFLICT);
4113 else
4114 bgp->default_af[afi][safi] = true;
4115 }
718e3744 4116
d62a17ae 4117 return CMD_SUCCESS;
718e3744 4118}
6b0655a2 4119
04b6bdc0 4120/* Display hostname in certain command outputs */
1ca2fd11 4121DEFUN (bgp_default_show_hostname,
04b6bdc0
DW
4122 bgp_default_show_hostname_cmd,
4123 "bgp default show-hostname",
e9273987 4124 BGP_STR
04b6bdc0 4125 "Configure BGP defaults\n"
0437e105 4126 "Show hostname in certain command outputs\n")
04b6bdc0 4127{
1ca2fd11
IR
4128 VTY_DECLVAR_CONTEXT(bgp, bgp);
4129 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
4130 return CMD_SUCCESS;
ff8a8a7a
CS
4131}
4132
1ca2fd11
IR
4133DEFUN (no_bgp_default_show_hostname,
4134 no_bgp_default_show_hostname_cmd,
4135 "no bgp default show-hostname",
4136 NO_STR
e9273987 4137 BGP_STR
1ca2fd11
IR
4138 "Configure BGP defaults\n"
4139 "Show hostname in certain command outputs\n")
ff8a8a7a 4140{
1ca2fd11
IR
4141 VTY_DECLVAR_CONTEXT(bgp, bgp);
4142 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
4143 return CMD_SUCCESS;
04b6bdc0
DW
4144}
4145
aef999a2 4146/* Display hostname in certain command outputs */
1d80f243
IR
4147DEFUN (bgp_default_show_nexthop_hostname,
4148 bgp_default_show_nexthop_hostname_cmd,
4149 "bgp default show-nexthop-hostname",
e9273987 4150 BGP_STR
1d80f243
IR
4151 "Configure BGP defaults\n"
4152 "Show hostname for nexthop in certain command outputs\n")
aef999a2 4153{
1ca2fd11
IR
4154 VTY_DECLVAR_CONTEXT(bgp, bgp);
4155 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
4156 return CMD_SUCCESS;
aef999a2
DA
4157}
4158
4159DEFUN (no_bgp_default_show_nexthop_hostname,
4160 no_bgp_default_show_nexthop_hostname_cmd,
4161 "no bgp default show-nexthop-hostname",
4162 NO_STR
e9273987 4163 BGP_STR
aef999a2
DA
4164 "Configure BGP defaults\n"
4165 "Show hostname for nexthop in certain command outputs\n")
4166{
1ca2fd11
IR
4167 VTY_DECLVAR_CONTEXT(bgp, bgp);
4168 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
4169 return CMD_SUCCESS;
aef999a2
DA
4170}
4171
8233ef81 4172/* "bgp network import-check" configuration. */
1ca2fd11
IR
4173DEFUN (bgp_network_import_check,
4174 bgp_network_import_check_cmd,
4175 "bgp network import-check",
e9273987 4176 BGP_STR
1ca2fd11
IR
4177 "BGP network command\n"
4178 "Check BGP network route exists in IGP\n")
718e3744 4179{
1ca2fd11
IR
4180 VTY_DECLVAR_CONTEXT(bgp, bgp);
4181 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
4182 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
4183 bgp_static_redo_import_check(bgp);
4184 }
078430f6 4185
1ca2fd11 4186 return CMD_SUCCESS;
718e3744 4187}
4188
d62a17ae 4189ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
4190 "bgp network import-check exact",
e9273987 4191 BGP_STR
d62a17ae 4192 "BGP network command\n"
4193 "Check BGP network route exists in IGP\n"
4194 "Match route precisely\n")
8233ef81 4195
1ca2fd11
IR
4196DEFUN (no_bgp_network_import_check,
4197 no_bgp_network_import_check_cmd,
4198 "no bgp network import-check",
4199 NO_STR
e9273987 4200 BGP_STR
1ca2fd11
IR
4201 "BGP network command\n"
4202 "Check BGP network route exists in IGP\n")
718e3744 4203{
1ca2fd11
IR
4204 VTY_DECLVAR_CONTEXT(bgp, bgp);
4205 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
4206 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
4207 bgp_static_redo_import_check(bgp);
4208 }
6b0655a2 4209
1ca2fd11 4210 return CMD_SUCCESS;
ff8a8a7a 4211}
718e3744 4212
1ca2fd11
IR
4213DEFUN (bgp_default_local_preference,
4214 bgp_default_local_preference_cmd,
4215 "bgp default local-preference (0-4294967295)",
e9273987 4216 BGP_STR
1ca2fd11
IR
4217 "Configure BGP defaults\n"
4218 "local preference (higher=more preferred)\n"
4219 "Configure default local preference value\n")
ff8a8a7a 4220{
1ca2fd11 4221 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 4222 int idx_number = 3;
1ca2fd11 4223 uint32_t local_pref;
718e3744 4224
1ca2fd11 4225 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 4226
1ca2fd11
IR
4227 bgp_default_local_preference_set(bgp, local_pref);
4228 bgp_clear_star_soft_in(vty, bgp->name);
718e3744 4229
1ca2fd11 4230 return CMD_SUCCESS;
718e3744 4231}
4232
1ca2fd11
IR
4233DEFUN (no_bgp_default_local_preference,
4234 no_bgp_default_local_preference_cmd,
4235 "no bgp default local-preference [(0-4294967295)]",
4236 NO_STR
e9273987 4237 BGP_STR
1ca2fd11
IR
4238 "Configure BGP defaults\n"
4239 "local preference (higher=more preferred)\n"
4240 "Configure default local preference value\n")
ff8a8a7a 4241{
1ca2fd11
IR
4242 VTY_DECLVAR_CONTEXT(bgp, bgp);
4243 bgp_default_local_preference_unset(bgp);
4244 bgp_clear_star_soft_in(vty, bgp->name);
4245
4246 return CMD_SUCCESS;
ff8a8a7a 4247}
6b0655a2 4248
ff8a8a7a 4249
1ca2fd11
IR
4250DEFUN (bgp_default_subgroup_pkt_queue_max,
4251 bgp_default_subgroup_pkt_queue_max_cmd,
4252 "bgp default subgroup-pkt-queue-max (20-100)",
e9273987 4253 BGP_STR
1ca2fd11
IR
4254 "Configure BGP defaults\n"
4255 "subgroup-pkt-queue-max\n"
4256 "Configure subgroup packet queue max\n")
8bd9d948 4257{
1ca2fd11 4258 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4259 int idx_number = 3;
1ca2fd11 4260 uint32_t max_size;
3f9c7369 4261
1ca2fd11 4262 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3f9c7369 4263
1ca2fd11 4264 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
ff8a8a7a 4265
1ca2fd11 4266 return CMD_SUCCESS;
8bd9d948
DS
4267}
4268
1ca2fd11
IR
4269DEFUN (no_bgp_default_subgroup_pkt_queue_max,
4270 no_bgp_default_subgroup_pkt_queue_max_cmd,
4271 "no bgp default subgroup-pkt-queue-max [(20-100)]",
4272 NO_STR
e9273987 4273 BGP_STR
1ca2fd11
IR
4274 "Configure BGP defaults\n"
4275 "subgroup-pkt-queue-max\n"
4276 "Configure subgroup packet queue max\n")
ff8a8a7a 4277{
1ca2fd11
IR
4278 VTY_DECLVAR_CONTEXT(bgp, bgp);
4279 bgp_default_subgroup_pkt_queue_max_unset(bgp);
4280 return CMD_SUCCESS;
ff8a8a7a 4281}
813d4307 4282
8bd9d948 4283
1ca2fd11
IR
4284DEFUN (bgp_rr_allow_outbound_policy,
4285 bgp_rr_allow_outbound_policy_cmd,
4286 "bgp route-reflector allow-outbound-policy",
e9273987 4287 BGP_STR
1ca2fd11
IR
4288 "Allow modifications made by out route-map\n"
4289 "on ibgp neighbors\n")
ff8a8a7a 4290{
1ca2fd11 4291 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 4292
1ca2fd11
IR
4293 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4294 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4295 update_group_announce_rrclients(bgp);
4296 bgp_clear_star_soft_out(vty, bgp->name);
4297 }
8bd9d948 4298
1ca2fd11
IR
4299 return CMD_SUCCESS;
4300}
ff8a8a7a 4301
1ca2fd11
IR
4302DEFUN (no_bgp_rr_allow_outbound_policy,
4303 no_bgp_rr_allow_outbound_policy_cmd,
4304 "no bgp route-reflector allow-outbound-policy",
4305 NO_STR
e9273987 4306 BGP_STR
1ca2fd11
IR
4307 "Allow modifications made by out route-map\n"
4308 "on ibgp neighbors\n")
8bd9d948 4309{
1ca2fd11 4310 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 4311
1ca2fd11
IR
4312 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4313 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4314 update_group_announce_rrclients(bgp);
4315 bgp_clear_star_soft_out(vty, bgp->name);
d62a17ae 4316 }
8bd9d948 4317
1ca2fd11 4318 return CMD_SUCCESS;
8bd9d948
DS
4319}
4320
1ca2fd11
IR
4321DEFUN (bgp_listen_limit,
4322 bgp_listen_limit_cmd,
4323 "bgp listen limit (1-65535)",
e9273987 4324 BGP_STR
1ca2fd11
IR
4325 "BGP Dynamic Neighbors listen commands\n"
4326 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4327 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 4328{
1ca2fd11 4329 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4330 int idx_number = 3;
1ca2fd11
IR
4331 int listen_limit;
4332
4333 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
f14e6fdb 4334
1ca2fd11 4335 bgp_listen_limit_set(bgp, listen_limit);
f14e6fdb 4336
1ca2fd11 4337 return CMD_SUCCESS;
f14e6fdb
DS
4338}
4339
1ca2fd11
IR
4340DEFUN (no_bgp_listen_limit,
4341 no_bgp_listen_limit_cmd,
4342 "no bgp listen limit [(1-65535)]",
4343 NO_STR
e9273987 4344 BGP_STR
1ca2fd11
IR
4345 "BGP Dynamic Neighbors listen commands\n"
4346 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4347 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 4348{
1ca2fd11
IR
4349 VTY_DECLVAR_CONTEXT(bgp, bgp);
4350 bgp_listen_limit_unset(bgp);
4351 return CMD_SUCCESS;
f14e6fdb
DS
4352}
4353
4354
20eb8864 4355/*
4356 * Check if this listen range is already configured. Check for exact
4357 * match or overlap based on input.
4358 */
d62a17ae 4359static struct peer_group *listen_range_exists(struct bgp *bgp,
4360 struct prefix *range, int exact)
4361{
4362 struct listnode *node, *nnode;
4363 struct listnode *node1, *nnode1;
4364 struct peer_group *group;
4365 struct prefix *lr;
4366 afi_t afi;
4367 int match;
4368
4369 afi = family2afi(range->family);
4370 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4371 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
4372 lr)) {
4373 if (exact)
4374 match = prefix_same(range, lr);
4375 else
4376 match = (prefix_match(range, lr)
4377 || prefix_match(lr, range));
4378 if (match)
4379 return group;
4380 }
4381 }
4382
4383 return NULL;
20eb8864 4384}
4385
f14e6fdb
DS
4386DEFUN (bgp_listen_range,
4387 bgp_listen_range_cmd,
d7b9898c 4388 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
e9273987 4389 BGP_STR
d7fa34c1
QY
4390 "Configure BGP dynamic neighbors listen range\n"
4391 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
4392 NEIGHBOR_ADDR_STR
4393 "Member of the peer-group\n"
4394 "Peer-group name\n")
f14e6fdb 4395{
d62a17ae 4396 VTY_DECLVAR_CONTEXT(bgp, bgp);
4397 struct prefix range;
4398 struct peer_group *group, *existing_group;
4399 afi_t afi;
4400 int ret;
4401 int idx = 0;
4402
4403 argv_find(argv, argc, "A.B.C.D/M", &idx);
4404 argv_find(argv, argc, "X:X::X:X/M", &idx);
4405 char *prefix = argv[idx]->arg;
d7b9898c 4406 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 4407 char *peergroup = argv[idx]->arg;
4408
4409 /* Convert IP prefix string to struct prefix. */
4410 ret = str2prefix(prefix, &range);
4411 if (!ret) {
4412 vty_out(vty, "%% Malformed listen range\n");
4413 return CMD_WARNING_CONFIG_FAILED;
4414 }
4415
4416 afi = family2afi(range.family);
4417
4418 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4419 vty_out(vty,
4420 "%% Malformed listen range (link-local address)\n");
4421 return CMD_WARNING_CONFIG_FAILED;
4422 }
4423
4424 apply_mask(&range);
4425
4426 /* Check if same listen range is already configured. */
4427 existing_group = listen_range_exists(bgp, &range, 1);
4428 if (existing_group) {
4429 if (strcmp(existing_group->name, peergroup) == 0)
4430 return CMD_SUCCESS;
4431 else {
4432 vty_out(vty,
4433 "%% Same listen range is attached to peer-group %s\n",
4434 existing_group->name);
4435 return CMD_WARNING_CONFIG_FAILED;
4436 }
4437 }
4438
4439 /* Check if an overlapping listen range exists. */
4440 if (listen_range_exists(bgp, &range, 0)) {
4441 vty_out(vty,
4442 "%% Listen range overlaps with existing listen range\n");
4443 return CMD_WARNING_CONFIG_FAILED;
4444 }
4445
4446 group = peer_group_lookup(bgp, peergroup);
4447 if (!group) {
4448 vty_out(vty, "%% Configure the peer-group first\n");
4449 return CMD_WARNING_CONFIG_FAILED;
4450 }
4451
4452 ret = peer_group_listen_range_add(group, &range);
4453 return bgp_vty_return(vty, ret);
f14e6fdb
DS
4454}
4455
4456DEFUN (no_bgp_listen_range,
4457 no_bgp_listen_range_cmd,
d7b9898c 4458 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
d7fa34c1 4459 NO_STR
e9273987 4460 BGP_STR
d7fa34c1
QY
4461 "Unconfigure BGP dynamic neighbors listen range\n"
4462 "Unconfigure BGP dynamic neighbors listen range\n"
4463 NEIGHBOR_ADDR_STR
4464 "Member of the peer-group\n"
4465 "Peer-group name\n")
f14e6fdb 4466{
d62a17ae 4467 VTY_DECLVAR_CONTEXT(bgp, bgp);
4468 struct prefix range;
4469 struct peer_group *group;
4470 afi_t afi;
4471 int ret;
4472 int idx = 0;
4473
4474 argv_find(argv, argc, "A.B.C.D/M", &idx);
4475 argv_find(argv, argc, "X:X::X:X/M", &idx);
4476 char *prefix = argv[idx]->arg;
21d88a71 4477 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 4478 char *peergroup = argv[idx]->arg;
4479
4480 /* Convert IP prefix string to struct prefix. */
4481 ret = str2prefix(prefix, &range);
4482 if (!ret) {
4483 vty_out(vty, "%% Malformed listen range\n");
4484 return CMD_WARNING_CONFIG_FAILED;
4485 }
4486
4487 afi = family2afi(range.family);
4488
4489 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4490 vty_out(vty,
4491 "%% Malformed listen range (link-local address)\n");
4492 return CMD_WARNING_CONFIG_FAILED;
4493 }
4494
4495 apply_mask(&range);
4496
4497 group = peer_group_lookup(bgp, peergroup);
4498 if (!group) {
4499 vty_out(vty, "%% Peer-group does not exist\n");
4500 return CMD_WARNING_CONFIG_FAILED;
4501 }
4502
4503 ret = peer_group_listen_range_del(group, &range);
4504 return bgp_vty_return(vty, ret);
4505}
4506
2b791107 4507void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 4508{
4509 struct peer_group *group;
4510 struct listnode *node, *nnode, *rnode, *nrnode;
4511 struct prefix *range;
4512 afi_t afi;
d62a17ae 4513
4514 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4515 vty_out(vty, " bgp listen limit %d\n",
4516 bgp->dynamic_neighbors_limit);
4517
4518 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4519 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4520 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4521 nrnode, range)) {
d62a17ae 4522 vty_out(vty,
2dbe669b
DA
4523 " bgp listen range %pFX peer-group %s\n",
4524 range, group->name);
d62a17ae 4525 }
4526 }
4527 }
f14e6fdb
DS
4528}
4529
4530
1ca2fd11
IR
4531DEFUN (bgp_disable_connected_route_check,
4532 bgp_disable_connected_route_check_cmd,
4533 "bgp disable-ebgp-connected-route-check",
e9273987 4534 BGP_STR
1ca2fd11 4535 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4536{
1ca2fd11
IR
4537 VTY_DECLVAR_CONTEXT(bgp, bgp);
4538 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4539 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 4540
1ca2fd11 4541 return CMD_SUCCESS;
907f92c8
DS
4542}
4543
1ca2fd11
IR
4544DEFUN (no_bgp_disable_connected_route_check,
4545 no_bgp_disable_connected_route_check_cmd,
4546 "no bgp disable-ebgp-connected-route-check",
4547 NO_STR
e9273987 4548 BGP_STR
1ca2fd11 4549 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4550{
1ca2fd11
IR
4551 VTY_DECLVAR_CONTEXT(bgp, bgp);
4552 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4553 bgp_clear_star_soft_in(vty, bgp->name);
d62a17ae 4554
1ca2fd11 4555 return CMD_SUCCESS;
d62a17ae 4556}
4557
4558
28c6e247
IR
4559static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
4560 const char *as_str)
4561{
4562 VTY_DECLVAR_CONTEXT(bgp, bgp);
4563 int ret;
4564 as_t as;
4565 int as_type = AS_SPECIFIED;
4566 union sockunion su;
4567
4568 if (as_str[0] == 'i') {
4569 as = 0;
4570 as_type = AS_INTERNAL;
4571 } else if (as_str[0] == 'e') {
4572 as = 0;
4573 as_type = AS_EXTERNAL;
8079a413
PG
4574 } else if (!asn_str2asn(as_str, &as))
4575 as_type = AS_UNSPECIFIED;
28c6e247 4576
8079a413
PG
4577 if (as_type == AS_UNSPECIFIED) {
4578 vty_out(vty, "%% Invalid peer AS: %s\n", as_str);
4579 return CMD_WARNING_CONFIG_FAILED;
4580 }
28c6e247
IR
4581 /* If peer is peer group or interface peer, call proper function. */
4582 ret = str2sockunion(peer_str, &su);
4583 if (ret < 0) {
4584 struct peer *peer;
4585
4586 /* Check if existing interface peer */
4587 peer = peer_lookup_by_conf_if(bgp, peer_str);
4588
de76ed8a 4589 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, as_str);
28c6e247
IR
4590
4591 /* if not interface peer, check peer-group settings */
4592 if (ret < 0 && !peer) {
de76ed8a
PG
4593 ret = peer_group_remote_as(bgp, peer_str, &as, as_type,
4594 as_str);
28c6e247
IR
4595 if (ret < 0) {
4596 vty_out(vty,
4597 "%% Create the peer-group or interface first\n");
4598 return CMD_WARNING_CONFIG_FAILED;
4599 }
4600 return CMD_SUCCESS;
4601 }
4602 } else {
4603 if (peer_address_self_check(bgp, &su)) {
4604 vty_out(vty,
4605 "%% Can not configure the local system as neighbor\n");
4606 return CMD_WARNING_CONFIG_FAILED;
4607 }
de76ed8a 4608 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, as_str);
28c6e247
IR
4609 }
4610
28c6e247
IR
4611 return bgp_vty_return(vty, ret);
4612}
4613
1ca2fd11
IR
4614DEFUN (bgp_default_shutdown,
4615 bgp_default_shutdown_cmd,
4616 "[no] bgp default shutdown",
4617 NO_STR
4618 BGP_STR
4619 "Configure BGP defaults\n"
4620 "Apply administrative shutdown to newly configured peers\n")
ff8a8a7a 4621{
1ca2fd11
IR
4622 VTY_DECLVAR_CONTEXT(bgp, bgp);
4623 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
4624 return CMD_SUCCESS;
f26845f9
QY
4625}
4626
736b68f3
DS
4627DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4628 BGP_STR
9ddf4b81 4629 "Administrative shutdown of the BGP instance\n"
736b68f3
DS
4630 "Add a shutdown message (RFC 8203)\n"
4631 "Shutdown message\n")
9cf59432 4632{
736b68f3 4633 char *msgstr = NULL;
8389c83a 4634
9cf59432
DS
4635 VTY_DECLVAR_CONTEXT(bgp, bgp);
4636
8389c83a 4637 if (argc > 3)
f80e35b6 4638 msgstr = argv_concat(argv, argc, 3);
8389c83a 4639
b776f48c
DA
4640 if (msgstr && strlen(msgstr) > BGP_ADMIN_SHUTDOWN_MSG_LEN) {
4641 vty_out(vty, "%% Shutdown message size exceeded %d\n",
4642 BGP_ADMIN_SHUTDOWN_MSG_LEN);
4643 return CMD_WARNING_CONFIG_FAILED;
4644 }
4645
8389c83a
DS
4646 bgp_shutdown_enable(bgp, msgstr);
4647 XFREE(MTYPE_TMP, msgstr);
9cf59432
DS
4648
4649 return CMD_SUCCESS;
4650}
4651
736b68f3 4652DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
9ddf4b81 4653 BGP_STR "Administrative shutdown of the BGP instance\n")
1e12ebbc
DS
4654{
4655 VTY_DECLVAR_CONTEXT(bgp, bgp);
4656
4657 bgp_shutdown_enable(bgp, NULL);
4658
4659 return CMD_SUCCESS;
4660}
8389c83a 4661
736b68f3 4662DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
9ddf4b81 4663 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
9cf59432
DS
4664{
4665 VTY_DECLVAR_CONTEXT(bgp, bgp);
4666
4667 bgp_shutdown_disable(bgp);
4668
4669 return CMD_SUCCESS;
4670}
4671
9ddf4b81 4672ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
1b6e7a88 4673 "no bgp shutdown message MSG...", NO_STR BGP_STR
9ddf4b81 4674 "Administrative shutdown of the BGP instance\n"
1b6e7a88 4675 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
1b6e7a88 4676
28c6e247
IR
4677DEFUN (neighbor_remote_as,
4678 neighbor_remote_as_cmd,
8079a413 4679 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <ASNUM|internal|external>",
28c6e247
IR
4680 NEIGHBOR_STR
4681 NEIGHBOR_ADDR_STR2
4682 "Specify a BGP neighbor\n"
4683 AS_STR
4684 "Internal BGP peer\n"
4685 "External BGP peer\n")
718e3744 4686{
d62a17ae 4687 int idx_peer = 1;
4688 int idx_remote_as = 3;
28c6e247
IR
4689 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
4690 argv[idx_remote_as]->arg);
d62a17ae 4691}
8666265e
DS
4692
4693DEFPY (bgp_allow_martian,
4694 bgp_allow_martian_cmd,
4695 "[no]$no bgp allow-martian-nexthop",
4696 NO_STR
4697 BGP_STR
4698 "Allow Martian nexthops to be received in the NLRI from a peer\n")
4699{
4700 VTY_DECLVAR_CONTEXT(bgp, bgp);
4701
4702 if (no)
4703 bgp->allow_martian = false;
4704 else
4705 bgp->allow_martian = true;
4706
4707 return CMD_SUCCESS;
4708}
4709
f852eb98
PG
4710/* Enable fast convergence of bgp sessions. If this is enabled, bgp
4711 * sessions do not wait for hold timer expiry to bring down the sessions
4712 * when nexthop becomes unreachable
4713 */
4714DEFUN(bgp_fast_convergence, bgp_fast_convergence_cmd, "bgp fast-convergence",
4715 BGP_STR "Fast convergence for bgp sessions\n")
4716{
4717 VTY_DECLVAR_CONTEXT(bgp, bgp);
4718 bgp->fast_convergence = true;
4719
4720 return CMD_SUCCESS;
4721}
4722
4723DEFUN(no_bgp_fast_convergence, no_bgp_fast_convergence_cmd,
4724 "no bgp fast-convergence",
4725 NO_STR BGP_STR "Fast convergence for bgp sessions\n")
4726{
4727 VTY_DECLVAR_CONTEXT(bgp, bgp);
4728 bgp->fast_convergence = false;
4729
4730 return CMD_SUCCESS;
4731}
d62a17ae 4732
28c6e247
IR
4733static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
4734 int v6only,
4735 const char *peer_group_name,
4736 const char *as_str)
d62a17ae 4737{
28c6e247
IR
4738 VTY_DECLVAR_CONTEXT(bgp, bgp);
4739 as_t as = 0;
4740 int as_type = AS_UNSPECIFIED;
d62a17ae 4741 struct peer *peer;
4742 struct peer_group *group;
4743 int ret = 0;
d62a17ae 4744
4745 group = peer_group_lookup(bgp, conf_if);
4746
4747 if (group) {
28c6e247
IR
4748 vty_out(vty, "%% Name conflict with peer-group \n");
4749 return CMD_WARNING_CONFIG_FAILED;
4750 }
4751
4752 if (as_str) {
4753 if (as_str[0] == 'i') {
4754 as_type = AS_INTERNAL;
4755 } else if (as_str[0] == 'e') {
4756 as_type = AS_EXTERNAL;
4757 } else {
4758 /* Get AS number. */
8079a413
PG
4759 if (asn_str2asn(as_str, &as))
4760 as_type = AS_SPECIFIED;
28c6e247 4761 }
d62a17ae 4762 }
4763
4764 peer = peer_lookup_by_conf_if(bgp, conf_if);
4765 if (peer) {
28c6e247 4766 if (as_str)
de76ed8a
PG
4767 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
4768 as_str);
d62a17ae 4769 } else {
e84c59af 4770 peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
de76ed8a 4771 NULL, true, as_str);
d62a17ae 4772
4773 if (!peer) {
28c6e247
IR
4774 vty_out(vty, "%% BGP failed to create peer\n");
4775 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4776 }
4777
4778 if (v6only)
527de3dc 4779 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4780
4781 /* Request zebra to initiate IPv6 RAs on this interface. We do
4782 * this
4783 * any unnumbered peer in order to not worry about run-time
4784 * transitions
4785 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4786 * address
4787 * gets deleted later etc.)
4788 */
4789 if (peer->ifp)
4790 bgp_zebra_initiate_radv(bgp, peer);
4791 }
4792
4793 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4794 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4795 if (v6only)
527de3dc 4796 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4797 else
527de3dc 4798 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4799
4800 /* v6only flag changed. Reset bgp seesion */
4801 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4802 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4803 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4804 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4805 } else
4806 bgp_session_reset(peer);
4807 }
4808
9fb964de
PM
4809 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4810 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4811 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
dc2f50f3 4812 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
9fb964de 4813 }
d62a17ae 4814
4815 if (peer_group_name) {
4816 group = peer_group_lookup(bgp, peer_group_name);
4817 if (!group) {
28c6e247
IR
4818 vty_out(vty, "%% Configure the peer-group first\n");
4819 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4820 }
4821
8395c1f8 4822 ret = peer_group_bind(bgp, NULL, peer, group, &as);
d62a17ae 4823 }
4824
28c6e247 4825 return bgp_vty_return(vty, ret);
a80beece
DS
4826}
4827
28c6e247
IR
4828DEFUN (neighbor_interface_config,
4829 neighbor_interface_config_cmd,
4830 "neighbor WORD interface [peer-group PGNAME]",
4831 NEIGHBOR_STR
4832 "Interface name or neighbor tag\n"
4833 "Enable BGP on interface\n"
4834 "Member of the peer-group\n"
4835 "Peer-group name\n")
4c48cf63 4836{
d62a17ae 4837 int idx_word = 1;
4838 int idx_peer_group_word = 4;
f4b8ec07 4839
d62a17ae 4840 if (argc > idx_peer_group_word)
28c6e247
IR
4841 return peer_conf_interface_get(
4842 vty, argv[idx_word]->arg, 0,
4843 argv[idx_peer_group_word]->arg, NULL);
4844 else
4845 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0,
4846 NULL, NULL);
4c48cf63
DW
4847}
4848
28c6e247
IR
4849DEFUN (neighbor_interface_config_v6only,
4850 neighbor_interface_config_v6only_cmd,
4851 "neighbor WORD interface v6only [peer-group PGNAME]",
4852 NEIGHBOR_STR
4853 "Interface name or neighbor tag\n"
4854 "Enable BGP on interface\n"
4855 "Enable BGP with v6 link-local only\n"
4856 "Member of the peer-group\n"
4857 "Peer-group name\n")
4c48cf63 4858{
d62a17ae 4859 int idx_word = 1;
4860 int idx_peer_group_word = 5;
31500417 4861
d62a17ae 4862 if (argc > idx_peer_group_word)
28c6e247
IR
4863 return peer_conf_interface_get(
4864 vty, argv[idx_word]->arg, 1,
4865 argv[idx_peer_group_word]->arg, NULL);
31500417 4866
28c6e247 4867 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL, NULL);
4c48cf63
DW
4868}
4869
a80beece 4870
28c6e247
IR
4871DEFUN (neighbor_interface_config_remote_as,
4872 neighbor_interface_config_remote_as_cmd,
8079a413 4873 "neighbor WORD interface remote-as <ASNUM|internal|external>",
28c6e247
IR
4874 NEIGHBOR_STR
4875 "Interface name or neighbor tag\n"
4876 "Enable BGP on interface\n"
4877 "Specify a BGP neighbor\n"
4878 AS_STR
4879 "Internal BGP peer\n"
4880 "External BGP peer\n")
b3a39dc5 4881{
d62a17ae 4882 int idx_word = 1;
4883 int idx_remote_as = 4;
28c6e247
IR
4884 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0, NULL,
4885 argv[idx_remote_as]->arg);
b3a39dc5
DD
4886}
4887
28c6e247
IR
4888DEFUN (neighbor_interface_v6only_config_remote_as,
4889 neighbor_interface_v6only_config_remote_as_cmd,
8079a413 4890 "neighbor WORD interface v6only remote-as <ASNUM|internal|external>",
28c6e247
IR
4891 NEIGHBOR_STR
4892 "Interface name or neighbor tag\n"
4893 "Enable BGP with v6 link-local only\n"
4894 "Enable BGP on interface\n"
4895 "Specify a BGP neighbor\n"
4896 AS_STR
4897 "Internal BGP peer\n"
4898 "External BGP peer\n")
b3a39dc5 4899{
d62a17ae 4900 int idx_word = 1;
4901 int idx_remote_as = 5;
28c6e247
IR
4902 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL,
4903 argv[idx_remote_as]->arg);
b3a39dc5
DD
4904}
4905
28c6e247
IR
4906DEFUN (neighbor_peer_group,
4907 neighbor_peer_group_cmd,
4908 "neighbor WORD peer-group",
4909 NEIGHBOR_STR
4910 "Interface name or neighbor tag\n"
4911 "Configure peer-group\n")
718e3744 4912{
28c6e247 4913 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4914 int idx_word = 1;
28c6e247
IR
4915 struct peer *peer;
4916 struct peer_group *group;
718e3744 4917
28c6e247
IR
4918 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4919 if (peer) {
4920 vty_out(vty, "%% Name conflict with interface: \n");
4921 return CMD_WARNING_CONFIG_FAILED;
4922 }
718e3744 4923
28c6e247
IR
4924 group = peer_group_get(bgp, argv[idx_word]->arg);
4925 if (!group) {
4926 vty_out(vty, "%% BGP failed to find or create peer-group\n");
4927 return CMD_WARNING_CONFIG_FAILED;
4928 }
718e3744 4929
28c6e247 4930 return CMD_SUCCESS;
718e3744 4931}
4932
1d80f243
IR
4933DEFUN (no_neighbor,
4934 no_neighbor_cmd,
4935 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4936 NO_STR
4937 NEIGHBOR_STR
4938 NEIGHBOR_ADDR_STR2
4939 "Specify a BGP neighbor\n"
4940 AS_STR
4941 "Internal BGP peer\n"
4942 "External BGP peer\n")
718e3744 4943{
28c6e247 4944 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4945 int idx_peer = 2;
28c6e247 4946 int ret;
d62a17ae 4947 union sockunion su;
28c6e247
IR
4948 struct peer_group *group;
4949 struct peer *peer;
4950 struct peer *other;
d62a17ae 4951
28c6e247
IR
4952 ret = str2sockunion(argv[idx_peer]->arg, &su);
4953 if (ret < 0) {
4954 /* look up for neighbor by interface name config. */
4955 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4956 if (peer) {
4957 /* Request zebra to terminate IPv6 RAs on this
4958 * interface. */
4959 if (peer->ifp)
4960 bgp_zebra_terminate_radv(peer->bgp, peer);
4961 peer_notify_unconfig(peer);
4962 peer_delete(peer);
4963 return CMD_SUCCESS;
d62a17ae 4964 }
28c6e247
IR
4965
4966 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4967 if (group) {
4968 peer_group_notify_unconfig(group);
4969 peer_group_delete(group);
4e2786df 4970 } else {
28c6e247 4971 vty_out(vty, "%% Create the peer-group first\n");
d62a17ae 4972 return CMD_WARNING_CONFIG_FAILED;
4973 }
28c6e247
IR
4974 } else {
4975 peer = peer_lookup(bgp, &su);
4976 if (peer) {
4977 if (peer_dynamic_neighbor(peer)) {
4978 vty_out(vty,
4979 "%% Operation not allowed on a dynamic neighbor\n");
4980 return CMD_WARNING_CONFIG_FAILED;
4981 }
d62a17ae 4982
28c6e247 4983 other = peer->doppelganger;
f4b8ec07 4984
28c6e247
IR
4985 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4986 bgp_zebra_terminate_radv(peer->bgp, peer);
f4b8ec07 4987
28c6e247
IR
4988 peer_notify_unconfig(peer);
4989 peer_delete(peer);
4990 if (other && other->status != Deleted) {
4991 peer_notify_unconfig(other);
4992 peer_delete(other);
4993 }
4994 }
4995 }
4996
4997 return CMD_SUCCESS;
a80beece
DS
4998}
4999
28c6e247
IR
5000DEFUN (no_neighbor_interface_config,
5001 no_neighbor_interface_config_cmd,
5002 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
5003 NO_STR
5004 NEIGHBOR_STR
5005 "Interface name\n"
5006 "Configure BGP on interface\n"
5007 "Enable BGP with v6 link-local only\n"
5008 "Member of the peer-group\n"
5009 "Peer-group name\n"
5010 "Specify a BGP neighbor\n"
5011 AS_STR
5012 "Internal BGP peer\n"
5013 "External BGP peer\n")
718e3744 5014{
28c6e247 5015 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 5016 int idx_word = 2;
28c6e247 5017 struct peer *peer;
718e3744 5018
28c6e247
IR
5019 /* look up for neighbor by interface name config. */
5020 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
5021 if (peer) {
5022 /* Request zebra to terminate IPv6 RAs on this interface. */
5023 if (peer->ifp)
5024 bgp_zebra_terminate_radv(peer->bgp, peer);
5025 peer_notify_unconfig(peer);
5026 peer_delete(peer);
5027 } else {
5028 vty_out(vty, "%% Create the bgp interface first\n");
5029 return CMD_WARNING_CONFIG_FAILED;
5030 }
5031 return CMD_SUCCESS;
718e3744 5032}
5033
28c6e247
IR
5034DEFUN (no_neighbor_peer_group,
5035 no_neighbor_peer_group_cmd,
5036 "no neighbor WORD peer-group",
5037 NO_STR
5038 NEIGHBOR_STR
5039 "Neighbor tag\n"
5040 "Configure peer-group\n")
718e3744 5041{
28c6e247
IR
5042 VTY_DECLVAR_CONTEXT(bgp, bgp);
5043 int idx_word = 2;
5044 struct peer_group *group;
f4b8ec07 5045
28c6e247
IR
5046 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5047 if (group) {
5048 peer_group_notify_unconfig(group);
5049 peer_group_delete(group);
f4b8ec07 5050 } else {
28c6e247 5051 vty_out(vty, "%% Create the peer-group first\n");
d62a17ae 5052 return CMD_WARNING_CONFIG_FAILED;
5053 }
28c6e247
IR
5054 return CMD_SUCCESS;
5055}
f4b8ec07 5056
28c6e247
IR
5057DEFUN (no_neighbor_interface_peer_group_remote_as,
5058 no_neighbor_interface_peer_group_remote_as_cmd,
8079a413 5059 "no neighbor WORD remote-as <ASNUM|internal|external>",
28c6e247
IR
5060 NO_STR
5061 NEIGHBOR_STR
5062 "Interface name or neighbor tag\n"
5063 "Specify a BGP neighbor\n"
5064 AS_STR
5065 "Internal BGP peer\n"
5066 "External BGP peer\n")
5067{
5068 VTY_DECLVAR_CONTEXT(bgp, bgp);
5069 int idx_word = 2;
5070 struct peer_group *group;
5071 struct peer *peer;
f4b8ec07 5072
28c6e247
IR
5073 /* look up for neighbor by interface name config. */
5074 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
5075 if (peer) {
de76ed8a 5076 peer_as_change(peer, 0, AS_UNSPECIFIED, NULL);
28c6e247
IR
5077 return CMD_SUCCESS;
5078 }
f4b8ec07 5079
28c6e247
IR
5080 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5081 if (group)
5082 peer_group_remote_as_delete(group);
5083 else {
5084 vty_out(vty, "%% Create the peer-group or interface first\n");
5085 return CMD_WARNING_CONFIG_FAILED;
5086 }
5087 return CMD_SUCCESS;
718e3744 5088}
6b0655a2 5089
28c6e247
IR
5090DEFUN (neighbor_local_as,
5091 neighbor_local_as_cmd,
8079a413 5092 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as ASNUM",
28c6e247
IR
5093 NEIGHBOR_STR
5094 NEIGHBOR_ADDR_STR2
5095 "Specify a local-as number\n"
8079a413 5096 "AS number expressed in dotted or plain format used as local AS\n")
718e3744 5097{
d62a17ae 5098 int idx_peer = 1;
5099 int idx_number = 3;
28c6e247
IR
5100 struct peer *peer;
5101 int ret;
5102 as_t as;
718e3744 5103
28c6e247
IR
5104 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5105 if (!peer)
d62a17ae 5106 return CMD_WARNING_CONFIG_FAILED;
718e3744 5107
8079a413
PG
5108 if (!asn_str2asn(argv[idx_number]->arg, &as)) {
5109 vty_out(vty, "%% Invalid neighbor local-as value: %s\n",
5110 argv[idx_number]->arg);
5111 return CMD_WARNING_CONFIG_FAILED;
5112 }
5113
de76ed8a 5114 ret = peer_local_as_set(peer, as, 0, 0, argv[idx_number]->arg);
28c6e247 5115 return bgp_vty_return(vty, ret);
718e3744 5116}
5117
28c6e247
IR
5118DEFUN (neighbor_local_as_no_prepend,
5119 neighbor_local_as_no_prepend_cmd,
8079a413 5120 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as ASNUM no-prepend",
28c6e247
IR
5121 NEIGHBOR_STR
5122 NEIGHBOR_ADDR_STR2
5123 "Specify a local-as number\n"
8079a413 5124 "AS number expressed in dotted or plain format used as local AS\n"
28c6e247 5125 "Do not prepend local-as to updates from ebgp peers\n")
718e3744 5126{
d62a17ae 5127 int idx_peer = 1;
5128 int idx_number = 3;
28c6e247
IR
5129 struct peer *peer;
5130 int ret;
5131 as_t as;
718e3744 5132
28c6e247
IR
5133 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5134 if (!peer)
d62a17ae 5135 return CMD_WARNING_CONFIG_FAILED;
718e3744 5136
8079a413
PG
5137 if (!asn_str2asn(argv[idx_number]->arg, &as)) {
5138 vty_out(vty, "%% Invalid neighbor local-as value: %s\n",
5139 argv[idx_number]->arg);
5140 return CMD_WARNING_CONFIG_FAILED;
5141 }
5142
de76ed8a 5143 ret = peer_local_as_set(peer, as, 1, 0, argv[idx_number]->arg);
28c6e247 5144 return bgp_vty_return(vty, ret);
718e3744 5145}
5146
28c6e247
IR
5147DEFUN (neighbor_local_as_no_prepend_replace_as,
5148 neighbor_local_as_no_prepend_replace_as_cmd,
8079a413 5149 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as ASNUM no-prepend replace-as",
28c6e247
IR
5150 NEIGHBOR_STR
5151 NEIGHBOR_ADDR_STR2
5152 "Specify a local-as number\n"
8079a413 5153 "AS number expressed in dotted or plain format used as local AS\n"
28c6e247
IR
5154 "Do not prepend local-as to updates from ebgp peers\n"
5155 "Do not prepend local-as to updates from ibgp peers\n")
9d3f9705 5156{
d62a17ae 5157 int idx_peer = 1;
5158 int idx_number = 3;
28c6e247
IR
5159 struct peer *peer;
5160 int ret;
5161 as_t as;
9d3f9705 5162
28c6e247
IR
5163 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5164 if (!peer)
d62a17ae 5165 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 5166
8079a413
PG
5167 if (!asn_str2asn(argv[idx_number]->arg, &as)) {
5168 vty_out(vty, "%% Invalid neighbor local-as value: %s\n",
5169 argv[idx_number]->arg);
5170 return CMD_WARNING_CONFIG_FAILED;
5171 }
5172
de76ed8a 5173 ret = peer_local_as_set(peer, as, 1, 1, argv[idx_number]->arg);
28c6e247 5174 return bgp_vty_return(vty, ret);
9d3f9705
AC
5175}
5176
28c6e247
IR
5177DEFUN (no_neighbor_local_as,
5178 no_neighbor_local_as_cmd,
8079a413 5179 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [ASNUM [no-prepend [replace-as]]]",
28c6e247
IR
5180 NO_STR
5181 NEIGHBOR_STR
5182 NEIGHBOR_ADDR_STR2
5183 "Specify a local-as number\n"
8079a413 5184 "AS number expressed in dotted or plain format used as local AS\n"
28c6e247
IR
5185 "Do not prepend local-as to updates from ebgp peers\n"
5186 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 5187{
d62a17ae 5188 int idx_peer = 2;
28c6e247
IR
5189 struct peer *peer;
5190 int ret;
718e3744 5191
28c6e247
IR
5192 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5193 if (!peer)
d62a17ae 5194 return CMD_WARNING_CONFIG_FAILED;
718e3744 5195
28c6e247
IR
5196 ret = peer_local_as_unset(peer);
5197 return bgp_vty_return(vty, ret);
718e3744 5198}
5199
718e3744 5200
3f9c7369
DS
5201DEFUN (neighbor_solo,
5202 neighbor_solo_cmd,
9ccf14f7 5203 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
5204 NEIGHBOR_STR
5205 NEIGHBOR_ADDR_STR2
5206 "Solo peer - part of its own update group\n")
5207{
d62a17ae 5208 int idx_peer = 1;
5209 struct peer *peer;
5210 int ret;
3f9c7369 5211
d62a17ae 5212 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5213 if (!peer)
5214 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 5215
d62a17ae 5216 ret = update_group_adjust_soloness(peer, 1);
5217 return bgp_vty_return(vty, ret);
3f9c7369
DS
5218}
5219
5220DEFUN (no_neighbor_solo,
5221 no_neighbor_solo_cmd,
9ccf14f7 5222 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
5223 NO_STR
5224 NEIGHBOR_STR
5225 NEIGHBOR_ADDR_STR2
5226 "Solo peer - part of its own update group\n")
5227{
d62a17ae 5228 int idx_peer = 2;
5229 struct peer *peer;
5230 int ret;
3f9c7369 5231
d62a17ae 5232 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5233 if (!peer)
5234 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 5235
d62a17ae 5236 ret = update_group_adjust_soloness(peer, 0);
5237 return bgp_vty_return(vty, ret);
3f9c7369
DS
5238}
5239
28c6e247
IR
5240DEFUN (neighbor_password,
5241 neighbor_password_cmd,
5242 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
5243 NEIGHBOR_STR
5244 NEIGHBOR_ADDR_STR2
5245 "Set a password\n"
5246 "The password\n")
0df7c91f 5247{
d62a17ae 5248 int idx_peer = 1;
5249 int idx_line = 3;
28c6e247
IR
5250 struct peer *peer;
5251 int ret;
0df7c91f 5252
28c6e247
IR
5253 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5254 if (!peer)
d62a17ae 5255 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 5256
28c6e247
IR
5257 ret = peer_password_set(peer, argv[idx_line]->arg);
5258 return bgp_vty_return(vty, ret);
0df7c91f
PJ
5259}
5260
28c6e247
IR
5261DEFUN (no_neighbor_password,
5262 no_neighbor_password_cmd,
5263 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
5264 NO_STR
5265 NEIGHBOR_STR
5266 NEIGHBOR_ADDR_STR2
5267 "Set a password\n"
5268 "The password\n")
0df7c91f 5269{
d62a17ae 5270 int idx_peer = 2;
28c6e247
IR
5271 struct peer *peer;
5272 int ret;
0df7c91f 5273
28c6e247
IR
5274 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5275 if (!peer)
d62a17ae 5276 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 5277
28c6e247
IR
5278 ret = peer_password_unset(peer);
5279 return bgp_vty_return(vty, ret);
0df7c91f 5280}
6b0655a2 5281
28c6e247
IR
5282DEFUN (neighbor_activate,
5283 neighbor_activate_cmd,
5284 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5285 NEIGHBOR_STR
5286 NEIGHBOR_ADDR_STR2
5287 "Enable the Address Family for this Neighbor\n")
718e3744 5288{
d62a17ae 5289 int idx_peer = 1;
28c6e247
IR
5290 int ret;
5291 struct peer *peer;
56ceae84 5292
28c6e247
IR
5293 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5294 if (!peer)
d62a17ae 5295 return CMD_WARNING_CONFIG_FAILED;
718e3744 5296
28c6e247
IR
5297 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5298 return bgp_vty_return(vty, ret);
718e3744 5299}
5300
d62a17ae 5301ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
5302 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5303 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5304 "Enable the Address Family for this Neighbor\n")
596c17ba 5305
28c6e247
IR
5306DEFUN (no_neighbor_activate,
5307 no_neighbor_activate_cmd,
5308 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5309 NO_STR
5310 NEIGHBOR_STR
5311 NEIGHBOR_ADDR_STR2
5312 "Enable the Address Family for this Neighbor\n")
718e3744 5313{
d62a17ae 5314 int idx_peer = 2;
28c6e247
IR
5315 int ret;
5316 struct peer *peer;
f4b8ec07 5317
28c6e247
IR
5318 /* Lookup peer. */
5319 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5320 if (!peer)
d62a17ae 5321 return CMD_WARNING_CONFIG_FAILED;
718e3744 5322
28c6e247
IR
5323 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5324 return bgp_vty_return(vty, ret);
718e3744 5325}
6b0655a2 5326
d62a17ae 5327ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
5328 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5329 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5330 "Enable the Address Family for this Neighbor\n")
596c17ba 5331
28c6e247
IR
5332DEFUN (neighbor_set_peer_group,
5333 neighbor_set_peer_group_cmd,
5334 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5335 NEIGHBOR_STR
5336 NEIGHBOR_ADDR_STR2
5337 "Member of the peer-group\n"
5338 "Peer-group name\n")
718e3744 5339{
28c6e247 5340 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 5341 int idx_peer = 1;
5342 int idx_word = 3;
28c6e247
IR
5343 int ret;
5344 as_t as;
5345 union sockunion su;
5346 struct peer *peer;
5347 struct peer_group *group;
5348
5349 ret = str2sockunion(argv[idx_peer]->arg, &su);
5350 if (ret < 0) {
5351 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
5352 if (!peer) {
5353 vty_out(vty, "%% Malformed address or name: %s\n",
5354 argv[idx_peer]->arg);
5355 return CMD_WARNING_CONFIG_FAILED;
5356 }
5357 } else {
5358 if (peer_address_self_check(bgp, &su)) {
5359 vty_out(vty,
5360 "%% Can not configure the local system as neighbor\n");
5361 return CMD_WARNING_CONFIG_FAILED;
5362 }
2a059a54 5363
28c6e247
IR
5364 /* Disallow for dynamic neighbor. */
5365 peer = peer_lookup(bgp, &su);
5366 if (peer && peer_dynamic_neighbor(peer)) {
5367 vty_out(vty,
5368 "%% Operation not allowed on a dynamic neighbor\n");
5369 return CMD_WARNING_CONFIG_FAILED;
5370 }
5371 }
5372
5373 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5374 if (!group) {
5375 vty_out(vty, "%% Configure the peer-group first\n");
d62a17ae 5376 return CMD_WARNING_CONFIG_FAILED;
28c6e247 5377 }
d62a17ae 5378
28c6e247 5379 ret = peer_group_bind(bgp, &su, peer, group, &as);
2a059a54 5380
28c6e247 5381 return bgp_vty_return(vty, ret);
d62a17ae 5382}
5383
5384ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
d7b9898c 5385 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 5386 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5387 "Member of the peer-group\n"
5388 "Peer-group name\n")
596c17ba 5389
28c6e247
IR
5390DEFUN (no_neighbor_set_peer_group,
5391 no_neighbor_set_peer_group_cmd,
5392 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5393 NO_STR
5394 NEIGHBOR_STR
5395 NEIGHBOR_ADDR_STR2
5396 "Member of the peer-group\n"
5397 "Peer-group name\n")
718e3744 5398{
28c6e247 5399 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 5400 int idx_peer = 2;
28c6e247
IR
5401 int idx_word = 4;
5402 int ret;
5403 struct peer *peer;
5404 struct peer_group *group;
d62a17ae 5405
28c6e247
IR
5406 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
5407 if (!peer)
d62a17ae 5408 return CMD_WARNING_CONFIG_FAILED;
b3a3290e 5409
28c6e247
IR
5410 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5411 if (!group) {
5412 vty_out(vty, "%% Configure the peer-group first\n");
5413 return CMD_WARNING_CONFIG_FAILED;
5414 }
718e3744 5415
28c6e247
IR
5416 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
5417 bgp_zebra_terminate_radv(peer->bgp, peer);
5418
5419 peer_notify_unconfig(peer);
5420 ret = peer_delete(peer);
5421
5422 return bgp_vty_return(vty, ret);
718e3744 5423}
6b0655a2 5424
d62a17ae 5425ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
71cc0c88 5426 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 5427 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5428 "Member of the peer-group\n"
5429 "Peer-group name\n")
596c17ba 5430
718e3744 5431/* neighbor passive. */
28c6e247
IR
5432DEFUN (neighbor_passive,
5433 neighbor_passive_cmd,
5434 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5435 NEIGHBOR_STR
5436 NEIGHBOR_ADDR_STR2
5437 "Don't send open messages to this neighbor\n")
718e3744 5438{
d62a17ae 5439 int idx_peer = 1;
28c6e247 5440 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 5441}
5442
28c6e247
IR
5443DEFUN (no_neighbor_passive,
5444 no_neighbor_passive_cmd,
5445 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5446 NO_STR
5447 NEIGHBOR_STR
5448 NEIGHBOR_ADDR_STR2
5449 "Don't send open messages to this neighbor\n")
718e3744 5450{
d62a17ae 5451 int idx_peer = 2;
28c6e247 5452 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 5453}
6b0655a2 5454
718e3744 5455/* neighbor shutdown. */
28c6e247
IR
5456DEFUN (neighbor_shutdown_msg,
5457 neighbor_shutdown_msg_cmd,
5458 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5459 NEIGHBOR_STR
5460 NEIGHBOR_ADDR_STR2
5461 "Administratively shut down this neighbor\n"
5462 "Add a shutdown message (RFC 8203)\n"
5463 "Shutdown message\n")
718e3744 5464{
d62a17ae 5465 int idx_peer = 1;
73d70fa6 5466
d62a17ae 5467 if (argc >= 5) {
28c6e247
IR
5468 struct peer *peer =
5469 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
d62a17ae 5470 char *message;
73d70fa6 5471
28c6e247
IR
5472 if (!peer)
5473 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5474 message = argv_concat(argv, argc, 4);
28c6e247
IR
5475 peer_tx_shutdown_message_set(peer, message);
5476 XFREE(MTYPE_TMP, message);
d62a17ae 5477 }
73d70fa6 5478
28c6e247 5479 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 5480}
5481
1d80f243 5482ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
d62a17ae 5483 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5484 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5485 "Administratively shut down this neighbor\n")
73d70fa6 5486
28c6e247
IR
5487DEFUN (no_neighbor_shutdown_msg,
5488 no_neighbor_shutdown_msg_cmd,
5489 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5490 NO_STR
5491 NEIGHBOR_STR
5492 NEIGHBOR_ADDR_STR2
5493 "Administratively shut down this neighbor\n"
5494 "Remove a shutdown message (RFC 8203)\n"
5495 "Shutdown message\n")
718e3744 5496{
d62a17ae 5497 int idx_peer = 2;
73d70fa6 5498
28c6e247
IR
5499 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5500 PEER_FLAG_SHUTDOWN);
718e3744 5501}
6b0655a2 5502
1d80f243 5503ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
d62a17ae 5504 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5505 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5506 "Administratively shut down this neighbor\n")
73d70fa6 5507
8336c896
DA
5508DEFUN(neighbor_shutdown_rtt,
5509 neighbor_shutdown_rtt_cmd,
5510 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5511 NEIGHBOR_STR
5512 NEIGHBOR_ADDR_STR2
5513 "Administratively shut down this neighbor\n"
5514 "Shutdown if round-trip-time is higher than expected\n"
5515 "Round-trip-time in milliseconds\n"
5516 "Specify the number of keepalives before shutdown\n"
5517 "The number of keepalives with higher RTT to shutdown\n")
5518{
5519 int idx_peer = 1;
5520 int idx_rtt = 4;
5521 int idx_count = 0;
5522 struct peer *peer;
5523
5524 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5525
5526 if (!peer)
5527 return CMD_WARNING_CONFIG_FAILED;
5528
5529 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5530
5531 if (argv_find(argv, argc, "count", &idx_count))
5532 peer->rtt_keepalive_conf =
5533 strtol(argv[idx_count + 1]->arg, NULL, 10);
5534
5535 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5536 PEER_FLAG_RTT_SHUTDOWN);
5537}
5538
5539DEFUN(no_neighbor_shutdown_rtt,
5540 no_neighbor_shutdown_rtt_cmd,
5541 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5542 NO_STR
5543 NEIGHBOR_STR
5544 NEIGHBOR_ADDR_STR2
5545 "Administratively shut down this neighbor\n"
5546 "Shutdown if round-trip-time is higher than expected\n"
5547 "Round-trip-time in milliseconds\n"
5548 "Specify the number of keepalives before shutdown\n"
5549 "The number of keepalives with higher RTT to shutdown\n")
5550{
5551 int idx_peer = 2;
5552 struct peer *peer;
5553
5554 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5555
5556 if (!peer)
5557 return CMD_WARNING_CONFIG_FAILED;
5558
5559 peer->rtt_expected = 0;
5560 peer->rtt_keepalive_conf = 1;
5561
5562 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5563 PEER_FLAG_RTT_SHUTDOWN);
5564}
5565
718e3744 5566/* neighbor capability dynamic. */
28c6e247
IR
5567DEFUN (neighbor_capability_dynamic,
5568 neighbor_capability_dynamic_cmd,
5569 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5570 NEIGHBOR_STR
5571 NEIGHBOR_ADDR_STR2
5572 "Advertise capability to the peer\n"
5573 "Advertise dynamic capability to this neighbor\n")
718e3744 5574{
d62a17ae 5575 int idx_peer = 1;
28c6e247
IR
5576 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5577 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 5578}
5579
28c6e247
IR
5580DEFUN (no_neighbor_capability_dynamic,
5581 no_neighbor_capability_dynamic_cmd,
5582 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5583 NO_STR
5584 NEIGHBOR_STR
5585 NEIGHBOR_ADDR_STR2
5586 "Advertise capability to the peer\n"
5587 "Advertise dynamic capability to this neighbor\n")
718e3744 5588{
d62a17ae 5589 int idx_peer = 2;
28c6e247
IR
5590 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5591 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 5592}
6b0655a2 5593
718e3744 5594/* neighbor dont-capability-negotiate */
5595DEFUN (neighbor_dont_capability_negotiate,
5596 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5597 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5598 NEIGHBOR_STR
5599 NEIGHBOR_ADDR_STR2
5600 "Do not perform capability negotiation\n")
5601{
d62a17ae 5602 int idx_peer = 1;
5603 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5604 PEER_FLAG_DONT_CAPABILITY);
718e3744 5605}
5606
5607DEFUN (no_neighbor_dont_capability_negotiate,
5608 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5609 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5610 NO_STR
5611 NEIGHBOR_STR
5612 NEIGHBOR_ADDR_STR2
5613 "Do not perform capability negotiation\n")
5614{
28c6e247
IR
5615 int idx_peer = 2;
5616 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5617 PEER_FLAG_DONT_CAPABILITY);
f4b8ec07
CS
5618}
5619
28c6e247
IR
5620/* neighbor capability extended next hop encoding */
5621DEFUN (neighbor_capability_enhe,
5622 neighbor_capability_enhe_cmd,
5623 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5624 NEIGHBOR_STR
5625 NEIGHBOR_ADDR_STR2
5626 "Advertise capability to the peer\n"
5627 "Advertise extended next-hop capability to the peer\n")
f4b8ec07 5628{
28c6e247 5629 int idx_peer = 1;
c4786405
DS
5630 struct peer *peer;
5631
5632 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5633 if (peer && peer->conf_if)
5634 return CMD_SUCCESS;
5635
28c6e247
IR
5636 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5637 PEER_FLAG_CAPABILITY_ENHE);
5638}
f4b8ec07 5639
28c6e247
IR
5640DEFUN (no_neighbor_capability_enhe,
5641 no_neighbor_capability_enhe_cmd,
5642 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5643 NO_STR
5644 NEIGHBOR_STR
5645 NEIGHBOR_ADDR_STR2
5646 "Advertise capability to the peer\n"
5647 "Advertise extended next-hop capability to the peer\n")
5648{
5649 int idx_peer = 2;
c4786405
DS
5650 struct peer *peer;
5651
5652 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5653 if (peer && peer->conf_if) {
5654 vty_out(vty,
5655 "Peer %s cannot have capability extended-nexthop turned off\n",
5656 argv[idx_peer]->arg);
5657 return CMD_WARNING_CONFIG_FAILED;
5658 }
5659
28c6e247
IR
5660 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5661 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
5662}
5663
d62a17ae 5664static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5665 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 5666 int set)
718e3744 5667{
d62a17ae 5668 int ret;
5669 struct peer *peer;
718e3744 5670
d62a17ae 5671 peer = peer_and_group_lookup_vty(vty, peer_str);
5672 if (!peer)
5673 return CMD_WARNING_CONFIG_FAILED;
718e3744 5674
d62a17ae 5675 if (set)
5676 ret = peer_af_flag_set(peer, afi, safi, flag);
5677 else
5678 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 5679
d62a17ae 5680 return bgp_vty_return(vty, ret);
718e3744 5681}
5682
d62a17ae 5683static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5684 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5685{
d62a17ae 5686 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 5687}
5688
d62a17ae 5689static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5690 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5691{
d62a17ae 5692 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 5693}
6b0655a2 5694
718e3744 5695/* neighbor capability orf prefix-list. */
5696DEFUN (neighbor_capability_orf_prefix,
5697 neighbor_capability_orf_prefix_cmd,
9ccf14f7 5698 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5699 NEIGHBOR_STR
5700 NEIGHBOR_ADDR_STR2
5701 "Advertise capability to the peer\n"
5702 "Advertise ORF capability to the peer\n"
5703 "Advertise prefixlist ORF capability to this neighbor\n"
5704 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5705 "Capability to RECEIVE the ORF from this neighbor\n"
5706 "Capability to SEND the ORF to this neighbor\n")
5707{
d62a17ae 5708 int idx_send_recv = 5;
db45f64d
DS
5709 char *peer_str = argv[1]->arg;
5710 struct peer *peer;
5711 afi_t afi = bgp_node_afi(vty);
5712 safi_t safi = bgp_node_safi(vty);
d62a17ae 5713
db45f64d
DS
5714 peer = peer_and_group_lookup_vty(vty, peer_str);
5715 if (!peer)
d62a17ae 5716 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5717
db45f64d
DS
5718 if (strmatch(argv[idx_send_recv]->text, "send"))
5719 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5720 PEER_FLAG_ORF_PREFIX_SM);
5721
5722 if (strmatch(argv[idx_send_recv]->text, "receive"))
5723 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5724 PEER_FLAG_ORF_PREFIX_RM);
5725
5726 if (strmatch(argv[idx_send_recv]->text, "both"))
5727 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5728 PEER_FLAG_ORF_PREFIX_SM)
5729 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5730 PEER_FLAG_ORF_PREFIX_RM);
5731
5732 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5733}
5734
5735ALIAS_HIDDEN(
5736 neighbor_capability_orf_prefix,
5737 neighbor_capability_orf_prefix_hidden_cmd,
5738 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5739 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5740 "Advertise capability to the peer\n"
5741 "Advertise ORF capability to the peer\n"
5742 "Advertise prefixlist ORF capability to this neighbor\n"
5743 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5744 "Capability to RECEIVE the ORF from this neighbor\n"
5745 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5746
718e3744 5747DEFUN (no_neighbor_capability_orf_prefix,
5748 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 5749 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5750 NO_STR
5751 NEIGHBOR_STR
5752 NEIGHBOR_ADDR_STR2
5753 "Advertise capability to the peer\n"
5754 "Advertise ORF capability to the peer\n"
5755 "Advertise prefixlist ORF capability to this neighbor\n"
5756 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5757 "Capability to RECEIVE the ORF from this neighbor\n"
5758 "Capability to SEND the ORF to this neighbor\n")
5759{
d62a17ae 5760 int idx_send_recv = 6;
db45f64d
DS
5761 char *peer_str = argv[2]->arg;
5762 struct peer *peer;
5763 afi_t afi = bgp_node_afi(vty);
5764 safi_t safi = bgp_node_safi(vty);
d62a17ae 5765
db45f64d
DS
5766 peer = peer_and_group_lookup_vty(vty, peer_str);
5767 if (!peer)
d62a17ae 5768 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5769
db45f64d
DS
5770 if (strmatch(argv[idx_send_recv]->text, "send"))
5771 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5772 PEER_FLAG_ORF_PREFIX_SM);
5773
5774 if (strmatch(argv[idx_send_recv]->text, "receive"))
5775 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5776 PEER_FLAG_ORF_PREFIX_RM);
5777
5778 if (strmatch(argv[idx_send_recv]->text, "both"))
5779 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5780 PEER_FLAG_ORF_PREFIX_SM)
5781 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5782 PEER_FLAG_ORF_PREFIX_RM);
5783
5784 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5785}
5786
5787ALIAS_HIDDEN(
5788 no_neighbor_capability_orf_prefix,
5789 no_neighbor_capability_orf_prefix_hidden_cmd,
5790 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5791 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5792 "Advertise capability to the peer\n"
5793 "Advertise ORF capability to the peer\n"
5794 "Advertise prefixlist ORF capability to this neighbor\n"
5795 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5796 "Capability to RECEIVE the ORF from this neighbor\n"
5797 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5798
718e3744 5799/* neighbor next-hop-self. */
28c6e247
IR
5800DEFUN (neighbor_nexthop_self,
5801 neighbor_nexthop_self_cmd,
5802 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5803 NEIGHBOR_STR
5804 NEIGHBOR_ADDR_STR2
5805 "Disable the next hop calculation for this neighbor\n")
718e3744 5806{
d62a17ae 5807 int idx_peer = 1;
28c6e247
IR
5808 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5809 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 5810}
9e7a53c1 5811
d62a17ae 5812ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5813 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5814 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5815 "Disable the next hop calculation for this neighbor\n")
596c17ba 5816
f4b8ec07 5817/* neighbor next-hop-self. */
28c6e247
IR
5818DEFUN (neighbor_nexthop_self_force,
5819 neighbor_nexthop_self_force_cmd,
5820 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5821 NEIGHBOR_STR
5822 NEIGHBOR_ADDR_STR2
5823 "Disable the next hop calculation for this neighbor\n"
5824 "Set the next hop to self for reflected routes\n")
f4b8ec07
CS
5825{
5826 int idx_peer = 1;
28c6e247
IR
5827 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5828 bgp_node_safi(vty),
5829 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 5830}
5831
d62a17ae 5832ALIAS_HIDDEN(neighbor_nexthop_self_force,
5833 neighbor_nexthop_self_force_hidden_cmd,
5834 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5835 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5836 "Disable the next hop calculation for this neighbor\n"
5837 "Set the next hop to self for reflected routes\n")
596c17ba 5838
1bc4e531
DA
5839ALIAS_HIDDEN(neighbor_nexthop_self_force,
5840 neighbor_nexthop_self_all_hidden_cmd,
5841 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5842 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5843 "Disable the next hop calculation for this neighbor\n"
5844 "Set the next hop to self for reflected routes\n")
5845
28c6e247
IR
5846DEFUN (no_neighbor_nexthop_self,
5847 no_neighbor_nexthop_self_cmd,
5848 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5849 NO_STR
5850 NEIGHBOR_STR
5851 NEIGHBOR_ADDR_STR2
5852 "Disable the next hop calculation for this neighbor\n")
718e3744 5853{
d62a17ae 5854 int idx_peer = 2;
28c6e247
IR
5855 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5856 bgp_node_afi(vty), bgp_node_safi(vty),
5857 PEER_FLAG_NEXTHOP_SELF);
718e3744 5858}
6b0655a2 5859
d62a17ae 5860ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5861 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5862 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5863 "Disable the next hop calculation for this neighbor\n")
596c17ba 5864
28c6e247
IR
5865DEFUN (no_neighbor_nexthop_self_force,
5866 no_neighbor_nexthop_self_force_cmd,
5867 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5868 NO_STR
5869 NEIGHBOR_STR
5870 NEIGHBOR_ADDR_STR2
5871 "Disable the next hop calculation for this neighbor\n"
5872 "Set the next hop to self for reflected routes\n")
88b8ed8d 5873{
d62a17ae 5874 int idx_peer = 2;
28c6e247
IR
5875 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5876 bgp_node_afi(vty), bgp_node_safi(vty),
5877 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 5878}
a538debe 5879
d62a17ae 5880ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5881 no_neighbor_nexthop_self_force_hidden_cmd,
5882 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5883 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5884 "Disable the next hop calculation for this neighbor\n"
5885 "Set the next hop to self for reflected routes\n")
596c17ba 5886
1bc4e531
DA
5887ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5888 no_neighbor_nexthop_self_all_hidden_cmd,
5889 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5890 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5891 "Disable the next hop calculation for this neighbor\n"
5892 "Set the next hop to self for reflected routes\n")
5893
c7122e14 5894/* neighbor as-override */
28c6e247
IR
5895DEFUN (neighbor_as_override,
5896 neighbor_as_override_cmd,
5897 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5898 NEIGHBOR_STR
5899 NEIGHBOR_ADDR_STR2
5900 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5901{
d62a17ae 5902 int idx_peer = 1;
28c6e247
IR
5903 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5904 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
5905}
5906
d62a17ae 5907ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5908 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5909 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5910 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5911
28c6e247
IR
5912DEFUN (no_neighbor_as_override,
5913 no_neighbor_as_override_cmd,
5914 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5915 NO_STR
5916 NEIGHBOR_STR
5917 NEIGHBOR_ADDR_STR2
5918 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5919{
d62a17ae 5920 int idx_peer = 2;
28c6e247
IR
5921 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5922 bgp_node_afi(vty), bgp_node_safi(vty),
5923 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
5924}
5925
d62a17ae 5926ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5927 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5928 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5929 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5930
718e3744 5931/* neighbor remove-private-AS. */
28c6e247
IR
5932DEFUN (neighbor_remove_private_as,
5933 neighbor_remove_private_as_cmd,
5934 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5935 NEIGHBOR_STR
5936 NEIGHBOR_ADDR_STR2
5937 "Remove private ASNs in outbound updates\n")
718e3744 5938{
d62a17ae 5939 int idx_peer = 1;
28c6e247
IR
5940 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5941 bgp_node_safi(vty),
5942 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 5943}
5944
d62a17ae 5945ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5946 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5947 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5948 "Remove private ASNs in outbound updates\n")
596c17ba 5949
28c6e247
IR
5950DEFUN (neighbor_remove_private_as_all,
5951 neighbor_remove_private_as_all_cmd,
5952 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5953 NEIGHBOR_STR
5954 NEIGHBOR_ADDR_STR2
5955 "Remove private ASNs in outbound updates\n"
5956 "Apply to all AS numbers\n")
5000f21c 5957{
d62a17ae 5958 int idx_peer = 1;
28c6e247
IR
5959 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5960 bgp_node_safi(vty),
5961 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
5962}
5963
d62a17ae 5964ALIAS_HIDDEN(neighbor_remove_private_as_all,
5965 neighbor_remove_private_as_all_hidden_cmd,
5966 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5967 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5968 "Remove private ASNs in outbound updates\n"
a0dfca37 5969 "Apply to all AS numbers\n")
596c17ba 5970
28c6e247
IR
5971DEFUN (neighbor_remove_private_as_replace_as,
5972 neighbor_remove_private_as_replace_as_cmd,
5973 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5974 NEIGHBOR_STR
5975 NEIGHBOR_ADDR_STR2
5976 "Remove private ASNs in outbound updates\n"
5977 "Replace private ASNs with our ASN in outbound updates\n")
5000f21c 5978{
d62a17ae 5979 int idx_peer = 1;
28c6e247
IR
5980 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5981 bgp_node_safi(vty),
5982 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
5983}
5984
d62a17ae 5985ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5986 neighbor_remove_private_as_replace_as_hidden_cmd,
5987 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5988 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5989 "Remove private ASNs in outbound updates\n"
5990 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5991
28c6e247
IR
5992DEFUN (neighbor_remove_private_as_all_replace_as,
5993 neighbor_remove_private_as_all_replace_as_cmd,
5994 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5995 NEIGHBOR_STR
5996 NEIGHBOR_ADDR_STR2
5997 "Remove private ASNs in outbound updates\n"
5998 "Apply to all AS numbers\n"
5999 "Replace private ASNs with our ASN in outbound updates\n")
5000f21c 6000{
d62a17ae 6001 int idx_peer = 1;
28c6e247
IR
6002 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6003 bgp_node_safi(vty),
6004 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
6005}
6006
d62a17ae 6007ALIAS_HIDDEN(
6008 neighbor_remove_private_as_all_replace_as,
6009 neighbor_remove_private_as_all_replace_as_hidden_cmd,
6010 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6011 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6012 "Remove private ASNs in outbound updates\n"
6013 "Apply to all AS numbers\n"
6014 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 6015
28c6e247
IR
6016DEFUN (no_neighbor_remove_private_as,
6017 no_neighbor_remove_private_as_cmd,
6018 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
6019 NO_STR
6020 NEIGHBOR_STR
6021 NEIGHBOR_ADDR_STR2
6022 "Remove private ASNs in outbound updates\n")
718e3744 6023{
d62a17ae 6024 int idx_peer = 2;
28c6e247
IR
6025 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6026 bgp_node_afi(vty), bgp_node_safi(vty),
6027 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 6028}
6b0655a2 6029
d62a17ae 6030ALIAS_HIDDEN(no_neighbor_remove_private_as,
6031 no_neighbor_remove_private_as_hidden_cmd,
6032 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
6033 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6034 "Remove private ASNs in outbound updates\n")
596c17ba 6035
28c6e247
IR
6036DEFUN (no_neighbor_remove_private_as_all,
6037 no_neighbor_remove_private_as_all_cmd,
6038 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
6039 NO_STR
6040 NEIGHBOR_STR
6041 NEIGHBOR_ADDR_STR2
6042 "Remove private ASNs in outbound updates\n"
6043 "Apply to all AS numbers\n")
88b8ed8d 6044{
d62a17ae 6045 int idx_peer = 2;
28c6e247
IR
6046 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6047 bgp_node_afi(vty), bgp_node_safi(vty),
6048 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 6049}
5000f21c 6050
d62a17ae 6051ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
6052 no_neighbor_remove_private_as_all_hidden_cmd,
6053 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
6054 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6055 "Remove private ASNs in outbound updates\n"
6056 "Apply to all AS numbers\n")
596c17ba 6057
28c6e247
IR
6058DEFUN (no_neighbor_remove_private_as_replace_as,
6059 no_neighbor_remove_private_as_replace_as_cmd,
6060 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
6061 NO_STR
6062 NEIGHBOR_STR
6063 NEIGHBOR_ADDR_STR2
6064 "Remove private ASNs in outbound updates\n"
6065 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 6066{
d62a17ae 6067 int idx_peer = 2;
28c6e247
IR
6068 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6069 bgp_node_afi(vty), bgp_node_safi(vty),
6070 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 6071}
5000f21c 6072
d62a17ae 6073ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
6074 no_neighbor_remove_private_as_replace_as_hidden_cmd,
6075 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
6076 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6077 "Remove private ASNs in outbound updates\n"
6078 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 6079
28c6e247
IR
6080DEFUN (no_neighbor_remove_private_as_all_replace_as,
6081 no_neighbor_remove_private_as_all_replace_as_cmd,
6082 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6083 NO_STR
6084 NEIGHBOR_STR
6085 NEIGHBOR_ADDR_STR2
6086 "Remove private ASNs in outbound updates\n"
6087 "Apply to all AS numbers\n"
6088 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 6089{
d62a17ae 6090 int idx_peer = 2;
28c6e247
IR
6091 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6092 bgp_node_afi(vty), bgp_node_safi(vty),
6093 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 6094}
5000f21c 6095
d62a17ae 6096ALIAS_HIDDEN(
6097 no_neighbor_remove_private_as_all_replace_as,
6098 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
6099 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6100 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6101 "Remove private ASNs in outbound updates\n"
6102 "Apply to all AS numbers\n"
6103 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 6104
5000f21c 6105
718e3744 6106/* neighbor send-community. */
28c6e247
IR
6107DEFUN (neighbor_send_community,
6108 neighbor_send_community_cmd,
6109 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6110 NEIGHBOR_STR
6111 NEIGHBOR_ADDR_STR2
6112 "Send Community attribute to this neighbor\n")
718e3744 6113{
d62a17ae 6114 int idx_peer = 1;
27c05d4d 6115
f63d4054
IR
6116 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6117 bgp_node_safi(vty),
6118 PEER_FLAG_SEND_COMMUNITY);
718e3744 6119}
6120
d62a17ae 6121ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
6122 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6123 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6124 "Send Community attribute to this neighbor\n")
596c17ba 6125
28c6e247
IR
6126DEFUN (no_neighbor_send_community,
6127 no_neighbor_send_community_cmd,
6128 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6129 NO_STR
6130 NEIGHBOR_STR
6131 NEIGHBOR_ADDR_STR2
6132 "Send Community attribute to this neighbor\n")
718e3744 6133{
d62a17ae 6134 int idx_peer = 2;
27c05d4d 6135
f63d4054
IR
6136 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6137 bgp_node_afi(vty), bgp_node_safi(vty),
6138 PEER_FLAG_SEND_COMMUNITY);
718e3744 6139}
6b0655a2 6140
d62a17ae 6141ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
6142 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6143 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6144 "Send Community attribute to this neighbor\n")
596c17ba 6145
718e3744 6146/* neighbor send-community extended. */
28c6e247
IR
6147DEFUN (neighbor_send_community_type,
6148 neighbor_send_community_type_cmd,
6149 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6150 NEIGHBOR_STR
6151 NEIGHBOR_ADDR_STR2
6152 "Send Community attribute to this neighbor\n"
6153 "Send Standard and Extended Community attributes\n"
6154 "Send Standard, Large and Extended Community attributes\n"
6155 "Send Extended Community attributes\n"
6156 "Send Standard Community attributes\n"
6157 "Send Large Community attributes\n")
718e3744 6158{
27c05d4d 6159 const char *type = argv[argc - 1]->text;
db45f64d 6160 char *peer_str = argv[1]->arg;
28c6e247 6161 struct peer *peer;
db45f64d 6162 afi_t afi = bgp_node_afi(vty);
28c6e247 6163 safi_t safi = bgp_node_safi(vty);
f4b8ec07 6164
28c6e247
IR
6165 peer = peer_and_group_lookup_vty(vty, peer_str);
6166 if (!peer)
6167 return CMD_WARNING_CONFIG_FAILED;
f4b8ec07 6168
28c6e247
IR
6169 if (strmatch(type, "standard"))
6170 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6171 PEER_FLAG_SEND_COMMUNITY);
f4b8ec07 6172
28c6e247
IR
6173 if (strmatch(type, "extended"))
6174 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6175 PEER_FLAG_SEND_EXT_COMMUNITY);
f4b8ec07 6176
28c6e247
IR
6177 if (strmatch(type, "large"))
6178 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6179 PEER_FLAG_SEND_LARGE_COMMUNITY);
f4b8ec07 6180
28c6e247
IR
6181 if (strmatch(type, "both")) {
6182 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6183 PEER_FLAG_SEND_COMMUNITY)
6184 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6185 PEER_FLAG_SEND_EXT_COMMUNITY);
f4b8ec07 6186 }
28c6e247
IR
6187 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6188 PEER_FLAG_SEND_COMMUNITY)
6189 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6190 PEER_FLAG_SEND_EXT_COMMUNITY)
6191 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6192 PEER_FLAG_SEND_LARGE_COMMUNITY);
d62a17ae 6193}
6194
6195ALIAS_HIDDEN(
6196 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
6197 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6198 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6199 "Send Community attribute to this neighbor\n"
6200 "Send Standard and Extended Community attributes\n"
6201 "Send Standard, Large and Extended Community attributes\n"
6202 "Send Extended Community attributes\n"
6203 "Send Standard Community attributes\n"
6204 "Send Large Community attributes\n")
596c17ba 6205
28c6e247
IR
6206DEFUN (no_neighbor_send_community_type,
6207 no_neighbor_send_community_type_cmd,
6208 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6209 NO_STR
6210 NEIGHBOR_STR
6211 NEIGHBOR_ADDR_STR2
6212 "Send Community attribute to this neighbor\n"
6213 "Send Standard and Extended Community attributes\n"
6214 "Send Standard, Large and Extended Community attributes\n"
6215 "Send Extended Community attributes\n"
6216 "Send Standard Community attributes\n"
6217 "Send Large Community attributes\n")
718e3744 6218{
d62a17ae 6219 const char *type = argv[argc - 1]->text;
db45f64d 6220 char *peer_str = argv[2]->arg;
28c6e247 6221 struct peer *peer;
db45f64d
DS
6222 afi_t afi = bgp_node_afi(vty);
6223 safi_t safi = bgp_node_safi(vty);
6224
28c6e247
IR
6225 peer = peer_and_group_lookup_vty(vty, peer_str);
6226 if (!peer)
f4b8ec07
CS
6227 return CMD_WARNING_CONFIG_FAILED;
6228
28c6e247
IR
6229 if (strmatch(type, "standard"))
6230 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6231 PEER_FLAG_SEND_COMMUNITY);
f4b8ec07 6232
28c6e247
IR
6233 if (strmatch(type, "extended"))
6234 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6235 PEER_FLAG_SEND_EXT_COMMUNITY);
f4b8ec07 6236
28c6e247
IR
6237 if (strmatch(type, "large"))
6238 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6239 PEER_FLAG_SEND_LARGE_COMMUNITY);
f4b8ec07
CS
6240
6241 if (strmatch(type, "both")) {
db45f64d 6242
28c6e247
IR
6243 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6244 PEER_FLAG_SEND_COMMUNITY)
6245 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6246 PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d
PM
6247 }
6248
28c6e247
IR
6249 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6250 PEER_FLAG_SEND_COMMUNITY)
6251 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6252 PEER_FLAG_SEND_EXT_COMMUNITY)
6253 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6254 PEER_FLAG_SEND_LARGE_COMMUNITY);
d62a17ae 6255}
6256
6257ALIAS_HIDDEN(
6258 no_neighbor_send_community_type,
6259 no_neighbor_send_community_type_hidden_cmd,
6260 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6261 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6262 "Send Community attribute to this neighbor\n"
6263 "Send Standard and Extended Community attributes\n"
6264 "Send Standard, Large and Extended Community attributes\n"
6265 "Send Extended Community attributes\n"
6266 "Send Standard Community attributes\n"
6267 "Send Large Community attributes\n")
596c17ba 6268
718e3744 6269/* neighbor soft-reconfig. */
28c6e247
IR
6270DEFUN (neighbor_soft_reconfiguration,
6271 neighbor_soft_reconfiguration_cmd,
6272 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6273 NEIGHBOR_STR
6274 NEIGHBOR_ADDR_STR2
6275 "Per neighbor soft reconfiguration\n"
6276 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 6277{
d62a17ae 6278 int idx_peer = 1;
28c6e247
IR
6279 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6280 bgp_node_safi(vty),
6281 PEER_FLAG_SOFT_RECONFIG);
718e3744 6282}
6283
d62a17ae 6284ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6285 neighbor_soft_reconfiguration_hidden_cmd,
6286 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6287 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6288 "Per neighbor soft reconfiguration\n"
6289 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 6290
28c6e247
IR
6291DEFUN (no_neighbor_soft_reconfiguration,
6292 no_neighbor_soft_reconfiguration_cmd,
6293 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6294 NO_STR
6295 NEIGHBOR_STR
6296 NEIGHBOR_ADDR_STR2
6297 "Per neighbor soft reconfiguration\n"
6298 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 6299{
d62a17ae 6300 int idx_peer = 2;
28c6e247
IR
6301 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6302 bgp_node_afi(vty), bgp_node_safi(vty),
6303 PEER_FLAG_SOFT_RECONFIG);
718e3744 6304}
6b0655a2 6305
d62a17ae 6306ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6307 no_neighbor_soft_reconfiguration_hidden_cmd,
6308 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6309 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6310 "Per neighbor soft reconfiguration\n"
6311 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 6312
28c6e247
IR
6313DEFUN (neighbor_route_reflector_client,
6314 neighbor_route_reflector_client_cmd,
6315 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6316 NEIGHBOR_STR
6317 NEIGHBOR_ADDR_STR2
6318 "Configure a neighbor as Route Reflector client\n")
718e3744 6319{
d62a17ae 6320 int idx_peer = 1;
28c6e247 6321 struct peer *peer;
718e3744 6322
6323
28c6e247
IR
6324 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6325 if (!peer)
d62a17ae 6326 return CMD_WARNING_CONFIG_FAILED;
718e3744 6327
28c6e247
IR
6328 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6329 bgp_node_safi(vty),
6330 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 6331}
6332
d62a17ae 6333ALIAS_HIDDEN(neighbor_route_reflector_client,
6334 neighbor_route_reflector_client_hidden_cmd,
6335 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6336 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6337 "Configure a neighbor as Route Reflector client\n")
596c17ba 6338
28c6e247
IR
6339DEFUN (no_neighbor_route_reflector_client,
6340 no_neighbor_route_reflector_client_cmd,
6341 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6342 NO_STR
6343 NEIGHBOR_STR
6344 NEIGHBOR_ADDR_STR2
6345 "Configure a neighbor as Route Reflector client\n")
718e3744 6346{
d62a17ae 6347 int idx_peer = 2;
28c6e247
IR
6348 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6349 bgp_node_afi(vty), bgp_node_safi(vty),
6350 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 6351}
6b0655a2 6352
d62a17ae 6353ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6354 no_neighbor_route_reflector_client_hidden_cmd,
6355 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6356 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6357 "Configure a neighbor as Route Reflector client\n")
596c17ba 6358
718e3744 6359/* neighbor route-server-client. */
28c6e247
IR
6360DEFUN (neighbor_route_server_client,
6361 neighbor_route_server_client_cmd,
6362 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6363 NEIGHBOR_STR
6364 NEIGHBOR_ADDR_STR2
6365 "Configure a neighbor as Route Server client\n")
718e3744 6366{
d62a17ae 6367 int idx_peer = 1;
28c6e247 6368 struct peer *peer;
f4b8ec07 6369
28c6e247
IR
6370 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6371 if (!peer)
d62a17ae 6372 return CMD_WARNING_CONFIG_FAILED;
28c6e247
IR
6373 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6374 bgp_node_safi(vty),
6375 PEER_FLAG_RSERVER_CLIENT);
718e3744 6376}
6377
d62a17ae 6378ALIAS_HIDDEN(neighbor_route_server_client,
6379 neighbor_route_server_client_hidden_cmd,
6380 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6381 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6382 "Configure a neighbor as Route Server client\n")
596c17ba 6383
28c6e247
IR
6384DEFUN (no_neighbor_route_server_client,
6385 no_neighbor_route_server_client_cmd,
6386 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6387 NO_STR
6388 NEIGHBOR_STR
6389 NEIGHBOR_ADDR_STR2
6390 "Configure a neighbor as Route Server client\n")
fee0f4c6 6391{
d62a17ae 6392 int idx_peer = 2;
28c6e247
IR
6393 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6394 bgp_node_afi(vty), bgp_node_safi(vty),
6395 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 6396}
6b0655a2 6397
d62a17ae 6398ALIAS_HIDDEN(no_neighbor_route_server_client,
6399 no_neighbor_route_server_client_hidden_cmd,
6400 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6401 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6402 "Configure a neighbor as Route Server client\n")
596c17ba 6403
fee0f4c6 6404DEFUN (neighbor_nexthop_local_unchanged,
6405 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 6406 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 6407 NEIGHBOR_STR
6408 NEIGHBOR_ADDR_STR2
6409 "Configure treatment of outgoing link-local nexthop attribute\n"
6410 "Leave link-local nexthop unchanged for this peer\n")
6411{
d62a17ae 6412 int idx_peer = 1;
6413 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6414 bgp_node_safi(vty),
6415 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 6416}
6b0655a2 6417
fee0f4c6 6418DEFUN (no_neighbor_nexthop_local_unchanged,
6419 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 6420 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 6421 NO_STR
6422 NEIGHBOR_STR
6423 NEIGHBOR_ADDR_STR2
6424 "Configure treatment of outgoing link-local-nexthop attribute\n"
6425 "Leave link-local nexthop unchanged for this peer\n")
718e3744 6426{
d62a17ae 6427 int idx_peer = 2;
6428 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6429 bgp_node_afi(vty), bgp_node_safi(vty),
6430 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 6431}
6b0655a2 6432
28c6e247
IR
6433DEFUN (neighbor_attr_unchanged,
6434 neighbor_attr_unchanged_cmd,
6435 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6436 NEIGHBOR_STR
6437 NEIGHBOR_ADDR_STR2
6438 "BGP attribute is propagated unchanged to this neighbor\n"
6439 "As-path attribute\n"
6440 "Nexthop attribute\n"
6441 "Med attribute\n")
718e3744 6442{
d62a17ae 6443 int idx = 0;
8eeb0335 6444 char *peer_str = argv[1]->arg;
28c6e247 6445 struct peer *peer;
db45f64d
DS
6446 bool aspath = false;
6447 bool nexthop = false;
6448 bool med = false;
8eeb0335
DW
6449 afi_t afi = bgp_node_afi(vty);
6450 safi_t safi = bgp_node_safi(vty);
28c6e247 6451 int ret = 0;
f4b8ec07 6452
28c6e247
IR
6453 peer = peer_and_group_lookup_vty(vty, peer_str);
6454 if (!peer)
8eeb0335 6455 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6456
6457 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
6458 aspath = true;
6459
d62a17ae 6460 idx = 0;
6461 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6462 nexthop = true;
6463
d62a17ae 6464 idx = 0;
6465 if (argv_find(argv, argc, "med", &idx))
db45f64d 6466 med = true;
d62a17ae 6467
8eeb0335 6468 /* no flags means all of them! */
db45f64d 6469 if (!aspath && !nexthop && !med) {
28c6e247
IR
6470 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
6471 PEER_FLAG_AS_PATH_UNCHANGED);
6472 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6473 PEER_FLAG_NEXTHOP_UNCHANGED);
6474 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6475 PEER_FLAG_MED_UNCHANGED);
8eeb0335 6476 } else {
28c6e247
IR
6477 if (!aspath) {
6478 if (peer_af_flag_check(peer, afi, safi,
6479 PEER_FLAG_AS_PATH_UNCHANGED)) {
6480 ret |= peer_af_flag_unset_vty(
6481 vty, peer_str, afi, safi,
6482 PEER_FLAG_AS_PATH_UNCHANGED);
6483 }
6484 } else
6485 ret |= peer_af_flag_set_vty(
6486 vty, peer_str, afi, safi,
6487 PEER_FLAG_AS_PATH_UNCHANGED);
6488
6489 if (!nexthop) {
6490 if (peer_af_flag_check(peer, afi, safi,
6491 PEER_FLAG_NEXTHOP_UNCHANGED)) {
6492 ret |= peer_af_flag_unset_vty(
6493 vty, peer_str, afi, safi,
6494 PEER_FLAG_NEXTHOP_UNCHANGED);
6495 }
6496 } else
6497 ret |= peer_af_flag_set_vty(
6498 vty, peer_str, afi, safi,
6499 PEER_FLAG_NEXTHOP_UNCHANGED);
6500
6501 if (!med) {
6502 if (peer_af_flag_check(peer, afi, safi,
6503 PEER_FLAG_MED_UNCHANGED)) {
6504 ret |= peer_af_flag_unset_vty(
6505 vty, peer_str, afi, safi,
6506 PEER_FLAG_MED_UNCHANGED);
6507 }
6508 } else
6509 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6510 PEER_FLAG_MED_UNCHANGED);
d62a17ae 6511 }
6512
28c6e247 6513 return ret;
d62a17ae 6514}
6515
6516ALIAS_HIDDEN(
6517 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6518 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6519 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6520 "BGP attribute is propagated unchanged to this neighbor\n"
6521 "As-path attribute\n"
6522 "Nexthop attribute\n"
6523 "Med attribute\n")
596c17ba 6524
28c6e247
IR
6525DEFUN (no_neighbor_attr_unchanged,
6526 no_neighbor_attr_unchanged_cmd,
6527 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6528 NO_STR
6529 NEIGHBOR_STR
6530 NEIGHBOR_ADDR_STR2
6531 "BGP attribute is propagated unchanged to this neighbor\n"
6532 "As-path attribute\n"
6533 "Nexthop attribute\n"
6534 "Med attribute\n")
718e3744 6535{
d62a17ae 6536 int idx = 0;
db45f64d 6537 char *peer_str = argv[2]->arg;
28c6e247 6538 struct peer *peer;
db45f64d
DS
6539 bool aspath = false;
6540 bool nexthop = false;
6541 bool med = false;
6542 afi_t afi = bgp_node_afi(vty);
6543 safi_t safi = bgp_node_safi(vty);
28c6e247 6544 int ret = 0;
f4b8ec07 6545
28c6e247
IR
6546 peer = peer_and_group_lookup_vty(vty, peer_str);
6547 if (!peer)
db45f64d 6548 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6549
6550 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
6551 aspath = true;
6552
d62a17ae 6553 idx = 0;
6554 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6555 nexthop = true;
6556
d62a17ae 6557 idx = 0;
6558 if (argv_find(argv, argc, "med", &idx))
db45f64d 6559 med = true;
d62a17ae 6560
28c6e247
IR
6561 if (!aspath && !nexthop && !med) // no flags means all of them!
6562 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6563 PEER_FLAG_AS_PATH_UNCHANGED)
6564 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6565 PEER_FLAG_NEXTHOP_UNCHANGED)
6566 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6567 PEER_FLAG_MED_UNCHANGED);
db45f64d
DS
6568
6569 if (aspath)
28c6e247
IR
6570 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6571 PEER_FLAG_AS_PATH_UNCHANGED);
db45f64d
DS
6572
6573 if (nexthop)
28c6e247
IR
6574 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6575 PEER_FLAG_NEXTHOP_UNCHANGED);
d62a17ae 6576
db45f64d 6577 if (med)
28c6e247
IR
6578 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6579 PEER_FLAG_MED_UNCHANGED);
db45f64d 6580
28c6e247 6581 return ret;
d62a17ae 6582}
6583
6584ALIAS_HIDDEN(
6585 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6586 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6587 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6588 "BGP attribute is propagated unchanged to this neighbor\n"
6589 "As-path attribute\n"
6590 "Nexthop attribute\n"
6591 "Med attribute\n")
718e3744 6592
28c6e247
IR
6593/* EBGP multihop configuration. */
6594static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
6595 const char *ttl_str)
718e3744 6596{
28c6e247
IR
6597 struct peer *peer;
6598 unsigned int ttl;
718e3744 6599
28c6e247
IR
6600 peer = peer_and_group_lookup_vty(vty, ip_str);
6601 if (!peer)
d62a17ae 6602 return CMD_WARNING_CONFIG_FAILED;
718e3744 6603
28c6e247
IR
6604 if (peer->conf_if)
6605 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
6606
6607 if (!ttl_str)
6608 ttl = MAXTTL;
6609 else
6610 ttl = strtoul(ttl_str, NULL, 10);
718e3744 6611
28c6e247 6612 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 6613}
6614
28c6e247 6615static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 6616{
28c6e247 6617 struct peer *peer;
718e3744 6618
28c6e247
IR
6619 peer = peer_and_group_lookup_vty(vty, ip_str);
6620 if (!peer)
d62a17ae 6621 return CMD_WARNING_CONFIG_FAILED;
718e3744 6622
28c6e247 6623 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 6624}
6625
28c6e247
IR
6626/* neighbor ebgp-multihop. */
6627DEFUN (neighbor_ebgp_multihop,
6628 neighbor_ebgp_multihop_cmd,
6629 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6630 NEIGHBOR_STR
6631 NEIGHBOR_ADDR_STR2
6632 "Allow EBGP neighbors not on directly connected networks\n")
718e3744 6633{
28c6e247
IR
6634 int idx_peer = 1;
6635 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
6636}
f4b8ec07 6637
28c6e247
IR
6638DEFUN (neighbor_ebgp_multihop_ttl,
6639 neighbor_ebgp_multihop_ttl_cmd,
6640 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6641 NEIGHBOR_STR
6642 NEIGHBOR_ADDR_STR2
6643 "Allow EBGP neighbors not on directly connected networks\n"
6644 "maximum hop count\n")
6645{
6646 int idx_peer = 1;
6647 int idx_number = 3;
6648 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
6649 argv[idx_number]->arg);
6650}
f4b8ec07 6651
28c6e247
IR
6652DEFUN (no_neighbor_ebgp_multihop,
6653 no_neighbor_ebgp_multihop_cmd,
6654 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6655 NO_STR
6656 NEIGHBOR_STR
6657 NEIGHBOR_ADDR_STR2
6658 "Allow EBGP neighbors not on directly connected networks\n"
6659 "maximum hop count\n")
6660{
6661 int idx_peer = 2;
6662 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 6663}
6664
97a52c82
DA
6665DEFPY (neighbor_aigp,
6666 neighbor_aigp_cmd,
6667 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor aigp",
6668 NO_STR
6669 NEIGHBOR_STR
6670 NEIGHBOR_ADDR_STR2
6671 "Enable send and receive of the AIGP attribute per neighbor\n")
6672{
6673 struct peer *peer;
6674
6675 peer = peer_and_group_lookup_vty(vty, neighbor);
6676 if (!peer)
6677 return CMD_WARNING_CONFIG_FAILED;
6678
6679 if (no)
6680 return peer_flag_unset_vty(vty, neighbor, PEER_FLAG_AIGP);
6681 else
6682 return peer_flag_set_vty(vty, neighbor, PEER_FLAG_AIGP);
6683}
6684
d864dd9e
EB
6685static uint8_t get_role_by_name(const char *role_str)
6686{
6687 if (strncmp(role_str, "peer", 2) == 0)
6688 return ROLE_PEER;
6689 if (strncmp(role_str, "provider", 2) == 0)
6690 return ROLE_PROVIDER;
6691 if (strncmp(role_str, "customer", 2) == 0)
6692 return ROLE_CUSTOMER;
6693 if (strncmp(role_str, "rs-server", 4) == 0)
6694 return ROLE_RS_SERVER;
6695 if (strncmp(role_str, "rs-client", 4) == 0)
6696 return ROLE_RS_CLIENT;
8f2d6021 6697 return ROLE_UNDEFINED;
d864dd9e
EB
6698}
6699
6700static int peer_role_set_vty(struct vty *vty, const char *ip_str,
8f2d6021 6701 const char *role_str, bool strict_mode)
d864dd9e
EB
6702{
6703 struct peer *peer;
6704
7dddd1f7 6705 peer = peer_and_group_lookup_vty(vty, ip_str);
d864dd9e
EB
6706 if (!peer)
6707 return CMD_WARNING_CONFIG_FAILED;
6708 uint8_t role = get_role_by_name(role_str);
6709
8f2d6021 6710 if (role == ROLE_UNDEFINED)
d864dd9e
EB
6711 return bgp_vty_return(vty, BGP_ERR_INVALID_ROLE_NAME);
6712 return bgp_vty_return(vty, peer_role_set(peer, role, strict_mode));
6713}
6714
6715static int peer_role_unset_vty(struct vty *vty, const char *ip_str)
6716{
6717 struct peer *peer;
6718
7dddd1f7 6719 peer = peer_and_group_lookup_vty(vty, ip_str);
d864dd9e
EB
6720 if (!peer)
6721 return CMD_WARNING_CONFIG_FAILED;
6722 return bgp_vty_return(vty, peer_role_unset(peer));
6723}
6724
8f2d6021 6725DEFPY(neighbor_role,
d864dd9e
EB
6726 neighbor_role_cmd,
6727 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer>",
6728 NEIGHBOR_STR
6729 NEIGHBOR_ADDR_STR2
6730 "Set session role\n"
6731 ROLE_STR)
6732{
6733 int idx_peer = 1;
6734 int idx_role = 3;
6735
6736 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
8f2d6021 6737 false);
d864dd9e
EB
6738}
6739
8f2d6021 6740DEFPY(neighbor_role_strict,
d864dd9e
EB
6741 neighbor_role_strict_cmd,
6742 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> strict-mode",
6743 NEIGHBOR_STR
6744 NEIGHBOR_ADDR_STR2
6745 "Set session role\n"
6746 ROLE_STR
6747 "Use additional restriction on peer\n")
6748{
6749 int idx_peer = 1;
6750 int idx_role = 3;
6751
6752 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
8f2d6021 6753 true);
d864dd9e
EB
6754}
6755
8f2d6021 6756DEFPY(no_neighbor_role,
d864dd9e
EB
6757 no_neighbor_role_cmd,
6758 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> [strict-mode]",
6759 NO_STR
6760 NEIGHBOR_STR
6761 NEIGHBOR_ADDR_STR2
8f2d6021 6762 "Set session role\n"
d864dd9e 6763 ROLE_STR
8f2d6021 6764 "Use additional restriction on peer\n")
d864dd9e
EB
6765{
6766 int idx_peer = 2;
6767
6768 return peer_role_unset_vty(vty, argv[idx_peer]->arg);
6769}
6b0655a2 6770
6ffd2079 6771/* disable-connected-check */
28c6e247
IR
6772DEFUN (neighbor_disable_connected_check,
6773 neighbor_disable_connected_check_cmd,
6774 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6775 NEIGHBOR_STR
6776 NEIGHBOR_ADDR_STR2
6777 "one-hop away EBGP peer using loopback address\n"
6778 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6779{
d62a17ae 6780 int idx_peer = 1;
28c6e247
IR
6781 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6782 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 6783}
6784
28c6e247
IR
6785DEFUN (no_neighbor_disable_connected_check,
6786 no_neighbor_disable_connected_check_cmd,
6787 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6788 NO_STR
6789 NEIGHBOR_STR
6790 NEIGHBOR_ADDR_STR2
6791 "one-hop away EBGP peer using loopback address\n"
6792 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6793{
d62a17ae 6794 int idx_peer = 2;
28c6e247
IR
6795 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6796 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 6797}
6798
7ab294ea
DA
6799/* disable-link-bw-encoding-ieee */
6800DEFUN(neighbor_disable_link_bw_encoding_ieee,
6801 neighbor_disable_link_bw_encoding_ieee_cmd,
27aa23a4
DA
6802 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6803 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7ab294ea 6804 "Disable IEEE floating-point encoding for extended community bandwidth\n")
27aa23a4
DA
6805{
6806 int idx_peer = 1;
6807
6808 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6809 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6810}
6811
7ab294ea
DA
6812DEFUN(no_neighbor_disable_link_bw_encoding_ieee,
6813 no_neighbor_disable_link_bw_encoding_ieee_cmd,
27aa23a4
DA
6814 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6815 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7ab294ea 6816 "Disable IEEE floating-point encoding for extended community bandwidth\n")
27aa23a4
DA
6817{
6818 int idx_peer = 2;
6819
6820 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6821 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6822}
6823
d08c0c80
DA
6824/* extended-optional-parameters */
6825DEFUN(neighbor_extended_optional_parameters,
6826 neighbor_extended_optional_parameters_cmd,
6827 "neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6828 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6829 "Force the extended optional parameters format for OPEN messages\n")
6830{
6831 int idx_peer = 1;
6832
6833 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6834 PEER_FLAG_EXTENDED_OPT_PARAMS);
6835}
6836
6837DEFUN(no_neighbor_extended_optional_parameters,
6838 no_neighbor_extended_optional_parameters_cmd,
6839 "no neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6840 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6841 "Force the extended optional parameters format for OPEN messages\n")
6842{
6843 int idx_peer = 2;
6844
6845 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6846 PEER_FLAG_EXTENDED_OPT_PARAMS);
6847}
47cbc09b
PM
6848
6849/* enforce-first-as */
28c6e247
IR
6850DEFUN (neighbor_enforce_first_as,
6851 neighbor_enforce_first_as_cmd,
6852 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6853 NEIGHBOR_STR
6854 NEIGHBOR_ADDR_STR2
6855 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
6856{
6857 int idx_peer = 1;
f4b8ec07 6858
28c6e247
IR
6859 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6860 PEER_FLAG_ENFORCE_FIRST_AS);
47cbc09b
PM
6861}
6862
28c6e247
IR
6863DEFUN (no_neighbor_enforce_first_as,
6864 no_neighbor_enforce_first_as_cmd,
6865 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6866 NO_STR
6867 NEIGHBOR_STR
6868 NEIGHBOR_ADDR_STR2
6869 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
6870{
6871 int idx_peer = 2;
f4b8ec07 6872
28c6e247
IR
6873 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6874 PEER_FLAG_ENFORCE_FIRST_AS);
47cbc09b
PM
6875}
6876
6877
28c6e247
IR
6878DEFUN (neighbor_description,
6879 neighbor_description_cmd,
6880 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6881 NEIGHBOR_STR
6882 NEIGHBOR_ADDR_STR2
6883 "Neighbor specific description\n"
6884 "Up to 80 characters describing this neighbor\n")
718e3744 6885{
d62a17ae 6886 int idx_peer = 1;
6887 int idx_line = 3;
28c6e247 6888 struct peer *peer;
d62a17ae 6889 char *str;
718e3744 6890
28c6e247
IR
6891 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6892 if (!peer)
d62a17ae 6893 return CMD_WARNING_CONFIG_FAILED;
718e3744 6894
d62a17ae 6895 str = argv_concat(argv, argc, idx_line);
718e3744 6896
28c6e247 6897 peer_description_set(peer, str);
718e3744 6898
d62a17ae 6899 XFREE(MTYPE_TMP, str);
718e3744 6900
28c6e247 6901 return CMD_SUCCESS;
718e3744 6902}
6903
28c6e247
IR
6904DEFUN (no_neighbor_description,
6905 no_neighbor_description_cmd,
6906 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6907 NO_STR
6908 NEIGHBOR_STR
6909 NEIGHBOR_ADDR_STR2
6910 "Neighbor specific description\n")
718e3744 6911{
d62a17ae 6912 int idx_peer = 2;
28c6e247 6913 struct peer *peer;
f4b8ec07 6914
28c6e247
IR
6915 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6916 if (!peer)
d62a17ae 6917 return CMD_WARNING_CONFIG_FAILED;
718e3744 6918
28c6e247 6919 peer_description_unset(peer);
718e3744 6920
28c6e247 6921 return CMD_SUCCESS;
718e3744 6922}
6923
1d80f243 6924ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
a14810f4
PM
6925 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6926 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6927 "Neighbor specific description\n"
6928 "Up to 80 characters describing this neighbor\n")
6b0655a2 6929
28c6e247
IR
6930/* Neighbor update-source. */
6931static int peer_update_source_vty(struct vty *vty, const char *peer_str,
6932 const char *source_str)
6933{
6934 struct peer *peer;
6935 struct prefix p;
6936 union sockunion su;
6937
6938 peer = peer_and_group_lookup_vty(vty, peer_str);
6939 if (!peer)
6940 return CMD_WARNING_CONFIG_FAILED;
6941
6942 if (peer->conf_if)
6943 return CMD_WARNING;
6944
6945 if (source_str) {
6946 if (str2sockunion(source_str, &su) == 0)
6947 peer_update_source_addr_set(peer, &su);
6948 else {
6949 if (str2prefix(source_str, &p)) {
6950 vty_out(vty,
6951 "%% Invalid update-source, remove prefix length \n");
6952 return CMD_WARNING_CONFIG_FAILED;
6953 } else
6954 peer_update_source_if_set(peer, source_str);
6955 }
6956 } else
6957 peer_update_source_unset(peer);
6958
6959 return CMD_SUCCESS;
6960}
6961
d62a17ae 6962#define BGP_UPDATE_SOURCE_HELP_STR \
6963 "IPv4 address\n" \
6964 "IPv6 address\n" \
6965 "Interface name (requires zebra to be running)\n"
369688c0 6966
28c6e247
IR
6967DEFUN (neighbor_update_source,
6968 neighbor_update_source_cmd,
6969 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
6970 NEIGHBOR_STR
6971 NEIGHBOR_ADDR_STR2
6972 "Source of routing updates\n"
6973 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 6974{
d62a17ae 6975 int idx_peer = 1;
6976 int idx_peer_2 = 3;
28c6e247 6977 return peer_update_source_vty(vty, argv[idx_peer]->arg,
d62a17ae 6978 argv[idx_peer_2]->arg);
718e3744 6979}
6980
28c6e247
IR
6981DEFUN (no_neighbor_update_source,
6982 no_neighbor_update_source_cmd,
6983 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
6984 NO_STR
6985 NEIGHBOR_STR
6986 NEIGHBOR_ADDR_STR2
6987 "Source of routing updates\n"
6988 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 6989{
d62a17ae 6990 int idx_peer = 2;
28c6e247 6991 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 6992}
6b0655a2 6993
d62a17ae 6994static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
6995 afi_t afi, safi_t safi,
6996 const char *rmap, int set)
718e3744 6997{
d62a17ae 6998 int ret;
6999 struct peer *peer;
80912664 7000 struct route_map *route_map = NULL;
718e3744 7001
d62a17ae 7002 peer = peer_and_group_lookup_vty(vty, peer_str);
7003 if (!peer)
7004 return CMD_WARNING_CONFIG_FAILED;
718e3744 7005
1de27621 7006 if (set) {
80912664
DS
7007 if (rmap)
7008 route_map = route_map_lookup_warn_noexist(vty, rmap);
1de27621
DA
7009 ret = peer_default_originate_set(peer, afi, safi,
7010 rmap, route_map);
7011 } else
d62a17ae 7012 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 7013
d62a17ae 7014 return bgp_vty_return(vty, ret);
718e3744 7015}
7016
7017/* neighbor default-originate. */
7018DEFUN (neighbor_default_originate,
7019 neighbor_default_originate_cmd,
9ccf14f7 7020 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 7021 NEIGHBOR_STR
7022 NEIGHBOR_ADDR_STR2
7023 "Originate default route to this neighbor\n")
7024{
d62a17ae 7025 int idx_peer = 1;
7026 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7027 bgp_node_afi(vty),
7028 bgp_node_safi(vty), NULL, 1);
718e3744 7029}
7030
d62a17ae 7031ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
7032 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
7033 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7034 "Originate default route to this neighbor\n")
596c17ba 7035
718e3744 7036DEFUN (neighbor_default_originate_rmap,
7037 neighbor_default_originate_rmap_cmd,
70dd370f 7038 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
718e3744 7039 NEIGHBOR_STR
7040 NEIGHBOR_ADDR_STR2
7041 "Originate default route to this neighbor\n"
7042 "Route-map to specify criteria to originate default\n"
7043 "route-map name\n")
7044{
d62a17ae 7045 int idx_peer = 1;
7046 int idx_word = 4;
7047 return peer_default_originate_set_vty(
7048 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7049 argv[idx_word]->arg, 1);
718e3744 7050}
7051
d62a17ae 7052ALIAS_HIDDEN(
7053 neighbor_default_originate_rmap,
7054 neighbor_default_originate_rmap_hidden_cmd,
70dd370f 7055 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
d62a17ae 7056 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7057 "Originate default route to this neighbor\n"
7058 "Route-map to specify criteria to originate default\n"
7059 "route-map name\n")
596c17ba 7060
718e3744 7061DEFUN (no_neighbor_default_originate,
7062 no_neighbor_default_originate_cmd,
70dd370f 7063 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
718e3744 7064 NO_STR
7065 NEIGHBOR_STR
7066 NEIGHBOR_ADDR_STR2
a636c635
DW
7067 "Originate default route to this neighbor\n"
7068 "Route-map to specify criteria to originate default\n"
7069 "route-map name\n")
718e3744 7070{
d62a17ae 7071 int idx_peer = 2;
7072 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7073 bgp_node_afi(vty),
7074 bgp_node_safi(vty), NULL, 0);
718e3744 7075}
7076
d62a17ae 7077ALIAS_HIDDEN(
7078 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
70dd370f 7079 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
d62a17ae 7080 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7081 "Originate default route to this neighbor\n"
7082 "Route-map to specify criteria to originate default\n"
7083 "route-map name\n")
596c17ba 7084
6b0655a2 7085
28c6e247
IR
7086/* Set neighbor's BGP port. */
7087static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
7088 const char *port_str)
718e3744 7089{
28c6e247
IR
7090 struct peer *peer;
7091 uint16_t port;
7092 struct servent *sp;
7093
a3aecc99 7094 peer = peer_and_group_lookup_vty(vty, ip_str);
28c6e247
IR
7095 if (!peer)
7096 return CMD_WARNING_CONFIG_FAILED;
7097
7098 if (!port_str) {
7099 sp = getservbyname("bgp", "tcp");
7100 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
7101 } else {
7102 port = strtoul(port_str, NULL, 10);
7103 }
718e3744 7104
28c6e247 7105 peer_port_set(peer, port);
718e3744 7106
28c6e247
IR
7107 return CMD_SUCCESS;
7108}
f4b8ec07 7109
28c6e247
IR
7110/* Set specified peer's BGP port. */
7111DEFUN (neighbor_port,
7112 neighbor_port_cmd,
a3aecc99 7113 "neighbor <A.B.C.D|X:X::X:X|WORD> port (0-65535)",
28c6e247 7114 NEIGHBOR_STR
a3aecc99 7115 NEIGHBOR_ADDR_STR2
28c6e247
IR
7116 "Neighbor's BGP port\n"
7117 "TCP port number\n")
7118{
7119 int idx_ip = 1;
7120 int idx_number = 3;
7121 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
7122 argv[idx_number]->arg);
f4b8ec07 7123}
6b0655a2 7124
28c6e247
IR
7125DEFUN (no_neighbor_port,
7126 no_neighbor_port_cmd,
a3aecc99 7127 "no neighbor <A.B.C.D|X:X::X:X|WORD> port [(0-65535)]",
28c6e247
IR
7128 NO_STR
7129 NEIGHBOR_STR
a3aecc99 7130 NEIGHBOR_ADDR_STR2
28c6e247
IR
7131 "Neighbor's BGP port\n"
7132 "TCP port number\n")
718e3744 7133{
f4b8ec07 7134 int idx_ip = 2;
28c6e247
IR
7135 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
7136}
7137
7138
7139/* neighbor weight. */
7140static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7141 safi_t safi, const char *weight_str)
7142{
7143 int ret;
7144 struct peer *peer;
7145 unsigned long weight;
718e3744 7146
28c6e247
IR
7147 peer = peer_and_group_lookup_vty(vty, ip_str);
7148 if (!peer)
7149 return CMD_WARNING_CONFIG_FAILED;
718e3744 7150
28c6e247 7151 weight = strtoul(weight_str, NULL, 10);
718e3744 7152
28c6e247
IR
7153 ret = peer_weight_set(peer, afi, safi, weight);
7154 return bgp_vty_return(vty, ret);
718e3744 7155}
7156
28c6e247
IR
7157static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7158 safi_t safi)
718e3744 7159{
28c6e247
IR
7160 int ret;
7161 struct peer *peer;
f4b8ec07 7162
28c6e247
IR
7163 peer = peer_and_group_lookup_vty(vty, ip_str);
7164 if (!peer)
d62a17ae 7165 return CMD_WARNING_CONFIG_FAILED;
718e3744 7166
28c6e247
IR
7167 ret = peer_weight_unset(peer, afi, safi);
7168 return bgp_vty_return(vty, ret);
7169}
f4b8ec07 7170
28c6e247
IR
7171DEFUN (neighbor_weight,
7172 neighbor_weight_cmd,
7173 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7174 NEIGHBOR_STR
7175 NEIGHBOR_ADDR_STR2
7176 "Set default weight for routes from this neighbor\n"
7177 "default weight\n")
7178{
7179 int idx_peer = 1;
7180 int idx_number = 3;
7181 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7182 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 7183}
7184
d62a17ae 7185ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
7186 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7187 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7188 "Set default weight for routes from this neighbor\n"
7189 "default weight\n")
596c17ba 7190
28c6e247
IR
7191DEFUN (no_neighbor_weight,
7192 no_neighbor_weight_cmd,
7193 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7194 NO_STR
7195 NEIGHBOR_STR
7196 NEIGHBOR_ADDR_STR2
7197 "Set default weight for routes from this neighbor\n"
7198 "default weight\n")
718e3744 7199{
d62a17ae 7200 int idx_peer = 2;
28c6e247
IR
7201 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
7202 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 7203}
7204
d62a17ae 7205ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
7206 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7207 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7208 "Set default weight for routes from this neighbor\n"
7209 "default weight\n")
596c17ba 7210
6b0655a2 7211
718e3744 7212/* Override capability negotiation. */
c36bc05f
IR
7213DEFUN (neighbor_override_capability,
7214 neighbor_override_capability_cmd,
7215 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7216 NEIGHBOR_STR
7217 NEIGHBOR_ADDR_STR2
7218 "Override capability negotiation result\n")
718e3744 7219{
d62a17ae 7220 int idx_peer = 1;
c36bc05f
IR
7221 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7222 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 7223}
7224
c36bc05f
IR
7225DEFUN (no_neighbor_override_capability,
7226 no_neighbor_override_capability_cmd,
7227 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7228 NO_STR
7229 NEIGHBOR_STR
7230 NEIGHBOR_ADDR_STR2
7231 "Override capability negotiation result\n")
718e3744 7232{
d62a17ae 7233 int idx_peer = 2;
c36bc05f
IR
7234 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7235 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 7236}
6b0655a2 7237
c36bc05f
IR
7238DEFUN (neighbor_strict_capability,
7239 neighbor_strict_capability_cmd,
7240 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7241 NEIGHBOR_STR
7242 NEIGHBOR_ADDR_STR2
7243 "Strict capability negotiation match\n")
718e3744 7244{
9fb964de
PM
7245 int idx_peer = 1;
7246
c36bc05f
IR
7247 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7248 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 7249}
7250
c36bc05f
IR
7251DEFUN (no_neighbor_strict_capability,
7252 no_neighbor_strict_capability_cmd,
7253 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7254 NO_STR
7255 NEIGHBOR_STR
7256 NEIGHBOR_ADDR_STR2
7257 "Strict capability negotiation match\n")
718e3744 7258{
9fb964de 7259 int idx_peer = 2;
8611c7f3 7260
c36bc05f
IR
7261 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7262 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 7263}
6b0655a2 7264
28c6e247
IR
7265static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
7266 const char *keep_str, const char *hold_str)
718e3744 7267{
28c6e247
IR
7268 int ret;
7269 struct peer *peer;
7270 uint32_t keepalive;
7271 uint32_t holdtime;
718e3744 7272
28c6e247
IR
7273 peer = peer_and_group_lookup_vty(vty, ip_str);
7274 if (!peer)
d62a17ae 7275 return CMD_WARNING_CONFIG_FAILED;
718e3744 7276
28c6e247
IR
7277 keepalive = strtoul(keep_str, NULL, 10);
7278 holdtime = strtoul(hold_str, NULL, 10);
718e3744 7279
28c6e247 7280 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 7281
28c6e247 7282 return bgp_vty_return(vty, ret);
718e3744 7283}
6b0655a2 7284
28c6e247 7285static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 7286{
28c6e247
IR
7287 int ret;
7288 struct peer *peer;
718e3744 7289
28c6e247
IR
7290 peer = peer_and_group_lookup_vty(vty, ip_str);
7291 if (!peer)
d62a17ae 7292 return CMD_WARNING_CONFIG_FAILED;
718e3744 7293
28c6e247 7294 ret = peer_timers_unset(peer);
718e3744 7295
28c6e247 7296 return bgp_vty_return(vty, ret);
718e3744 7297}
6b0655a2 7298
28c6e247
IR
7299DEFUN (neighbor_timers,
7300 neighbor_timers_cmd,
7301 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
7302 NEIGHBOR_STR
7303 NEIGHBOR_ADDR_STR2
7304 "BGP per neighbor timers\n"
7305 "Keepalive interval\n"
7306 "Holdtime\n")
718e3744 7307{
f4b8ec07 7308 int idx_peer = 1;
28c6e247
IR
7309 int idx_number = 3;
7310 int idx_number_2 = 4;
7311 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
7312 argv[idx_number]->arg,
7313 argv[idx_number_2]->arg);
7314}
7315
7316DEFUN (no_neighbor_timers,
7317 no_neighbor_timers_cmd,
7318 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
7319 NO_STR
7320 NEIGHBOR_STR
7321 NEIGHBOR_ADDR_STR2
7322 "BGP per neighbor timers\n"
7323 "Keepalive interval\n"
7324 "Holdtime\n")
7325{
7326 int idx_peer = 2;
7327 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
7328}
7329
7330
7331static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
7332 const char *time_str)
7333{
7334 int ret;
7335 struct peer *peer;
7336 uint32_t connect;
718e3744 7337
28c6e247
IR
7338 peer = peer_and_group_lookup_vty(vty, ip_str);
7339 if (!peer)
d62a17ae 7340 return CMD_WARNING_CONFIG_FAILED;
718e3744 7341
28c6e247
IR
7342 connect = strtoul(time_str, NULL, 10);
7343
7344 ret = peer_timers_connect_set(peer, connect);
718e3744 7345
28c6e247 7346 return bgp_vty_return(vty, ret);
718e3744 7347}
7348
28c6e247 7349static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 7350{
28c6e247
IR
7351 int ret;
7352 struct peer *peer;
718e3744 7353
28c6e247
IR
7354 peer = peer_and_group_lookup_vty(vty, ip_str);
7355 if (!peer)
d62a17ae 7356 return CMD_WARNING_CONFIG_FAILED;
718e3744 7357
28c6e247
IR
7358 ret = peer_timers_connect_unset(peer);
7359
7360 return bgp_vty_return(vty, ret);
7361}
7362
7363DEFUN (neighbor_timers_connect,
7364 neighbor_timers_connect_cmd,
7365 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7366 NEIGHBOR_STR
7367 NEIGHBOR_ADDR_STR2
7368 "BGP per neighbor timers\n"
7369 "BGP connect timer\n"
7370 "Connect timer\n")
7371{
7372 int idx_peer = 1;
7373 int idx_number = 4;
7374 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
7375 argv[idx_number]->arg);
7376}
718e3744 7377
28c6e247
IR
7378DEFUN (no_neighbor_timers_connect,
7379 no_neighbor_timers_connect_cmd,
7380 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7381 NO_STR
7382 NEIGHBOR_STR
7383 NEIGHBOR_ADDR_STR2
7384 "BGP per neighbor timers\n"
7385 "BGP connect timer\n"
7386 "Connect timer\n")
7387{
7388 int idx_peer = 2;
7389 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 7390}
7391
d43114f3
DS
7392DEFPY (neighbor_timers_delayopen,
7393 neighbor_timers_delayopen_cmd,
7394 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
7395 NEIGHBOR_STR
7396 NEIGHBOR_ADDR_STR2
7397 "BGP per neighbor timers\n"
7398 "RFC 4271 DelayOpenTimer\n"
7399 "DelayOpenTime timer interval\n")
7400{
7401 struct peer *peer;
7402
7403 peer = peer_and_group_lookup_vty(vty, neighbor);
7404 if (!peer)
7405 return CMD_WARNING_CONFIG_FAILED;
7406
7407 if (!interval) {
7408 if (peer_timers_delayopen_unset(peer))
7409 return CMD_WARNING_CONFIG_FAILED;
7410 } else {
7411 if (peer_timers_delayopen_set(peer, interval))
7412 return CMD_WARNING_CONFIG_FAILED;
7413 }
7414
7415 return CMD_SUCCESS;
7416}
7417
7418DEFPY (no_neighbor_timers_delayopen,
7419 no_neighbor_timers_delayopen_cmd,
7420 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7421 NO_STR
7422 NEIGHBOR_STR
7423 NEIGHBOR_ADDR_STR2
7424 "BGP per neighbor timers\n"
7425 "RFC 4271 DelayOpenTimer\n"
7426 "DelayOpenTime timer interval\n")
7427{
7428 struct peer *peer;
7429
7430 peer = peer_and_group_lookup_vty(vty, neighbor);
7431 if (!peer)
7432 return CMD_WARNING_CONFIG_FAILED;
7433
7434 if (peer_timers_delayopen_unset(peer))
7435 return CMD_WARNING_CONFIG_FAILED;
7436
7437 return CMD_SUCCESS;
7438}
7439
28c6e247
IR
7440static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
7441 const char *time_str, int set)
718e3744 7442{
28c6e247
IR
7443 int ret;
7444 struct peer *peer;
7445 uint32_t routeadv = 0;
718e3744 7446
28c6e247
IR
7447 peer = peer_and_group_lookup_vty(vty, ip_str);
7448 if (!peer)
d62a17ae 7449 return CMD_WARNING_CONFIG_FAILED;
718e3744 7450
28c6e247
IR
7451 if (time_str)
7452 routeadv = strtoul(time_str, NULL, 10);
7453
7454 if (set)
7455 ret = peer_advertise_interval_set(peer, routeadv);
7456 else
7457 ret = peer_advertise_interval_unset(peer);
718e3744 7458
28c6e247 7459 return bgp_vty_return(vty, ret);
718e3744 7460}
7461
28c6e247
IR
7462DEFUN (neighbor_advertise_interval,
7463 neighbor_advertise_interval_cmd,
7464 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7465 NEIGHBOR_STR
7466 NEIGHBOR_ADDR_STR2
7467 "Minimum interval between sending BGP routing updates\n"
7468 "time in seconds\n")
718e3744 7469{
28c6e247
IR
7470 int idx_peer = 1;
7471 int idx_number = 3;
7472 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
7473 argv[idx_number]->arg, 1);
7474}
f4b8ec07 7475
28c6e247
IR
7476DEFUN (no_neighbor_advertise_interval,
7477 no_neighbor_advertise_interval_cmd,
7478 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7479 NO_STR
7480 NEIGHBOR_STR
7481 NEIGHBOR_ADDR_STR2
7482 "Minimum interval between sending BGP routing updates\n"
7483 "time in seconds\n")
7484{
7485 int idx_peer = 2;
7486 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 7487}
7488
6b0655a2 7489
518f0eb1
DS
7490/* Time to wait before processing route-map updates */
7491DEFUN (bgp_set_route_map_delay_timer,
7492 bgp_set_route_map_delay_timer_cmd,
6147e2c6 7493 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
7494 SET_STR
7495 "BGP route-map delay timer\n"
7496 "Time in secs to wait before processing route-map changes\n"
f414725f 7497 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 7498{
d62a17ae 7499 int idx_number = 3;
d7c0a89a 7500 uint32_t rmap_delay_timer;
d62a17ae 7501
7502 if (argv[idx_number]->arg) {
7503 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7504 bm->rmap_update_timer = rmap_delay_timer;
7505
7506 /* if the dynamic update handling is being disabled, and a timer
7507 * is
7508 * running, stop the timer and act as if the timer has already
7509 * fired.
7510 */
7511 if (!rmap_delay_timer && bm->t_rmap_update) {
fa5806c3 7512 THREAD_OFF(bm->t_rmap_update);
d62a17ae 7513 thread_execute(bm->master, bgp_route_map_update_timer,
7514 NULL, 0);
7515 }
7516 return CMD_SUCCESS;
7517 } else {
7518 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7519 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 7520 }
518f0eb1
DS
7521}
7522
7523DEFUN (no_bgp_set_route_map_delay_timer,
7524 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 7525 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 7526 NO_STR
3a2d747c 7527 BGP_STR
518f0eb1 7528 "Default BGP route-map delay timer\n"
8334fd5a
DW
7529 "Reset to default time to wait for processing route-map changes\n"
7530 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 7531{
518f0eb1 7532
d62a17ae 7533 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 7534
d62a17ae 7535 return CMD_SUCCESS;
518f0eb1
DS
7536}
7537
28c6e247
IR
7538/* neighbor interface */
7539static int peer_interface_vty(struct vty *vty, const char *ip_str,
7540 const char *str)
718e3744 7541{
28c6e247 7542 struct peer *peer;
718e3744 7543
28c6e247
IR
7544 peer = peer_lookup_vty(vty, ip_str);
7545 if (!peer || peer->conf_if) {
7546 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
7547 return CMD_WARNING_CONFIG_FAILED;
7548 }
718e3744 7549
28c6e247
IR
7550 if (str)
7551 peer_interface_set(peer, str);
7552 else
7553 peer_interface_unset(peer);
718e3744 7554
28c6e247 7555 return CMD_SUCCESS;
718e3744 7556}
7557
28c6e247
IR
7558DEFUN (neighbor_interface,
7559 neighbor_interface_cmd,
7560 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7561 NEIGHBOR_STR
7562 NEIGHBOR_ADDR_STR
7563 "Interface\n"
7564 "Interface name\n")
718e3744 7565{
28c6e247
IR
7566 int idx_ip = 1;
7567 int idx_word = 3;
294d8425 7568
28c6e247
IR
7569 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
7570}
f4b8ec07 7571
28c6e247
IR
7572DEFUN (no_neighbor_interface,
7573 no_neighbor_interface_cmd,
294d8425 7574 "no neighbor <A.B.C.D|X:X::X:X> interface WORD",
28c6e247
IR
7575 NO_STR
7576 NEIGHBOR_STR
294d8425 7577 NEIGHBOR_ADDR_STR
28c6e247
IR
7578 "Interface\n"
7579 "Interface name\n")
7580{
7581 int idx_peer = 2;
294d8425 7582
28c6e247 7583 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 7584}
6b0655a2 7585
718e3744 7586DEFUN (neighbor_distribute_list,
7587 neighbor_distribute_list_cmd,
c60dec36 7588 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
718e3744 7589 NEIGHBOR_STR
7590 NEIGHBOR_ADDR_STR2
7591 "Filter updates to/from this neighbor\n"
718e3744 7592 "IP Access-list name\n"
7593 "Filter incoming updates\n"
7594 "Filter outgoing updates\n")
7595{
d62a17ae 7596 int idx_peer = 1;
7597 int idx_acl = 3;
7598 int direct, ret;
7599 struct peer *peer;
a8206004 7600
d62a17ae 7601 const char *pstr = argv[idx_peer]->arg;
7602 const char *acl = argv[idx_acl]->arg;
7603 const char *inout = argv[argc - 1]->text;
a8206004 7604
d62a17ae 7605 peer = peer_and_group_lookup_vty(vty, pstr);
7606 if (!peer)
7607 return CMD_WARNING_CONFIG_FAILED;
a8206004 7608
d62a17ae 7609 /* Check filter direction. */
7610 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7611 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7612 direct, acl);
a8206004 7613
d62a17ae 7614 return bgp_vty_return(vty, ret);
718e3744 7615}
7616
d62a17ae 7617ALIAS_HIDDEN(
7618 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
c60dec36 7619 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
d62a17ae 7620 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7621 "Filter updates to/from this neighbor\n"
d62a17ae 7622 "IP Access-list name\n"
7623 "Filter incoming updates\n"
7624 "Filter outgoing updates\n")
596c17ba 7625
718e3744 7626DEFUN (no_neighbor_distribute_list,
7627 no_neighbor_distribute_list_cmd,
c60dec36 7628 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
718e3744 7629 NO_STR
7630 NEIGHBOR_STR
7631 NEIGHBOR_ADDR_STR2
7632 "Filter updates to/from this neighbor\n"
718e3744 7633 "IP Access-list name\n"
7634 "Filter incoming updates\n"
7635 "Filter outgoing updates\n")
7636{
d62a17ae 7637 int idx_peer = 2;
7638 int direct, ret;
7639 struct peer *peer;
a8206004 7640
d62a17ae 7641 const char *pstr = argv[idx_peer]->arg;
7642 const char *inout = argv[argc - 1]->text;
a8206004 7643
d62a17ae 7644 peer = peer_and_group_lookup_vty(vty, pstr);
7645 if (!peer)
7646 return CMD_WARNING_CONFIG_FAILED;
a8206004 7647
d62a17ae 7648 /* Check filter direction. */
7649 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7650 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7651 direct);
a8206004 7652
d62a17ae 7653 return bgp_vty_return(vty, ret);
718e3744 7654}
6b0655a2 7655
d62a17ae 7656ALIAS_HIDDEN(
7657 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
c60dec36 7658 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
d62a17ae 7659 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7660 "Filter updates to/from this neighbor\n"
d62a17ae 7661 "IP Access-list name\n"
7662 "Filter incoming updates\n"
7663 "Filter outgoing updates\n")
596c17ba 7664
718e3744 7665/* Set prefix list to the peer. */
642ef664
IR
7666static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
7667 afi_t afi, safi_t safi,
7668 const char *name_str,
7669 const char *direct_str)
718e3744 7670{
642ef664
IR
7671 int ret;
7672 int direct = FILTER_IN;
7673 struct peer *peer;
718e3744 7674
642ef664
IR
7675 peer = peer_and_group_lookup_vty(vty, ip_str);
7676 if (!peer)
d62a17ae 7677 return CMD_WARNING_CONFIG_FAILED;
e52702f2 7678
642ef664
IR
7679 /* Check filter direction. */
7680 if (strncmp(direct_str, "i", 1) == 0)
7681 direct = FILTER_IN;
7682 else if (strncmp(direct_str, "o", 1) == 0)
7683 direct = FILTER_OUT;
718e3744 7684
642ef664 7685 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 7686
642ef664
IR
7687 return bgp_vty_return(vty, ret);
7688}
7689
7690static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
7691 afi_t afi, safi_t safi,
7692 const char *direct_str)
7693{
7694 int ret;
7695 struct peer *peer;
7696 int direct = FILTER_IN;
7697
7698 peer = peer_and_group_lookup_vty(vty, ip_str);
7699 if (!peer)
7700 return CMD_WARNING_CONFIG_FAILED;
7701
7702 /* Check filter direction. */
7703 if (strncmp(direct_str, "i", 1) == 0)
7704 direct = FILTER_IN;
7705 else if (strncmp(direct_str, "o", 1) == 0)
7706 direct = FILTER_OUT;
7707
7708 ret = peer_prefix_list_unset(peer, afi, safi, direct);
7709
7710 return bgp_vty_return(vty, ret);
7711}
7712
7713DEFUN (neighbor_prefix_list,
7714 neighbor_prefix_list_cmd,
7715 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7716 NEIGHBOR_STR
7717 NEIGHBOR_ADDR_STR2
7718 "Filter updates to/from this neighbor\n"
7719 "Name of a prefix list\n"
7720 "Filter incoming updates\n"
7721 "Filter outgoing updates\n")
7722{
7723 int idx_peer = 1;
7724 int idx_word = 3;
7725 int idx_in_out = 4;
7726 return peer_prefix_list_set_vty(
7727 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7728 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 7729}
7730
d62a17ae 7731ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7732 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7733 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7734 "Filter updates to/from this neighbor\n"
7735 "Name of a prefix list\n"
7736 "Filter incoming updates\n"
7737 "Filter outgoing updates\n")
596c17ba 7738
642ef664
IR
7739DEFUN (no_neighbor_prefix_list,
7740 no_neighbor_prefix_list_cmd,
7741 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7742 NO_STR
7743 NEIGHBOR_STR
7744 NEIGHBOR_ADDR_STR2
7745 "Filter updates to/from this neighbor\n"
7746 "Name of a prefix list\n"
7747 "Filter incoming updates\n"
7748 "Filter outgoing updates\n")
7749{
7750 int idx_peer = 2;
7751 int idx_in_out = 5;
7752 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7753 bgp_node_afi(vty), bgp_node_safi(vty),
7754 argv[idx_in_out]->arg);
7755}
7756
7757ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7758 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7759 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7760 "Filter updates to/from this neighbor\n"
7761 "Name of a prefix list\n"
7762 "Filter incoming updates\n"
7763 "Filter outgoing updates\n")
7764
d62a17ae 7765static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7766 safi_t safi, const char *name_str,
7767 const char *direct_str)
718e3744 7768{
d62a17ae 7769 int ret;
7770 struct peer *peer;
7771 int direct = FILTER_IN;
718e3744 7772
d62a17ae 7773 peer = peer_and_group_lookup_vty(vty, ip_str);
7774 if (!peer)
7775 return CMD_WARNING_CONFIG_FAILED;
718e3744 7776
d62a17ae 7777 /* Check filter direction. */
7778 if (strncmp(direct_str, "i", 1) == 0)
7779 direct = FILTER_IN;
7780 else if (strncmp(direct_str, "o", 1) == 0)
7781 direct = FILTER_OUT;
718e3744 7782
d62a17ae 7783 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 7784
d62a17ae 7785 return bgp_vty_return(vty, ret);
718e3744 7786}
7787
d62a17ae 7788static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7789 safi_t safi, const char *direct_str)
718e3744 7790{
d62a17ae 7791 int ret;
7792 struct peer *peer;
7793 int direct = FILTER_IN;
718e3744 7794
d62a17ae 7795 peer = peer_and_group_lookup_vty(vty, ip_str);
7796 if (!peer)
7797 return CMD_WARNING_CONFIG_FAILED;
718e3744 7798
d62a17ae 7799 /* Check filter direction. */
7800 if (strncmp(direct_str, "i", 1) == 0)
7801 direct = FILTER_IN;
7802 else if (strncmp(direct_str, "o", 1) == 0)
7803 direct = FILTER_OUT;
718e3744 7804
d62a17ae 7805 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 7806
d62a17ae 7807 return bgp_vty_return(vty, ret);
718e3744 7808}
7809
7810DEFUN (neighbor_filter_list,
7811 neighbor_filter_list_cmd,
de71d43e 7812 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
718e3744 7813 NEIGHBOR_STR
7814 NEIGHBOR_ADDR_STR2
7815 "Establish BGP filters\n"
7816 "AS path access-list name\n"
7817 "Filter incoming routes\n"
7818 "Filter outgoing routes\n")
7819{
d62a17ae 7820 int idx_peer = 1;
7821 int idx_word = 3;
7822 int idx_in_out = 4;
7823 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7824 bgp_node_safi(vty), argv[idx_word]->arg,
7825 argv[idx_in_out]->arg);
718e3744 7826}
7827
d62a17ae 7828ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
de71d43e 7829 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
d62a17ae 7830 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7831 "Establish BGP filters\n"
7832 "AS path access-list name\n"
7833 "Filter incoming routes\n"
7834 "Filter outgoing routes\n")
596c17ba 7835
718e3744 7836DEFUN (no_neighbor_filter_list,
7837 no_neighbor_filter_list_cmd,
de71d43e 7838 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
718e3744 7839 NO_STR
7840 NEIGHBOR_STR
7841 NEIGHBOR_ADDR_STR2
7842 "Establish BGP filters\n"
7843 "AS path access-list name\n"
7844 "Filter incoming routes\n"
7845 "Filter outgoing routes\n")
7846{
d62a17ae 7847 int idx_peer = 2;
7848 int idx_in_out = 5;
7849 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7850 bgp_node_afi(vty), bgp_node_safi(vty),
7851 argv[idx_in_out]->arg);
718e3744 7852}
6b0655a2 7853
d62a17ae 7854ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
de71d43e 7855 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
d62a17ae 7856 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7857 "Establish BGP filters\n"
7858 "AS path access-list name\n"
7859 "Filter incoming routes\n"
7860 "Filter outgoing routes\n")
596c17ba 7861
7f7940e6
MK
7862/* Set advertise-map to the peer. */
7863static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7864 afi_t afi, safi_t safi,
cf2ad4d8
MK
7865 const char *advertise_str,
7866 const char *condition_str, bool condition,
7867 bool set)
7f7940e6
MK
7868{
7869 int ret = CMD_WARNING_CONFIG_FAILED;
7870 struct peer *peer;
7871 struct route_map *advertise_map;
7872 struct route_map *condition_map;
7873
7874 peer = peer_and_group_lookup_vty(vty, ip_str);
7875 if (!peer)
7876 return ret;
7877
7878 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7879 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7880
cf2ad4d8
MK
7881 if (set)
7882 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7883 advertise_map, condition_str,
7884 condition_map, condition);
7885 else
7886 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7887 advertise_map, condition_str,
7888 condition_map, condition);
7f7940e6
MK
7889
7890 return bgp_vty_return(vty, ret);
7891}
7892
389e4f92
QY
7893DEFPY (bgp_condadv_period,
7894 bgp_condadv_period_cmd,
7895 "[no$no] bgp conditional-advertisement timer (5-240)$period",
7896 NO_STR
7897 BGP_STR
7898 "Conditional advertisement settings\n"
7899 "Set period to rescan BGP table to check if condition is met\n"
7900 "Period between BGP table scans, in seconds; default 60\n")
7901{
7902 VTY_DECLVAR_CONTEXT(bgp, bgp);
7903
7904 bgp->condition_check_period =
7905 no ? DEFAULT_CONDITIONAL_ROUTES_POLL_TIME : period;
7906
7907 return CMD_SUCCESS;
7908}
7909
cf2ad4d8 7910DEFPY (neighbor_advertise_map,
7f7940e6 7911 neighbor_advertise_map_cmd,
3ccddc25 7912 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor advertise-map RMAP_NAME$advertise_str <exist-map|non-exist-map>$exist RMAP_NAME$condition_str",
cf2ad4d8 7913 NO_STR
7f7940e6
MK
7914 NEIGHBOR_STR
7915 NEIGHBOR_ADDR_STR2
7916 "Route-map to conditionally advertise routes\n"
7917 "Name of advertise map\n"
7918 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 7919 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 7920 "Name of the exist or non exist map\n")
7f7940e6 7921{
7f7940e6
MK
7922 bool condition = CONDITION_EXIST;
7923
52b84062 7924 if (!strcmp(exist, "non-exist-map"))
7f7940e6
MK
7925 condition = CONDITION_NON_EXIST;
7926
52b84062
MK
7927 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7928 bgp_node_safi(vty), advertise_str,
7929 condition_str, condition, !no);
7f7940e6
MK
7930}
7931
7932ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
3ccddc25 7933 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor advertise-map RMAP_NAME$advertise_str <exist-map|non-exist-map>$exist RMAP_NAME$condition_str",
7f7940e6
MK
7934 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7935 "Route-map to conditionally advertise routes\n"
7936 "Name of advertise map\n"
7937 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 7938 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 7939 "Name of the exist or non exist map\n")
7f7940e6 7940
718e3744 7941/* Set route-map to the peer. */
0ea8d871
IR
7942static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7943 afi_t afi, safi_t safi, const char *name_str,
7944 const char *direct_str)
718e3744 7945{
0ea8d871
IR
7946 int ret;
7947 struct peer *peer;
7948 int direct = RMAP_IN;
7949 struct route_map *route_map;
718e3744 7950
0ea8d871
IR
7951 peer = peer_and_group_lookup_vty(vty, ip_str);
7952 if (!peer)
d62a17ae 7953 return CMD_WARNING_CONFIG_FAILED;
718e3744 7954
0ea8d871
IR
7955 /* Check filter direction. */
7956 if (strncmp(direct_str, "in", 2) == 0)
7957 direct = RMAP_IN;
7958 else if (strncmp(direct_str, "o", 1) == 0)
7959 direct = RMAP_OUT;
718e3744 7960
0ea8d871
IR
7961 route_map = route_map_lookup_warn_noexist(vty, name_str);
7962 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
718e3744 7963
0ea8d871
IR
7964 return bgp_vty_return(vty, ret);
7965}
7966
7967static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7968 afi_t afi, safi_t safi,
7969 const char *direct_str)
7970{
7971 int ret;
7972 struct peer *peer;
7973 int direct = RMAP_IN;
7974
7975 peer = peer_and_group_lookup_vty(vty, ip_str);
7976 if (!peer)
7977 return CMD_WARNING_CONFIG_FAILED;
7978
7979 /* Check filter direction. */
7980 if (strncmp(direct_str, "in", 2) == 0)
7981 direct = RMAP_IN;
7982 else if (strncmp(direct_str, "o", 1) == 0)
7983 direct = RMAP_OUT;
7984
7985 ret = peer_route_map_unset(peer, afi, safi, direct);
7986
7987 return bgp_vty_return(vty, ret);
7988}
7989
7990DEFUN (neighbor_route_map,
7991 neighbor_route_map_cmd,
70dd370f 7992 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
0ea8d871
IR
7993 NEIGHBOR_STR
7994 NEIGHBOR_ADDR_STR2
7995 "Apply route map to neighbor\n"
7996 "Name of route map\n"
7997 "Apply map to incoming routes\n"
7998 "Apply map to outbound routes\n")
7999{
8000 int idx_peer = 1;
8001 int idx_word = 3;
8002 int idx_in_out = 4;
8003 return peer_route_map_set_vty(
8004 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8005 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 8006}
8007
d6d7ed37 8008ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
70dd370f 8009 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
d6d7ed37
IR
8010 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8011 "Apply route map to neighbor\n"
8012 "Name of route map\n"
8013 "Apply map to incoming routes\n"
8014 "Apply map to outbound routes\n")
8015
0ea8d871
IR
8016DEFUN (no_neighbor_route_map,
8017 no_neighbor_route_map_cmd,
70dd370f 8018 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
0ea8d871
IR
8019 NO_STR
8020 NEIGHBOR_STR
8021 NEIGHBOR_ADDR_STR2
8022 "Apply route map to neighbor\n"
8023 "Name of route map\n"
8024 "Apply map to incoming routes\n"
8025 "Apply map to outbound routes\n")
8026{
8027 int idx_peer = 2;
8028 int idx_in_out = 5;
8029 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
8030 bgp_node_afi(vty), bgp_node_safi(vty),
8031 argv[idx_in_out]->arg);
8032}
8033
8034ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
70dd370f 8035 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
d6d7ed37
IR
8036 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8037 "Apply route map to neighbor\n"
8038 "Name of route map\n"
8039 "Apply map to incoming routes\n"
8040 "Apply map to outbound routes\n")
8041
718e3744 8042/* Set unsuppress-map to the peer. */
d62a17ae 8043static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
8044 afi_t afi, safi_t safi,
8045 const char *name_str)
718e3744 8046{
d62a17ae 8047 int ret;
8048 struct peer *peer;
1de27621 8049 struct route_map *route_map;
718e3744 8050
d62a17ae 8051 peer = peer_and_group_lookup_vty(vty, ip_str);
8052 if (!peer)
8053 return CMD_WARNING_CONFIG_FAILED;
718e3744 8054
1de27621
DA
8055 route_map = route_map_lookup_warn_noexist(vty, name_str);
8056 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
718e3744 8057
d62a17ae 8058 return bgp_vty_return(vty, ret);
718e3744 8059}
8060
8061/* Unset route-map from the peer. */
d62a17ae 8062static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
8063 afi_t afi, safi_t safi)
718e3744 8064{
d62a17ae 8065 int ret;
8066 struct peer *peer;
718e3744 8067
d62a17ae 8068 peer = peer_and_group_lookup_vty(vty, ip_str);
8069 if (!peer)
8070 return CMD_WARNING_CONFIG_FAILED;
718e3744 8071
d62a17ae 8072 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 8073
d62a17ae 8074 return bgp_vty_return(vty, ret);
718e3744 8075}
8076
8077DEFUN (neighbor_unsuppress_map,
8078 neighbor_unsuppress_map_cmd,
9ccf14f7 8079 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 8080 NEIGHBOR_STR
8081 NEIGHBOR_ADDR_STR2
8082 "Route-map to selectively unsuppress suppressed routes\n"
8083 "Name of route map\n")
8084{
d62a17ae 8085 int idx_peer = 1;
8086 int idx_word = 3;
8087 return peer_unsuppress_map_set_vty(
8088 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8089 argv[idx_word]->arg);
718e3744 8090}
8091
d62a17ae 8092ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
8093 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8094 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8095 "Route-map to selectively unsuppress suppressed routes\n"
8096 "Name of route map\n")
596c17ba 8097
718e3744 8098DEFUN (no_neighbor_unsuppress_map,
8099 no_neighbor_unsuppress_map_cmd,
9ccf14f7 8100 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 8101 NO_STR
8102 NEIGHBOR_STR
8103 NEIGHBOR_ADDR_STR2
8104 "Route-map to selectively unsuppress suppressed routes\n"
8105 "Name of route map\n")
8106{
d62a17ae 8107 int idx_peer = 2;
8108 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
8109 bgp_node_afi(vty),
8110 bgp_node_safi(vty));
718e3744 8111}
6b0655a2 8112
d62a17ae 8113ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
8114 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8115 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8116 "Route-map to selectively unsuppress suppressed routes\n"
8117 "Name of route map\n")
596c17ba 8118
7e62b792
IR
8119static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
8120 afi_t afi, safi_t safi,
8121 const char *num_str,
8122 const char *threshold_str, int warning,
8123 const char *restart_str,
8124 const char *force_str)
8125{
8126 int ret;
8127 struct peer *peer;
8128 uint32_t max;
8129 uint8_t threshold;
8130 uint16_t restart;
8131
8132 peer = peer_and_group_lookup_vty(vty, ip_str);
8133 if (!peer)
8134 return CMD_WARNING_CONFIG_FAILED;
8135
8136 max = strtoul(num_str, NULL, 10);
8137 if (threshold_str)
8138 threshold = atoi(threshold_str);
8139 else
8140 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
8141
8142 if (restart_str)
8143 restart = atoi(restart_str);
8144 else
8145 restart = 0;
8146
8147 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
8148 restart, force_str ? true : false);
8149
8150 return bgp_vty_return(vty, ret);
8151}
8152
8153static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
8154 afi_t afi, safi_t safi)
8155{
8156 int ret;
8157 struct peer *peer;
8158
8159 peer = peer_and_group_lookup_vty(vty, ip_str);
8160 if (!peer)
8161 return CMD_WARNING_CONFIG_FAILED;
8162
8163 ret = peer_maximum_prefix_unset(peer, afi, safi);
8164
8165 return bgp_vty_return(vty, ret);
8166}
8167
fde246e8 8168/* Maximum number of prefix to be sent to the neighbor. */
1d80f243
IR
8169DEFUN(neighbor_maximum_prefix_out,
8170 neighbor_maximum_prefix_out_cmd,
8171 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
8172 NEIGHBOR_STR
8173 NEIGHBOR_ADDR_STR2
8174 "Maximum number of prefixes to be sent to this peer\n"
8175 "Maximum no. of prefix limit\n")
fde246e8 8176{
80444d30 8177 int ret;
fde246e8
DA
8178 int idx_peer = 1;
8179 int idx_number = 3;
7e62b792
IR
8180 struct peer *peer;
8181 uint32_t max;
fde246e8
DA
8182 afi_t afi = bgp_node_afi(vty);
8183 safi_t safi = bgp_node_safi(vty);
8184
7e62b792
IR
8185 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8186 if (!peer)
fde246e8
DA
8187 return CMD_WARNING_CONFIG_FAILED;
8188
7e62b792 8189 max = strtoul(argv[idx_number]->arg, NULL, 10);
fde246e8 8190
80444d30 8191 ret = peer_maximum_prefix_out_set(peer, afi, safi, max);
fde246e8 8192
80444d30 8193 return bgp_vty_return(vty, ret);
fde246e8
DA
8194}
8195
1d80f243
IR
8196DEFUN(no_neighbor_maximum_prefix_out,
8197 no_neighbor_maximum_prefix_out_cmd,
bc03c622 8198 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out [(1-4294967295)]",
1d80f243
IR
8199 NO_STR
8200 NEIGHBOR_STR
8201 NEIGHBOR_ADDR_STR2
bc03c622
LS
8202 "Maximum number of prefixes to be sent to this peer\n"
8203 "Maximum no. of prefix limit\n")
fde246e8 8204{
80444d30 8205 int ret;
fde246e8 8206 int idx_peer = 2;
7e62b792 8207 struct peer *peer;
fde246e8
DA
8208 afi_t afi = bgp_node_afi(vty);
8209 safi_t safi = bgp_node_safi(vty);
8210
7e62b792
IR
8211 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8212 if (!peer)
fde246e8
DA
8213 return CMD_WARNING_CONFIG_FAILED;
8214
80444d30 8215 ret = peer_maximum_prefix_out_unset(peer, afi, safi);
fde246e8 8216
80444d30 8217 return bgp_vty_return(vty, ret);
fde246e8
DA
8218}
8219
9cbd06e0
DA
8220/* Maximum number of prefix configuration. Prefix count is different
8221 for each peer configuration. So this configuration can be set for
718e3744 8222 each peer configuration. */
1d80f243
IR
8223DEFUN (neighbor_maximum_prefix,
8224 neighbor_maximum_prefix_cmd,
8225 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8226 NEIGHBOR_STR
8227 NEIGHBOR_ADDR_STR2
8228 "Maximum number of prefix accept from this peer\n"
8229 "maximum no. of prefix limit\n"
8230 "Force checking all received routes not only accepted\n")
718e3744 8231{
d62a17ae 8232 int idx_peer = 1;
8233 int idx_number = 3;
9cbd06e0 8234 int idx_force = 0;
7e62b792 8235 char *force = NULL;
9cbd06e0
DA
8236
8237 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 8238 force = argv[idx_force]->arg;
9cbd06e0 8239
7e62b792
IR
8240 return peer_maximum_prefix_set_vty(
8241 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8242 argv[idx_number]->arg, NULL, 0, NULL, force);
718e3744 8243}
8244
d62a17ae 8245ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 8246 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
d62a17ae 8247 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8248 "Maximum number of prefix accept from this peer\n"
9cbd06e0
DA
8249 "maximum no. of prefix limit\n"
8250 "Force checking all received routes not only accepted\n")
596c17ba 8251
1d80f243
IR
8252DEFUN (neighbor_maximum_prefix_threshold,
8253 neighbor_maximum_prefix_threshold_cmd,
8254 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8255 NEIGHBOR_STR
8256 NEIGHBOR_ADDR_STR2
8257 "Maximum number of prefix accept from this peer\n"
8258 "maximum no. of prefix limit\n"
8259 "Threshold value (%) at which to generate a warning msg\n"
8260 "Force checking all received routes not only accepted\n")
e0701b79 8261{
d62a17ae 8262 int idx_peer = 1;
8263 int idx_number = 3;
8264 int idx_number_2 = 4;
9cbd06e0 8265 int idx_force = 0;
7e62b792 8266 char *force = NULL;
9cbd06e0
DA
8267
8268 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 8269 force = argv[idx_force]->arg;
9cbd06e0 8270
7e62b792
IR
8271 return peer_maximum_prefix_set_vty(
8272 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8273 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
0a486e5f 8274}
e0701b79 8275
d62a17ae 8276ALIAS_HIDDEN(
8277 neighbor_maximum_prefix_threshold,
8278 neighbor_maximum_prefix_threshold_hidden_cmd,
9cbd06e0 8279 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
d62a17ae 8280 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8281 "Maximum number of prefix accept from this peer\n"
8282 "maximum no. of prefix limit\n"
9cbd06e0
DA
8283 "Threshold value (%) at which to generate a warning msg\n"
8284 "Force checking all received routes not only accepted\n")
596c17ba 8285
1d80f243
IR
8286DEFUN (neighbor_maximum_prefix_warning,
8287 neighbor_maximum_prefix_warning_cmd,
8288 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8289 NEIGHBOR_STR
8290 NEIGHBOR_ADDR_STR2
8291 "Maximum number of prefix accept from this peer\n"
8292 "maximum no. of prefix limit\n"
8293 "Only give warning message when limit is exceeded\n"
8294 "Force checking all received routes not only accepted\n")
718e3744 8295{
d62a17ae 8296 int idx_peer = 1;
8297 int idx_number = 3;
9cbd06e0 8298 int idx_force = 0;
7e62b792 8299 char *force = NULL;
9cbd06e0
DA
8300
8301 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 8302 force = argv[idx_force]->arg;
9cbd06e0 8303
7e62b792
IR
8304 return peer_maximum_prefix_set_vty(
8305 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8306 argv[idx_number]->arg, NULL, 1, NULL, force);
718e3744 8307}
8308
d62a17ae 8309ALIAS_HIDDEN(
8310 neighbor_maximum_prefix_warning,
8311 neighbor_maximum_prefix_warning_hidden_cmd,
9cbd06e0 8312 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
d62a17ae 8313 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8314 "Maximum number of prefix accept from this peer\n"
8315 "maximum no. of prefix limit\n"
9cbd06e0
DA
8316 "Only give warning message when limit is exceeded\n"
8317 "Force checking all received routes not only accepted\n")
596c17ba 8318
1d80f243
IR
8319DEFUN (neighbor_maximum_prefix_threshold_warning,
8320 neighbor_maximum_prefix_threshold_warning_cmd,
8321 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8322 NEIGHBOR_STR
8323 NEIGHBOR_ADDR_STR2
8324 "Maximum number of prefix accept from this peer\n"
8325 "maximum no. of prefix limit\n"
8326 "Threshold value (%) at which to generate a warning msg\n"
8327 "Only give warning message when limit is exceeded\n"
8328 "Force checking all received routes not only accepted\n")
e0701b79 8329{
d62a17ae 8330 int idx_peer = 1;
8331 int idx_number = 3;
8332 int idx_number_2 = 4;
9cbd06e0 8333 int idx_force = 0;
7e62b792 8334 char *force = NULL;
9cbd06e0
DA
8335
8336 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 8337 force = argv[idx_force]->arg;
9cbd06e0 8338
7e62b792
IR
8339 return peer_maximum_prefix_set_vty(
8340 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8341 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
0a486e5f 8342}
8343
d62a17ae 8344ALIAS_HIDDEN(
8345 neighbor_maximum_prefix_threshold_warning,
8346 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
9cbd06e0 8347 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
d62a17ae 8348 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8349 "Maximum number of prefix accept from this peer\n"
8350 "maximum no. of prefix limit\n"
8351 "Threshold value (%) at which to generate a warning msg\n"
9cbd06e0
DA
8352 "Only give warning message when limit is exceeded\n"
8353 "Force checking all received routes not only accepted\n")
596c17ba 8354
1d80f243
IR
8355DEFUN (neighbor_maximum_prefix_restart,
8356 neighbor_maximum_prefix_restart_cmd,
8357 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8358 NEIGHBOR_STR
8359 NEIGHBOR_ADDR_STR2
8360 "Maximum number of prefix accept from this peer\n"
8361 "maximum no. of prefix limit\n"
8362 "Restart bgp connection after limit is exceeded\n"
8363 "Restart interval in minutes\n"
8364 "Force checking all received routes not only accepted\n")
0a486e5f 8365{
d62a17ae 8366 int idx_peer = 1;
8367 int idx_number = 3;
8368 int idx_number_2 = 5;
9cbd06e0 8369 int idx_force = 0;
7e62b792 8370 char *force = NULL;
9cbd06e0
DA
8371
8372 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 8373 force = argv[idx_force]->arg;
9cbd06e0 8374
7e62b792
IR
8375 return peer_maximum_prefix_set_vty(
8376 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8377 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
0a486e5f 8378}
8379
d62a17ae 8380ALIAS_HIDDEN(
8381 neighbor_maximum_prefix_restart,
8382 neighbor_maximum_prefix_restart_hidden_cmd,
9cbd06e0 8383 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
d62a17ae 8384 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8385 "Maximum number of prefix accept from this peer\n"
8386 "maximum no. of prefix limit\n"
8387 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
8388 "Restart interval in minutes\n"
8389 "Force checking all received routes not only accepted\n")
596c17ba 8390
1d80f243
IR
8391DEFUN (neighbor_maximum_prefix_threshold_restart,
8392 neighbor_maximum_prefix_threshold_restart_cmd,
8393 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8394 NEIGHBOR_STR
8395 NEIGHBOR_ADDR_STR2
8396 "Maximum number of prefixes to accept from this peer\n"
8397 "maximum no. of prefix limit\n"
8398 "Threshold value (%) at which to generate a warning msg\n"
8399 "Restart bgp connection after limit is exceeded\n"
8400 "Restart interval in minutes\n"
8401 "Force checking all received routes not only accepted\n")
0a486e5f 8402{
d62a17ae 8403 int idx_peer = 1;
8404 int idx_number = 3;
8405 int idx_number_2 = 4;
8406 int idx_number_3 = 6;
9cbd06e0 8407 int idx_force = 0;
7e62b792 8408 char *force = NULL;
9cbd06e0
DA
8409
8410 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 8411 force = argv[idx_force]->arg;
9cbd06e0 8412
7e62b792
IR
8413 return peer_maximum_prefix_set_vty(
8414 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8415 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
8416 argv[idx_number_3]->arg, force);
d62a17ae 8417}
8418
8419ALIAS_HIDDEN(
8420 neighbor_maximum_prefix_threshold_restart,
8421 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
9cbd06e0 8422 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
d62a17ae 8423 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8424 "Maximum number of prefixes to accept from this peer\n"
8425 "maximum no. of prefix limit\n"
8426 "Threshold value (%) at which to generate a warning msg\n"
8427 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
8428 "Restart interval in minutes\n"
8429 "Force checking all received routes not only accepted\n")
596c17ba 8430
1d80f243
IR
8431DEFUN (no_neighbor_maximum_prefix,
8432 no_neighbor_maximum_prefix_cmd,
8433 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8434 NO_STR
8435 NEIGHBOR_STR
8436 NEIGHBOR_ADDR_STR2
8437 "Maximum number of prefixes to accept from this peer\n"
8438 "maximum no. of prefix limit\n"
8439 "Threshold value (%) at which to generate a warning msg\n"
8440 "Restart bgp connection after limit is exceeded\n"
8441 "Restart interval in minutes\n"
8442 "Only give warning message when limit is exceeded\n"
8443 "Force checking all received routes not only accepted\n")
718e3744 8444{
d62a17ae 8445 int idx_peer = 2;
7e62b792
IR
8446 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
8447 bgp_node_afi(vty),
8448 bgp_node_safi(vty));
718e3744 8449}
e52702f2 8450
d62a17ae 8451ALIAS_HIDDEN(
8452 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 8453 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
d62a17ae 8454 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8455 "Maximum number of prefixes to accept from this peer\n"
8456 "maximum no. of prefix limit\n"
8457 "Threshold value (%) at which to generate a warning msg\n"
8458 "Restart bgp connection after limit is exceeded\n"
8459 "Restart interval in minutes\n"
9cbd06e0
DA
8460 "Only give warning message when limit is exceeded\n"
8461 "Force checking all received routes not only accepted\n")
596c17ba 8462
46dbf9d0
DA
8463/* "neighbor accept-own" */
8464DEFPY (neighbor_accept_own,
8465 neighbor_accept_own_cmd,
8466 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor accept-own",
8467 NO_STR
8468 NEIGHBOR_STR
8469 NEIGHBOR_ADDR_STR2
8470 "Enable handling of self-originated VPN routes containing ACCEPT_OWN community\n")
8471{
8472 struct peer *peer;
8473 afi_t afi = bgp_node_afi(vty);
8474 safi_t safi = bgp_node_safi(vty);
8475 int ret;
8476
8477 peer = peer_and_group_lookup_vty(vty, neighbor);
8478 if (!peer)
8479 return CMD_WARNING_CONFIG_FAILED;
8480
8481 if (no)
8482 ret = peer_af_flag_unset(peer, afi, safi, PEER_FLAG_ACCEPT_OWN);
8483 else
8484 ret = peer_af_flag_set(peer, afi, safi, PEER_FLAG_ACCEPT_OWN);
8485
8486 return bgp_vty_return(vty, ret);
8487}
8488
01da2d26
DA
8489/* "neighbor soo" */
8490DEFPY (neighbor_soo,
8491 neighbor_soo_cmd,
8492 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo ASN:NN_OR_IP-ADDRESS:NN$soo",
8493 NEIGHBOR_STR
8494 NEIGHBOR_ADDR_STR2
8495 "Set the Site-of-Origin (SoO) extended community\n"
8496 "VPN extended community\n")
8497{
8498 struct peer *peer;
8499 afi_t afi = bgp_node_afi(vty);
8500 safi_t safi = bgp_node_safi(vty);
8501 struct ecommunity *ecomm_soo;
8502
8503 peer = peer_and_group_lookup_vty(vty, neighbor);
8504 if (!peer)
8505 return CMD_WARNING_CONFIG_FAILED;
8506
8507 ecomm_soo = ecommunity_str2com(soo, ECOMMUNITY_SITE_ORIGIN, 0);
8508 if (!ecomm_soo) {
8509 vty_out(vty, "%% Malformed SoO extended community\n");
8510 return CMD_WARNING;
8511 }
8512 ecommunity_str(ecomm_soo);
8513
8514 if (!ecommunity_match(peer->soo[afi][safi], ecomm_soo)) {
8515 ecommunity_free(&peer->soo[afi][safi]);
8516 peer->soo[afi][safi] = ecomm_soo;
8517 peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO);
8518 }
8519
8520 return bgp_vty_return(vty,
8521 peer_af_flag_set(peer, afi, safi, PEER_FLAG_SOO));
8522}
8523
8524DEFPY (no_neighbor_soo,
8525 no_neighbor_soo_cmd,
8526 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo [ASN:NN_OR_IP-ADDRESS:NN$soo]",
8527 NO_STR
8528 NEIGHBOR_STR
8529 NEIGHBOR_ADDR_STR2
8530 "Set the Site-of-Origin (SoO) extended community\n"
8531 "VPN extended community\n")
8532{
8533 struct peer *peer;
8534 afi_t afi = bgp_node_afi(vty);
8535 safi_t safi = bgp_node_safi(vty);
8536
8537 peer = peer_and_group_lookup_vty(vty, neighbor);
8538 if (!peer)
8539 return CMD_WARNING_CONFIG_FAILED;
8540
8541 ecommunity_free(&peer->soo[afi][safi]);
8542
8543 return bgp_vty_return(
8544 vty, peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO));
8545}
718e3744 8546
718e3744 8547/* "neighbor allowas-in" */
8548DEFUN (neighbor_allowas_in,
8549 neighbor_allowas_in_cmd,
fd8503f5 8550 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 8551 NEIGHBOR_STR
8552 NEIGHBOR_ADDR_STR2
31500417 8553 "Accept as-path with my AS present in it\n"
f79f7a7b 8554 "Number of occurrences of AS number\n"
fd8503f5 8555 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 8556{
d62a17ae 8557 int idx_peer = 1;
8558 int idx_number_origin = 3;
8559 int ret;
8560 int origin = 0;
8561 struct peer *peer;
8562 int allow_num = 0;
8563
8564 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8565 if (!peer)
8566 return CMD_WARNING_CONFIG_FAILED;
8567
8568 if (argc <= idx_number_origin)
8569 allow_num = 3;
8570 else {
8571 if (argv[idx_number_origin]->type == WORD_TKN)
8572 origin = 1;
8573 else
8574 allow_num = atoi(argv[idx_number_origin]->arg);
8575 }
8576
8577 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8578 allow_num, origin);
8579
8580 return bgp_vty_return(vty, ret);
8581}
8582
8583ALIAS_HIDDEN(
8584 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8585 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8586 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8587 "Accept as-path with my AS present in it\n"
f79f7a7b 8588 "Number of occurrences of AS number\n"
d62a17ae 8589 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 8590
718e3744 8591DEFUN (no_neighbor_allowas_in,
8592 no_neighbor_allowas_in_cmd,
fd8503f5 8593 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 8594 NO_STR
8595 NEIGHBOR_STR
8596 NEIGHBOR_ADDR_STR2
8334fd5a 8597 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8598 "Number of occurrences of AS number\n"
fd8503f5 8599 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 8600{
d62a17ae 8601 int idx_peer = 2;
8602 int ret;
8603 struct peer *peer;
718e3744 8604
d62a17ae 8605 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8606 if (!peer)
8607 return CMD_WARNING_CONFIG_FAILED;
718e3744 8608
d62a17ae 8609 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8610 bgp_node_safi(vty));
718e3744 8611
d62a17ae 8612 return bgp_vty_return(vty, ret);
718e3744 8613}
6b0655a2 8614
d62a17ae 8615ALIAS_HIDDEN(
8616 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8617 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8618 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8619 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8620 "Number of occurrences of AS number\n"
d62a17ae 8621 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 8622
28c6e247
IR
8623DEFUN (neighbor_ttl_security,
8624 neighbor_ttl_security_cmd,
8625 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8626 NEIGHBOR_STR
8627 NEIGHBOR_ADDR_STR2
8628 "BGP ttl-security parameters\n"
8629 "Specify the maximum number of hops to the BGP peer\n"
8630 "Number of hops to BGP peer\n")
fa411a21 8631{
d62a17ae 8632 int idx_peer = 1;
8633 int idx_number = 4;
28c6e247
IR
8634 struct peer *peer;
8635 int gtsm_hops;
d62a17ae 8636
28c6e247
IR
8637 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8638 if (!peer)
d62a17ae 8639 return CMD_WARNING_CONFIG_FAILED;
8640
28c6e247
IR
8641 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
8642
8643 /*
8644 * If 'neighbor swpX', then this is for directly connected peers,
8645 * we should not accept a ttl-security hops value greater than 1.
8646 */
8647 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
8648 vty_out(vty,
8649 "%s is directly connected peer, hops cannot exceed 1\n",
8650 argv[idx_peer]->arg);
8651 return CMD_WARNING_CONFIG_FAILED;
8652 }
7ebe625c 8653
28c6e247 8654 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
8655}
8656
1d80f243
IR
8657DEFUN (no_neighbor_ttl_security,
8658 no_neighbor_ttl_security_cmd,
8659 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8660 NO_STR
8661 NEIGHBOR_STR
8662 NEIGHBOR_ADDR_STR2
8663 "BGP ttl-security parameters\n"
8664 "Specify the maximum number of hops to the BGP peer\n"
8665 "Number of hops to BGP peer\n")
fa411a21 8666{
d62a17ae 8667 int idx_peer = 2;
28c6e247 8668 struct peer *peer;
fa411a21 8669
28c6e247
IR
8670 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8671 if (!peer)
d62a17ae 8672 return CMD_WARNING_CONFIG_FAILED;
fa411a21 8673
28c6e247 8674 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 8675}
6b0655a2 8676
7c0e4312
DA
8677/* disable-addpath-rx */
8678DEFUN(neighbor_disable_addpath_rx,
8679 neighbor_disable_addpath_rx_cmd,
8680 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8681 NEIGHBOR_STR
8682 NEIGHBOR_ADDR_STR2
8683 "Do not accept additional paths\n")
8684{
8685 char *peer_str = argv[1]->arg;
8686 struct peer *peer;
8687 afi_t afi = bgp_node_afi(vty);
8688 safi_t safi = bgp_node_safi(vty);
8689
8690 peer = peer_and_group_lookup_vty(vty, peer_str);
8691 if (!peer)
8692 return CMD_WARNING_CONFIG_FAILED;
8693
8694 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
8695 PEER_FLAG_DISABLE_ADDPATH_RX);
8696}
8697
8698DEFUN(no_neighbor_disable_addpath_rx,
8699 no_neighbor_disable_addpath_rx_cmd,
8700 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8701 NO_STR
8702 NEIGHBOR_STR
8703 NEIGHBOR_ADDR_STR2
8704 "Do not accept additional paths\n")
8705{
8706 char *peer_str = argv[2]->arg;
8707 struct peer *peer;
8708 afi_t afi = bgp_node_afi(vty);
8709 safi_t safi = bgp_node_safi(vty);
8710
8711 peer = peer_and_group_lookup_vty(vty, peer_str);
8712 if (!peer)
8713 return CMD_WARNING_CONFIG_FAILED;
8714
8715 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
8716 PEER_FLAG_DISABLE_ADDPATH_RX);
8717}
8718
adbac85e
DW
8719DEFUN (neighbor_addpath_tx_all_paths,
8720 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8721 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8722 NEIGHBOR_STR
8723 NEIGHBOR_ADDR_STR2
8724 "Use addpath to advertise all paths to a neighbor\n")
8725{
d62a17ae 8726 int idx_peer = 1;
8727 struct peer *peer;
adbac85e 8728
d62a17ae 8729 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8730 if (!peer)
8731 return CMD_WARNING_CONFIG_FAILED;
adbac85e 8732
dcc68b5e
MS
8733 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8734 BGP_ADDPATH_ALL);
8735 return CMD_SUCCESS;
adbac85e
DW
8736}
8737
d62a17ae 8738ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8739 neighbor_addpath_tx_all_paths_hidden_cmd,
8740 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8741 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8742 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8743
adbac85e
DW
8744DEFUN (no_neighbor_addpath_tx_all_paths,
8745 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8746 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8747 NO_STR
8748 NEIGHBOR_STR
8749 NEIGHBOR_ADDR_STR2
8750 "Use addpath to advertise all paths to a neighbor\n")
8751{
d62a17ae 8752 int idx_peer = 2;
dcc68b5e
MS
8753 struct peer *peer;
8754
8755 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8756 if (!peer)
8757 return CMD_WARNING_CONFIG_FAILED;
8758
8759 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8760 != BGP_ADDPATH_ALL) {
8761 vty_out(vty,
8762 "%% Peer not currently configured to transmit all paths.");
8763 return CMD_WARNING_CONFIG_FAILED;
8764 }
8765
8766 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8767 BGP_ADDPATH_NONE);
8768
8769 return CMD_SUCCESS;
adbac85e
DW
8770}
8771
d62a17ae 8772ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8773 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8774 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8775 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8776 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8777
06370dac
DW
8778DEFUN (neighbor_addpath_tx_bestpath_per_as,
8779 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8780 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8781 NEIGHBOR_STR
8782 NEIGHBOR_ADDR_STR2
8783 "Use addpath to advertise the bestpath per each neighboring AS\n")
8784{
d62a17ae 8785 int idx_peer = 1;
8786 struct peer *peer;
06370dac 8787
d62a17ae 8788 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8789 if (!peer)
8790 return CMD_WARNING_CONFIG_FAILED;
06370dac 8791
dcc68b5e
MS
8792 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8793 BGP_ADDPATH_BEST_PER_AS);
8794
8795 return CMD_SUCCESS;
06370dac
DW
8796}
8797
d62a17ae 8798ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8799 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8800 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8801 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8802 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8803
06370dac
DW
8804DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8805 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8806 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8807 NO_STR
8808 NEIGHBOR_STR
8809 NEIGHBOR_ADDR_STR2
8810 "Use addpath to advertise the bestpath per each neighboring AS\n")
8811{
d62a17ae 8812 int idx_peer = 2;
dcc68b5e
MS
8813 struct peer *peer;
8814
8815 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8816 if (!peer)
8817 return CMD_WARNING_CONFIG_FAILED;
8818
8819 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8820 != BGP_ADDPATH_BEST_PER_AS) {
8821 vty_out(vty,
8822 "%% Peer not currently configured to transmit all best path per as.");
8823 return CMD_WARNING_CONFIG_FAILED;
8824 }
8825
8826 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8827 BGP_ADDPATH_NONE);
8828
8829 return CMD_SUCCESS;
06370dac
DW
8830}
8831
d62a17ae 8832ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8833 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8834 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8835 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8836 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8837
2b31007c
RZ
8838DEFPY(
8839 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8840 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8841 NEIGHBOR_STR
8842 NEIGHBOR_ADDR_STR2
8843 "Detect AS loops before sending to neighbor\n")
8844{
8845 struct peer *peer;
8846
8847 peer = peer_and_group_lookup_vty(vty, neighbor);
8848 if (!peer)
8849 return CMD_WARNING_CONFIG_FAILED;
8850
8851 peer->as_path_loop_detection = true;
8852
8853 return CMD_SUCCESS;
8854}
8855
8856DEFPY(
8857 no_neighbor_aspath_loop_detection,
8858 no_neighbor_aspath_loop_detection_cmd,
8859 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8860 NO_STR
8861 NEIGHBOR_STR
8862 NEIGHBOR_ADDR_STR2
8863 "Detect AS loops before sending to neighbor\n")
8864{
8865 struct peer *peer;
8866
8867 peer = peer_and_group_lookup_vty(vty, neighbor);
8868 if (!peer)
8869 return CMD_WARNING_CONFIG_FAILED;
8870
8871 peer->as_path_loop_detection = false;
8872
8873 return CMD_SUCCESS;
8874}
8875
a5c6a9b1
DA
8876DEFPY(neighbor_path_attribute_discard,
8877 neighbor_path_attribute_discard_cmd,
8878 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor path-attribute discard (1-255)...",
8879 NEIGHBOR_STR
8880 NEIGHBOR_ADDR_STR2
8881 "Manipulate path attributes from incoming UPDATE messages\n"
8882 "Drop specified attributes from incoming UPDATE messages\n"
8883 "Attribute number\n")
8884{
8885 struct peer *peer;
8886 int idx = 0;
8887 const char *discard_attrs = NULL;
8888
8889 peer = peer_and_group_lookup_vty(vty, neighbor);
8890 if (!peer)
8891 return CMD_WARNING_CONFIG_FAILED;
8892
8893 argv_find(argv, argc, "(1-255)", &idx);
8894 if (idx)
8895 discard_attrs = argv_concat(argv, argc, idx);
8896
b986d7f4
DA
8897 bgp_path_attribute_discard_vty(vty, peer, discard_attrs, true);
8898
8899 return CMD_SUCCESS;
8900}
8901
8902DEFPY(no_neighbor_path_attribute_discard,
8903 no_neighbor_path_attribute_discard_cmd,
8904 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor path-attribute discard [(1-255)]",
8905 NO_STR
8906 NEIGHBOR_STR
8907 NEIGHBOR_ADDR_STR2
8908 "Manipulate path attributes from incoming UPDATE messages\n"
8909 "Drop specified attributes from incoming UPDATE messages\n"
8910 "Attribute number\n")
8911{
8912 struct peer *peer;
8913 int idx = 0;
8914 const char *discard_attrs = NULL;
8915
8916 peer = peer_and_group_lookup_vty(vty, neighbor);
8917 if (!peer)
8918 return CMD_WARNING_CONFIG_FAILED;
8919
8920 argv_find(argv, argc, "(1-255)", &idx);
8921 if (idx)
8922 discard_attrs = argv[idx]->arg;
8923
8924 bgp_path_attribute_discard_vty(vty, peer, discard_attrs, false);
a5c6a9b1
DA
8925
8926 return CMD_SUCCESS;
8927}
8928
b9c7bc5a 8929static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
c6423c31 8930 struct ecommunity **list, bool is_rt6)
ddb5b488 8931{
b9c7bc5a
PZ
8932 struct ecommunity *ecom = NULL;
8933 struct ecommunity *ecomadd;
ddb5b488 8934
b9c7bc5a 8935 for (; argc; --argc, ++argv) {
9a659715
PG
8936 if (is_rt6)
8937 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8938 ECOMMUNITY_ROUTE_TARGET,
8939 0);
8940 else
8941 ecomadd = ecommunity_str2com(argv[0]->arg,
8942 ECOMMUNITY_ROUTE_TARGET,
8943 0);
b9c7bc5a
PZ
8944 if (!ecomadd) {
8945 vty_out(vty, "Malformed community-list value\n");
8946 if (ecom)
8947 ecommunity_free(&ecom);
8948 return CMD_WARNING_CONFIG_FAILED;
8949 }
ddb5b488 8950
b9c7bc5a
PZ
8951 if (ecom) {
8952 ecommunity_merge(ecom, ecomadd);
8953 ecommunity_free(&ecomadd);
8954 } else {
8955 ecom = ecomadd;
8956 }
8957 }
8958
8959 if (*list) {
8960 ecommunity_free(&*list);
ddb5b488 8961 }
b9c7bc5a
PZ
8962 *list = ecom;
8963
8964 return CMD_SUCCESS;
ddb5b488
PZ
8965}
8966
0ca70ba5
DS
8967/*
8968 * v2vimport is true if we are handling a `import vrf ...` command
8969 */
8970static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 8971{
0ca70ba5
DS
8972 afi_t afi;
8973
ddb5b488 8974 switch (vty->node) {
b9c7bc5a 8975 case BGP_IPV4_NODE:
0ca70ba5
DS
8976 afi = AFI_IP;
8977 break;
b9c7bc5a 8978 case BGP_IPV6_NODE:
0ca70ba5
DS
8979 afi = AFI_IP6;
8980 break;
ddb5b488
PZ
8981 default:
8982 vty_out(vty,
b9c7bc5a 8983 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 8984 return AFI_MAX;
ddb5b488 8985 }
69b07479 8986
0ca70ba5
DS
8987 if (!v2vimport) {
8988 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8989 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8990 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8991 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8992 vty_out(vty,
8993 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8994 return AFI_MAX;
8995 }
8996 } else {
8997 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8998 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8999 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9000 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
9001 vty_out(vty,
9002 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
9003 return AFI_MAX;
9004 }
9005 }
9006 return afi;
ddb5b488
PZ
9007}
9008
585f1adc
IR
9009DEFPY (af_rd_vpn_export,
9010 af_rd_vpn_export_cmd,
9011 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
9012 NO_STR
9013 "Specify route distinguisher\n"
9014 "Between current address-family and vpn\n"
9015 "For routes leaked from current address-family to vpn\n"
9016 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
ddb5b488 9017{
585f1adc
IR
9018 VTY_DECLVAR_CONTEXT(bgp, bgp);
9019 struct prefix_rd prd;
9020 int ret;
ddb5b488 9021 afi_t afi;
b9c7bc5a 9022 int idx = 0;
585f1adc 9023 bool yes = true;
b9c7bc5a 9024
585f1adc
IR
9025 if (argv_find(argv, argc, "no", &idx))
9026 yes = false;
ddb5b488 9027
585f1adc
IR
9028 if (yes) {
9029 ret = str2prefix_rd(rd_str, &prd);
9030 if (!ret) {
9031 vty_out(vty, "%% Malformed rd\n");
9032 return CMD_WARNING_CONFIG_FAILED;
9033 }
9034 }
ddb5b488 9035
585f1adc
IR
9036 afi = vpn_policy_getafi(vty, bgp, false);
9037 if (afi == AFI_MAX)
9038 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9039
585f1adc
IR
9040 /*
9041 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9042 */
9043 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9044 bgp_get_default(), bgp);
ddb5b488 9045
585f1adc
IR
9046 if (yes) {
9047 bgp->vpn_policy[afi].tovpn_rd = prd;
9048 SET_FLAG(bgp->vpn_policy[afi].flags,
9049 BGP_VPN_POLICY_TOVPN_RD_SET);
9050 } else {
9051 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9052 BGP_VPN_POLICY_TOVPN_RD_SET);
9053 }
69b07479 9054
585f1adc
IR
9055 /* post-change: re-export vpn routes */
9056 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9057 bgp_get_default(), bgp);
9058
9059 return CMD_SUCCESS;
ddb5b488
PZ
9060}
9061
b9c7bc5a
PZ
9062ALIAS (af_rd_vpn_export,
9063 af_no_rd_vpn_export_cmd,
9064 "no rd vpn export",
ddb5b488 9065 NO_STR
b9c7bc5a
PZ
9066 "Specify route distinguisher\n"
9067 "Between current address-family and vpn\n"
9068 "For routes leaked from current address-family to vpn\n")
ddb5b488 9069
b9c7bc5a
PZ
9070DEFPY (af_label_vpn_export,
9071 af_label_vpn_export_cmd,
e70e9f8e 9072 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 9073 NO_STR
ddb5b488 9074 "label value for VRF\n"
b9c7bc5a
PZ
9075 "Between current address-family and vpn\n"
9076 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
9077 "Label Value <0-1048575>\n"
9078 "Automatically assign a label\n")
ddb5b488
PZ
9079{
9080 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 9081 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 9082 afi_t afi;
b9c7bc5a 9083 int idx = 0;
c6423c31 9084 bool yes = true;
b9c7bc5a
PZ
9085
9086 if (argv_find(argv, argc, "no", &idx))
c6423c31 9087 yes = false;
ddb5b488 9088
21a16cc2
PZ
9089 /* If "no ...", squash trailing parameter */
9090 if (!yes)
9091 label_auto = NULL;
9092
e70e9f8e
PZ
9093 if (yes) {
9094 if (!label_auto)
9095 label = label_val; /* parser should force unsigned */
9096 }
ddb5b488 9097
0ca70ba5 9098 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9099 if (afi == AFI_MAX)
9100 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 9101
e70e9f8e 9102
69b07479
DS
9103 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9104 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
9105 /* no change */
9106 return CMD_SUCCESS;
e70e9f8e 9107
69b07479
DS
9108 /*
9109 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9110 */
9111 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9112 bgp_get_default(), bgp);
9113
9114 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9115 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
9116
9117 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
9118
9119 /*
9120 * label has previously been automatically
9121 * assigned by labelpool: release it
9122 *
9123 * NB if tovpn_label == MPLS_LABEL_NONE it
9124 * means the automatic assignment is in flight
9125 * and therefore the labelpool callback must
9126 * detect that the auto label is not needed.
9127 */
9128
9129 bgp_lp_release(LP_TYPE_VRF,
9130 &bgp->vpn_policy[afi],
9131 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 9132 }
69b07479
DS
9133 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9134 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9135 }
ddb5b488 9136
69b07479
DS
9137 bgp->vpn_policy[afi].tovpn_label = label;
9138 if (label_auto) {
9139 SET_FLAG(bgp->vpn_policy[afi].flags,
9140 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9141 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
9142 vpn_leak_label_callback);
ddb5b488
PZ
9143 }
9144
69b07479
DS
9145 /* post-change: re-export vpn routes */
9146 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9147 bgp_get_default(), bgp);
9148
0d020cd6 9149 hook_call(bgp_snmp_update_last_changed, bgp);
ddb5b488
PZ
9150 return CMD_SUCCESS;
9151}
9152
b72c9e14
HS
9153DEFPY (af_sid_vpn_export,
9154 af_sid_vpn_export_cmd,
46279a11 9155 "[no] sid vpn export <(1-1048575)$sid_idx|auto$sid_auto>",
b72c9e14
HS
9156 NO_STR
9157 "sid value for VRF\n"
9158 "Between current address-family and vpn\n"
9159 "For routes leaked from current address-family to vpn\n"
9160 "Sid allocation index\n"
9161 "Automatically assign a label\n")
9162{
9163 VTY_DECLVAR_CONTEXT(bgp, bgp);
9164 afi_t afi;
9165 int debug = 0;
9166 int idx = 0;
9167 bool yes = true;
9168
9169 if (argv_find(argv, argc, "no", &idx))
9170 yes = false;
9171 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
9172 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
9173
9174 afi = vpn_policy_getafi(vty, bgp, false);
9175 if (afi == AFI_MAX)
9176 return CMD_WARNING_CONFIG_FAILED;
9177
9178 if (!yes) {
9179 /* implement me */
4d4c404b 9180 vty_out(vty, "It's not implemented\n");
b72c9e14
HS
9181 return CMD_WARNING_CONFIG_FAILED;
9182 }
9183
527588aa
CS
9184 if (bgp->tovpn_sid_index != 0 ||
9185 CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)) {
9186 vty_out(vty,
9187 "per-vrf sid and per-af sid are mutually exclusive\n"
9188 "Failed: per-vrf sid is configured. Remove per-vrf sid before configuring per-af sid\n");
9189 return CMD_WARNING_CONFIG_FAILED;
9190 }
9191
b72c9e14
HS
9192 /* skip when it's already configured */
9193 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9194 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9195 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
9196 return CMD_SUCCESS;
9197
7de4c885
HS
9198 /*
9199 * mode change between sid_idx and sid_auto isn't supported.
9200 * user must negate sid vpn export when they want to change the mode
9201 */
b72c9e14
HS
9202 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9203 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9204 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
9205 vty_out(vty, "it's already configured as %s.\n",
9206 sid_auto ? "auto-mode" : "idx-mode");
9207 return CMD_WARNING_CONFIG_FAILED;
9208 }
9209
9210 /* pre-change */
9211 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9212 bgp_get_default(), bgp);
9213
9214 if (sid_auto) {
9215 /* SID allocation auto-mode */
9216 if (debug)
9217 zlog_debug("%s: auto sid alloc.", __func__);
9218 SET_FLAG(bgp->vpn_policy[afi].flags,
9219 BGP_VPN_POLICY_TOVPN_SID_AUTO);
9220 } else {
9221 /* SID allocation index-mode */
9222 if (debug)
9223 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
9224 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
9225 }
9226
9227 /* post-change */
9228 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9229 bgp_get_default(), bgp);
9230 return CMD_SUCCESS;
9231}
9232
527588aa
CS
9233DEFPY (bgp_sid_vpn_export,
9234 bgp_sid_vpn_export_cmd,
346bbb39 9235 "[no] sid vpn per-vrf export <(1-1048575)$sid_idx|auto$sid_auto>",
527588aa
CS
9236 NO_STR
9237 "sid value for VRF\n"
9238 "Between current vrf and vpn\n"
9239 "sid per-VRF (both IPv4 and IPv6 address families)\n"
9240 "For routes leaked from current vrf to vpn\n"
9241 "Sid allocation index\n"
9242 "Automatically assign a label\n")
9243{
9244 VTY_DECLVAR_CONTEXT(bgp, bgp);
9245 int debug;
9246
9247 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
9248 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
9249
9250 if (no) {
e606d8ec
CS
9251 /* when per-VRF SID is not set, do nothing */
9252 if (bgp->tovpn_sid_index == 0 &&
9253 !CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO))
9254 return CMD_SUCCESS;
9255
9256 sid_idx = 0;
9257 sid_auto = false;
9258 bgp->tovpn_sid_index = 0;
9259 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO);
527588aa
CS
9260 }
9261
9262 if (bgp->vpn_policy[AFI_IP].tovpn_sid_index != 0 ||
9263 CHECK_FLAG(bgp->vpn_policy[AFI_IP].flags,
9264 BGP_VPN_POLICY_TOVPN_SID_AUTO) ||
9265 bgp->vpn_policy[AFI_IP6].tovpn_sid_index != 0 ||
9266 CHECK_FLAG(bgp->vpn_policy[AFI_IP6].flags,
9267 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
9268 vty_out(vty,
9269 "per-vrf sid and per-af sid are mutually exclusive\n"
9270 "Failed: per-af sid is configured. Remove per-af sid before configuring per-vrf sid\n");
9271 return CMD_WARNING_CONFIG_FAILED;
9272 }
9273
9274 /* skip when it's already configured */
9275 if ((sid_idx != 0 && bgp->tovpn_sid_index != 0) ||
9276 (sid_auto && CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)))
9277 return CMD_SUCCESS;
9278
9279 /*
9280 * mode change between sid_idx and sid_auto isn't supported.
9281 * user must negate sid vpn export when they want to change the mode
9282 */
9283 if ((sid_auto && bgp->tovpn_sid_index != 0) ||
9284 (sid_idx != 0 &&
9285 CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO))) {
9286 vty_out(vty, "it's already configured as %s.\n",
9287 sid_auto ? "auto-mode" : "idx-mode");
9288 return CMD_WARNING_CONFIG_FAILED;
9289 }
9290
9291 /* pre-change */
9292 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP, bgp_get_default(),
9293 bgp);
9294 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP6, bgp_get_default(),
9295 bgp);
9296
9297 if (sid_auto) {
9298 /* SID allocation auto-mode */
9299 if (debug)
9300 zlog_debug("%s: auto per-vrf sid alloc.", __func__);
9301 SET_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO);
e606d8ec 9302 } else if (sid_idx != 0) {
527588aa
CS
9303 /* SID allocation index-mode */
9304 if (debug)
9305 zlog_debug("%s: idx %ld per-vrf sid alloc.", __func__,
9306 sid_idx);
9307 bgp->tovpn_sid_index = sid_idx;
9308 }
9309
9310 /* post-change */
9311 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP, bgp_get_default(),
9312 bgp);
9313 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP6,
9314 bgp_get_default(), bgp);
9315
9316 return CMD_SUCCESS;
9317}
9318
b9c7bc5a
PZ
9319ALIAS (af_label_vpn_export,
9320 af_no_label_vpn_export_cmd,
9321 "no label vpn export",
9322 NO_STR
9323 "label value for VRF\n"
9324 "Between current address-family and vpn\n"
9325 "For routes leaked from current address-family to vpn\n")
ddb5b488 9326
e606d8ec
CS
9327ALIAS (bgp_sid_vpn_export,
9328 no_bgp_sid_vpn_export_cmd,
9329 "no$no sid vpn per-vrf export",
9330 NO_STR
9331 "sid value for VRF\n"
9332 "Between current vrf and vpn\n"
9333 "sid per-VRF (both IPv4 and IPv6 address families)\n"
9334 "For routes leaked from current vrf to vpn\n")
9335
585f1adc 9336DEFPY (af_nexthop_vpn_export,
b9c7bc5a 9337 af_nexthop_vpn_export_cmd,
8c85ca28 9338 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
b9c7bc5a 9339 NO_STR
ddb5b488 9340 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
9341 "Between current address-family and vpn\n"
9342 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
9343 "IPv4 prefix\n"
9344 "IPv6 prefix\n")
9345{
585f1adc 9346 VTY_DECLVAR_CONTEXT(bgp, bgp);
ddb5b488 9347 afi_t afi;
ddb5b488
PZ
9348 struct prefix p;
9349
8c85ca28
QY
9350 if (!no) {
9351 if (!nexthop_su) {
9352 vty_out(vty, "%% Nexthop required\n");
9353 return CMD_WARNING_CONFIG_FAILED;
9354 }
8c85ca28 9355 if (!sockunion2hostprefix(nexthop_su, &p))
b9c7bc5a
PZ
9356 return CMD_WARNING_CONFIG_FAILED;
9357 }
ddb5b488 9358
585f1adc
IR
9359 afi = vpn_policy_getafi(vty, bgp, false);
9360 if (afi == AFI_MAX)
9361 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9362
585f1adc
IR
9363 /*
9364 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9365 */
9366 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9367 bgp_get_default(), bgp);
ddb5b488 9368
585f1adc
IR
9369 if (!no) {
9370 bgp->vpn_policy[afi].tovpn_nexthop = p;
9371 SET_FLAG(bgp->vpn_policy[afi].flags,
9372 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9373 } else {
9374 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9375 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9376 }
69b07479 9377
585f1adc
IR
9378 /* post-change: re-export vpn routes */
9379 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9380 bgp_get_default(), bgp);
37a87b8f 9381
585f1adc 9382 return CMD_SUCCESS;
ddb5b488
PZ
9383}
9384
b9c7bc5a 9385static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 9386{
b9c7bc5a
PZ
9387 if (!strcmp(dstr, "import")) {
9388 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9389 } else if (!strcmp(dstr, "export")) {
9390 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9391 } else if (!strcmp(dstr, "both")) {
9392 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9393 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9394 } else {
9395 vty_out(vty, "%% direction parse error\n");
9396 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9397 }
ddb5b488
PZ
9398 return CMD_SUCCESS;
9399}
9400
b9c7bc5a
PZ
9401DEFPY (af_rt_vpn_imexport,
9402 af_rt_vpn_imexport_cmd,
9403 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9404 NO_STR
9405 "Specify route target list\n"
ddb5b488 9406 "Specify route target list\n"
b9c7bc5a
PZ
9407 "Between current address-family and vpn\n"
9408 "For routes leaked from vpn to current address-family: match any\n"
9409 "For routes leaked from current address-family to vpn: set\n"
9410 "both import: match any and export: set\n"
ddb5b488
PZ
9411 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9412{
9413 VTY_DECLVAR_CONTEXT(bgp, bgp);
9414 int ret;
9415 struct ecommunity *ecom = NULL;
9416 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9c2fd3fe 9417 enum vpn_policy_direction dir;
ddb5b488
PZ
9418 afi_t afi;
9419 int idx = 0;
c6423c31 9420 bool yes = true;
ddb5b488 9421
b9c7bc5a 9422 if (argv_find(argv, argc, "no", &idx))
c6423c31 9423 yes = false;
b9c7bc5a 9424
0ca70ba5 9425 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9426 if (afi == AFI_MAX)
9427 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9428
b9c7bc5a 9429 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
9430 if (ret != CMD_SUCCESS)
9431 return ret;
9432
b9c7bc5a
PZ
9433 if (yes) {
9434 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9435 vty_out(vty, "%% Missing RTLIST\n");
9436 return CMD_WARNING_CONFIG_FAILED;
9437 }
c6423c31 9438 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
b9c7bc5a
PZ
9439 if (ret != CMD_SUCCESS) {
9440 return ret;
9441 }
ddb5b488
PZ
9442 }
9443
69b07479
DS
9444 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9445 if (!dodir[dir])
ddb5b488 9446 continue;
ddb5b488 9447
69b07479 9448 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 9449
69b07479
DS
9450 if (yes) {
9451 if (bgp->vpn_policy[afi].rtlist[dir])
9452 ecommunity_free(
9453 &bgp->vpn_policy[afi].rtlist[dir]);
9454 bgp->vpn_policy[afi].rtlist[dir] =
9455 ecommunity_dup(ecom);
9456 } else {
9457 if (bgp->vpn_policy[afi].rtlist[dir])
9458 ecommunity_free(
9459 &bgp->vpn_policy[afi].rtlist[dir]);
9460 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 9461 }
69b07479
DS
9462
9463 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 9464 }
69b07479 9465
d555f3e9
PZ
9466 if (ecom)
9467 ecommunity_free(&ecom);
ddb5b488
PZ
9468
9469 return CMD_SUCCESS;
9470}
9471
b9c7bc5a
PZ
9472ALIAS (af_rt_vpn_imexport,
9473 af_no_rt_vpn_imexport_cmd,
9474 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
9475 NO_STR
9476 "Specify route target list\n"
b9c7bc5a
PZ
9477 "Specify route target list\n"
9478 "Between current address-family and vpn\n"
9479 "For routes leaked from vpn to current address-family\n"
9480 "For routes leaked from current address-family to vpn\n"
9481 "both import and export\n")
9482
585f1adc 9483DEFPY (af_route_map_vpn_imexport,
b9c7bc5a
PZ
9484 af_route_map_vpn_imexport_cmd,
9485/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9486 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9487 NO_STR
ddb5b488 9488 "Specify route map\n"
b9c7bc5a
PZ
9489 "Between current address-family and vpn\n"
9490 "For routes leaked from vpn to current address-family\n"
9491 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
9492 "name of route-map\n")
9493{
585f1adc
IR
9494 VTY_DECLVAR_CONTEXT(bgp, bgp);
9495 int ret;
9496 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9c2fd3fe 9497 enum vpn_policy_direction dir;
ddb5b488 9498 afi_t afi;
ddb5b488 9499 int idx = 0;
585f1adc 9500 bool yes = true;
ddb5b488 9501
585f1adc
IR
9502 if (argv_find(argv, argc, "no", &idx))
9503 yes = false;
ddb5b488 9504
585f1adc
IR
9505 afi = vpn_policy_getafi(vty, bgp, false);
9506 if (afi == AFI_MAX)
9507 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9508
585f1adc
IR
9509 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9510 if (ret != CMD_SUCCESS)
9511 return ret;
ddb5b488 9512
585f1adc
IR
9513 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9514 if (!dodir[dir])
9515 continue;
69b07479 9516
585f1adc
IR
9517 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9518
9519 if (yes) {
9520 if (bgp->vpn_policy[afi].rmap_name[dir])
9521 XFREE(MTYPE_ROUTE_MAP_NAME,
9522 bgp->vpn_policy[afi].rmap_name[dir]);
9523 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
9524 MTYPE_ROUTE_MAP_NAME, rmap_str);
9525 bgp->vpn_policy[afi].rmap[dir] =
9526 route_map_lookup_warn_noexist(vty, rmap_str);
9527 if (!bgp->vpn_policy[afi].rmap[dir])
9528 return CMD_SUCCESS;
9529 } else {
9530 if (bgp->vpn_policy[afi].rmap_name[dir])
9531 XFREE(MTYPE_ROUTE_MAP_NAME,
9532 bgp->vpn_policy[afi].rmap_name[dir]);
9533 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9534 bgp->vpn_policy[afi].rmap[dir] = NULL;
9535 }
9536
9537 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9538 }
ddb5b488 9539
585f1adc 9540 return CMD_SUCCESS;
ddb5b488
PZ
9541}
9542
b9c7bc5a
PZ
9543ALIAS (af_route_map_vpn_imexport,
9544 af_no_route_map_vpn_imexport_cmd,
9545 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
9546 NO_STR
9547 "Specify route map\n"
b9c7bc5a
PZ
9548 "Between current address-family and vpn\n"
9549 "For routes leaked from vpn to current address-family\n"
9550 "For routes leaked from current address-family to vpn\n")
9551
bb4f6190 9552DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
ae6a6fb4 9553 "import vrf route-map RMAP$rmap_str",
bb4f6190
DS
9554 "Import routes from another VRF\n"
9555 "Vrf routes being filtered\n"
9556 "Specify route map\n"
9557 "name of route-map\n")
9558{
9559 VTY_DECLVAR_CONTEXT(bgp, bgp);
9c2fd3fe 9560 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
bb4f6190 9561 afi_t afi;
bb4f6190
DS
9562 struct bgp *bgp_default;
9563
0ca70ba5 9564 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
9565 if (afi == AFI_MAX)
9566 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
9567
9568 bgp_default = bgp_get_default();
9569 if (!bgp_default) {
9570 int32_t ret;
9571 as_t as = bgp->as;
9572
9573 /* Auto-create assuming the same AS */
5d5393b9 9574 ret = bgp_get_vty(&bgp_default, &as, NULL,
e55b0883
PG
9575 BGP_INSTANCE_TYPE_DEFAULT, NULL,
9576 ASNOTATION_UNDEFINED);
bb4f6190
DS
9577
9578 if (ret) {
9579 vty_out(vty,
9580 "VRF default is not configured as a bgp instance\n");
9581 return CMD_WARNING;
9582 }
9583 }
9584
69b07479 9585 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 9586
ae6a6fb4
DS
9587 if (bgp->vpn_policy[afi].rmap_name[dir])
9588 XFREE(MTYPE_ROUTE_MAP_NAME,
9589 bgp->vpn_policy[afi].rmap_name[dir]);
9590 bgp->vpn_policy[afi].rmap_name[dir] =
9591 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9592 bgp->vpn_policy[afi].rmap[dir] =
9593 route_map_lookup_warn_noexist(vty, rmap_str);
9594 if (!bgp->vpn_policy[afi].rmap[dir])
9595 return CMD_SUCCESS;
9596
9597 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9598 BGP_CONFIG_VRF_TO_VRF_IMPORT);
bb4f6190 9599
69b07479
DS
9600 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9601
bb4f6190
DS
9602 return CMD_SUCCESS;
9603}
9604
ae6a6fb4
DS
9605DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9606 "no import vrf route-map [RMAP$rmap_str]",
bb4f6190
DS
9607 NO_STR
9608 "Import routes from another VRF\n"
9609 "Vrf routes being filtered\n"
ae6a6fb4
DS
9610 "Specify route map\n"
9611 "name of route-map\n")
9612{
9613 VTY_DECLVAR_CONTEXT(bgp, bgp);
9c2fd3fe 9614 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
ae6a6fb4
DS
9615 afi_t afi;
9616
9617 afi = vpn_policy_getafi(vty, bgp, true);
9618 if (afi == AFI_MAX)
9619 return CMD_WARNING_CONFIG_FAILED;
9620
9621 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9622
9623 if (bgp->vpn_policy[afi].rmap_name[dir])
9624 XFREE(MTYPE_ROUTE_MAP_NAME,
9625 bgp->vpn_policy[afi].rmap_name[dir]);
9626 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9627 bgp->vpn_policy[afi].rmap[dir] = NULL;
9628
9629 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9630 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9631 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9632
9633 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9634
9635 return CMD_SUCCESS;
9636}
bb4f6190 9637
585f1adc
IR
9638DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
9639 "[no] import vrf VIEWVRFNAME$import_name",
9640 NO_STR
9641 "Import routes from another VRF\n"
9642 "VRF to import from\n"
9643 "The name of the VRF\n")
12a844a5 9644{
585f1adc
IR
9645 VTY_DECLVAR_CONTEXT(bgp, bgp);
9646 struct listnode *node;
9647 struct bgp *vrf_bgp, *bgp_default;
9648 int32_t ret = 0;
9649 as_t as = bgp->as;
9650 bool remove = false;
9651 int32_t idx = 0;
9652 char *vname;
9653 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
12a844a5
DS
9654 safi_t safi;
9655 afi_t afi;
9656
867f0cca 9657 if (import_name == NULL) {
9658 vty_out(vty, "%% Missing import name\n");
9659 return CMD_WARNING;
9660 }
9661
ae6a6fb4
DS
9662 if (strcmp(import_name, "route-map") == 0) {
9663 vty_out(vty, "%% Must include route-map name\n");
9664 return CMD_WARNING;
9665 }
9666
585f1adc
IR
9667 if (argv_find(argv, argc, "no", &idx))
9668 remove = true;
9669
9670 afi = vpn_policy_getafi(vty, bgp, true);
9671 if (afi == AFI_MAX)
9672 return CMD_WARNING_CONFIG_FAILED;
9673
12a844a5
DS
9674 safi = bgp_node_safi(vty);
9675
585f1adc
IR
9676 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
9677 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
9678 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
9679 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
9680 remove ? "unimport" : "import", import_name);
9681 return CMD_WARNING;
9682 }
25679caa 9683
585f1adc
IR
9684 bgp_default = bgp_get_default();
9685 if (!bgp_default) {
9686 /* Auto-create assuming the same AS */
9687 ret = bgp_get_vty(&bgp_default, &as, NULL,
e55b0883
PG
9688 BGP_INSTANCE_TYPE_DEFAULT, NULL,
9689 ASNOTATION_UNDEFINED);
12a844a5 9690
585f1adc
IR
9691 if (ret) {
9692 vty_out(vty,
9693 "VRF default is not configured as a bgp instance\n");
9694 return CMD_WARNING;
9695 }
9696 }
12a844a5 9697
585f1adc
IR
9698 vrf_bgp = bgp_lookup_by_name(import_name);
9699 if (!vrf_bgp) {
9700 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
9701 vrf_bgp = bgp_default;
9702 else
9703 /* Auto-create assuming the same AS */
e55b0883
PG
9704 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type,
9705 NULL, ASNOTATION_UNDEFINED);
585f1adc
IR
9706 if (ret) {
9707 vty_out(vty,
9708 "VRF %s is not configured as a bgp instance\n",
9709 import_name);
9710 return CMD_WARNING;
9711 }
9712 }
9713
9714 if (remove) {
9715 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
9716 } else {
9717 /* Already importing from "import_vrf"? */
9718 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
9719 vname)) {
9720 if (strcmp(vname, import_name) == 0)
9721 return CMD_WARNING;
9722 }
9723
9724 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
9725 }
9726
9727 return CMD_SUCCESS;
12a844a5
DS
9728}
9729
b9c7bc5a 9730/* This command is valid only in a bgp vrf instance or the default instance */
585f1adc 9731DEFPY (bgp_imexport_vpn,
b9c7bc5a
PZ
9732 bgp_imexport_vpn_cmd,
9733 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
9734 NO_STR
9735 "Import routes to this address-family\n"
9736 "Export routes from this address-family\n"
9737 "to/from default instance VPN RIB\n")
ddb5b488 9738{
585f1adc
IR
9739 VTY_DECLVAR_CONTEXT(bgp, bgp);
9740 int previous_state;
37a87b8f 9741 afi_t afi;
585f1adc
IR
9742 safi_t safi;
9743 int idx = 0;
9744 bool yes = true;
9745 int flag;
9c2fd3fe 9746 enum vpn_policy_direction dir;
585f1adc
IR
9747
9748 if (argv_find(argv, argc, "no", &idx))
9749 yes = false;
9750
9751 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
9752 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
9753
9754 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
9755 return CMD_WARNING_CONFIG_FAILED;
9756 }
ddb5b488 9757
b9c7bc5a
PZ
9758 afi = bgp_node_afi(vty);
9759 safi = bgp_node_safi(vty);
585f1adc
IR
9760 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
9761 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
9762 return CMD_WARNING_CONFIG_FAILED;
9763 }
ddb5b488 9764
b9c7bc5a 9765 if (!strcmp(direction_str, "import")) {
585f1adc
IR
9766 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
9767 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b9c7bc5a 9768 } else if (!strcmp(direction_str, "export")) {
585f1adc
IR
9769 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
9770 dir = BGP_VPN_POLICY_DIR_TOVPN;
b9c7bc5a
PZ
9771 } else {
9772 vty_out(vty, "%% unknown direction %s\n", direction_str);
9773 return CMD_WARNING_CONFIG_FAILED;
9774 }
9775
585f1adc 9776 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488 9777
585f1adc
IR
9778 if (yes) {
9779 SET_FLAG(bgp->af_flags[afi][safi], flag);
9780 if (!previous_state) {
9781 /* trigger export current vrf */
9782 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9783 }
9784 } else {
9785 if (previous_state) {
9786 /* trigger un-export current vrf */
9787 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9788 }
9789 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
9790 }
37a87b8f 9791
1ca2fd11
IR
9792 hook_call(bgp_snmp_init_stats, bgp);
9793
585f1adc 9794 return CMD_SUCCESS;
ddb5b488
PZ
9795}
9796
301ad80a
PG
9797DEFPY (af_routetarget_import,
9798 af_routetarget_import_cmd,
9a659715 9799 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
301ad80a
PG
9800 NO_STR
9801 "Specify route target list\n"
9802 "Specify route target list\n"
9a659715
PG
9803 "Specify route target list\n"
9804 "Specify route target list\n"
301ad80a
PG
9805 "Flow-spec redirect type route target\n"
9806 "Import routes to this address-family\n"
9a659715 9807 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
301ad80a
PG
9808{
9809 VTY_DECLVAR_CONTEXT(bgp, bgp);
9810 int ret;
9811 struct ecommunity *ecom = NULL;
301ad80a 9812 afi_t afi;
9a659715 9813 int idx = 0, idx_unused = 0;
c6423c31
PG
9814 bool yes = true;
9815 bool rt6 = false;
301ad80a
PG
9816
9817 if (argv_find(argv, argc, "no", &idx))
c6423c31 9818 yes = false;
301ad80a 9819
9a659715
PG
9820 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9821 argv_find(argv, argc, "route-target6", &idx_unused))
c6423c31 9822 rt6 = true;
301ad80a 9823
0ca70ba5 9824 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9825 if (afi == AFI_MAX)
9826 return CMD_WARNING_CONFIG_FAILED;
9827
9a659715
PG
9828 if (rt6 && afi != AFI_IP6)
9829 return CMD_WARNING_CONFIG_FAILED;
9830
301ad80a
PG
9831 if (yes) {
9832 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9833 vty_out(vty, "%% Missing RTLIST\n");
9834 return CMD_WARNING_CONFIG_FAILED;
9835 }
9a659715 9836 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
301ad80a
PG
9837 if (ret != CMD_SUCCESS)
9838 return ret;
9839 }
69b07479
DS
9840
9841 if (yes) {
9842 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9843 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9844 .import_redirect_rtlist);
69b07479
DS
9845 bgp->vpn_policy[afi].import_redirect_rtlist =
9846 ecommunity_dup(ecom);
9847 } else {
9848 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9849 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9850 .import_redirect_rtlist);
69b07479 9851 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 9852 }
69b07479 9853
301ad80a
PG
9854 if (ecom)
9855 ecommunity_free(&ecom);
9856
9857 return CMD_SUCCESS;
9858}
9859
505e5056 9860DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 9861 address_family_ipv4_safi_cmd,
9862 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9863 "Enter Address Family command mode\n"
00e6edb9 9864 BGP_AF_STR
7c40bf39 9865 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 9866{
f51bae9c 9867
d62a17ae 9868 if (argc == 3) {
585f1adc
IR
9869 VTY_DECLVAR_CONTEXT(bgp, bgp);
9870 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9871 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
a4d82a8a 9872 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9873 && safi != SAFI_EVPN) {
31947174
MK
9874 vty_out(vty,
9875 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9876 return CMD_WARNING_CONFIG_FAILED;
9877 }
585f1adc
IR
9878 vty->node = bgp_node_type(AFI_IP, safi);
9879 } else
9880 vty->node = BGP_IPV4_NODE;
718e3744 9881
d62a17ae 9882 return CMD_SUCCESS;
718e3744 9883}
9884
505e5056 9885DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 9886 address_family_ipv6_safi_cmd,
9887 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9888 "Enter Address Family command mode\n"
00e6edb9 9889 BGP_AF_STR
7c40bf39 9890 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 9891{
d62a17ae 9892 if (argc == 3) {
585f1adc
IR
9893 VTY_DECLVAR_CONTEXT(bgp, bgp);
9894 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9895 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
a4d82a8a 9896 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9897 && safi != SAFI_EVPN) {
31947174
MK
9898 vty_out(vty,
9899 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9900 return CMD_WARNING_CONFIG_FAILED;
9901 }
585f1adc
IR
9902 vty->node = bgp_node_type(AFI_IP6, safi);
9903 } else
9904 vty->node = BGP_IPV6_NODE;
25ffbdc1 9905
d62a17ae 9906 return CMD_SUCCESS;
25ffbdc1 9907}
718e3744 9908
d6902373 9909#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 9910DEFUN_NOSH (address_family_vpnv4,
718e3744 9911 address_family_vpnv4_cmd,
8334fd5a 9912 "address-family vpnv4 [unicast]",
718e3744 9913 "Enter Address Family command mode\n"
00e6edb9
DA
9914 BGP_AF_STR
9915 BGP_AF_MODIFIER_STR)
718e3744 9916{
d62a17ae 9917 vty->node = BGP_VPNV4_NODE;
9918 return CMD_SUCCESS;
718e3744 9919}
9920
505e5056 9921DEFUN_NOSH (address_family_vpnv6,
8ecd3266 9922 address_family_vpnv6_cmd,
8334fd5a 9923 "address-family vpnv6 [unicast]",
8ecd3266 9924 "Enter Address Family command mode\n"
00e6edb9
DA
9925 BGP_AF_STR
9926 BGP_AF_MODIFIER_STR)
8ecd3266 9927{
d62a17ae 9928 vty->node = BGP_VPNV6_NODE;
9929 return CMD_SUCCESS;
8ecd3266 9930}
64e4a6c5 9931#endif /* KEEP_OLD_VPN_COMMANDS */
d6902373 9932
505e5056 9933DEFUN_NOSH (address_family_evpn,
4e0b7b6d 9934 address_family_evpn_cmd,
7111c1a0 9935 "address-family l2vpn evpn",
4e0b7b6d 9936 "Enter Address Family command mode\n"
00e6edb9
DA
9937 BGP_AF_STR
9938 BGP_AF_MODIFIER_STR)
4e0b7b6d 9939{
2131d5cf 9940 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 9941 vty->node = BGP_EVPN_NODE;
9942 return CMD_SUCCESS;
4e0b7b6d
PG
9943}
9944
bfaab44d
HS
9945DEFUN_NOSH (bgp_segment_routing_srv6,
9946 bgp_segment_routing_srv6_cmd,
9947 "segment-routing srv6",
9948 "Segment-Routing configuration\n"
9949 "Segment-Routing SRv6 configuration\n")
9950{
9951 VTY_DECLVAR_CONTEXT(bgp, bgp);
92a9e6f2 9952 bgp->srv6_enabled = true;
bfaab44d
HS
9953 vty->node = BGP_SRV6_NODE;
9954 return CMD_SUCCESS;
9955}
9956
0249b8b6
HS
9957DEFUN (no_bgp_segment_routing_srv6,
9958 no_bgp_segment_routing_srv6_cmd,
9959 "no segment-routing srv6",
9960 NO_STR
9961 "Segment-Routing configuration\n"
9962 "Segment-Routing SRv6 configuration\n")
9963{
9964 VTY_DECLVAR_CONTEXT(bgp, bgp);
9965
9966 if (strlen(bgp->srv6_locator_name) > 0)
9967 if (bgp_srv6_locator_unset(bgp) < 0)
9968 return CMD_WARNING_CONFIG_FAILED;
9969
9970 bgp->srv6_enabled = false;
9971 return CMD_SUCCESS;
9972}
9973
a0281b2e
HS
9974DEFPY (bgp_srv6_locator,
9975 bgp_srv6_locator_cmd,
9976 "locator NAME$name",
9977 "Specify SRv6 locator\n"
9978 "Specify SRv6 locator\n")
9979{
9980 VTY_DECLVAR_CONTEXT(bgp, bgp);
7de4c885 9981 int ret;
a0281b2e
HS
9982
9983 if (strlen(bgp->srv6_locator_name) > 0
9984 && strcmp(name, bgp->srv6_locator_name) != 0) {
9985 vty_out(vty, "srv6 locator is already configured\n");
9986 return CMD_WARNING_CONFIG_FAILED;
7de4c885
HS
9987 }
9988
9989 snprintf(bgp->srv6_locator_name,
9990 sizeof(bgp->srv6_locator_name), "%s", name);
a0281b2e 9991
7de4c885 9992 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
a0281b2e
HS
9993 if (ret < 0)
9994 return CMD_WARNING_CONFIG_FAILED;
9995
9996 return CMD_SUCCESS;
9997}
9998
0249b8b6
HS
9999DEFPY (no_bgp_srv6_locator,
10000 no_bgp_srv6_locator_cmd,
10001 "no locator NAME$name",
10002 NO_STR
10003 "Specify SRv6 locator\n"
10004 "Specify SRv6 locator\n")
10005{
10006 VTY_DECLVAR_CONTEXT(bgp, bgp);
10007
10008 /* when locator isn't configured, do nothing */
10009 if (strlen(bgp->srv6_locator_name) < 1)
10010 return CMD_SUCCESS;
10011
10012 /* name validation */
10013 if (strcmp(name, bgp->srv6_locator_name) != 0) {
10014 vty_out(vty, "%% No srv6 locator is configured\n");
10015 return CMD_WARNING_CONFIG_FAILED;
10016 }
10017
10018 /* unset locator */
10019 if (bgp_srv6_locator_unset(bgp) < 0)
10020 return CMD_WARNING_CONFIG_FAILED;
10021
10022 return CMD_SUCCESS;
10023}
10024
ea372e81
HS
10025DEFPY (show_bgp_srv6,
10026 show_bgp_srv6_cmd,
10027 "show bgp segment-routing srv6",
10028 SHOW_STR
10029 BGP_STR
10030 "BGP Segment Routing\n"
10031 "BGP Segment Routing SRv6\n")
10032{
10033 struct bgp *bgp;
10034 struct listnode *node;
1c21a234 10035 struct srv6_locator_chunk *chunk;
ea372e81 10036 struct bgp_srv6_function *func;
ea372e81
HS
10037
10038 bgp = bgp_get_default();
96db4340 10039 if (!bgp)
ea372e81
HS
10040 return CMD_SUCCESS;
10041
10042 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
10043 vty_out(vty, "locator_chunks:\n");
dccef127 10044 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk)) {
511211bf 10045 vty_out(vty, "- %pFX\n", &chunk->prefix);
dccef127
CS
10046 vty_out(vty, " block-length: %d\n", chunk->block_bits_length);
10047 vty_out(vty, " node-length: %d\n", chunk->node_bits_length);
10048 vty_out(vty, " func-length: %d\n",
10049 chunk->function_bits_length);
10050 vty_out(vty, " arg-length: %d\n", chunk->argument_bits_length);
10051 }
ea372e81
HS
10052
10053 vty_out(vty, "functions:\n");
10054 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
07380148 10055 vty_out(vty, "- sid: %pI6\n", &func->sid);
ea372e81
HS
10056 vty_out(vty, " locator: %s\n", func->locator_name);
10057 }
10058
10059 vty_out(vty, "bgps:\n");
10060 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
10061 vty_out(vty, "- name: %s\n",
10062 bgp->name ? bgp->name : "default");
10063
1830895a
CS
10064 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %pI6\n",
10065 bgp->vpn_policy[AFI_IP].tovpn_sid);
10066 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %pI6\n",
10067 bgp->vpn_policy[AFI_IP6].tovpn_sid);
9f5d4430 10068 vty_out(vty, " per-vrf tovpn_sid: %pI6\n", bgp->tovpn_sid);
ea372e81
HS
10069 }
10070
10071 return CMD_SUCCESS;
10072}
10073
505e5056 10074DEFUN_NOSH (exit_address_family,
718e3744 10075 exit_address_family_cmd,
10076 "exit-address-family",
10077 "Exit from Address Family configuration mode\n")
10078{
d62a17ae 10079 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
10080 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
10081 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
10082 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
10083 || vty->node == BGP_EVPN_NODE
10084 || vty->node == BGP_FLOWSPECV4_NODE
10085 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 10086 vty->node = BGP_NODE;
10087 return CMD_SUCCESS;
718e3744 10088}
6b0655a2 10089
8ad7271d 10090/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 10091static int bgp_clear_prefix(struct vty *vty, const char *view_name,
10092 const char *ip_str, afi_t afi, safi_t safi,
10093 struct prefix_rd *prd)
10094{
10095 int ret;
10096 struct prefix match;
9bcb3eef
DS
10097 struct bgp_dest *dest;
10098 struct bgp_dest *rm;
d62a17ae 10099 struct bgp *bgp;
10100 struct bgp_table *table;
10101 struct bgp_table *rib;
10102
10103 /* BGP structure lookup. */
10104 if (view_name) {
10105 bgp = bgp_lookup_by_name(view_name);
10106 if (bgp == NULL) {
10107 vty_out(vty, "%% Can't find BGP instance %s\n",
10108 view_name);
10109 return CMD_WARNING;
10110 }
10111 } else {
10112 bgp = bgp_get_default();
10113 if (bgp == NULL) {
10114 vty_out(vty, "%% No BGP process is configured\n");
10115 return CMD_WARNING;
10116 }
10117 }
10118
10119 /* Check IP address argument. */
10120 ret = str2prefix(ip_str, &match);
10121 if (!ret) {
10122 vty_out(vty, "%% address is malformed\n");
10123 return CMD_WARNING;
10124 }
10125
10126 match.family = afi2family(afi);
10127 rib = bgp->rib[afi][safi];
10128
10129 if (safi == SAFI_MPLS_VPN) {
9bcb3eef
DS
10130 for (dest = bgp_table_top(rib); dest;
10131 dest = bgp_route_next(dest)) {
10132 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 10133
9bcb3eef 10134 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
d62a17ae 10135 continue;
10136
9bcb3eef 10137 table = bgp_dest_get_bgp_table_info(dest);
b54892e0
DS
10138 if (table == NULL)
10139 continue;
10140
4953391b
DA
10141 rm = bgp_node_match(table, &match);
10142 if (rm != NULL) {
b54892e0 10143 const struct prefix *rm_p =
9bcb3eef 10144 bgp_dest_get_prefix(rm);
b54892e0
DS
10145
10146 if (rm_p->prefixlen == match.prefixlen) {
10147 SET_FLAG(rm->flags,
10148 BGP_NODE_USER_CLEAR);
10149 bgp_process(bgp, rm, afi, safi);
d62a17ae 10150 }
9bcb3eef 10151 bgp_dest_unlock_node(rm);
d62a17ae 10152 }
10153 }
10154 } else {
4953391b
DA
10155 dest = bgp_node_match(rib, &match);
10156 if (dest != NULL) {
9bcb3eef 10157 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 10158
9bcb3eef
DS
10159 if (dest_p->prefixlen == match.prefixlen) {
10160 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
10161 bgp_process(bgp, dest, afi, safi);
d62a17ae 10162 }
9bcb3eef 10163 bgp_dest_unlock_node(dest);
d62a17ae 10164 }
10165 }
10166
10167 return CMD_SUCCESS;
8ad7271d
DS
10168}
10169
b09b5ae0 10170/* one clear bgp command to rule them all */
718e3744 10171DEFUN (clear_ip_bgp_all,
10172 clear_ip_bgp_all_cmd,
8079a413 10173 "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|ASNUM|external|peer-group PGNAME> [<soft [<in|out>]|in [prefix-filter]|out|message-stats>]",
718e3744 10174 CLEAR_STR
10175 IP_STR
10176 BGP_STR
838758ac 10177 BGP_INSTANCE_HELP_STR
510afcd6 10178 BGP_AFI_HELP_STR
00e6edb9 10179 BGP_AF_STR
510afcd6 10180 BGP_SAFI_WITH_LABEL_HELP_STR
00e6edb9 10181 BGP_AF_MODIFIER_STR
b09b5ae0 10182 "Clear all peers\n"
453c92f6 10183 "BGP IPv4 neighbor to clear\n"
a80beece 10184 "BGP IPv6 neighbor to clear\n"
838758ac 10185 "BGP neighbor on interface to clear\n"
8079a413 10186 "Clear peers with the AS number in plain or dotted format\n"
b09b5ae0 10187 "Clear all external peers\n"
718e3744 10188 "Clear all members of peer-group\n"
b09b5ae0 10189 "BGP peer-group name\n"
b09b5ae0
DW
10190 BGP_SOFT_STR
10191 BGP_SOFT_IN_STR
b09b5ae0
DW
10192 BGP_SOFT_OUT_STR
10193 BGP_SOFT_IN_STR
10194 "Push out prefix-list ORF and do inbound soft reconfig\n"
3cb14f26
DS
10195 BGP_SOFT_OUT_STR
10196 "Reset message statistics\n")
718e3744 10197{
d62a17ae 10198 char *vrf = NULL;
10199
dc912615
DS
10200 afi_t afi = AFI_UNSPEC;
10201 safi_t safi = SAFI_UNSPEC;
d62a17ae 10202 enum clear_sort clr_sort = clear_peer;
10203 enum bgp_clear_type clr_type;
10204 char *clr_arg = NULL;
10205
10206 int idx = 0;
10207
10208 /* clear [ip] bgp */
10209 if (argv_find(argv, argc, "ip", &idx))
10210 afi = AFI_IP;
10211
9a8bdf1c
PG
10212 /* [<vrf> VIEWVRFNAME] */
10213 if (argv_find(argv, argc, "vrf", &idx)) {
10214 vrf = argv[idx + 1]->arg;
10215 idx += 2;
10216 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10217 vrf = NULL;
10218 } else if (argv_find(argv, argc, "view", &idx)) {
10219 /* [<view> VIEWVRFNAME] */
d62a17ae 10220 vrf = argv[idx + 1]->arg;
10221 idx += 2;
10222 }
d62a17ae 10223 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
10224 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
10225 argv_find_and_parse_safi(argv, argc, &idx, &safi);
10226
8079a413 10227 /* <*|A.B.C.D|X:X::X:X|WORD|ASNUM|external|peer-group PGNAME> */
d62a17ae 10228 if (argv_find(argv, argc, "*", &idx)) {
10229 clr_sort = clear_all;
10230 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
10231 clr_sort = clear_peer;
10232 clr_arg = argv[idx]->arg;
10233 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
10234 clr_sort = clear_peer;
10235 clr_arg = argv[idx]->arg;
10236 } else if (argv_find(argv, argc, "peer-group", &idx)) {
10237 clr_sort = clear_group;
10238 idx++;
10239 clr_arg = argv[idx]->arg;
d7b9898c 10240 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
d62a17ae 10241 clr_sort = clear_peer;
10242 clr_arg = argv[idx]->arg;
8fa7d444
DS
10243 } else if (argv_find(argv, argc, "WORD", &idx)) {
10244 clr_sort = clear_peer;
10245 clr_arg = argv[idx]->arg;
8079a413 10246 } else if (argv_find(argv, argc, "ASNUM", &idx)) {
d62a17ae 10247 clr_sort = clear_as;
10248 clr_arg = argv[idx]->arg;
10249 } else if (argv_find(argv, argc, "external", &idx)) {
10250 clr_sort = clear_external;
10251 }
10252
3cb14f26 10253 /* [<soft [<in|out>]|in [prefix-filter]|out|message-stats>] */
d62a17ae 10254 if (argv_find(argv, argc, "soft", &idx)) {
10255 if (argv_find(argv, argc, "in", &idx)
10256 || argv_find(argv, argc, "out", &idx))
10257 clr_type = strmatch(argv[idx]->text, "in")
10258 ? BGP_CLEAR_SOFT_IN
10259 : BGP_CLEAR_SOFT_OUT;
10260 else
10261 clr_type = BGP_CLEAR_SOFT_BOTH;
10262 } else if (argv_find(argv, argc, "in", &idx)) {
10263 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
10264 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
10265 : BGP_CLEAR_SOFT_IN;
10266 } else if (argv_find(argv, argc, "out", &idx)) {
10267 clr_type = BGP_CLEAR_SOFT_OUT;
3cb14f26
DS
10268 } else if (argv_find(argv, argc, "message-stats", &idx)) {
10269 clr_type = BGP_CLEAR_MESSAGE_STATS;
d62a17ae 10270 } else
10271 clr_type = BGP_CLEAR_SOFT_NONE;
10272
1ca2fd11 10273 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 10274}
01080f7c 10275
8ad7271d
DS
10276DEFUN (clear_ip_bgp_prefix,
10277 clear_ip_bgp_prefix_cmd,
18c57037 10278 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
10279 CLEAR_STR
10280 IP_STR
10281 BGP_STR
838758ac 10282 BGP_INSTANCE_HELP_STR
8ad7271d 10283 "Clear bestpath and re-advertise\n"
0c7b1b01 10284 "IPv4 prefix\n")
8ad7271d 10285{
d62a17ae 10286 char *vrf = NULL;
10287 char *prefix = NULL;
8ad7271d 10288
d62a17ae 10289 int idx = 0;
01080f7c 10290
d62a17ae 10291 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
10292 if (argv_find(argv, argc, "vrf", &idx)) {
10293 vrf = argv[idx + 1]->arg;
10294 idx += 2;
10295 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10296 vrf = NULL;
10297 } else if (argv_find(argv, argc, "view", &idx)) {
10298 /* [<view> VIEWVRFNAME] */
10299 vrf = argv[idx + 1]->arg;
10300 idx += 2;
10301 }
0c7b1b01 10302
d62a17ae 10303 prefix = argv[argc - 1]->arg;
8ad7271d 10304
d62a17ae 10305 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 10306}
8ad7271d 10307
b09b5ae0
DW
10308DEFUN (clear_bgp_ipv6_safi_prefix,
10309 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 10310 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 10311 CLEAR_STR
3a2d747c 10312 IP_STR
718e3744 10313 BGP_STR
00e6edb9 10314 BGP_AF_STR
46f296b4 10315 BGP_SAFI_HELP_STR
b09b5ae0 10316 "Clear bestpath and re-advertise\n"
0c7b1b01 10317 "IPv6 prefix\n")
718e3744 10318{
9b475e76
PG
10319 int idx_safi = 0;
10320 int idx_ipv6_prefix = 0;
10321 safi_t safi = SAFI_UNICAST;
10322 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10323 argv[idx_ipv6_prefix]->arg : NULL;
10324
10325 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 10326 return bgp_clear_prefix(
9b475e76
PG
10327 vty, NULL, prefix, AFI_IP6,
10328 safi, NULL);
838758ac 10329}
01080f7c 10330
b09b5ae0
DW
10331DEFUN (clear_bgp_instance_ipv6_safi_prefix,
10332 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 10333 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 10334 CLEAR_STR
3a2d747c 10335 IP_STR
718e3744 10336 BGP_STR
838758ac 10337 BGP_INSTANCE_HELP_STR
00e6edb9 10338 BGP_AF_STR
46f296b4 10339 BGP_SAFI_HELP_STR
b09b5ae0 10340 "Clear bestpath and re-advertise\n"
0c7b1b01 10341 "IPv6 prefix\n")
718e3744 10342{
9b475e76 10343 int idx_safi = 0;
9a8bdf1c 10344 int idx_vrfview = 0;
9b475e76
PG
10345 int idx_ipv6_prefix = 0;
10346 safi_t safi = SAFI_UNICAST;
10347 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10348 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 10349 char *vrfview = NULL;
9b475e76 10350
9a8bdf1c
PG
10351 /* [<view|vrf> VIEWVRFNAME] */
10352 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
10353 vrfview = argv[idx_vrfview + 1]->arg;
10354 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
10355 vrfview = NULL;
10356 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
10357 /* [<view> VIEWVRFNAME] */
10358 vrfview = argv[idx_vrfview + 1]->arg;
10359 }
9b475e76
PG
10360 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10361
d62a17ae 10362 return bgp_clear_prefix(
9b475e76
PG
10363 vty, vrfview, prefix,
10364 AFI_IP6, safi, NULL);
718e3744 10365}
10366
b09b5ae0
DW
10367DEFUN (show_bgp_views,
10368 show_bgp_views_cmd,
d6e3c605 10369 "show [ip] bgp views",
b09b5ae0 10370 SHOW_STR
d6e3c605 10371 IP_STR
01080f7c 10372 BGP_STR
b09b5ae0 10373 "Show the defined BGP views\n")
01080f7c 10374{
d62a17ae 10375 struct list *inst = bm->bgp;
10376 struct listnode *node;
10377 struct bgp *bgp;
01080f7c 10378
d62a17ae 10379 vty_out(vty, "Defined BGP views:\n");
10380 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10381 /* Skip VRFs. */
10382 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
10383 continue;
9eb11997
PG
10384 vty_out(vty, "\t%s (AS%s)\n", bgp->name ? bgp->name : "(null)",
10385 bgp->as_pretty);
d62a17ae 10386 }
e52702f2 10387
d62a17ae 10388 return CMD_SUCCESS;
e0081f70
ML
10389}
10390
4acd6bc9
SPG
10391static inline void calc_peers_cfgd_estbd(struct bgp *bgp, int *peers_cfgd,
10392 int *peers_estbd)
10393{
10394 struct peer *peer;
10395 struct listnode *node;
10396
10397 *peers_cfgd = *peers_estbd = 0;
10398 for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer)) {
10399 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10400 continue;
10401 (*peers_cfgd)++;
10402 if (peer_established(peer))
10403 (*peers_estbd)++;
10404 }
10405}
10406
10407static void print_bgp_vrfs(struct bgp *bgp, struct vty *vty, json_object *json,
10408 const char *type)
10409{
10410 int peers_cfg, peers_estb;
10411
10412 calc_peers_cfgd_estbd(bgp, &peers_cfg, &peers_estb);
10413
10414 if (json) {
10415 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10416 ? -1
10417 : (int64_t)bgp->vrf_id;
10418 json_object_string_add(json, "type", type);
10419 json_object_int_add(json, "vrfId", vrf_id_ui);
10420 json_object_string_addf(json, "routerId", "%pI4",
10421 &bgp->router_id);
10422 json_object_int_add(json, "numConfiguredPeers", peers_cfg);
10423 json_object_int_add(json, "numEstablishedPeers", peers_estb);
10424 json_object_int_add(json, "l3vni", bgp->l3vni);
10425 json_object_string_addf(json, "rmac", "%pEA", &bgp->rmac);
10426 json_object_string_add(
10427 json, "interface",
10428 ifindex2ifname(bgp->l3vni_svi_ifindex, bgp->vrf_id));
10429 }
10430}
10431
10432static int show_bgp_vrfs_detail_common(struct vty *vty, struct bgp *bgp,
10433 json_object *json, const char *name,
10434 const char *type, bool use_vrf)
10435{
10436 int peers_cfg, peers_estb;
10437
10438 calc_peers_cfgd_estbd(bgp, &peers_cfg, &peers_estb);
10439
10440 if (use_vrf) {
10441 if (json) {
10442 print_bgp_vrfs(bgp, vty, json, type);
10443 } else {
10444 vty_out(vty, "BGP instance %s VRF id %d\n",
10445 bgp->name_pretty,
10446 bgp->vrf_id == VRF_UNKNOWN ? -1
10447 : (int)bgp->vrf_id);
10448 vty_out(vty, "Router Id %pI4\n", &bgp->router_id);
10449 vty_out(vty,
10450 "Num Configured Peers %d, Established %d\n",
10451 peers_cfg, peers_estb);
10452 if (bgp->l3vni) {
10453 vty_out(vty,
10454 "L3VNI %u, L3VNI-SVI %s, Router MAC %pEA\n",
10455 bgp->l3vni,
10456 ifindex2ifname(bgp->l3vni_svi_ifindex,
10457 bgp->vrf_id),
10458 &bgp->rmac);
10459 }
10460 }
10461 } else {
10462 if (json) {
10463 print_bgp_vrfs(bgp, vty, json, type);
10464 } else {
10465 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
10466 type,
10467 bgp->vrf_id == VRF_UNKNOWN ? -1
10468 : (int)bgp->vrf_id,
10469 &bgp->router_id, peers_cfg, peers_estb, name);
10470 vty_out(vty, "%11s %-16u %-21pEA %-20s\n", " ",
10471 bgp->l3vni, &bgp->rmac,
10472 ifindex2ifname(bgp->l3vni_svi_ifindex,
10473 bgp->vrf_id));
10474 }
10475 }
10476
10477 return CMD_SUCCESS;
10478}
10479
10480DEFPY (show_bgp_vrfs,
8386ac43 10481 show_bgp_vrfs_cmd,
4acd6bc9 10482 "show [ip] bgp vrfs [<VRFNAME$vrf_name>] [json]",
8386ac43 10483 SHOW_STR
d6e3c605 10484 IP_STR
8386ac43 10485 BGP_STR
10486 "Show BGP VRFs\n"
4acd6bc9 10487 "Specific VRF name\n"
9973d184 10488 JSON_STR)
8386ac43 10489{
d62a17ae 10490 struct list *inst = bm->bgp;
10491 struct listnode *node;
10492 struct bgp *bgp;
9f049418 10493 bool uj = use_json(argc, argv);
d62a17ae 10494 json_object *json = NULL;
10495 json_object *json_vrfs = NULL;
4acd6bc9 10496 json_object *json_vrf = NULL;
d62a17ae 10497 int count = 0;
4acd6bc9
SPG
10498 const char *name = vrf_name;
10499 const char *type;
d62a17ae 10500
4acd6bc9 10501 if (uj)
d62a17ae 10502 json = json_object_new_object();
4acd6bc9
SPG
10503
10504 if (name) {
10505 if (strmatch(name, VRF_DEFAULT_NAME)) {
10506 bgp = bgp_get_default();
10507 type = "DFLT";
10508 } else {
10509 bgp = bgp_lookup_by_name(name);
10510 type = "VRF";
10511 }
10512 if (!bgp) {
10513 if (uj)
10514 vty_json(vty, json);
10515 else
10516 vty_out(vty,
10517 "%% Specified BGP instance not found\n");
10518
10519 return CMD_WARNING;
10520 }
10521 }
10522
10523 if (vrf_name) {
10524 if (uj)
10525 json_vrf = json_object_new_object();
10526
10527 show_bgp_vrfs_detail_common(vty, bgp, json_vrf, name, type,
10528 true);
10529
10530 if (uj) {
10531 json_object_object_add(json, name, json_vrf);
10532 vty_json(vty, json);
10533 }
10534
10535 return CMD_SUCCESS;
d62a17ae 10536 }
10537
4acd6bc9
SPG
10538 if (uj)
10539 json_vrfs = json_object_new_object();
10540
d62a17ae 10541 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
4acd6bc9 10542 const char *name;
d62a17ae 10543
10544 /* Skip Views. */
10545 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
10546 continue;
10547
10548 count++;
efb4077a 10549 if (!uj && count == 1) {
fe1dc5a3 10550 vty_out(vty,
efb4077a 10551 "%4s %-5s %-16s %9s %10s %-37s\n",
3c0e7aa4 10552 "Type", "Id", "routerId", "#PeersCfg",
efb4077a
CS
10553 "#PeersEstb", "Name");
10554 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
10555 "L3-VNI", "RouterMAC", "Interface");
10556 }
d62a17ae 10557 if (uj)
10558 json_vrf = json_object_new_object();
10559
d62a17ae 10560 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
5742e42b 10561 name = VRF_DEFAULT_NAME;
d62a17ae 10562 type = "DFLT";
10563 } else {
10564 name = bgp->name;
10565 type = "VRF";
10566 }
10567
4acd6bc9
SPG
10568 show_bgp_vrfs_detail_common(vty, bgp, json_vrf, name, type,
10569 false);
a8bf7d9c 10570
4acd6bc9 10571 if (uj)
d62a17ae 10572 json_object_object_add(json_vrfs, name, json_vrf);
d62a17ae 10573 }
10574
10575 if (uj) {
10576 json_object_object_add(json, "vrfs", json_vrfs);
d62a17ae 10577 json_object_int_add(json, "totalVrfs", count);
75eeda93 10578 vty_json(vty, json);
d62a17ae 10579 } else {
10580 if (count)
10581 vty_out(vty,
10582 "\nTotal number of VRFs (including default): %d\n",
10583 count);
10584 }
10585
10586 return CMD_SUCCESS;
8386ac43 10587}
10588
48ecf8f5
DS
10589DEFUN (show_bgp_mac_hash,
10590 show_bgp_mac_hash_cmd,
10591 "show bgp mac hash",
10592 SHOW_STR
10593 BGP_STR
10594 "Mac Address\n"
10595 "Mac Address database\n")
10596{
10597 bgp_mac_dump_table(vty);
10598
10599 return CMD_SUCCESS;
10600}
acf71666 10601
e3b78da8 10602static void show_tip_entry(struct hash_bucket *bucket, void *args)
acf71666 10603{
0291c246 10604 struct vty *vty = (struct vty *)args;
e3b78da8 10605 struct tip_addr *tip = (struct tip_addr *)bucket->data;
acf71666 10606
23d0a753 10607 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
acf71666
MK
10608}
10609
10610static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10611{
10612 vty_out(vty, "self nexthop database:\n");
af97a18b 10613 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
10614
10615 vty_out(vty, "Tunnel-ip database:\n");
10616 hash_iterate(bgp->tip_hash,
e3b78da8 10617 (void (*)(struct hash_bucket *, void *))show_tip_entry,
acf71666
MK
10618 vty);
10619}
10620
15c81ca4
DS
10621DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10622 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10623 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
10624 "martian next-hops\n"
10625 "martian next-hop database\n")
acf71666 10626{
0291c246 10627 struct bgp *bgp = NULL;
15c81ca4 10628 int idx = 0;
9a8bdf1c
PG
10629 char *name = NULL;
10630
10631 /* [<vrf> VIEWVRFNAME] */
10632 if (argv_find(argv, argc, "vrf", &idx)) {
10633 name = argv[idx + 1]->arg;
10634 if (name && strmatch(name, VRF_DEFAULT_NAME))
10635 name = NULL;
10636 } else if (argv_find(argv, argc, "view", &idx))
10637 /* [<view> VIEWVRFNAME] */
10638 name = argv[idx + 1]->arg;
10639 if (name)
10640 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
10641 else
10642 bgp = bgp_get_default();
acf71666 10643
acf71666
MK
10644 if (!bgp) {
10645 vty_out(vty, "%% No BGP process is configured\n");
10646 return CMD_WARNING;
10647 }
10648 bgp_show_martian_nexthops(vty, bgp);
10649
10650 return CMD_SUCCESS;
10651}
10652
f412b39a 10653DEFUN (show_bgp_memory,
4bf6a362 10654 show_bgp_memory_cmd,
7fa12b13 10655 "show [ip] bgp memory",
4bf6a362 10656 SHOW_STR
3a2d747c 10657 IP_STR
4bf6a362
PJ
10658 BGP_STR
10659 "Global BGP memory statistics\n")
10660{
d62a17ae 10661 char memstrbuf[MTYPE_MEMSTR_LEN];
10662 unsigned long count;
10663
10664 /* RIB related usage stats */
10665 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10666 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10667 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9bcb3eef 10668 count * sizeof(struct bgp_dest)));
d62a17ae 10669
10670 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10671 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10672 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 10673 count * sizeof(struct bgp_path_info)));
d62a17ae 10674 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10675 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10676 count,
4b7e6066
DS
10677 mtype_memstr(
10678 memstrbuf, sizeof(memstrbuf),
10679 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 10680
10681 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10682 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10683 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10684 count * sizeof(struct bgp_static)));
10685
10686 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10687 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10688 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10689 count * sizeof(struct bpacket)));
10690
10691 /* Adj-In/Out */
10692 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10693 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10694 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10695 count * sizeof(struct bgp_adj_in)));
10696 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10697 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10698 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10699 count * sizeof(struct bgp_adj_out)));
10700
10701 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10702 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10703 count,
10704 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10705 count * sizeof(struct bgp_nexthop_cache)));
10706
10707 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10708 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10709 count,
10710 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10711 count * sizeof(struct bgp_damp_info)));
10712
10713 /* Attributes */
10714 count = attr_count();
10715 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10716 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10717 count * sizeof(struct attr)));
10718
10719 if ((count = attr_unknown_count()))
10720 vty_out(vty, "%ld unknown attributes\n", count);
10721
10722 /* AS_PATH attributes */
10723 count = aspath_count();
10724 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10725 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10726 count * sizeof(struct aspath)));
10727
10728 count = mtype_stats_alloc(MTYPE_AS_SEG);
10729 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10730 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10731 count * sizeof(struct assegment)));
10732
10733 /* Other attributes */
10734 if ((count = community_count()))
10735 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
10736 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10737 count * sizeof(struct community)));
d62a17ae 10738 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
145f7619
DA
10739 vty_out(vty,
10740 "%ld BGP ext-community entries, using %s of memory\n",
10741 count,
10742 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10743 count * sizeof(struct ecommunity)));
d62a17ae 10744 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10745 vty_out(vty,
10746 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
10747 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10748 count * sizeof(struct lcommunity)));
d62a17ae 10749
10750 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10751 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10752 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10753 count * sizeof(struct cluster_list)));
10754
10755 /* Peer related usage */
10756 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10757 vty_out(vty, "%ld peers, using %s of memory\n", count,
10758 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10759 count * sizeof(struct peer)));
10760
10761 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10762 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10763 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10764 count * sizeof(struct peer_group)));
10765
10766 /* Other */
d62a17ae 10767 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10768 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
10769 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10770 count * sizeof(regex_t)));
d62a17ae 10771 return CMD_SUCCESS;
4bf6a362 10772}
fee0f4c6 10773
57a9c8a8
DS
10774static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10775{
10776 json_object *bestpath = json_object_new_object();
10777
892fedb6 10778 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
57a9c8a8
DS
10779 json_object_string_add(bestpath, "asPath", "ignore");
10780
892fedb6 10781 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
57a9c8a8
DS
10782 json_object_string_add(bestpath, "asPath", "confed");
10783
892fedb6
DA
10784 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10785 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
a4d82a8a 10786 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
10787 "as-set");
10788 else
a4d82a8a 10789 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
10790 "true");
10791 } else
a4d82a8a 10792 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8 10793
ee88563a
JM
10794 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
10795 json_object_boolean_true_add(bestpath, "peerTypeRelax");
10796
892fedb6 10797 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
57a9c8a8 10798 json_object_string_add(bestpath, "compareRouterId", "true");
892fedb6
DA
10799 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10800 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10801 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
a4d82a8a 10802 json_object_string_add(bestpath, "med", "confed");
892fedb6 10803 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
57a9c8a8
DS
10804 json_object_string_add(bestpath, "med",
10805 "missing-as-worst");
10806 else
10807 json_object_string_add(bestpath, "med", "true");
10808 }
10809
10810 json_object_object_add(json, "bestPath", bestpath);
10811}
10812
3577f1c5
DD
10813/* Print the error code/subcode for why the peer is down */
10814static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10815 json_object *json_peer, bool use_json)
10816{
10817 const char *code_str;
10818 const char *subcode_str;
10819
10820 if (use_json) {
10821 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10822 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10823 char errorcodesubcode_hexstr[5];
10824 char errorcodesubcode_str[256];
10825
10826 code_str = bgp_notify_code_str(peer->notify.code);
10827 subcode_str = bgp_notify_subcode_str(
10828 peer->notify.code,
10829 peer->notify.subcode);
10830
772270f3
QY
10831 snprintf(errorcodesubcode_hexstr,
10832 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10833 peer->notify.code, peer->notify.subcode);
3577f1c5
DD
10834 json_object_string_add(json_peer,
10835 "lastErrorCodeSubcode",
10836 errorcodesubcode_hexstr);
10837 snprintf(errorcodesubcode_str, 255, "%s%s",
10838 code_str, subcode_str);
10839 json_object_string_add(json_peer,
10840 "lastNotificationReason",
10841 errorcodesubcode_str);
eea685b6
DA
10842 json_object_boolean_add(json_peer,
10843 "lastNotificationHardReset",
10844 peer->notify.hard_reset);
3577f1c5
DD
10845 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10846 && peer->notify.code == BGP_NOTIFY_CEASE
10847 && (peer->notify.subcode
10848 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10849 || peer->notify.subcode
10850 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10851 && peer->notify.length) {
10852 char msgbuf[1024];
10853 const char *msg_str;
10854
10855 msg_str = bgp_notify_admin_message(
10856 msgbuf, sizeof(msgbuf),
10857 (uint8_t *)peer->notify.data,
10858 peer->notify.length);
10859 if (msg_str)
10860 json_object_string_add(
10861 json_peer,
10862 "lastShutdownDescription",
10863 msg_str);
10864 }
10865
c258527b 10866 }
3577f1c5
DD
10867 json_object_string_add(json_peer, "lastResetDueTo",
10868 peer_down_str[(int)peer->last_reset]);
05912a17
DD
10869 json_object_int_add(json_peer, "lastResetCode",
10870 peer->last_reset);
3577f1c5
DD
10871 } else {
10872 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10873 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10874 code_str = bgp_notify_code_str(peer->notify.code);
10875 subcode_str =
10876 bgp_notify_subcode_str(peer->notify.code,
10877 peer->notify.subcode);
eea685b6 10878 vty_out(vty, " Notification %s (%s%s%s)\n",
3577f1c5 10879 peer->last_reset == PEER_DOWN_NOTIFY_SEND
eea685b6
DA
10880 ? "sent"
10881 : "received",
10882 code_str, subcode_str,
10883 peer->notify.hard_reset
10884 ? bgp_notify_subcode_str(
10885 BGP_NOTIFY_CEASE,
10886 BGP_NOTIFY_CEASE_HARD_RESET)
10887 : "");
3577f1c5 10888 } else {
e91c24c8 10889 vty_out(vty, " %s\n",
3577f1c5
DD
10890 peer_down_str[(int)peer->last_reset]);
10891 }
10892 }
10893}
10894
10895static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10896 safi_t safi)
10897{
feb17238 10898 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
3577f1c5
DD
10899}
10900
10901static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10902 struct peer *peer, json_object *json_peer,
10903 int max_neighbor_width, bool use_json)
10904{
10905 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10906 int len;
10907
10908 if (use_json) {
10909 if (peer_dynamic_neighbor(peer))
10910 json_object_boolean_true_add(json_peer,
10911 "dynamicPeer");
10912 if (peer->hostname)
10913 json_object_string_add(json_peer, "hostname",
10914 peer->hostname);
10915
10916 if (peer->domainname)
10917 json_object_string_add(json_peer, "domainname",
10918 peer->domainname);
10919 json_object_int_add(json_peer, "connectionsEstablished",
10920 peer->established);
10921 json_object_int_add(json_peer, "connectionsDropped",
10922 peer->dropped);
10923 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10924 use_json, json_peer);
feb17238 10925 if (peer_established(peer))
3577f1c5
DD
10926 json_object_string_add(json_peer, "lastResetDueTo",
10927 "AFI/SAFI Not Negotiated");
10928 else
10929 bgp_show_peer_reset(NULL, peer, json_peer, true);
10930 } else {
10931 dn_flag[1] = '\0';
10932 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10933 if (peer->hostname
892fedb6 10934 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
3577f1c5
DD
10935 len = vty_out(vty, "%s%s(%s)", dn_flag,
10936 peer->hostname, peer->host);
10937 else
10938 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10939
10940 /* pad the neighbor column with spaces */
10941 if (len < max_neighbor_width)
10942 vty_out(vty, "%*s", max_neighbor_width - len,
10943 " ");
e91c24c8 10944 vty_out(vty, "%7d %7d %9s", peer->established,
3577f1c5
DD
10945 peer->dropped,
10946 peer_uptime(peer->uptime, timebuf,
10947 BGP_UPTIME_LEN, 0, NULL));
feb17238 10948 if (peer_established(peer))
3577f1c5
DD
10949 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10950 else
10951 bgp_show_peer_reset(vty, peer, NULL,
10952 false);
10953 }
10954}
c258527b 10955
565e9ddd 10956/* Strip peer's description to the given size. */
cb75bb31
DA
10957static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10958{
10959 static char stripped[BUFSIZ];
64541ffa
FD
10960 uint32_t i = 0;
10961 uint32_t last_space = 0;
cb75bb31 10962
64541ffa
FD
10963 while (i < size) {
10964 if (*(desc + i) == 0) {
10965 stripped[i] = '\0';
10966 return stripped;
10967 }
10968 if (i != 0 && *(desc + i) == ' ' && last_space != i - 1)
10969 last_space = i;
10970 stripped[i] = *(desc + i);
10971 i++;
10972 }
10973
10974 if (last_space > size)
10975 stripped[size + 1] = '\0';
10976 else
10977 stripped[last_space] = '\0';
cb75bb31
DA
10978
10979 return stripped;
10980}
3577f1c5 10981
8c1d4cd5
LS
10982/* Determine whether var peer should be filtered out of the summary. */
10983static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
10984 struct peer *fpeer, int as_type,
10985 as_t as)
10986{
10987
10988 /* filter neighbor XXXX */
10989 if (fpeer && fpeer != peer)
10990 return true;
10991
10992 /* filter remote-as (internal|external) */
10993 if (as_type != AS_UNSPECIFIED) {
10994 if (peer->as_type == AS_SPECIFIED) {
10995 if (as_type == AS_INTERNAL) {
10996 if (peer->as != peer->local_as)
10997 return true;
10998 } else if (peer->as == peer->local_as)
10999 return true;
11000 } else if (as_type != peer->as_type)
11001 return true;
11002 } else if (as && as != peer->as) /* filter remote-as XXX */
11003 return true;
11004
11005 return false;
11006}
11007
565e9ddd
DA
11008/* Show BGP peer's summary information.
11009 *
11010 * Peer's description is stripped according to if `wide` option is given
11011 * or not.
11012 *
11013 * When adding new columns to `show bgp summary` output, please make
11014 * sure `Desc` is the lastest column to show because it can contain
11015 * whitespaces and the whole output will be tricky.
11016 */
d62a17ae 11017static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
8c1d4cd5 11018 struct peer *fpeer, int as_type, as_t as,
96c81f66 11019 uint16_t show_flags)
d62a17ae 11020{
11021 struct peer *peer;
11022 struct listnode *node, *nnode;
11023 unsigned int count = 0, dn_count = 0;
11024 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
11025 char neighbor_buf[VTY_BUFSIZ];
11026 int neighbor_col_default_width = 16;
3577f1c5 11027 int len, failed_count = 0;
ce1944f0 11028 unsigned int filtered_count = 0;
d62a17ae 11029 int max_neighbor_width = 0;
11030 int pfx_rcd_safi;
3c13337d 11031 json_object *json = NULL;
d62a17ae 11032 json_object *json_peer = NULL;
11033 json_object *json_peers = NULL;
50e05855 11034 struct peer_af *paf;
d3ada366 11035 struct bgp_filter *filter;
85eeb029
DA
11036 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11037 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11038 bool show_established =
11039 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11040 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
96c81f66 11041 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
d62a17ae 11042
11043 /* labeled-unicast routes are installed in the unicast table so in order
11044 * to
11045 * display the correct PfxRcd value we must look at SAFI_UNICAST
11046 */
3577f1c5 11047
d62a17ae 11048 if (safi == SAFI_LABELED_UNICAST)
11049 pfx_rcd_safi = SAFI_UNICAST;
11050 else
11051 pfx_rcd_safi = safi;
11052
11053 if (use_json) {
3c13337d 11054 json = json_object_new_object();
d62a17ae 11055 json_peers = json_object_new_object();
3577f1c5 11056 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8c1d4cd5
LS
11057 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11058 as_type, as)) {
ce1944f0 11059 filtered_count++;
8c1d4cd5
LS
11060 count++;
11061 continue;
11062 }
11063
3577f1c5
DD
11064 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11065 continue;
11066
11067 if (peer->afc[afi][safi]) {
11068 /* See if we have at least a single failed peer */
11069 if (bgp_has_peer_failed(peer, afi, safi))
11070 failed_count++;
11071 count++;
11072 }
11073 if (peer_dynamic_neighbor(peer))
11074 dn_count++;
11075 }
c258527b 11076
d62a17ae 11077 } else {
11078 /* Loop over all neighbors that will be displayed to determine
11079 * how many
11080 * characters are needed for the Neighbor column
11081 */
11082 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8c1d4cd5
LS
11083 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11084 as_type, as)) {
ce1944f0 11085 filtered_count++;
8c1d4cd5
LS
11086 count++;
11087 continue;
11088 }
11089
d62a17ae 11090 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11091 continue;
11092
11093 if (peer->afc[afi][safi]) {
11094 memset(dn_flag, '\0', sizeof(dn_flag));
11095 if (peer_dynamic_neighbor(peer))
11096 dn_flag[0] = '*';
11097
11098 if (peer->hostname
892fedb6
DA
11099 && CHECK_FLAG(bgp->flags,
11100 BGP_FLAG_SHOW_HOSTNAME))
772270f3
QY
11101 snprintf(neighbor_buf,
11102 sizeof(neighbor_buf),
11103 "%s%s(%s) ", dn_flag,
11104 peer->hostname, peer->host);
d62a17ae 11105 else
772270f3
QY
11106 snprintf(neighbor_buf,
11107 sizeof(neighbor_buf), "%s%s ",
11108 dn_flag, peer->host);
d62a17ae 11109
11110 len = strlen(neighbor_buf);
11111
11112 if (len > max_neighbor_width)
11113 max_neighbor_width = len;
c258527b 11114
3577f1c5
DD
11115 /* See if we have at least a single failed peer */
11116 if (bgp_has_peer_failed(peer, afi, safi))
11117 failed_count++;
11118 count++;
d62a17ae 11119 }
11120 }
f933309e 11121
d62a17ae 11122 /* Originally we displayed the Neighbor column as 16
11123 * characters wide so make that the default
11124 */
11125 if (max_neighbor_width < neighbor_col_default_width)
11126 max_neighbor_width = neighbor_col_default_width;
11127 }
f933309e 11128
3577f1c5
DD
11129 if (show_failed && !failed_count) {
11130 if (use_json) {
11131 json_object_int_add(json, "failedPeersCount", 0);
11132 json_object_int_add(json, "dynamicPeers", dn_count);
c258527b 11133 json_object_int_add(json, "totalPeers", count);
3577f1c5 11134
75eeda93 11135 vty_json(vty, json);
3577f1c5
DD
11136 } else {
11137 vty_out(vty, "%% No failed BGP neighbors found\n");
3577f1c5
DD
11138 }
11139 return CMD_SUCCESS;
11140 }
c258527b 11141
3577f1c5 11142 count = 0; /* Reset the value as its used again */
ce1944f0 11143 filtered_count = 0;
800867d8 11144 dn_count = 0;
d62a17ae 11145 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
11146 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11147 continue;
11148
ea47320b
DL
11149 if (!peer->afc[afi][safi])
11150 continue;
d62a17ae 11151
ea47320b
DL
11152 if (!count) {
11153 unsigned long ents;
11154 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 11155 int64_t vrf_id_ui;
d62a17ae 11156
a4d82a8a
PZ
11157 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
11158 ? -1
11159 : (int64_t)bgp->vrf_id;
ea47320b
DL
11160
11161 /* Usage summary and header */
11162 if (use_json) {
c949c771
DA
11163 json_object_string_addf(json, "routerId",
11164 "%pI4",
11165 &bgp->router_id);
e84c7c12
PG
11166 asn_asn2json(json, "as", bgp->as,
11167 bgp->asnotation);
60466a63 11168 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
11169 json_object_string_add(
11170 json, "vrfName",
11171 (bgp->inst_type
11172 == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11173 ? VRF_DEFAULT_NAME
ea47320b
DL
11174 : bgp->name);
11175 } else {
11176 vty_out(vty,
9eb11997
PG
11177 "BGP router identifier %pI4, local AS number %s vrf-id %d",
11178 &bgp->router_id, bgp->as_pretty,
a4d82a8a
PZ
11179 bgp->vrf_id == VRF_UNKNOWN
11180 ? -1
11181 : (int)bgp->vrf_id);
ea47320b
DL
11182 vty_out(vty, "\n");
11183 }
d62a17ae 11184
ea47320b 11185 if (bgp_update_delay_configured(bgp)) {
d62a17ae 11186 if (use_json) {
ea47320b 11187 json_object_int_add(
60466a63 11188 json, "updateDelayLimit",
ea47320b 11189 bgp->v_update_delay);
d62a17ae 11190
ea47320b
DL
11191 if (bgp->v_update_delay
11192 != bgp->v_establish_wait)
d62a17ae 11193 json_object_int_add(
11194 json,
ea47320b
DL
11195 "updateDelayEstablishWait",
11196 bgp->v_establish_wait);
d62a17ae 11197
60466a63 11198 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
11199 json_object_string_add(
11200 json,
11201 "updateDelayFirstNeighbor",
11202 bgp->update_delay_begin_time);
11203 json_object_boolean_true_add(
11204 json,
11205 "updateDelayInProgress");
11206 } else {
11207 if (bgp->update_delay_over) {
d62a17ae 11208 json_object_string_add(
11209 json,
11210 "updateDelayFirstNeighbor",
11211 bgp->update_delay_begin_time);
ea47320b 11212 json_object_string_add(
d62a17ae 11213 json,
ea47320b
DL
11214 "updateDelayBestpathResumed",
11215 bgp->update_delay_end_time);
11216 json_object_string_add(
d62a17ae 11217 json,
ea47320b
DL
11218 "updateDelayZebraUpdateResume",
11219 bgp->update_delay_zebra_resume_time);
11220 json_object_string_add(
11221 json,
11222 "updateDelayPeerUpdateResume",
11223 bgp->update_delay_peers_resume_time);
d62a17ae 11224 }
ea47320b
DL
11225 }
11226 } else {
11227 vty_out(vty,
11228 "Read-only mode update-delay limit: %d seconds\n",
11229 bgp->v_update_delay);
11230 if (bgp->v_update_delay
11231 != bgp->v_establish_wait)
d62a17ae 11232 vty_out(vty,
ea47320b
DL
11233 " Establish wait: %d seconds\n",
11234 bgp->v_establish_wait);
d62a17ae 11235
60466a63 11236 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
11237 vty_out(vty,
11238 " First neighbor established: %s\n",
11239 bgp->update_delay_begin_time);
11240 vty_out(vty,
11241 " Delay in progress\n");
11242 } else {
11243 if (bgp->update_delay_over) {
d62a17ae 11244 vty_out(vty,
11245 " First neighbor established: %s\n",
11246 bgp->update_delay_begin_time);
11247 vty_out(vty,
ea47320b
DL
11248 " Best-paths resumed: %s\n",
11249 bgp->update_delay_end_time);
11250 vty_out(vty,
11251 " zebra update resumed: %s\n",
11252 bgp->update_delay_zebra_resume_time);
11253 vty_out(vty,
11254 " peers update resumed: %s\n",
11255 bgp->update_delay_peers_resume_time);
d62a17ae 11256 }
11257 }
11258 }
ea47320b 11259 }
d62a17ae 11260
ea47320b
DL
11261 if (use_json) {
11262 if (bgp_maxmed_onstartup_configured(bgp)
11263 && bgp->maxmed_active)
11264 json_object_boolean_true_add(
60466a63 11265 json, "maxMedOnStartup");
ea47320b
DL
11266 if (bgp->v_maxmed_admin)
11267 json_object_boolean_true_add(
60466a63 11268 json, "maxMedAdministrative");
d62a17ae 11269
ea47320b
DL
11270 json_object_int_add(
11271 json, "tableVersion",
60466a63 11272 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 11273
60466a63
QY
11274 ents = bgp_table_count(bgp->rib[afi][safi]);
11275 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
11276 json_object_int_add(
11277 json, "ribMemory",
9bcb3eef 11278 ents * sizeof(struct bgp_dest));
d62a17ae 11279
210ec2a0 11280 ents = bgp->af_peer_count[afi][safi];
60466a63
QY
11281 json_object_int_add(json, "peerCount", ents);
11282 json_object_int_add(json, "peerMemory",
11283 ents * sizeof(struct peer));
d62a17ae 11284
ea47320b
DL
11285 if ((ents = listcount(bgp->group))) {
11286 json_object_int_add(
60466a63 11287 json, "peerGroupCount", ents);
ea47320b
DL
11288 json_object_int_add(
11289 json, "peerGroupMemory",
996c9314
LB
11290 ents * sizeof(struct
11291 peer_group));
ea47320b 11292 }
d62a17ae 11293
ea47320b
DL
11294 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11295 BGP_CONFIG_DAMPENING))
11296 json_object_boolean_true_add(
60466a63 11297 json, "dampeningEnabled");
ea47320b 11298 } else {
96c81f66
LS
11299 if (!show_terse) {
11300 if (bgp_maxmed_onstartup_configured(bgp)
11301 && bgp->maxmed_active)
11302 vty_out(vty,
11303 "Max-med on-startup active\n");
11304 if (bgp->v_maxmed_admin)
11305 vty_out(vty,
11306 "Max-med administrative active\n");
d62a17ae 11307
96c81f66
LS
11308 vty_out(vty,
11309 "BGP table version %" PRIu64
11310 "\n",
11311 bgp_table_version(
11312 bgp->rib[afi][safi]));
ea47320b 11313
96c81f66
LS
11314 ents = bgp_table_count(
11315 bgp->rib[afi][safi]);
d62a17ae 11316 vty_out(vty,
96c81f66 11317 "RIB entries %ld, using %s of memory\n",
d62a17ae 11318 ents,
11319 mtype_memstr(
11320 memstrbuf,
11321 sizeof(memstrbuf),
96c81f66
LS
11322 ents
11323 * sizeof(
11324 struct
11325 bgp_dest)));
d62a17ae 11326
96c81f66
LS
11327 /* Peer related usage */
11328 ents = bgp->af_peer_count[afi][safi];
11329 vty_out(vty,
11330 "Peers %ld, using %s of memory\n",
11331 ents,
11332 mtype_memstr(
11333 memstrbuf,
11334 sizeof(memstrbuf),
11335 ents
11336 * sizeof(
11337 struct
11338 peer)));
d62a17ae 11339
96c81f66
LS
11340 if ((ents = listcount(bgp->group)))
11341 vty_out(vty,
11342 "Peer groups %ld, using %s of memory\n",
11343 ents,
11344 mtype_memstr(
11345 memstrbuf,
11346 sizeof(memstrbuf),
11347 ents
11348 * sizeof(
11349 struct
11350 peer_group)));
11351
11352 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11353 BGP_CONFIG_DAMPENING))
11354 vty_out(vty,
11355 "Dampening enabled.\n");
11356 }
11357 if (show_failed) {
11358 vty_out(vty, "\n");
11359
11360 /* Subtract 8 here because 'Neighbor' is
11361 * 8 characters */
11362 vty_out(vty, "Neighbor");
11363 vty_out(vty, "%*s",
11364 max_neighbor_width - 8, " ");
85eeb029
DA
11365 vty_out(vty,
11366 BGP_SHOW_SUMMARY_HEADER_FAILED);
96c81f66 11367 }
d62a17ae 11368 }
ea47320b 11369 }
d62a17ae 11370
d55811cc 11371 paf = peer_af_find(peer, afi, safi);
d3ada366 11372 filter = &peer->filter[afi][safi];
db92d226 11373
ea47320b 11374 count++;
3577f1c5
DD
11375 /* Works for both failed & successful cases */
11376 if (peer_dynamic_neighbor(peer))
11377 dn_count++;
d62a17ae 11378
ea47320b 11379 if (use_json) {
3577f1c5 11380 json_peer = NULL;
8c1d4cd5 11381 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
ce1944f0
LS
11382 as_type, as)) {
11383 filtered_count++;
8c1d4cd5 11384 continue;
ce1944f0 11385 }
3577f1c5
DD
11386 if (show_failed &&
11387 bgp_has_peer_failed(peer, afi, safi)) {
11388 json_peer = json_object_new_object();
11389 bgp_show_failed_summary(vty, bgp, peer,
11390 json_peer, 0, use_json);
11391 } else if (!show_failed) {
10b49f14 11392 if (show_established
ce1944f0
LS
11393 && bgp_has_peer_failed(peer, afi, safi)) {
11394 filtered_count++;
10b49f14 11395 continue;
ce1944f0 11396 }
10b49f14 11397
3577f1c5
DD
11398 json_peer = json_object_new_object();
11399 if (peer_dynamic_neighbor(peer)) {
11400 json_object_boolean_true_add(json_peer,
11401 "dynamicPeer");
11402 }
d62a17ae 11403
3577f1c5
DD
11404 if (peer->hostname)
11405 json_object_string_add(json_peer, "hostname",
11406 peer->hostname);
11407
11408 if (peer->domainname)
11409 json_object_string_add(json_peer, "domainname",
11410 peer->domainname);
11411
44a4d55e
PG
11412 asn_asn2json(json_peer, "remoteAs", peer->as,
11413 bgp->asnotation);
11414 asn_asn2json(json_peer, "localAs",
11415 peer->change_local_as
11416 ? peer->change_local_as
11417 : peer->local_as,
11418 bgp->asnotation);
3577f1c5
DD
11419 json_object_int_add(json_peer, "version", 4);
11420 json_object_int_add(json_peer, "msgRcvd",
11421 PEER_TOTAL_RX(peer));
11422 json_object_int_add(json_peer, "msgSent",
11423 PEER_TOTAL_TX(peer));
11424
43aa5965
QY
11425 atomic_size_t outq_count, inq_count;
11426 outq_count = atomic_load_explicit(
11427 &peer->obuf->count,
11428 memory_order_relaxed);
11429 inq_count = atomic_load_explicit(
11430 &peer->ibuf->count,
11431 memory_order_relaxed);
11432
3577f1c5
DD
11433 json_object_int_add(json_peer, "tableVersion",
11434 peer->version[afi][safi]);
11435 json_object_int_add(json_peer, "outq",
43aa5965
QY
11436 outq_count);
11437 json_object_int_add(json_peer, "inq",
11438 inq_count);
3577f1c5
DD
11439 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
11440 use_json, json_peer);
11441
3577f1c5
DD
11442 json_object_int_add(json_peer, "pfxRcd",
11443 peer->pcount[afi][pfx_rcd_safi]);
11444
3577f1c5 11445 if (paf && PAF_SUBGRP(paf))
a616dd1f
DA
11446 json_object_int_add(
11447 json_peer, "pfxSnt",
11448 (PAF_SUBGRP(paf))->scount);
11449 else
11450 json_object_int_add(json_peer, "pfxSnt",
11451 0);
0e1f8ab5
DA
11452
11453 /* BGP FSM state */
cb9196e7 11454 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
736b68f3
DS
11455 || CHECK_FLAG(peer->bgp->flags,
11456 BGP_FLAG_SHUTDOWN))
0e1f8ab5
DA
11457 json_object_string_add(json_peer,
11458 "state",
3577f1c5
DD
11459 "Idle (Admin)");
11460 else if (peer->afc_recv[afi][safi])
11461 json_object_string_add(
0e1f8ab5
DA
11462 json_peer, "state",
11463 lookup_msg(bgp_status_msg,
11464 peer->status, NULL));
11465 else if (CHECK_FLAG(
11466 peer->sflags,
11467 PEER_STATUS_PREFIX_OVERFLOW))
11468 json_object_string_add(json_peer,
11469 "state",
3577f1c5
DD
11470 "Idle (PfxCt)");
11471 else
11472 json_object_string_add(
0e1f8ab5
DA
11473 json_peer, "state",
11474 lookup_msg(bgp_status_msg,
11475 peer->status, NULL));
11476
11477 /* BGP peer state */
11478 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11479 || CHECK_FLAG(peer->bgp->flags,
11480 BGP_FLAG_SHUTDOWN))
11481 json_object_string_add(json_peer,
11482 "peerState",
11483 "Admin");
11484 else if (CHECK_FLAG(
11485 peer->sflags,
11486 PEER_STATUS_PREFIX_OVERFLOW))
11487 json_object_string_add(json_peer,
11488 "peerState",
11489 "PfxCt");
11490 else if (CHECK_FLAG(peer->flags,
11491 PEER_FLAG_PASSIVE))
11492 json_object_string_add(json_peer,
11493 "peerState",
11494 "Passive");
11495 else if (CHECK_FLAG(peer->sflags,
11496 PEER_STATUS_NSF_WAIT))
11497 json_object_string_add(json_peer,
11498 "peerState",
11499 "NSF passive");
11500 else if (CHECK_FLAG(
11501 peer->bgp->flags,
11502 BGP_FLAG_EBGP_REQUIRES_POLICY)
11503 && (!bgp_inbound_policy_exists(peer,
11504 filter)
11505 || !bgp_outbound_policy_exists(
11506 peer, filter)))
11507 json_object_string_add(json_peer,
11508 "peerState",
11509 "Policy");
11510 else
11511 json_object_string_add(
11512 json_peer, "peerState", "OK");
11513
200116db
DD
11514 json_object_int_add(json_peer, "connectionsEstablished",
11515 peer->established);
11516 json_object_int_add(json_peer, "connectionsDropped",
11517 peer->dropped);
aa72bd7e
PG
11518 if (peer->desc)
11519 json_object_string_add(
11520 json_peer, "desc", peer->desc);
b4e9dcba 11521 }
3577f1c5
DD
11522 /* Avoid creating empty peer dicts in JSON */
11523 if (json_peer == NULL)
11524 continue;
ea47320b
DL
11525
11526 if (peer->conf_if)
60466a63 11527 json_object_string_add(json_peer, "idType",
ea47320b
DL
11528 "interface");
11529 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
11530 json_object_string_add(json_peer, "idType",
11531 "ipv4");
ea47320b 11532 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
11533 json_object_string_add(json_peer, "idType",
11534 "ipv6");
ea47320b
DL
11535 json_object_object_add(json_peers, peer->host,
11536 json_peer);
11537 } else {
8c1d4cd5 11538 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
ce1944f0
LS
11539 as_type, as)) {
11540 filtered_count++;
8c1d4cd5 11541 continue;
ce1944f0 11542 }
3577f1c5
DD
11543 if (show_failed &&
11544 bgp_has_peer_failed(peer, afi, safi)) {
11545 bgp_show_failed_summary(vty, bgp, peer, NULL,
11546 max_neighbor_width,
11547 use_json);
11548 } else if (!show_failed) {
10b49f14 11549 if (show_established
ce1944f0
LS
11550 && bgp_has_peer_failed(peer, afi, safi)) {
11551 filtered_count++;
10b49f14 11552 continue;
ce1944f0 11553 }
96c81f66
LS
11554
11555 if ((count - filtered_count) == 1) {
11556 /* display headline before the first
11557 * neighbor line */
11558 vty_out(vty, "\n");
11559
11560 /* Subtract 8 here because 'Neighbor' is
11561 * 8 characters */
11562 vty_out(vty, "Neighbor");
11563 vty_out(vty, "%*s",
11564 max_neighbor_width - 8, " ");
11565 vty_out(vty,
11566 show_wide
11567 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
11568 : BGP_SHOW_SUMMARY_HEADER_ALL);
11569 }
11570
3577f1c5
DD
11571 memset(dn_flag, '\0', sizeof(dn_flag));
11572 if (peer_dynamic_neighbor(peer)) {
11573 dn_flag[0] = '*';
11574 }
d62a17ae 11575
3577f1c5 11576 if (peer->hostname
892fedb6
DA
11577 && CHECK_FLAG(bgp->flags,
11578 BGP_FLAG_SHOW_HOSTNAME))
3577f1c5 11579 len = vty_out(vty, "%s%s(%s)", dn_flag,
892fedb6
DA
11580 peer->hostname,
11581 peer->host);
d62a17ae 11582 else
3577f1c5
DD
11583 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11584
11585 /* pad the neighbor column with spaces */
11586 if (len < max_neighbor_width)
11587 vty_out(vty, "%*s", max_neighbor_width - len,
11588 " ");
11589
43aa5965
QY
11590 atomic_size_t outq_count, inq_count;
11591 outq_count = atomic_load_explicit(
11592 &peer->obuf->count,
11593 memory_order_relaxed);
11594 inq_count = atomic_load_explicit(
11595 &peer->ibuf->count,
11596 memory_order_relaxed);
11597
44a4d55e
PG
11598 vty_out(vty, "4 ");
11599 vty_out(vty, ASN_FORMAT_SPACE(bgp->asnotation),
11600 &peer->as);
11601 if (show_wide) {
85eeb029 11602 vty_out(vty,
44a4d55e
PG
11603 ASN_FORMAT_SPACE(
11604 bgp->asnotation),
85eeb029 11605 peer->change_local_as
44a4d55e
PG
11606 ? &peer->change_local_as
11607 : &peer->local_as);
11608 vty_out(vty,
11609 " %9u %9u %8" PRIu64
11610 " %4zu %4zu %8s",
85eeb029
DA
11611 PEER_TOTAL_RX(peer),
11612 PEER_TOTAL_TX(peer),
11613 peer->version[afi][safi],
11614 inq_count, outq_count,
11615 peer_uptime(peer->uptime,
11616 timebuf,
11617 BGP_UPTIME_LEN, 0,
11618 NULL));
44a4d55e
PG
11619 } else {
11620 vty_out(vty,
11621 " %9u %9u %8" PRIu64
11622 " %4zu %4zu %8s",
11623 PEER_TOTAL_RX(peer),
85eeb029
DA
11624 PEER_TOTAL_TX(peer),
11625 peer->version[afi][safi],
11626 inq_count, outq_count,
11627 peer_uptime(peer->uptime,
11628 timebuf,
11629 BGP_UPTIME_LEN, 0,
11630 NULL));
44a4d55e 11631 }
feb17238 11632 if (peer_established(peer)) {
d3ada366
DA
11633 if (peer->afc_recv[afi][safi]) {
11634 if (CHECK_FLAG(
11635 bgp->flags,
11636 BGP_FLAG_EBGP_REQUIRES_POLICY)
11637 && !bgp_inbound_policy_exists(
11638 peer, filter))
11639 vty_out(vty, " %12s",
11640 "(Policy)");
11641 else
11642 vty_out(vty,
6cde4b45 11643 " %12u",
d3ada366
DA
11644 peer->pcount
11645 [afi]
11646 [pfx_rcd_safi]);
11647 } else {
749d0f27 11648 vty_out(vty, " NoNeg");
d3ada366 11649 }
db92d226 11650
d3ada366
DA
11651 if (paf && PAF_SUBGRP(paf)) {
11652 if (CHECK_FLAG(
11653 bgp->flags,
11654 BGP_FLAG_EBGP_REQUIRES_POLICY)
11655 && !bgp_outbound_policy_exists(
11656 peer, filter))
11657 vty_out(vty, " %8s",
11658 "(Policy)");
11659 else
11660 vty_out(vty,
6cde4b45 11661 " %8u",
d3ada366
DA
11662 (PAF_SUBGRP(
11663 paf))
11664 ->scount);
749d0f27
DA
11665 } else {
11666 vty_out(vty, " NoNeg");
d3ada366 11667 }
db92d226 11668 } else {
736b68f3
DS
11669 if (CHECK_FLAG(peer->flags,
11670 PEER_FLAG_SHUTDOWN)
11671 || CHECK_FLAG(peer->bgp->flags,
11672 BGP_FLAG_SHUTDOWN))
3577f1c5
DD
11673 vty_out(vty, " Idle (Admin)");
11674 else if (CHECK_FLAG(
11675 peer->sflags,
11676 PEER_STATUS_PREFIX_OVERFLOW))
11677 vty_out(vty, " Idle (PfxCt)");
11678 else
11679 vty_out(vty, " %12s",
11680 lookup_msg(bgp_status_msg,
11681 peer->status, NULL));
db92d226 11682
6cde4b45 11683 vty_out(vty, " %8u", 0);
3577f1c5 11684 }
565e9ddd
DA
11685 /* Make sure `Desc` column is the lastest in
11686 * the output.
11687 */
aa72bd7e 11688 if (peer->desc)
cb75bb31
DA
11689 vty_out(vty, " %s",
11690 bgp_peer_description_stripped(
85eeb029
DA
11691 peer->desc,
11692 show_wide ? 64 : 20));
aa72bd7e
PG
11693 else
11694 vty_out(vty, " N/A");
3577f1c5 11695 vty_out(vty, "\n");
d62a17ae 11696 }
3577f1c5 11697
d62a17ae 11698 }
11699 }
f933309e 11700
d62a17ae 11701 if (use_json) {
11702 json_object_object_add(json, "peers", json_peers);
3577f1c5 11703 json_object_int_add(json, "failedPeers", failed_count);
ce1944f0
LS
11704 json_object_int_add(json, "displayedPeers",
11705 count - filtered_count);
d62a17ae 11706 json_object_int_add(json, "totalPeers", count);
11707 json_object_int_add(json, "dynamicPeers", dn_count);
11708
3577f1c5
DD
11709 if (!show_failed)
11710 bgp_show_bestpath_json(bgp, json);
57a9c8a8 11711
75eeda93 11712 vty_json(vty, json);
d62a17ae 11713 } else {
ce1944f0 11714 if (count) {
96c81f66
LS
11715 if (filtered_count == count)
11716 vty_out(vty, "\n%% No matching neighbor\n");
11717 else {
11718 if (show_failed)
11719 vty_out(vty, "\nDisplayed neighbors %d",
11720 failed_count);
11721 else if (as_type != AS_UNSPECIFIED || as
11722 || fpeer || show_established)
ce1944f0
LS
11723 vty_out(vty, "\nDisplayed neighbors %d",
11724 count - filtered_count);
96c81f66
LS
11725
11726 vty_out(vty, "\nTotal number of neighbors %d\n",
11727 count);
ce1944f0 11728 }
ce1944f0 11729 } else {
d6ceaca3 11730 vty_out(vty, "No %s neighbor is configured\n",
5cb5f4d0 11731 get_afi_safi_str(afi, safi, false));
d62a17ae 11732 }
b05a1c8b 11733
d6ceaca3 11734 if (dn_count) {
d62a17ae 11735 vty_out(vty, "* - dynamic neighbor\n");
11736 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11737 dn_count, bgp->dynamic_neighbors_limit);
11738 }
11739 }
1ff9a340 11740
d62a17ae 11741 return CMD_SUCCESS;
718e3744 11742}
11743
d62a17ae 11744static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8c1d4cd5 11745 int safi, struct peer *fpeer, int as_type,
96c81f66 11746 as_t as, uint16_t show_flags)
d62a17ae 11747{
11748 int is_first = 1;
11749 int afi_wildcard = (afi == AFI_MAX);
11750 int safi_wildcard = (safi == SAFI_MAX);
11751 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 11752 bool nbr_output = false;
85eeb029 11753 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 11754
11755 if (use_json && is_wildcard)
11756 vty_out(vty, "{\n");
11757 if (afi_wildcard)
11758 afi = 1; /* AFI_IP */
11759 while (afi < AFI_MAX) {
11760 if (safi_wildcard)
11761 safi = 1; /* SAFI_UNICAST */
11762 while (safi < SAFI_MAX) {
318cac96 11763 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 11764 nbr_output = true;
f86897b9 11765
d62a17ae 11766 if (is_wildcard) {
11767 /*
11768 * So limit output to those afi/safi
11769 * pairs that
11770 * actualy have something interesting in
11771 * them
11772 */
11773 if (use_json) {
d62a17ae 11774 if (!is_first)
11775 vty_out(vty, ",\n");
11776 else
11777 is_first = 0;
11778
11779 vty_out(vty, "\"%s\":",
5cb5f4d0
DD
11780 get_afi_safi_str(afi,
11781 safi,
11782 true));
d62a17ae 11783 } else {
6cac2fcc
LS
11784 vty_out(vty,
11785 "\n%s Summary (%s):\n",
5cb5f4d0
DD
11786 get_afi_safi_str(afi,
11787 safi,
6cac2fcc
LS
11788 false),
11789 bgp->name_pretty);
d62a17ae 11790 }
11791 }
8c1d4cd5
LS
11792 bgp_show_summary(vty, bgp, afi, safi, fpeer,
11793 as_type, as, show_flags);
d62a17ae 11794 }
11795 safi++;
d62a17ae 11796 if (!safi_wildcard)
11797 safi = SAFI_MAX;
11798 }
11799 afi++;
ee851c8c 11800 if (!afi_wildcard)
d62a17ae 11801 afi = AFI_MAX;
11802 }
11803
11804 if (use_json && is_wildcard)
11805 vty_out(vty, "}\n");
ca61fd25
DS
11806 else if (!nbr_output) {
11807 if (use_json)
11808 vty_out(vty, "{}\n");
11809 else
6cac2fcc
LS
11810 vty_out(vty, "%% No BGP neighbors found in %s\n",
11811 bgp->name_pretty);
ca61fd25 11812 }
d62a17ae 11813}
11814
11815static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8c1d4cd5
LS
11816 safi_t safi,
11817 const char *neighbor,
11818 int as_type, as_t as,
96c81f66 11819 uint16_t show_flags)
d62a17ae 11820{
11821 struct listnode *node, *nnode;
11822 struct bgp *bgp;
8c1d4cd5 11823 struct peer *fpeer = NULL;
d62a17ae 11824 int is_first = 1;
9f049418 11825 bool nbr_output = false;
85eeb029 11826 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 11827
11828 if (use_json)
11829 vty_out(vty, "{\n");
11830
11831 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 11832 nbr_output = true;
d62a17ae 11833 if (use_json) {
d62a17ae 11834 if (!is_first)
11835 vty_out(vty, ",\n");
11836 else
11837 is_first = 0;
11838
11839 vty_out(vty, "\"%s\":",
11840 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11841 ? VRF_DEFAULT_NAME
d62a17ae 11842 : bgp->name);
d62a17ae 11843 }
8c1d4cd5
LS
11844 if (neighbor) {
11845 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11846 use_json);
11847 if (!fpeer)
11848 continue;
11849 }
11850 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11851 as, show_flags);
d62a17ae 11852 }
11853
11854 if (use_json)
11855 vty_out(vty, "}\n");
9f049418
DS
11856 else if (!nbr_output)
11857 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 11858}
11859
11860int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8c1d4cd5 11861 safi_t safi, const char *neighbor, int as_type,
96c81f66 11862 as_t as, uint16_t show_flags)
d62a17ae 11863{
11864 struct bgp *bgp;
85eeb029 11865 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
8c1d4cd5 11866 struct peer *fpeer = NULL;
d62a17ae 11867
11868 if (name) {
11869 if (strmatch(name, "all")) {
85eeb029 11870 bgp_show_all_instances_summary_vty(vty, afi, safi,
8c1d4cd5
LS
11871 neighbor, as_type,
11872 as, show_flags);
d62a17ae 11873 return CMD_SUCCESS;
11874 } else {
11875 bgp = bgp_lookup_by_name(name);
11876
11877 if (!bgp) {
11878 if (use_json)
11879 vty_out(vty, "{}\n");
11880 else
11881 vty_out(vty,
ca61fd25 11882 "%% BGP instance not found\n");
d62a17ae 11883 return CMD_WARNING;
11884 }
11885
8c1d4cd5
LS
11886 if (neighbor) {
11887 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11888 use_json);
11889 if (!fpeer)
11890 return CMD_WARNING;
11891 }
11892 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
11893 as_type, as, show_flags);
d62a17ae 11894 return CMD_SUCCESS;
11895 }
11896 }
11897
11898 bgp = bgp_get_default();
11899
8c1d4cd5
LS
11900 if (bgp) {
11901 if (neighbor) {
11902 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11903 use_json);
11904 if (!fpeer)
11905 return CMD_WARNING;
11906 }
11907 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11908 as, show_flags);
11909 } else {
ca61fd25
DS
11910 if (use_json)
11911 vty_out(vty, "{}\n");
11912 else
11913 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
11914 return CMD_WARNING;
11915 }
d62a17ae 11916
11917 return CMD_SUCCESS;
4fb25c53
DW
11918}
11919
716b2d8a 11920/* `show [ip] bgp summary' commands. */
8c1d4cd5
LS
11921DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
11922 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
11923 " [" BGP_SAFI_WITH_LABEL_CMD_STR
8079a413 11924 "]] [all$all] summary [established|failed] [<neighbor <A.B.C.D|X:X::X:X|WORD>|remote-as <ASNUM|internal|external>>] [terse] [wide] [json$uj]",
8c1d4cd5
LS
11925 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11926 BGP_SAFI_WITH_LABEL_HELP_STR
11927 "Display the entries for all address families\n"
11928 "Summary of BGP neighbor status\n"
11929 "Show only sessions in Established state\n"
11930 "Show only sessions not in Established state\n"
11931 "Show only the specified neighbor session\n"
11932 "Neighbor to display information about\n"
11933 "Neighbor to display information about\n"
11934 "Neighbor on BGP configured interface\n"
8079a413 11935 "Show only the specified remote AS sessions\n" AS_STR
8c1d4cd5
LS
11936 "Internal (iBGP) AS sessions\n"
11937 "External (eBGP) AS sessions\n"
96c81f66 11938 "Shorten the information on BGP instances\n"
8c1d4cd5 11939 "Increase table width for longer output\n" JSON_STR)
718e3744 11940{
d62a17ae 11941 char *vrf = NULL;
11942 afi_t afi = AFI_MAX;
11943 safi_t safi = SAFI_MAX;
8c1d4cd5
LS
11944 as_t as = 0; /* 0 means AS filter not set */
11945 int as_type = AS_UNSPECIFIED;
96c81f66 11946 uint16_t show_flags = 0;
d62a17ae 11947
11948 int idx = 0;
11949
11950 /* show [ip] bgp */
96f3485c 11951 if (!all && argv_find(argv, argc, "ip", &idx))
d62a17ae 11952 afi = AFI_IP;
9a8bdf1c
PG
11953 /* [<vrf> VIEWVRFNAME] */
11954 if (argv_find(argv, argc, "vrf", &idx)) {
11955 vrf = argv[idx + 1]->arg;
11956 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11957 vrf = NULL;
11958 } else if (argv_find(argv, argc, "view", &idx))
11959 /* [<view> VIEWVRFNAME] */
11960 vrf = argv[idx + 1]->arg;
d62a17ae 11961 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11962 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11963 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11964 }
11965
3577f1c5 11966 if (argv_find(argv, argc, "failed", &idx))
85eeb029
DA
11967 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11968
10b49f14 11969 if (argv_find(argv, argc, "established", &idx))
85eeb029
DA
11970 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11971
8c1d4cd5
LS
11972 if (argv_find(argv, argc, "remote-as", &idx)) {
11973 if (argv[idx + 1]->arg[0] == 'i')
11974 as_type = AS_INTERNAL;
11975 else if (argv[idx + 1]->arg[0] == 'e')
11976 as_type = AS_EXTERNAL;
8079a413
PG
11977 else if (!asn_str2asn(argv[idx + 1]->arg, &as)) {
11978 vty_out(vty,
11979 "%% Invalid neighbor remote-as value: %s\n",
11980 argv[idx + 1]->arg);
11981 return CMD_SUCCESS;
11982 }
8c1d4cd5
LS
11983 }
11984
96c81f66
LS
11985 if (argv_find(argv, argc, "terse", &idx))
11986 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11987
85eeb029
DA
11988 if (argv_find(argv, argc, "wide", &idx))
11989 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11990
11991 if (argv_find(argv, argc, "json", &idx))
11992 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
3577f1c5 11993
8c1d4cd5
LS
11994 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
11995 show_flags);
d62a17ae 11996}
11997
5cb5f4d0 11998const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
d62a17ae 11999{
5cb5f4d0
DD
12000 if (for_json)
12001 return get_afi_safi_json_str(afi, safi);
d62a17ae 12002 else
5cb5f4d0 12003 return get_afi_safi_vty_str(afi, safi);
27162734
LB
12004}
12005
d62a17ae 12006
12007static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
12008 afi_t afi, safi_t safi,
d7c0a89a
QY
12009 uint16_t adv_smcap, uint16_t adv_rmcap,
12010 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 12011 bool use_json, json_object *json_pref)
d62a17ae 12012{
12013 /* Send-Mode */
12014 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
12015 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
12016 if (use_json) {
12017 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
12018 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
12019 json_object_string_add(json_pref, "sendMode",
12020 "advertisedAndReceived");
12021 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
12022 json_object_string_add(json_pref, "sendMode",
12023 "advertised");
12024 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
12025 json_object_string_add(json_pref, "sendMode",
12026 "received");
12027 } else {
12028 vty_out(vty, " Send-mode: ");
12029 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
12030 vty_out(vty, "advertised");
12031 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
12032 vty_out(vty, "%sreceived",
12033 CHECK_FLAG(p->af_cap[afi][safi],
12034 adv_smcap)
12035 ? ", "
12036 : "");
12037 vty_out(vty, "\n");
12038 }
12039 }
12040
12041 /* Receive-Mode */
12042 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
12043 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
12044 if (use_json) {
12045 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
12046 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
12047 json_object_string_add(json_pref, "recvMode",
12048 "advertisedAndReceived");
12049 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
12050 json_object_string_add(json_pref, "recvMode",
12051 "advertised");
12052 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
12053 json_object_string_add(json_pref, "recvMode",
12054 "received");
12055 } else {
12056 vty_out(vty, " Receive-mode: ");
12057 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
12058 vty_out(vty, "advertised");
12059 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
12060 vty_out(vty, "%sreceived",
12061 CHECK_FLAG(p->af_cap[afi][safi],
12062 adv_rmcap)
12063 ? ", "
12064 : "");
12065 vty_out(vty, "\n");
12066 }
12067 }
12068}
12069
eea685b6
DA
12070static void bgp_show_neighnor_graceful_restart_flags(struct vty *vty,
12071 struct peer *p,
eea685b6 12072 json_object *json)
2986cac2 12073{
eea685b6
DA
12074 bool rbit = false;
12075 bool nbit = false;
2986cac2 12076
13909c4f
DS
12077 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
12078 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
feb17238 12079 && (peer_established(p))) {
eea685b6
DA
12080 rbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_R_BIT_RCV);
12081 nbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_N_BIT_RCV);
2986cac2 12082 }
12083
403e64f8 12084 if (json) {
eea685b6
DA
12085 json_object_boolean_add(json, "rBit", rbit);
12086 json_object_boolean_add(json, "nBit", nbit);
2986cac2 12087 } else {
eea685b6
DA
12088 vty_out(vty, "\n R bit: %s", rbit ? "True" : "False");
12089 vty_out(vty, "\n N bit: %s\n", nbit ? "True" : "False");
2986cac2 12090 }
12091}
12092
13909c4f
DS
12093static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
12094 struct peer *peer,
13909c4f 12095 json_object *json)
2986cac2 12096{
2bb5d39b 12097 const char *mode = "NotApplicable";
2986cac2 12098
403e64f8 12099 if (!json)
a53ca37b 12100 vty_out(vty, "\n Remote GR Mode: ");
2986cac2 12101
13909c4f 12102 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
feb17238 12103 && (peer_established(peer))) {
2986cac2 12104
13909c4f
DS
12105 if ((peer->nsf_af_count == 0)
12106 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 12107
2986cac2 12108 mode = "Disable";
12109
13909c4f
DS
12110 } else if (peer->nsf_af_count == 0
12111 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 12112
2986cac2 12113 mode = "Helper";
12114
13909c4f
DS
12115 } else if (peer->nsf_af_count != 0
12116 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 12117
2986cac2 12118 mode = "Restart";
2986cac2 12119 }
12120 }
12121
403e64f8 12122 if (json)
13909c4f 12123 json_object_string_add(json, "remoteGrMode", mode);
403e64f8 12124 else
0e4e879b 12125 vty_out(vty, "%s\n", mode);
2986cac2 12126}
12127
13909c4f
DS
12128static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
12129 struct peer *p,
13909c4f 12130 json_object *json)
2986cac2 12131{
12132 const char *mode = "Invalid";
12133
403e64f8 12134 if (!json)
a53ca37b 12135 vty_out(vty, " Local GR Mode: ");
2986cac2 12136
12137 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
12138 mode = "Helper";
12139 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
12140 mode = "Restart";
12141 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
12142 mode = "Disable";
2ba1fe69 12143 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
2986cac2 12144 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
12145 mode = "Helper*";
12146 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
12147 mode = "Restart*";
12148 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
12149 mode = "Disable*";
12150 else
12151 mode = "Invalid*";
2ba1fe69 12152 }
2986cac2 12153
403e64f8 12154 if (json)
13909c4f 12155 json_object_string_add(json, "localGrMode", mode);
403e64f8 12156 else
0e4e879b 12157 vty_out(vty, "%s\n", mode);
2986cac2 12158}
12159
13909c4f 12160static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
403e64f8 12161 struct vty *vty, struct peer *peer, json_object *json)
2986cac2 12162{
2ba1fe69 12163 afi_t afi;
12164 safi_t safi;
2986cac2 12165 json_object *json_afi_safi = NULL;
12166 json_object *json_timer = NULL;
12167 json_object *json_endofrib_status = NULL;
9e3b51a7 12168 bool eor_flag = false;
2986cac2 12169
df8d723c
DA
12170 FOREACH_AFI_SAFI_NSF (afi, safi) {
12171 if (!peer->afc[afi][safi])
12172 continue;
2986cac2 12173
df8d723c
DA
12174 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) ||
12175 !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
12176 continue;
9e3b51a7 12177
403e64f8 12178 if (json) {
df8d723c
DA
12179 json_afi_safi = json_object_new_object();
12180 json_endofrib_status = json_object_new_object();
12181 json_timer = json_object_new_object();
12182 }
2986cac2 12183
df8d723c
DA
12184 if (peer->eor_stime[afi][safi] >= peer->pkt_stime[afi][safi])
12185 eor_flag = true;
12186 else
12187 eor_flag = false;
2986cac2 12188
403e64f8 12189 if (!json) {
df8d723c
DA
12190 vty_out(vty, " %s:\n",
12191 get_afi_safi_str(afi, safi, false));
2986cac2 12192
df8d723c
DA
12193 vty_out(vty, " F bit: ");
12194 }
2986cac2 12195
df8d723c
DA
12196 if (peer->nsf[afi][safi] &&
12197 CHECK_FLAG(peer->af_cap[afi][safi],
12198 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
2986cac2 12199
403e64f8 12200 if (json) {
df8d723c
DA
12201 json_object_boolean_true_add(json_afi_safi,
12202 "fBit");
12203 } else
12204 vty_out(vty, "True\n");
12205 } else {
403e64f8 12206 if (json)
df8d723c
DA
12207 json_object_boolean_false_add(json_afi_safi,
12208 "fBit");
12209 else
12210 vty_out(vty, "False\n");
12211 }
2986cac2 12212
403e64f8 12213 if (!json)
df8d723c 12214 vty_out(vty, " End-of-RIB sent: ");
2986cac2 12215
df8d723c
DA
12216 if (CHECK_FLAG(peer->af_sflags[afi][safi],
12217 PEER_STATUS_EOR_SEND)) {
403e64f8 12218 if (json) {
df8d723c
DA
12219 json_object_boolean_true_add(
12220 json_endofrib_status, "endOfRibSend");
9e3b51a7 12221
df8d723c
DA
12222 PRINT_EOR_JSON(eor_flag);
12223 } else {
12224 vty_out(vty, "Yes\n");
12225 vty_out(vty,
12226 " End-of-RIB sent after update: ");
2986cac2 12227
df8d723c
DA
12228 PRINT_EOR(eor_flag);
12229 }
12230 } else {
403e64f8 12231 if (json) {
df8d723c
DA
12232 json_object_boolean_false_add(
12233 json_endofrib_status, "endOfRibSend");
12234 json_object_boolean_false_add(
12235 json_endofrib_status,
12236 "endOfRibSentAfterUpdate");
13909c4f 12237 } else {
df8d723c
DA
12238 vty_out(vty, "No\n");
12239 vty_out(vty,
12240 " End-of-RIB sent after update: ");
12241 vty_out(vty, "No\n");
13909c4f 12242 }
df8d723c 12243 }
2986cac2 12244
403e64f8 12245 if (!json)
df8d723c 12246 vty_out(vty, " End-of-RIB received: ");
a53ca37b 12247
df8d723c
DA
12248 if (CHECK_FLAG(peer->af_sflags[afi][safi],
12249 PEER_STATUS_EOR_RECEIVED)) {
403e64f8 12250 if (json)
df8d723c
DA
12251 json_object_boolean_true_add(
12252 json_endofrib_status, "endOfRibRecv");
12253 else
12254 vty_out(vty, "Yes\n");
12255 } else {
403e64f8 12256 if (json)
df8d723c
DA
12257 json_object_boolean_false_add(
12258 json_endofrib_status, "endOfRibRecv");
12259 else
12260 vty_out(vty, "No\n");
12261 }
12262
403e64f8 12263 if (json) {
df8d723c
DA
12264 json_object_int_add(json_timer, "stalePathTimer",
12265 peer->bgp->stalepath_time);
12266
12267 if (peer->t_gr_stale != NULL) {
12268 json_object_int_add(json_timer,
12269 "stalePathTimerRemaining",
12270 thread_timer_remain_second(
12271 peer->t_gr_stale));
a53ca37b
DA
12272 }
12273
df8d723c
DA
12274 /* Display Configured Selection
12275 * Deferral only when when
12276 * Gr mode is enabled.
12277 */
12278 if (CHECK_FLAG(peer->flags,
12279 PEER_FLAG_GRACEFUL_RESTART)) {
13909c4f 12280 json_object_int_add(json_timer,
df8d723c 12281 "selectionDeferralTimer",
13909c4f 12282 peer->bgp->stalepath_time);
df8d723c 12283 }
2986cac2 12284
df8d723c
DA
12285 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
12286 NULL) {
2986cac2 12287
df8d723c
DA
12288 json_object_int_add(
12289 json_timer,
12290 "selectionDeferralTimerRemaining",
12291 thread_timer_remain_second(
12292 peer->bgp->gr_info[afi][safi]
12293 .t_select_deferral));
12294 }
12295 } else {
12296 vty_out(vty, " Timers:\n");
12297 vty_out(vty,
12298 " Configured Stale Path Time(sec): %u\n",
12299 peer->bgp->stalepath_time);
2986cac2 12300
df8d723c 12301 if (peer->t_gr_stale != NULL)
13909c4f 12302 vty_out(vty,
df8d723c
DA
12303 " Stale Path Remaining(sec): %ld\n",
12304 thread_timer_remain_second(
12305 peer->t_gr_stale));
12306 /* Display Configured Selection
12307 * Deferral only when when
12308 * Gr mode is enabled.
12309 */
12310 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
12311 vty_out(vty,
12312 " Configured Selection Deferral Time(sec): %u\n",
12313 peer->bgp->select_defer_time);
2986cac2 12314
df8d723c
DA
12315 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
12316 NULL)
12317 vty_out(vty,
12318 " Selection Deferral Time Remaining(sec): %ld\n",
12319 thread_timer_remain_second(
12320 peer->bgp->gr_info[afi][safi]
12321 .t_select_deferral));
12322 }
403e64f8 12323 if (json) {
df8d723c
DA
12324 json_object_object_add(json_afi_safi, "endOfRibStatus",
12325 json_endofrib_status);
12326 json_object_object_add(json_afi_safi, "timers",
12327 json_timer);
12328 json_object_object_add(
12329 json, get_afi_safi_str(afi, safi, true),
12330 json_afi_safi);
2986cac2 12331 }
12332 }
12333}
12334
36235319
QY
12335static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
12336 struct peer *p,
36235319 12337 json_object *json)
2986cac2 12338{
403e64f8 12339 if (json) {
2986cac2 12340 json_object *json_timer = NULL;
12341
12342 json_timer = json_object_new_object();
12343
13909c4f
DS
12344 json_object_int_add(json_timer, "configuredRestartTimer",
12345 p->bgp->restart_time);
2986cac2 12346
13909c4f
DS
12347 json_object_int_add(json_timer, "receivedRestartTimer",
12348 p->v_gr_restart);
2986cac2 12349
13909c4f
DS
12350 if (p->t_gr_restart != NULL)
12351 json_object_int_add(
12352 json_timer, "restartTimerRemaining",
12353 thread_timer_remain_second(p->t_gr_restart));
2986cac2 12354
12355 json_object_object_add(json, "timers", json_timer);
12356 } else {
12357
a53ca37b
DA
12358 vty_out(vty, " Timers:\n");
12359 vty_out(vty, " Configured Restart Time(sec): %u\n",
13909c4f 12360 p->bgp->restart_time);
2986cac2 12361
a53ca37b 12362 vty_out(vty, " Received Restart Time(sec): %u\n",
13909c4f
DS
12363 p->v_gr_restart);
12364 if (p->t_gr_restart != NULL)
a53ca37b 12365 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
13909c4f 12366 thread_timer_remain_second(p->t_gr_restart));
36235319 12367 if (p->t_gr_restart != NULL) {
a53ca37b 12368 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
36235319
QY
12369 thread_timer_remain_second(p->t_gr_restart));
12370 }
2986cac2 12371 }
12372}
12373
12374static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
403e64f8 12375 json_object *json)
2986cac2 12376{
2986cac2 12377 char dn_flag[2] = {0};
2b7165e7
QY
12378 /* '*' + v6 address of neighbor */
12379 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
2986cac2 12380
2986cac2 12381 if (!p->conf_if && peer_dynamic_neighbor(p))
12382 dn_flag[0] = '*';
12383
12384 if (p->conf_if) {
403e64f8 12385 if (json)
47e12884
DA
12386 json_object_string_addf(json, "neighborAddr", "%pSU",
12387 &p->su);
2986cac2 12388 else
47e12884
DA
12389 vty_out(vty, "BGP neighbor on %s: %pSU\n", p->conf_if,
12390 &p->su);
2986cac2 12391 } else {
772270f3
QY
12392 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
12393 p->host);
2986cac2 12394
403e64f8 12395 if (json)
36235319
QY
12396 json_object_string_add(json, "neighborAddr",
12397 neighborAddr);
2986cac2 12398 else
36235319 12399 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
2986cac2 12400 }
12401
12402 /* more gr info in new format */
403e64f8 12403 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, json);
2986cac2 12404}
12405
d62a17ae 12406static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 12407 safi_t safi, bool use_json,
d62a17ae 12408 json_object *json_neigh)
12409{
0291c246
MK
12410 struct bgp_filter *filter;
12411 struct peer_af *paf;
12412 char orf_pfx_name[BUFSIZ];
12413 int orf_pfx_count;
12414 json_object *json_af = NULL;
12415 json_object *json_prefA = NULL;
12416 json_object *json_prefB = NULL;
12417 json_object *json_addr = NULL;
fa36596c 12418 json_object *json_advmap = NULL;
d62a17ae 12419
12420 if (use_json) {
12421 json_addr = json_object_new_object();
12422 json_af = json_object_new_object();
12423 filter = &p->filter[afi][safi];
12424
12425 if (peer_group_active(p))
12426 json_object_string_add(json_addr, "peerGroupMember",
12427 p->group->name);
12428
12429 paf = peer_af_find(p, afi, safi);
12430 if (paf && PAF_SUBGRP(paf)) {
12431 json_object_int_add(json_addr, "updateGroupId",
12432 PAF_UPDGRP(paf)->id);
12433 json_object_int_add(json_addr, "subGroupId",
12434 PAF_SUBGRP(paf)->id);
12435 json_object_int_add(json_addr, "packetQueueLength",
12436 bpacket_queue_virtual_length(paf));
12437 }
12438
12439 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12440 || CHECK_FLAG(p->af_cap[afi][safi],
12441 PEER_CAP_ORF_PREFIX_SM_RCV)
12442 || CHECK_FLAG(p->af_cap[afi][safi],
12443 PEER_CAP_ORF_PREFIX_RM_ADV)
12444 || CHECK_FLAG(p->af_cap[afi][safi],
12445 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12446 json_object_int_add(json_af, "orfType",
12447 ORF_TYPE_PREFIX);
12448 json_prefA = json_object_new_object();
12449 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
12450 PEER_CAP_ORF_PREFIX_SM_ADV,
12451 PEER_CAP_ORF_PREFIX_RM_ADV,
12452 PEER_CAP_ORF_PREFIX_SM_RCV,
12453 PEER_CAP_ORF_PREFIX_RM_RCV,
12454 use_json, json_prefA);
12455 json_object_object_add(json_af, "orfPrefixList",
12456 json_prefA);
12457 }
12458
12459 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12460 || CHECK_FLAG(p->af_cap[afi][safi],
12461 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12462 || CHECK_FLAG(p->af_cap[afi][safi],
12463 PEER_CAP_ORF_PREFIX_RM_ADV)
12464 || CHECK_FLAG(p->af_cap[afi][safi],
12465 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12466 json_object_int_add(json_af, "orfOldType",
12467 ORF_TYPE_PREFIX_OLD);
12468 json_prefB = json_object_new_object();
12469 bgp_show_peer_afi_orf_cap(
12470 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12471 PEER_CAP_ORF_PREFIX_RM_ADV,
12472 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12473 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
12474 json_prefB);
12475 json_object_object_add(json_af, "orfOldPrefixList",
12476 json_prefB);
12477 }
12478
12479 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12480 || CHECK_FLAG(p->af_cap[afi][safi],
12481 PEER_CAP_ORF_PREFIX_SM_RCV)
12482 || CHECK_FLAG(p->af_cap[afi][safi],
12483 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12484 || CHECK_FLAG(p->af_cap[afi][safi],
12485 PEER_CAP_ORF_PREFIX_RM_ADV)
12486 || CHECK_FLAG(p->af_cap[afi][safi],
12487 PEER_CAP_ORF_PREFIX_RM_RCV)
12488 || CHECK_FLAG(p->af_cap[afi][safi],
12489 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12490 json_object_object_add(json_addr, "afDependentCap",
12491 json_af);
12492 else
12493 json_object_free(json_af);
12494
772270f3
QY
12495 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12496 p->host, afi, safi);
d62a17ae 12497 orf_pfx_count = prefix_bgp_show_prefix_list(
12498 NULL, afi, orf_pfx_name, use_json);
12499
12500 if (CHECK_FLAG(p->af_sflags[afi][safi],
12501 PEER_STATUS_ORF_PREFIX_SEND)
12502 || orf_pfx_count) {
12503 if (CHECK_FLAG(p->af_sflags[afi][safi],
12504 PEER_STATUS_ORF_PREFIX_SEND))
12505 json_object_boolean_true_add(json_neigh,
12506 "orfSent");
12507 if (orf_pfx_count)
12508 json_object_int_add(json_addr, "orfRecvCounter",
12509 orf_pfx_count);
12510 }
12511 if (CHECK_FLAG(p->af_sflags[afi][safi],
12512 PEER_STATUS_ORF_WAIT_REFRESH))
12513 json_object_string_add(
12514 json_addr, "orfFirstUpdate",
12515 "deferredUntilORFOrRouteRefreshRecvd");
12516
12517 if (CHECK_FLAG(p->af_flags[afi][safi],
12518 PEER_FLAG_REFLECTOR_CLIENT))
12519 json_object_boolean_true_add(json_addr,
12520 "routeReflectorClient");
12521 if (CHECK_FLAG(p->af_flags[afi][safi],
12522 PEER_FLAG_RSERVER_CLIENT))
12523 json_object_boolean_true_add(json_addr,
12524 "routeServerClient");
12525 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12526 json_object_boolean_true_add(json_addr,
12527 "inboundSoftConfigPermit");
12528
12529 if (CHECK_FLAG(p->af_flags[afi][safi],
12530 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12531 json_object_boolean_true_add(
12532 json_addr,
12533 "privateAsNumsAllReplacedInUpdatesToNbr");
12534 else if (CHECK_FLAG(p->af_flags[afi][safi],
12535 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12536 json_object_boolean_true_add(
12537 json_addr,
12538 "privateAsNumsReplacedInUpdatesToNbr");
12539 else if (CHECK_FLAG(p->af_flags[afi][safi],
12540 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12541 json_object_boolean_true_add(
12542 json_addr,
12543 "privateAsNumsAllRemovedInUpdatesToNbr");
12544 else if (CHECK_FLAG(p->af_flags[afi][safi],
12545 PEER_FLAG_REMOVE_PRIVATE_AS))
12546 json_object_boolean_true_add(
12547 json_addr,
12548 "privateAsNumsRemovedInUpdatesToNbr");
12549
b2ac1d0d
MS
12550 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN)) {
12551 if (CHECK_FLAG(p->af_flags[afi][safi],
12552 PEER_FLAG_ALLOWAS_IN_ORIGIN))
12553 json_object_boolean_true_add(json_addr,
12554 "allowAsInOrigin");
12555 else
12556 json_object_int_add(json_addr, "allowAsInCount",
12557 p->allowas_in[afi][safi]);
12558 }
12559
dcc68b5e
MS
12560 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12561 json_object_boolean_true_add(
12562 json_addr,
12563 bgp_addpath_names(p->addpath_type[afi][safi])
12564 ->type_json_name);
d62a17ae 12565
12566 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12567 json_object_string_add(json_addr,
12568 "overrideASNsInOutboundUpdates",
12569 "ifAspathEqualRemoteAs");
12570
12571 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12572 || CHECK_FLAG(p->af_flags[afi][safi],
12573 PEER_FLAG_FORCE_NEXTHOP_SELF))
12574 json_object_boolean_true_add(json_addr,
12575 "routerAlwaysNextHop");
12576 if (CHECK_FLAG(p->af_flags[afi][safi],
12577 PEER_FLAG_AS_PATH_UNCHANGED))
12578 json_object_boolean_true_add(
12579 json_addr, "unchangedAsPathPropogatedToNbr");
12580 if (CHECK_FLAG(p->af_flags[afi][safi],
12581 PEER_FLAG_NEXTHOP_UNCHANGED))
12582 json_object_boolean_true_add(
12583 json_addr, "unchangedNextHopPropogatedToNbr");
12584 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12585 json_object_boolean_true_add(
12586 json_addr, "unchangedMedPropogatedToNbr");
12587 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12588 || CHECK_FLAG(p->af_flags[afi][safi],
12589 PEER_FLAG_SEND_EXT_COMMUNITY)) {
12590 if (CHECK_FLAG(p->af_flags[afi][safi],
12591 PEER_FLAG_SEND_COMMUNITY)
12592 && CHECK_FLAG(p->af_flags[afi][safi],
12593 PEER_FLAG_SEND_EXT_COMMUNITY))
12594 json_object_string_add(json_addr,
12595 "commAttriSentToNbr",
12596 "extendedAndStandard");
12597 else if (CHECK_FLAG(p->af_flags[afi][safi],
12598 PEER_FLAG_SEND_EXT_COMMUNITY))
12599 json_object_string_add(json_addr,
12600 "commAttriSentToNbr",
12601 "extended");
12602 else
12603 json_object_string_add(json_addr,
12604 "commAttriSentToNbr",
12605 "standard");
12606 }
12607 if (CHECK_FLAG(p->af_flags[afi][safi],
12608 PEER_FLAG_DEFAULT_ORIGINATE)) {
12609 if (p->default_rmap[afi][safi].name)
12610 json_object_string_add(
12611 json_addr, "defaultRouteMap",
12612 p->default_rmap[afi][safi].name);
12613
12614 if (paf && PAF_SUBGRP(paf)
12615 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12616 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12617 json_object_boolean_true_add(json_addr,
12618 "defaultSent");
12619 else
12620 json_object_boolean_true_add(json_addr,
12621 "defaultNotSent");
12622 }
12623
dff8f48d 12624 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 12625 if (is_evpn_enabled())
60466a63
QY
12626 json_object_boolean_true_add(
12627 json_addr, "advertiseAllVnis");
dff8f48d
MK
12628 }
12629
d62a17ae 12630 if (filter->plist[FILTER_IN].name
12631 || filter->dlist[FILTER_IN].name
12632 || filter->aslist[FILTER_IN].name
12633 || filter->map[RMAP_IN].name)
12634 json_object_boolean_true_add(json_addr,
12635 "inboundPathPolicyConfig");
12636 if (filter->plist[FILTER_OUT].name
12637 || filter->dlist[FILTER_OUT].name
12638 || filter->aslist[FILTER_OUT].name
12639 || filter->map[RMAP_OUT].name || filter->usmap.name)
12640 json_object_boolean_true_add(
12641 json_addr, "outboundPathPolicyConfig");
12642
12643 /* prefix-list */
12644 if (filter->plist[FILTER_IN].name)
12645 json_object_string_add(json_addr,
12646 "incomingUpdatePrefixFilterList",
12647 filter->plist[FILTER_IN].name);
12648 if (filter->plist[FILTER_OUT].name)
12649 json_object_string_add(json_addr,
12650 "outgoingUpdatePrefixFilterList",
12651 filter->plist[FILTER_OUT].name);
12652
12653 /* distribute-list */
12654 if (filter->dlist[FILTER_IN].name)
12655 json_object_string_add(
12656 json_addr, "incomingUpdateNetworkFilterList",
12657 filter->dlist[FILTER_IN].name);
12658 if (filter->dlist[FILTER_OUT].name)
12659 json_object_string_add(
12660 json_addr, "outgoingUpdateNetworkFilterList",
12661 filter->dlist[FILTER_OUT].name);
12662
12663 /* filter-list. */
12664 if (filter->aslist[FILTER_IN].name)
12665 json_object_string_add(json_addr,
12666 "incomingUpdateAsPathFilterList",
12667 filter->aslist[FILTER_IN].name);
12668 if (filter->aslist[FILTER_OUT].name)
12669 json_object_string_add(json_addr,
12670 "outgoingUpdateAsPathFilterList",
12671 filter->aslist[FILTER_OUT].name);
12672
12673 /* route-map. */
12674 if (filter->map[RMAP_IN].name)
12675 json_object_string_add(
12676 json_addr, "routeMapForIncomingAdvertisements",
12677 filter->map[RMAP_IN].name);
12678 if (filter->map[RMAP_OUT].name)
12679 json_object_string_add(
12680 json_addr, "routeMapForOutgoingAdvertisements",
12681 filter->map[RMAP_OUT].name);
12682
9dac9fc8 12683 /* ebgp-requires-policy (inbound) */
1d3fdccf 12684 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12685 && !bgp_inbound_policy_exists(p, filter))
12686 json_object_string_add(
12687 json_addr, "inboundEbgpRequiresPolicy",
12688 "Inbound updates discarded due to missing policy");
12689
12690 /* ebgp-requires-policy (outbound) */
1d3fdccf 12691 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12692 && (!bgp_outbound_policy_exists(p, filter)))
12693 json_object_string_add(
12694 json_addr, "outboundEbgpRequiresPolicy",
12695 "Outbound updates discarded due to missing policy");
12696
d62a17ae 12697 /* unsuppress-map */
12698 if (filter->usmap.name)
12699 json_object_string_add(json_addr,
12700 "selectiveUnsuppressRouteMap",
12701 filter->usmap.name);
12702
fa36596c
MK
12703 /* advertise-map */
12704 if (filter->advmap.aname) {
12705 json_advmap = json_object_new_object();
12706 json_object_string_add(json_advmap, "condition",
12707 filter->advmap.condition
12708 ? "EXIST"
12709 : "NON_EXIST");
12710 json_object_string_add(json_advmap, "conditionMap",
12711 filter->advmap.cname);
12712 json_object_string_add(json_advmap, "advertiseMap",
12713 filter->advmap.aname);
ecf2b628
QY
12714 json_object_string_add(
12715 json_advmap, "advertiseStatus",
12716 filter->advmap.update_type ==
12717 UPDATE_TYPE_ADVERTISE
12718 ? "Advertise"
12719 : "Withdraw");
fa36596c
MK
12720 json_object_object_add(json_addr, "advertiseMap",
12721 json_advmap);
12722 }
12723
d62a17ae 12724 /* Receive prefix count */
12725 json_object_int_add(json_addr, "acceptedPrefixCounter",
12726 p->pcount[afi][safi]);
50e05855
AD
12727 if (paf && PAF_SUBGRP(paf))
12728 json_object_int_add(json_addr, "sentPrefixCounter",
12729 (PAF_SUBGRP(paf))->scount);
d62a17ae 12730
fde246e8
DA
12731 /* Maximum prefix */
12732 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12733 json_object_int_add(json_addr, "prefixOutAllowedMax",
12734 p->pmax_out[afi][safi]);
12735
d62a17ae 12736 /* Maximum prefix */
12737 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12738 json_object_int_add(json_addr, "prefixAllowedMax",
12739 p->pmax[afi][safi]);
12740 if (CHECK_FLAG(p->af_flags[afi][safi],
12741 PEER_FLAG_MAX_PREFIX_WARNING))
12742 json_object_boolean_true_add(
12743 json_addr, "prefixAllowedMaxWarning");
12744 json_object_int_add(json_addr,
12745 "prefixAllowedWarningThresh",
12746 p->pmax_threshold[afi][safi]);
12747 if (p->pmax_restart[afi][safi])
12748 json_object_int_add(
12749 json_addr,
12750 "prefixAllowedRestartIntervalMsecs",
12751 p->pmax_restart[afi][safi] * 60000);
12752 }
2986cac2 12753 json_object_object_add(json_neigh,
36235319 12754 get_afi_safi_str(afi, safi, true),
d62a17ae 12755 json_addr);
12756
12757 } else {
12758 filter = &p->filter[afi][safi];
12759
12760 vty_out(vty, " For address family: %s\n",
5cb5f4d0 12761 get_afi_safi_str(afi, safi, false));
d62a17ae 12762
12763 if (peer_group_active(p))
12764 vty_out(vty, " %s peer-group member\n",
12765 p->group->name);
12766
12767 paf = peer_af_find(p, afi, safi);
12768 if (paf && PAF_SUBGRP(paf)) {
6cde4b45 12769 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
d62a17ae 12770 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12771 vty_out(vty, " Packet Queue length %d\n",
12772 bpacket_queue_virtual_length(paf));
12773 } else {
12774 vty_out(vty, " Not part of any update group\n");
12775 }
12776 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12777 || CHECK_FLAG(p->af_cap[afi][safi],
12778 PEER_CAP_ORF_PREFIX_SM_RCV)
12779 || CHECK_FLAG(p->af_cap[afi][safi],
12780 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12781 || CHECK_FLAG(p->af_cap[afi][safi],
12782 PEER_CAP_ORF_PREFIX_RM_ADV)
12783 || CHECK_FLAG(p->af_cap[afi][safi],
12784 PEER_CAP_ORF_PREFIX_RM_RCV)
12785 || CHECK_FLAG(p->af_cap[afi][safi],
12786 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12787 vty_out(vty, " AF-dependant capabilities:\n");
12788
12789 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12790 || CHECK_FLAG(p->af_cap[afi][safi],
12791 PEER_CAP_ORF_PREFIX_SM_RCV)
12792 || CHECK_FLAG(p->af_cap[afi][safi],
12793 PEER_CAP_ORF_PREFIX_RM_ADV)
12794 || CHECK_FLAG(p->af_cap[afi][safi],
12795 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12796 vty_out(vty,
12797 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12798 ORF_TYPE_PREFIX);
12799 bgp_show_peer_afi_orf_cap(
12800 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12801 PEER_CAP_ORF_PREFIX_RM_ADV,
12802 PEER_CAP_ORF_PREFIX_SM_RCV,
12803 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12804 }
12805 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12806 || CHECK_FLAG(p->af_cap[afi][safi],
12807 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12808 || CHECK_FLAG(p->af_cap[afi][safi],
12809 PEER_CAP_ORF_PREFIX_RM_ADV)
12810 || CHECK_FLAG(p->af_cap[afi][safi],
12811 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12812 vty_out(vty,
12813 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12814 ORF_TYPE_PREFIX_OLD);
12815 bgp_show_peer_afi_orf_cap(
12816 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12817 PEER_CAP_ORF_PREFIX_RM_ADV,
12818 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12819 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12820 }
12821
772270f3
QY
12822 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12823 p->host, afi, safi);
d62a17ae 12824 orf_pfx_count = prefix_bgp_show_prefix_list(
12825 NULL, afi, orf_pfx_name, use_json);
12826
12827 if (CHECK_FLAG(p->af_sflags[afi][safi],
12828 PEER_STATUS_ORF_PREFIX_SEND)
12829 || orf_pfx_count) {
12830 vty_out(vty, " Outbound Route Filter (ORF):");
12831 if (CHECK_FLAG(p->af_sflags[afi][safi],
12832 PEER_STATUS_ORF_PREFIX_SEND))
12833 vty_out(vty, " sent;");
12834 if (orf_pfx_count)
12835 vty_out(vty, " received (%d entries)",
12836 orf_pfx_count);
12837 vty_out(vty, "\n");
12838 }
12839 if (CHECK_FLAG(p->af_sflags[afi][safi],
12840 PEER_STATUS_ORF_WAIT_REFRESH))
12841 vty_out(vty,
12842 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12843
12844 if (CHECK_FLAG(p->af_flags[afi][safi],
12845 PEER_FLAG_REFLECTOR_CLIENT))
12846 vty_out(vty, " Route-Reflector Client\n");
12847 if (CHECK_FLAG(p->af_flags[afi][safi],
12848 PEER_FLAG_RSERVER_CLIENT))
12849 vty_out(vty, " Route-Server Client\n");
12850 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12851 vty_out(vty,
12852 " Inbound soft reconfiguration allowed\n");
12853
12854 if (CHECK_FLAG(p->af_flags[afi][safi],
12855 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12856 vty_out(vty,
12857 " Private AS numbers (all) replaced in updates to this neighbor\n");
12858 else if (CHECK_FLAG(p->af_flags[afi][safi],
12859 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12860 vty_out(vty,
12861 " Private AS numbers replaced in updates to this neighbor\n");
12862 else if (CHECK_FLAG(p->af_flags[afi][safi],
12863 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12864 vty_out(vty,
12865 " Private AS numbers (all) removed in updates to this neighbor\n");
12866 else if (CHECK_FLAG(p->af_flags[afi][safi],
12867 PEER_FLAG_REMOVE_PRIVATE_AS))
12868 vty_out(vty,
12869 " Private AS numbers removed in updates to this neighbor\n");
12870
b2ac1d0d
MS
12871 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN)) {
12872 if (CHECK_FLAG(p->af_flags[afi][safi],
12873 PEER_FLAG_ALLOWAS_IN_ORIGIN))
12874 vty_out(vty,
12875 " Local AS allowed as path origin\n");
12876 else
12877 vty_out(vty,
12878 " Local AS allowed in path, %d occurrences\n",
12879 p->allowas_in[afi][safi]);
12880 }
12881
dcc68b5e
MS
12882 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12883 vty_out(vty, " %s\n",
12884 bgp_addpath_names(p->addpath_type[afi][safi])
12885 ->human_description);
d62a17ae 12886
12887 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12888 vty_out(vty,
12889 " Override ASNs in outbound updates if aspath equals remote-as\n");
12890
12891 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12892 || CHECK_FLAG(p->af_flags[afi][safi],
12893 PEER_FLAG_FORCE_NEXTHOP_SELF))
12894 vty_out(vty, " NEXT_HOP is always this router\n");
12895 if (CHECK_FLAG(p->af_flags[afi][safi],
12896 PEER_FLAG_AS_PATH_UNCHANGED))
12897 vty_out(vty,
12898 " AS_PATH is propagated unchanged to this neighbor\n");
12899 if (CHECK_FLAG(p->af_flags[afi][safi],
12900 PEER_FLAG_NEXTHOP_UNCHANGED))
12901 vty_out(vty,
12902 " NEXT_HOP is propagated unchanged to this neighbor\n");
12903 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12904 vty_out(vty,
12905 " MED is propagated unchanged to this neighbor\n");
12906 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12907 || CHECK_FLAG(p->af_flags[afi][safi],
12908 PEER_FLAG_SEND_EXT_COMMUNITY)
12909 || CHECK_FLAG(p->af_flags[afi][safi],
12910 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12911 vty_out(vty,
12912 " Community attribute sent to this neighbor");
12913 if (CHECK_FLAG(p->af_flags[afi][safi],
12914 PEER_FLAG_SEND_COMMUNITY)
12915 && CHECK_FLAG(p->af_flags[afi][safi],
12916 PEER_FLAG_SEND_EXT_COMMUNITY)
12917 && CHECK_FLAG(p->af_flags[afi][safi],
12918 PEER_FLAG_SEND_LARGE_COMMUNITY))
12919 vty_out(vty, "(all)\n");
12920 else if (CHECK_FLAG(p->af_flags[afi][safi],
12921 PEER_FLAG_SEND_LARGE_COMMUNITY))
12922 vty_out(vty, "(large)\n");
12923 else if (CHECK_FLAG(p->af_flags[afi][safi],
12924 PEER_FLAG_SEND_EXT_COMMUNITY))
12925 vty_out(vty, "(extended)\n");
12926 else
12927 vty_out(vty, "(standard)\n");
12928 }
12929 if (CHECK_FLAG(p->af_flags[afi][safi],
12930 PEER_FLAG_DEFAULT_ORIGINATE)) {
12931 vty_out(vty, " Default information originate,");
12932
12933 if (p->default_rmap[afi][safi].name)
12934 vty_out(vty, " default route-map %s%s,",
12935 p->default_rmap[afi][safi].map ? "*"
12936 : "",
12937 p->default_rmap[afi][safi].name);
12938 if (paf && PAF_SUBGRP(paf)
12939 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12940 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12941 vty_out(vty, " default sent\n");
12942 else
12943 vty_out(vty, " default not sent\n");
12944 }
12945
dff8f48d
MK
12946 /* advertise-vni-all */
12947 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 12948 if (is_evpn_enabled())
dff8f48d
MK
12949 vty_out(vty, " advertise-all-vni\n");
12950 }
12951
d62a17ae 12952 if (filter->plist[FILTER_IN].name
12953 || filter->dlist[FILTER_IN].name
12954 || filter->aslist[FILTER_IN].name
12955 || filter->map[RMAP_IN].name)
12956 vty_out(vty, " Inbound path policy configured\n");
12957 if (filter->plist[FILTER_OUT].name
12958 || filter->dlist[FILTER_OUT].name
12959 || filter->aslist[FILTER_OUT].name
12960 || filter->map[RMAP_OUT].name || filter->usmap.name)
12961 vty_out(vty, " Outbound path policy configured\n");
12962
12963 /* prefix-list */
12964 if (filter->plist[FILTER_IN].name)
12965 vty_out(vty,
12966 " Incoming update prefix filter list is %s%s\n",
12967 filter->plist[FILTER_IN].plist ? "*" : "",
12968 filter->plist[FILTER_IN].name);
12969 if (filter->plist[FILTER_OUT].name)
12970 vty_out(vty,
12971 " Outgoing update prefix filter list is %s%s\n",
12972 filter->plist[FILTER_OUT].plist ? "*" : "",
12973 filter->plist[FILTER_OUT].name);
12974
12975 /* distribute-list */
12976 if (filter->dlist[FILTER_IN].name)
12977 vty_out(vty,
12978 " Incoming update network filter list is %s%s\n",
12979 filter->dlist[FILTER_IN].alist ? "*" : "",
12980 filter->dlist[FILTER_IN].name);
12981 if (filter->dlist[FILTER_OUT].name)
12982 vty_out(vty,
12983 " Outgoing update network filter list is %s%s\n",
12984 filter->dlist[FILTER_OUT].alist ? "*" : "",
12985 filter->dlist[FILTER_OUT].name);
12986
12987 /* filter-list. */
12988 if (filter->aslist[FILTER_IN].name)
12989 vty_out(vty,
12990 " Incoming update AS path filter list is %s%s\n",
12991 filter->aslist[FILTER_IN].aslist ? "*" : "",
12992 filter->aslist[FILTER_IN].name);
12993 if (filter->aslist[FILTER_OUT].name)
12994 vty_out(vty,
12995 " Outgoing update AS path filter list is %s%s\n",
12996 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12997 filter->aslist[FILTER_OUT].name);
12998
12999 /* route-map. */
13000 if (filter->map[RMAP_IN].name)
13001 vty_out(vty,
13002 " Route map for incoming advertisements is %s%s\n",
13003 filter->map[RMAP_IN].map ? "*" : "",
13004 filter->map[RMAP_IN].name);
13005 if (filter->map[RMAP_OUT].name)
13006 vty_out(vty,
13007 " Route map for outgoing advertisements is %s%s\n",
13008 filter->map[RMAP_OUT].map ? "*" : "",
13009 filter->map[RMAP_OUT].name);
13010
9dac9fc8 13011 /* ebgp-requires-policy (inbound) */
1d3fdccf 13012 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
13013 && !bgp_inbound_policy_exists(p, filter))
13014 vty_out(vty,
13015 " Inbound updates discarded due to missing policy\n");
13016
13017 /* ebgp-requires-policy (outbound) */
1d3fdccf 13018 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
13019 && !bgp_outbound_policy_exists(p, filter))
13020 vty_out(vty,
13021 " Outbound updates discarded due to missing policy\n");
13022
d62a17ae 13023 /* unsuppress-map */
13024 if (filter->usmap.name)
13025 vty_out(vty,
13026 " Route map for selective unsuppress is %s%s\n",
13027 filter->usmap.map ? "*" : "",
13028 filter->usmap.name);
13029
7f7940e6
MK
13030 /* advertise-map */
13031 if (filter->advmap.aname && filter->advmap.cname)
13032 vty_out(vty,
13033 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
13034 filter->advmap.condition ? "EXIST"
13035 : "NON_EXIST",
13036 filter->advmap.cmap ? "*" : "",
13037 filter->advmap.cname,
13038 filter->advmap.amap ? "*" : "",
13039 filter->advmap.aname,
ecf2b628
QY
13040 filter->advmap.update_type ==
13041 UPDATE_TYPE_ADVERTISE
c385f82a
MK
13042 ? "Advertise"
13043 : "Withdraw");
7f7940e6 13044
d62a17ae 13045 /* Receive prefix count */
6cde4b45 13046 vty_out(vty, " %u accepted prefixes\n",
a0a87037 13047 p->pcount[afi][safi]);
d62a17ae 13048
fde246e8
DA
13049 /* maximum-prefix-out */
13050 if (CHECK_FLAG(p->af_flags[afi][safi],
13051 PEER_FLAG_MAX_PREFIX_OUT))
13052 vty_out(vty,
6cde4b45 13053 " Maximum allowed prefixes sent %u\n",
fde246e8
DA
13054 p->pmax_out[afi][safi]);
13055
d62a17ae 13056 /* Maximum prefix */
13057 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
a0a87037 13058 vty_out(vty,
6cde4b45 13059 " Maximum prefixes allowed %u%s\n",
d62a17ae 13060 p->pmax[afi][safi],
13061 CHECK_FLAG(p->af_flags[afi][safi],
13062 PEER_FLAG_MAX_PREFIX_WARNING)
13063 ? " (warning-only)"
13064 : "");
13065 vty_out(vty, " Threshold for warning message %d%%",
13066 p->pmax_threshold[afi][safi]);
13067 if (p->pmax_restart[afi][safi])
13068 vty_out(vty, ", restart interval %d min",
13069 p->pmax_restart[afi][safi]);
13070 vty_out(vty, "\n");
13071 }
13072
13073 vty_out(vty, "\n");
13074 }
13075}
13076
9f049418 13077static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 13078 json_object *json)
718e3744 13079{
d62a17ae 13080 struct bgp *bgp;
d62a17ae 13081 char timebuf[BGP_UPTIME_LEN];
13082 char dn_flag[2];
d62a17ae 13083 afi_t afi;
13084 safi_t safi;
d7c0a89a
QY
13085 uint16_t i;
13086 uint8_t *msg;
d62a17ae 13087 json_object *json_neigh = NULL;
13088 time_t epoch_tbuf;
4ab46701 13089 uint32_t sync_tcp_mss;
718e3744 13090
d62a17ae 13091 bgp = p->bgp;
13092
13093 if (use_json)
13094 json_neigh = json_object_new_object();
13095
13096 memset(dn_flag, '\0', sizeof(dn_flag));
13097 if (!p->conf_if && peer_dynamic_neighbor(p))
13098 dn_flag[0] = '*';
13099
13100 if (!use_json) {
13101 if (p->conf_if) /* Configured interface name. */
47e12884
DA
13102 vty_out(vty, "BGP neighbor on %s: %pSU, ", p->conf_if,
13103 &p->su);
d62a17ae 13104 else /* Configured IP address. */
13105 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
13106 p->host);
13107 }
13108
13109 if (use_json) {
13110 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
13111 json_object_string_add(json_neigh, "bgpNeighborAddr",
13112 "none");
13113 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
47e12884
DA
13114 json_object_string_addf(json_neigh, "bgpNeighborAddr",
13115 "%pSU", &p->su);
d62a17ae 13116
44a4d55e 13117 asn_asn2json(json_neigh, "remoteAs", p->as, bgp->asnotation);
d62a17ae 13118
13119 if (p->change_local_as)
44a4d55e
PG
13120 asn_asn2json(json_neigh, "localAs", p->change_local_as,
13121 bgp->asnotation);
d62a17ae 13122 else
44a4d55e
PG
13123 asn_asn2json(json_neigh, "localAs", p->local_as,
13124 bgp->asnotation);
d62a17ae 13125
13126 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
13127 json_object_boolean_true_add(json_neigh,
13128 "localAsNoPrepend");
13129
13130 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
13131 json_object_boolean_true_add(json_neigh,
13132 "localAsReplaceAs");
13133 } else {
44a4d55e
PG
13134 if ((p->as_type == AS_SPECIFIED) ||
13135 (p->as_type == AS_EXTERNAL) ||
13136 (p->as_type == AS_INTERNAL)) {
13137 vty_out(vty, "remote AS ");
13138 vty_out(vty, ASN_FORMAT(bgp->asnotation), &p->as);
13139 vty_out(vty, ", ");
13140 } else
d62a17ae 13141 vty_out(vty, "remote AS Unspecified, ");
44a4d55e
PG
13142 vty_out(vty, "local AS ");
13143 vty_out(vty, ASN_FORMAT(bgp->asnotation),
13144 p->change_local_as ? &p->change_local_as
13145 : &p->local_as);
13146 vty_out(vty, "%s%s, ",
d62a17ae 13147 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
13148 ? " no-prepend"
13149 : "",
13150 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
13151 ? " replace-as"
13152 : "");
13153 }
faa16034
DS
13154 /* peer type internal or confed-internal */
13155 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
d62a17ae 13156 if (use_json) {
13157 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13158 json_object_boolean_true_add(
13159 json_neigh, "nbrConfedInternalLink");
13160 else
13161 json_object_boolean_true_add(json_neigh,
13162 "nbrInternalLink");
13163 } else {
13164 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13165 vty_out(vty, "confed-internal link\n");
13166 else
13167 vty_out(vty, "internal link\n");
13168 }
faa16034
DS
13169 /* peer type external or confed-external */
13170 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
d62a17ae 13171 if (use_json) {
13172 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13173 json_object_boolean_true_add(
13174 json_neigh, "nbrConfedExternalLink");
13175 else
13176 json_object_boolean_true_add(json_neigh,
13177 "nbrExternalLink");
13178 } else {
13179 if (bgp_confederation_peers_check(bgp, p->as))
13180 vty_out(vty, "confed-external link\n");
13181 else
13182 vty_out(vty, "external link\n");
13183 }
faa16034
DS
13184 } else {
13185 if (use_json)
13186 json_object_boolean_true_add(json_neigh,
13187 "nbrUnspecifiedLink");
13188 else
13189 vty_out(vty, "unspecified link\n");
d62a17ae 13190 }
13191
d864dd9e
EB
13192 /* Roles */
13193 if (use_json) {
13194 json_object_string_add(json_neigh, "localRole",
8f2d6021
EB
13195 bgp_get_name_by_role(p->local_role));
13196 json_object_string_add(json_neigh, "remoteRole",
13197 bgp_get_name_by_role(p->remote_role));
d864dd9e
EB
13198 } else {
13199 vty_out(vty, " Local Role: %s\n",
8f2d6021
EB
13200 bgp_get_name_by_role(p->local_role));
13201 vty_out(vty, " Remote Role: %s\n",
13202 bgp_get_name_by_role(p->remote_role));
d864dd9e
EB
13203 }
13204
13205
d62a17ae 13206 /* Description. */
13207 if (p->desc) {
13208 if (use_json)
13209 json_object_string_add(json_neigh, "nbrDesc", p->desc);
13210 else
13211 vty_out(vty, " Description: %s\n", p->desc);
13212 }
13213
13214 if (p->hostname) {
13215 if (use_json) {
432e7e46
KQ
13216 json_object_string_add(json_neigh, "hostname",
13217 p->hostname);
d62a17ae 13218
13219 if (p->domainname)
13220 json_object_string_add(json_neigh, "domainname",
13221 p->domainname);
13222 } else {
13223 if (p->domainname && (p->domainname[0] != '\0'))
13224 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
13225 p->domainname);
13226 else
13227 vty_out(vty, "Hostname: %s\n", p->hostname);
13228 }
432e7e46
KQ
13229 } else {
13230 if (use_json)
13231 json_object_string_add(json_neigh, "hostname",
13232 "Unknown");
d62a17ae 13233 }
13234
13235 /* Peer-group */
13236 if (p->group) {
13237 if (use_json) {
13238 json_object_string_add(json_neigh, "peerGroup",
13239 p->group->name);
13240
13241 if (dn_flag[0]) {
13242 struct prefix prefix, *range = NULL;
13243
0154d8ce
DS
13244 if (sockunion2hostprefix(&(p->su), &prefix))
13245 range = peer_group_lookup_dynamic_neighbor_range(
13246 p->group, &prefix);
d62a17ae 13247
13248 if (range) {
67d7e256 13249 json_object_string_addf(
d62a17ae 13250 json_neigh,
67d7e256
DA
13251 "peerSubnetRangeGroup", "%pFX",
13252 range);
d62a17ae 13253 }
13254 }
13255 } else {
13256 vty_out(vty,
13257 " Member of peer-group %s for session parameters\n",
13258 p->group->name);
13259
13260 if (dn_flag[0]) {
13261 struct prefix prefix, *range = NULL;
13262
0154d8ce
DS
13263 if (sockunion2hostprefix(&(p->su), &prefix))
13264 range = peer_group_lookup_dynamic_neighbor_range(
13265 p->group, &prefix);
d62a17ae 13266
13267 if (range) {
d62a17ae 13268 vty_out(vty,
1b78780b
DL
13269 " Belongs to the subnet range group: %pFX\n",
13270 range);
d62a17ae 13271 }
13272 }
13273 }
13274 }
13275
13276 if (use_json) {
13277 /* Administrative shutdown. */
cb9196e7
DS
13278 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13279 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 13280 json_object_boolean_true_add(json_neigh,
13281 "adminShutDown");
13282
13283 /* BGP Version. */
13284 json_object_int_add(json_neigh, "bgpVersion", 4);
c949c771
DA
13285 json_object_string_addf(json_neigh, "remoteRouterId", "%pI4",
13286 &p->remote_id);
13287 json_object_string_addf(json_neigh, "localRouterId", "%pI4",
13288 &bgp->router_id);
d62a17ae 13289
13290 /* Confederation */
13291 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13292 && bgp_confederation_peers_check(bgp, p->as))
13293 json_object_boolean_true_add(json_neigh,
13294 "nbrCommonAdmin");
13295
13296 /* Status. */
13297 json_object_string_add(
13298 json_neigh, "bgpState",
13299 lookup_msg(bgp_status_msg, p->status, NULL));
13300
feb17238 13301 if (peer_established(p)) {
d62a17ae 13302 time_t uptime;
d62a17ae 13303
083ec940 13304 uptime = monotime(NULL);
d62a17ae 13305 uptime -= p->uptime;
d62a17ae 13306 epoch_tbuf = time(NULL) - uptime;
13307
d3c7efed
DS
13308 json_object_int_add(json_neigh, "bgpTimerUpMsec",
13309 uptime * 1000);
d62a17ae 13310 json_object_string_add(json_neigh, "bgpTimerUpString",
13311 peer_uptime(p->uptime, timebuf,
13312 BGP_UPTIME_LEN, 0,
13313 NULL));
13314 json_object_int_add(json_neigh,
13315 "bgpTimerUpEstablishedEpoch",
13316 epoch_tbuf);
13317 }
13318
13319 else if (p->status == Active) {
13320 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13321 json_object_string_add(json_neigh, "bgpStateIs",
13322 "passive");
13323 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13324 json_object_string_add(json_neigh, "bgpStateIs",
13325 "passiveNSF");
13326 }
13327
13328 /* read timer */
13329 time_t uptime;
a2700b50 13330 struct tm tm;
d62a17ae 13331
083ec940 13332 uptime = monotime(NULL);
d62a17ae 13333 uptime -= p->readtime;
a2700b50
MS
13334 gmtime_r(&uptime, &tm);
13335
d62a17ae 13336 json_object_int_add(json_neigh, "bgpTimerLastRead",
a2700b50
MS
13337 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13338 + (tm.tm_hour * 3600000));
d62a17ae 13339
083ec940 13340 uptime = monotime(NULL);
d62a17ae 13341 uptime -= p->last_write;
a2700b50
MS
13342 gmtime_r(&uptime, &tm);
13343
d62a17ae 13344 json_object_int_add(json_neigh, "bgpTimerLastWrite",
a2700b50
MS
13345 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13346 + (tm.tm_hour * 3600000));
d62a17ae 13347
083ec940 13348 uptime = monotime(NULL);
d62a17ae 13349 uptime -= p->update_time;
a2700b50
MS
13350 gmtime_r(&uptime, &tm);
13351
d62a17ae 13352 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
a2700b50
MS
13353 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13354 + (tm.tm_hour * 3600000));
d62a17ae 13355
13356 /* Configured timer values. */
9b1b9623
TA
13357 json_object_int_add(json_neigh,
13358 "bgpTimerConfiguredHoldTimeMsecs",
e93d5c29
TA
13359 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13360 ? p->holdtime * 1000
13361 : bgp->default_holdtime * 1000);
13362 json_object_int_add(json_neigh,
13363 "bgpTimerConfiguredKeepAliveIntervalMsecs",
13364 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13365 ? p->keepalive * 1000
13366 : bgp->default_keepalive * 1000);
d62a17ae 13367 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
13368 p->v_holdtime * 1000);
13369 json_object_int_add(json_neigh,
13370 "bgpTimerKeepAliveIntervalMsecs",
13371 p->v_keepalive * 1000);
d43114f3
DS
13372 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
13373 json_object_int_add(json_neigh,
13374 "bgpTimerDelayOpenTimeMsecs",
13375 p->v_delayopen * 1000);
13376 }
13377
4ab46701
AR
13378 /* Configured and Synced tcp-mss value for peer */
13379 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13380 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13381 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
13382 p->tcp_mss);
13383 json_object_int_add(json_neigh, "bgpTcpMssSynced",
13384 sync_tcp_mss);
13385 }
13386
d08c0c80
DA
13387 /* Extended Optional Parameters Length for BGP OPEN Message */
13388 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
13389 json_object_boolean_true_add(
13390 json_neigh, "extendedOptionalParametersLength");
13391 else
13392 json_object_boolean_false_add(
13393 json_neigh, "extendedOptionalParametersLength");
6e37924b
DA
13394
13395 /* Conditional advertisements */
13396 json_object_int_add(
13397 json_neigh,
13398 "bgpTimerConfiguredConditionalAdvertisementsSec",
13399 bgp->condition_check_period);
13400 if (thread_is_scheduled(bgp->t_condition_check))
13401 json_object_int_add(
13402 json_neigh,
13403 "bgpTimerUntilConditionalAdvertisementsSec",
13404 thread_timer_remain_second(
13405 bgp->t_condition_check));
d62a17ae 13406 } else {
13407 /* Administrative shutdown. */
cb9196e7
DS
13408 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13409 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 13410 vty_out(vty, " Administratively shut down\n");
13411
13412 /* BGP Version. */
13413 vty_out(vty, " BGP version 4");
07380148
DA
13414 vty_out(vty, ", remote router ID %pI4", &p->remote_id);
13415 vty_out(vty, ", local router ID %pI4\n", &bgp->router_id);
d62a17ae 13416
13417 /* Confederation */
13418 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13419 && bgp_confederation_peers_check(bgp, p->as))
13420 vty_out(vty,
13421 " Neighbor under common administration\n");
13422
13423 /* Status. */
13424 vty_out(vty, " BGP state = %s",
13425 lookup_msg(bgp_status_msg, p->status, NULL));
13426
feb17238 13427 if (peer_established(p))
d62a17ae 13428 vty_out(vty, ", up for %8s",
13429 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
13430 0, NULL));
13431
13432 else if (p->status == Active) {
13433 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13434 vty_out(vty, " (passive)");
13435 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13436 vty_out(vty, " (NSF passive)");
13437 }
13438 vty_out(vty, "\n");
13439
13440 /* read timer */
13441 vty_out(vty, " Last read %s",
13442 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
13443 NULL));
13444 vty_out(vty, ", Last write %s\n",
13445 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
13446 NULL));
13447
13448 /* Configured timer values. */
13449 vty_out(vty,
e93d5c29 13450 " Hold time is %d seconds, keepalive interval is %d seconds\n",
d62a17ae 13451 p->v_holdtime, p->v_keepalive);
e93d5c29
TA
13452 vty_out(vty, " Configured hold time is %d seconds",
13453 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13454 ? p->holdtime
13455 : bgp->default_holdtime);
9b1b9623 13456 vty_out(vty, ", keepalive interval is %d seconds\n",
e93d5c29
TA
13457 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13458 ? p->keepalive
13459 : bgp->default_keepalive);
d43114f3
DS
13460 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
13461 vty_out(vty,
13462 " Configured DelayOpenTime is %d seconds\n",
13463 p->delayopen);
4ab46701
AR
13464
13465 /* Configured and synced tcp-mss value for peer */
13466 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13467 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13468 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
13469 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
13470 }
d08c0c80
DA
13471
13472 /* Extended Optional Parameters Length for BGP OPEN Message */
13473 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
13474 vty_out(vty,
13475 " Extended Optional Parameters Length is enabled\n");
6e37924b
DA
13476
13477 /* Conditional advertisements */
13478 vty_out(vty,
13479 " Configured conditional advertisements interval is %d seconds\n",
13480 bgp->condition_check_period);
13481 if (thread_is_scheduled(bgp->t_condition_check))
13482 vty_out(vty,
13483 " Time until conditional advertisements begin is %lu seconds\n",
13484 thread_timer_remain_second(
13485 bgp->t_condition_check));
d62a17ae 13486 }
13487 /* Capability. */
10711563
DA
13488 if (peer_established(p) &&
13489 (p->cap || peer_afc_advertised(p) || peer_afc_received(p))) {
13490 if (use_json) {
13491 json_object *json_cap = NULL;
d62a17ae 13492
10711563 13493 json_cap = json_object_new_object();
d62a17ae 13494
10711563
DA
13495 /* AS4 */
13496 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13497 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13498 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV) &&
13499 CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
ef56aee4 13500 json_object_string_add(
10711563 13501 json_cap, "4byteAs",
ef56aee4 13502 "advertisedAndReceived");
10711563
DA
13503 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13504 json_object_string_add(json_cap,
13505 "4byteAs",
13506 "advertised");
13507 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13508 json_object_string_add(json_cap,
13509 "4byteAs",
13510 "received");
13511 }
ef56aee4 13512
10711563
DA
13513 /* Extended Message Support */
13514 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV) &&
13515 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV))
13516 json_object_string_add(json_cap,
13517 "extendedMessage",
13518 "advertisedAndReceived");
13519 else if (CHECK_FLAG(p->cap,
13520 PEER_CAP_EXTENDED_MESSAGE_ADV))
13521 json_object_string_add(json_cap,
13522 "extendedMessage",
13523 "advertised");
13524 else if (CHECK_FLAG(p->cap,
13525 PEER_CAP_EXTENDED_MESSAGE_RCV))
13526 json_object_string_add(json_cap,
13527 "extendedMessage",
13528 "received");
ef56aee4 13529
10711563
DA
13530 /* AddPath */
13531 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13532 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13533 json_object *json_add = NULL;
13534 const char *print_store;
d62a17ae 13535
10711563 13536 json_add = json_object_new_object();
d62a17ae 13537
10711563
DA
13538 FOREACH_AFI_SAFI (afi, safi) {
13539 json_object *json_sub = NULL;
13540 json_sub = json_object_new_object();
13541 print_store = get_afi_safi_str(
13542 afi, safi, true);
d62a17ae 13543
10711563
DA
13544 if (CHECK_FLAG(
13545 p->af_cap[afi][safi],
13546 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13547 CHECK_FLAG(
13548 p->af_cap[afi][safi],
13549 PEER_CAP_ADDPATH_AF_TX_RCV)) {
05c7a1cc
QY
13550 if (CHECK_FLAG(
13551 p->af_cap[afi]
13552 [safi],
10711563
DA
13553 PEER_CAP_ADDPATH_AF_TX_ADV) &&
13554 CHECK_FLAG(
05c7a1cc
QY
13555 p->af_cap[afi]
13556 [safi],
10711563
DA
13557 PEER_CAP_ADDPATH_AF_TX_RCV))
13558 json_object_boolean_true_add(
13559 json_sub,
13560 "txAdvertisedAndReceived");
13561 else if (
13562 CHECK_FLAG(
13563 p->af_cap[afi]
13564 [safi],
13565 PEER_CAP_ADDPATH_AF_TX_ADV))
13566 json_object_boolean_true_add(
13567 json_sub,
13568 "txAdvertised");
13569 else if (
13570 CHECK_FLAG(
13571 p->af_cap[afi]
13572 [safi],
13573 PEER_CAP_ADDPATH_AF_TX_RCV))
13574 json_object_boolean_true_add(
13575 json_sub,
13576 "txReceived");
13577 }
d62a17ae 13578
10711563
DA
13579 if (CHECK_FLAG(
13580 p->af_cap[afi][safi],
13581 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13582 CHECK_FLAG(
13583 p->af_cap[afi][safi],
13584 PEER_CAP_ADDPATH_AF_RX_RCV)) {
05c7a1cc
QY
13585 if (CHECK_FLAG(
13586 p->af_cap[afi]
13587 [safi],
10711563
DA
13588 PEER_CAP_ADDPATH_AF_RX_ADV) &&
13589 CHECK_FLAG(
13590 p->af_cap[afi]
13591 [safi],
13592 PEER_CAP_ADDPATH_AF_RX_RCV))
13593 json_object_boolean_true_add(
13594 json_sub,
13595 "rxAdvertisedAndReceived");
13596 else if (
13597 CHECK_FLAG(
13598 p->af_cap[afi]
13599 [safi],
13600 PEER_CAP_ADDPATH_AF_RX_ADV))
13601 json_object_boolean_true_add(
13602 json_sub,
13603 "rxAdvertised");
13604 else if (
13605 CHECK_FLAG(
13606 p->af_cap[afi]
13607 [safi],
13608 PEER_CAP_ADDPATH_AF_RX_RCV))
13609 json_object_boolean_true_add(
13610 json_sub,
13611 "rxReceived");
05c7a1cc
QY
13612 }
13613
10711563
DA
13614 if (CHECK_FLAG(
13615 p->af_cap[afi][safi],
13616 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13617 CHECK_FLAG(
13618 p->af_cap[afi][safi],
13619 PEER_CAP_ADDPATH_AF_TX_RCV) ||
13620 CHECK_FLAG(
13621 p->af_cap[afi][safi],
13622 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13623 CHECK_FLAG(
13624 p->af_cap[afi][safi],
13625 PEER_CAP_ADDPATH_AF_RX_RCV))
13626 json_object_object_add(
13627 json_add, print_store,
13628 json_sub);
13629 else
13630 json_object_free(json_sub);
d62a17ae 13631 }
13632
10711563
DA
13633 json_object_object_add(json_cap, "addPath",
13634 json_add);
13635 }
d62a17ae 13636
10711563
DA
13637 /* Dynamic */
13638 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13639 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13640 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV) &&
13641 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13642 json_object_string_add(
13643 json_cap, "dynamic",
13644 "advertisedAndReceived");
13645 else if (CHECK_FLAG(p->cap,
13646 PEER_CAP_DYNAMIC_ADV))
13647 json_object_string_add(json_cap,
13648 "dynamic",
13649 "advertised");
13650 else if (CHECK_FLAG(p->cap,
13651 PEER_CAP_DYNAMIC_RCV))
13652 json_object_string_add(json_cap,
13653 "dynamic",
13654 "received");
13655 }
d62a17ae 13656
d864dd9e
EB
13657 /* Role */
13658 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13659 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13660 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV) &&
13661 CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13662 json_object_string_add(
13663 json_cap, "role",
13664 "advertisedAndReceived");
13665 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13666 json_object_string_add(json_cap, "role",
13667 "advertised");
13668 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13669 json_object_string_add(json_cap, "role",
13670 "received");
13671 }
13672
10711563
DA
13673 /* Extended nexthop */
13674 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13675 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13676 json_object *json_nxt = NULL;
13677 const char *print_store;
d62a17ae 13678
d62a17ae 13679
10711563
DA
13680 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV) &&
13681 CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13682 json_object_string_add(
13683 json_cap, "extendedNexthop",
13684 "advertisedAndReceived");
13685 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13686 json_object_string_add(
13687 json_cap, "extendedNexthop",
13688 "advertised");
13689 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13690 json_object_string_add(
13691 json_cap, "extendedNexthop",
13692 "received");
d62a17ae 13693
10711563
DA
13694 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13695 json_nxt = json_object_new_object();
d62a17ae 13696
10711563
DA
13697 for (safi = SAFI_UNICAST;
13698 safi < SAFI_MAX; safi++) {
13699 if (CHECK_FLAG(
13700 p->af_cap[AFI_IP]
13701 [safi],
13702 PEER_CAP_ENHE_AF_RCV)) {
13703 print_store =
13704 get_afi_safi_str(
d62a17ae 13705 AFI_IP,
10711563
DA
13706 safi,
13707 true);
13708 json_object_string_add(
13709 json_nxt,
13710 print_store,
13711 "recieved"); /* misspelled for compatibility */
d62a17ae 13712 }
d62a17ae 13713 }
10711563
DA
13714 json_object_object_add(
13715 json_cap,
13716 "extendedNexthopFamililesByPeer",
13717 json_nxt);
d62a17ae 13718 }
10711563 13719 }
d62a17ae 13720
10711563
DA
13721 /* Long-lived Graceful Restart */
13722 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13723 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13724 json_object *json_llgr = NULL;
13725 const char *afi_safi_str;
8606be87 13726
10711563
DA
13727 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV) &&
13728 CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13729 json_object_string_add(
13730 json_cap,
13731 "longLivedGracefulRestart",
13732 "advertisedAndReceived");
13733 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13734 json_object_string_add(
13735 json_cap,
13736 "longLivedGracefulRestart",
13737 "advertised");
13738 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13739 json_object_string_add(
13740 json_cap,
13741 "longLivedGracefulRestart",
13742 "received");
8606be87 13743
10711563
DA
13744 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13745 json_llgr = json_object_new_object();
8606be87 13746
10711563
DA
13747 FOREACH_AFI_SAFI (afi, safi) {
13748 if (CHECK_FLAG(
13749 p->af_cap[afi]
13750 [safi],
13751 PEER_CAP_ENHE_AF_RCV)) {
13752 afi_safi_str =
13753 get_afi_safi_str(
8606be87
DA
13754 afi,
13755 safi,
13756 true);
10711563
DA
13757 json_object_string_add(
13758 json_llgr,
13759 afi_safi_str,
13760 "received");
8606be87 13761 }
8606be87 13762 }
10711563
DA
13763 json_object_object_add(
13764 json_cap,
13765 "longLivedGracefulRestartByPeer",
13766 json_llgr);
8606be87 13767 }
10711563 13768 }
8606be87 13769
10711563
DA
13770 /* Route Refresh */
13771 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13772 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13773 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13774 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) &&
13775 (CHECK_FLAG(p->cap,
13776 PEER_CAP_REFRESH_NEW_RCV) ||
13777 CHECK_FLAG(p->cap,
13778 PEER_CAP_REFRESH_OLD_RCV))) {
13779 if (CHECK_FLAG(
13780 p->cap,
13781 PEER_CAP_REFRESH_OLD_RCV) &&
13782 CHECK_FLAG(
13783 p->cap,
13784 PEER_CAP_REFRESH_NEW_RCV))
13785 json_object_string_add(
13786 json_cap,
13787 "routeRefresh",
13788 "advertisedAndReceivedOldNew");
13789 else {
d62a17ae 13790 if (CHECK_FLAG(
13791 p->cap,
10711563 13792 PEER_CAP_REFRESH_OLD_RCV))
d62a17ae 13793 json_object_string_add(
13794 json_cap,
13795 "routeRefresh",
10711563
DA
13796 "advertisedAndReceivedOld");
13797 else
13798 json_object_string_add(
13799 json_cap,
13800 "routeRefresh",
13801 "advertisedAndReceivedNew");
d62a17ae 13802 }
10711563
DA
13803 } else if (CHECK_FLAG(p->cap,
13804 PEER_CAP_REFRESH_ADV))
13805 json_object_string_add(json_cap,
13806 "routeRefresh",
13807 "advertised");
13808 else if (CHECK_FLAG(p->cap,
13809 PEER_CAP_REFRESH_NEW_RCV) ||
13810 CHECK_FLAG(p->cap,
13811 PEER_CAP_REFRESH_OLD_RCV))
13812 json_object_string_add(json_cap,
13813 "routeRefresh",
13814 "received");
13815 }
d62a17ae 13816
10711563
DA
13817 /* Enhanced Route Refresh */
13818 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13819 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13820 if (CHECK_FLAG(p->cap,
13821 PEER_CAP_ENHANCED_RR_ADV) &&
13822 CHECK_FLAG(p->cap,
13823 PEER_CAP_ENHANCED_RR_RCV))
d77114b7 13824 json_object_string_add(
10711563
DA
13825 json_cap,
13826 "enhancedRouteRefresh",
13827 "advertisedAndReceived");
13828 else if (CHECK_FLAG(p->cap,
13829 PEER_CAP_ENHANCED_RR_ADV))
d77114b7 13830 json_object_string_add(
10711563
DA
13831 json_cap,
13832 "enhancedRouteRefresh",
13833 "advertised");
13834 else if (CHECK_FLAG(p->cap,
9af52ccf 13835 PEER_CAP_ENHANCED_RR_RCV))
10711563
DA
13836 json_object_string_add(
13837 json_cap,
13838 "enhancedRouteRefresh",
13839 "received");
13840 }
d77114b7 13841
10711563
DA
13842 /* Multiprotocol Extensions */
13843 json_object *json_multi = NULL;
d77114b7 13844
10711563 13845 json_multi = json_object_new_object();
d77114b7 13846
10711563
DA
13847 FOREACH_AFI_SAFI (afi, safi) {
13848 if (p->afc_adv[afi][safi] ||
13849 p->afc_recv[afi][safi]) {
13850 json_object *json_exten = NULL;
13851 json_exten = json_object_new_object();
13852
13853 if (p->afc_adv[afi][safi] &&
13854 p->afc_recv[afi][safi])
13855 json_object_boolean_true_add(
13856 json_exten,
9af52ccf 13857 "advertisedAndReceived");
10711563
DA
13858 else if (p->afc_adv[afi][safi])
13859 json_object_boolean_true_add(
13860 json_exten,
9af52ccf 13861 "advertised");
10711563
DA
13862 else if (p->afc_recv[afi][safi])
13863 json_object_boolean_true_add(
13864 json_exten, "received");
9af52ccf 13865
10711563
DA
13866 json_object_object_add(
13867 json_multi,
13868 get_afi_safi_str(afi, safi,
13869 true),
13870 json_exten);
13871 }
13872 }
13873 json_object_object_add(json_cap,
13874 "multiprotocolExtensions",
13875 json_multi);
d62a17ae 13876
10711563
DA
13877 /* Hostname capabilities */
13878 json_object *json_hname = NULL;
d62a17ae 13879
10711563 13880 json_hname = json_object_new_object();
d62a17ae 13881
10711563
DA
13882 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13883 json_object_string_add(
13884 json_hname, "advHostName",
13885 bgp->peer_self->hostname
13886 ? bgp->peer_self->hostname
13887 : "n/a");
13888 json_object_string_add(
13889 json_hname, "advDomainName",
13890 bgp->peer_self->domainname
13891 ? bgp->peer_self->domainname
13892 : "n/a");
13893 }
d77114b7 13894
d77114b7 13895
10711563
DA
13896 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13897 json_object_string_add(
13898 json_hname, "rcvHostName",
13899 p->hostname ? p->hostname : "n/a");
13900 json_object_string_add(
13901 json_hname, "rcvDomainName",
13902 p->domainname ? p->domainname : "n/a");
13903 }
d77114b7 13904
10711563
DA
13905 json_object_object_add(json_cap, "hostName",
13906 json_hname);
d77114b7 13907
17be83bf 13908 /* Graceful Restart */
10711563
DA
13909 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13910 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13911 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) &&
13912 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
d77114b7 13913 json_object_string_add(
10711563
DA
13914 json_cap, "gracefulRestart",
13915 "advertisedAndReceived");
13916 else if (CHECK_FLAG(p->cap,
13917 PEER_CAP_RESTART_ADV))
d77114b7 13918 json_object_string_add(
10711563
DA
13919 json_cap,
13920 "gracefulRestartCapability",
13921 "advertised");
13922 else if (CHECK_FLAG(p->cap,
13923 PEER_CAP_RESTART_RCV))
13924 json_object_string_add(
13925 json_cap,
13926 "gracefulRestartCapability",
13927 "received");
d77114b7 13928
10711563
DA
13929 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13930 int restart_af_count = 0;
13931 json_object *json_restart = NULL;
13932 json_restart = json_object_new_object();
d62a17ae 13933
10711563
DA
13934 json_object_int_add(
13935 json_cap,
13936 "gracefulRestartRemoteTimerMsecs",
13937 p->v_gr_restart * 1000);
d62a17ae 13938
10711563 13939 FOREACH_AFI_SAFI (afi, safi) {
05c7a1cc
QY
13940 if (CHECK_FLAG(
13941 p->af_cap[afi]
13942 [safi],
10711563
DA
13943 PEER_CAP_RESTART_AF_RCV)) {
13944 json_object *json_sub =
13945 NULL;
13946 json_sub =
13947 json_object_new_object();
d62a17ae 13948
05c7a1cc
QY
13949 if (CHECK_FLAG(
13950 p->af_cap
13951 [afi]
13952 [safi],
10711563
DA
13953 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13954 json_object_boolean_true_add(
13955 json_sub,
13956 "preserved");
13957 restart_af_count++;
d62a17ae 13958 json_object_object_add(
10711563
DA
13959 json_restart,
13960 get_afi_safi_str(
13961 afi,
13962 safi,
13963 true),
13964 json_sub);
d62a17ae 13965 }
d62a17ae 13966 }
10711563
DA
13967 if (!restart_af_count) {
13968 json_object_string_add(
13969 json_cap,
13970 "addressFamiliesByPeer",
13971 "none");
13972 json_object_free(json_restart);
13973 } else
13974 json_object_object_add(
13975 json_cap,
13976 "addressFamiliesByPeer",
13977 json_restart);
d62a17ae 13978 }
10711563
DA
13979 }
13980 json_object_object_add(
13981 json_neigh, "neighborCapabilities", json_cap);
13982 } else {
13983 vty_out(vty, " Neighbor capabilities:\n");
13984
13985 /* AS4 */
13986 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13987 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13988 vty_out(vty, " 4 Byte AS:");
13989 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13990 vty_out(vty, " advertised");
13991 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13992 vty_out(vty, " %sreceived",
13993 CHECK_FLAG(p->cap,
13994 PEER_CAP_AS4_ADV)
13995 ? "and "
13996 : "");
13997 vty_out(vty, "\n");
13998 }
d62a17ae 13999
10711563
DA
14000 /* Extended Message Support */
14001 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV) ||
14002 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV)) {
14003 vty_out(vty, " Extended Message:");
ef56aee4 14004 if (CHECK_FLAG(p->cap,
10711563
DA
14005 PEER_CAP_EXTENDED_MESSAGE_ADV))
14006 vty_out(vty, " advertised");
14007 if (CHECK_FLAG(p->cap,
14008 PEER_CAP_EXTENDED_MESSAGE_RCV))
14009 vty_out(vty, " %sreceived",
14010 CHECK_FLAG(
14011 p->cap,
14012 PEER_CAP_EXTENDED_MESSAGE_ADV)
14013 ? "and "
14014 : "");
14015 vty_out(vty, "\n");
14016 }
d62a17ae 14017
10711563
DA
14018 /* AddPath */
14019 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
14020 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
14021 vty_out(vty, " AddPath:\n");
d62a17ae 14022
10711563 14023 FOREACH_AFI_SAFI (afi, safi) {
ef56aee4 14024 if (CHECK_FLAG(
10711563
DA
14025 p->af_cap[afi][safi],
14026 PEER_CAP_ADDPATH_AF_TX_ADV) ||
14027 CHECK_FLAG(
14028 p->af_cap[afi][safi],
14029 PEER_CAP_ADDPATH_AF_TX_RCV)) {
14030 vty_out(vty, " %s: TX ",
14031 get_afi_safi_str(
14032 afi, safi,
14033 false));
ef56aee4 14034
10711563
DA
14035 if (CHECK_FLAG(
14036 p->af_cap[afi]
14037 [safi],
14038 PEER_CAP_ADDPATH_AF_TX_ADV))
14039 vty_out(vty,
14040 "advertised");
d62a17ae 14041
05c7a1cc
QY
14042 if (CHECK_FLAG(
14043 p->af_cap[afi]
14044 [safi],
10711563 14045 PEER_CAP_ADDPATH_AF_TX_RCV))
05c7a1cc 14046 vty_out(vty,
10711563
DA
14047 "%sreceived",
14048 CHECK_FLAG(
14049 p->af_cap
14050 [afi]
14051 [safi],
14052 PEER_CAP_ADDPATH_AF_TX_ADV)
14053 ? " and "
14054 : "");
05c7a1cc 14055
10711563
DA
14056 vty_out(vty, "\n");
14057 }
d62a17ae 14058
9af52ccf 14059 if (CHECK_FLAG(
10711563
DA
14060 p->af_cap[afi][safi],
14061 PEER_CAP_ADDPATH_AF_RX_ADV) ||
14062 CHECK_FLAG(
14063 p->af_cap[afi][safi],
14064 PEER_CAP_ADDPATH_AF_RX_RCV)) {
14065 vty_out(vty, " %s: RX ",
5cb5f4d0 14066 get_afi_safi_str(
10711563
DA
14067 afi, safi,
14068 false));
d62a17ae 14069
05c7a1cc
QY
14070 if (CHECK_FLAG(
14071 p->af_cap[afi]
14072 [safi],
10711563 14073 PEER_CAP_ADDPATH_AF_RX_ADV))
05c7a1cc 14074 vty_out(vty,
10711563 14075 "advertised");
d62a17ae 14076
10711563
DA
14077 if (CHECK_FLAG(
14078 p->af_cap[afi]
14079 [safi],
14080 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc 14081 vty_out(vty,
10711563
DA
14082 "%sreceived",
14083 CHECK_FLAG(
14084 p->af_cap
14085 [afi]
14086 [safi],
14087 PEER_CAP_ADDPATH_AF_RX_ADV)
14088 ? " and "
05c7a1cc 14089 : "");
d62a17ae 14090
05c7a1cc 14091 vty_out(vty, "\n");
05c7a1cc 14092 }
d62a17ae 14093 }
10711563 14094 }
d62a17ae 14095
10711563
DA
14096 /* Dynamic */
14097 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
14098 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
14099 vty_out(vty, " Dynamic:");
14100 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV))
14101 vty_out(vty, " advertised");
14102 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
14103 vty_out(vty, " %sreceived",
14104 CHECK_FLAG(p->cap,
14105 PEER_CAP_DYNAMIC_ADV)
14106 ? "and "
14107 : "");
14108 vty_out(vty, "\n");
14109 }
d62a17ae 14110
d864dd9e
EB
14111 /* Role */
14112 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
14113 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
14114 vty_out(vty, " Role:");
14115 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
14116 vty_out(vty, " advertised");
14117 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
14118 vty_out(vty, " %sreceived",
14119 CHECK_FLAG(p->cap,
14120 PEER_CAP_ROLE_ADV)
14121 ? "and "
14122 : "");
14123 vty_out(vty, "\n");
14124 }
14125
10711563
DA
14126 /* Extended nexthop */
14127 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
14128 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
14129 vty_out(vty, " Extended nexthop:");
14130 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
14131 vty_out(vty, " advertised");
14132 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
14133 vty_out(vty, " %sreceived",
14134 CHECK_FLAG(p->cap,
14135 PEER_CAP_ENHE_ADV)
14136 ? "and "
14137 : "");
14138 vty_out(vty, "\n");
d62a17ae 14139
10711563 14140 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
57f7feb6 14141 vty_out(vty,
10711563
DA
14142 " Address families by peer:\n ");
14143 for (safi = SAFI_UNICAST;
14144 safi < SAFI_MAX; safi++)
14145 if (CHECK_FLAG(
14146 p->af_cap[AFI_IP]
14147 [safi],
14148 PEER_CAP_ENHE_AF_RCV))
14149 vty_out(vty,
14150 " %s\n",
14151 get_afi_safi_str(
14152 AFI_IP,
14153 safi,
14154 false));
d62a17ae 14155 }
10711563 14156 }
d62a17ae 14157
10711563
DA
14158 /* Long-lived Graceful Restart */
14159 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
14160 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
14161 vty_out(vty,
14162 " Long-lived Graceful Restart:");
14163 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
14164 vty_out(vty, " advertised");
14165 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
14166 vty_out(vty, " %sreceived",
14167 CHECK_FLAG(p->cap,
14168 PEER_CAP_LLGR_ADV)
14169 ? "and "
14170 : "");
14171 vty_out(vty, "\n");
8606be87 14172
10711563 14173 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
57f7feb6 14174 vty_out(vty,
10711563
DA
14175 " Address families by peer:\n");
14176 FOREACH_AFI_SAFI (afi, safi)
14177 if (CHECK_FLAG(
14178 p->af_cap[afi]
14179 [safi],
14180 PEER_CAP_LLGR_AF_RCV))
14181 vty_out(vty,
14182 " %s\n",
14183 get_afi_safi_str(
14184 afi,
14185 safi,
14186 false));
8606be87 14187 }
10711563 14188 }
8606be87 14189
10711563
DA
14190 /* Route Refresh */
14191 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
14192 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
14193 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
14194 vty_out(vty, " Route refresh:");
14195 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV))
14196 vty_out(vty, " advertised");
14197 if (CHECK_FLAG(p->cap,
14198 PEER_CAP_REFRESH_NEW_RCV) ||
14199 CHECK_FLAG(p->cap,
14200 PEER_CAP_REFRESH_OLD_RCV))
14201 vty_out(vty, " %sreceived(%s)",
14202 CHECK_FLAG(p->cap,
14203 PEER_CAP_REFRESH_ADV)
14204 ? "and "
14205 : "",
14206 (CHECK_FLAG(
14207 p->cap,
14208 PEER_CAP_REFRESH_OLD_RCV) &&
14209 CHECK_FLAG(
14210 p->cap,
14211 PEER_CAP_REFRESH_NEW_RCV))
14212 ? "old & new"
14213 : CHECK_FLAG(
14214 p->cap,
14215 PEER_CAP_REFRESH_OLD_RCV)
14216 ? "old"
14217 : "new");
d62a17ae 14218
d77114b7 14219 vty_out(vty, "\n");
10711563 14220 }
d62a17ae 14221
10711563
DA
14222 /* Enhanced Route Refresh */
14223 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
14224 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
14225 vty_out(vty, " Enhanced Route Refresh:");
14226 if (CHECK_FLAG(p->cap,
14227 PEER_CAP_ENHANCED_RR_ADV))
14228 vty_out(vty, " advertised");
14229 if (CHECK_FLAG(p->cap,
14230 PEER_CAP_ENHANCED_RR_RCV))
14231 vty_out(vty, " %sreceived",
14232 CHECK_FLAG(p->cap,
14233 PEER_CAP_REFRESH_ADV)
14234 ? "and "
14235 : "");
14236 vty_out(vty, "\n");
14237 }
14238
14239 /* Multiprotocol Extensions */
14240 FOREACH_AFI_SAFI (afi, safi)
14241 if (p->afc_adv[afi][safi] ||
14242 p->afc_recv[afi][safi]) {
14243 vty_out(vty, " Address Family %s:",
14244 get_afi_safi_str(afi, safi,
14245 false));
14246 if (p->afc_adv[afi][safi])
9af52ccf 14247 vty_out(vty, " advertised");
10711563 14248 if (p->afc_recv[afi][safi])
9af52ccf 14249 vty_out(vty, " %sreceived",
10711563 14250 p->afc_adv[afi][safi]
9af52ccf
DA
14251 ? "and "
14252 : "");
14253 vty_out(vty, "\n");
14254 }
14255
10711563
DA
14256 /* Hostname capability */
14257 vty_out(vty, " Hostname Capability:");
d62a17ae 14258
10711563
DA
14259 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
14260 vty_out(vty,
14261 " advertised (name: %s,domain name: %s)",
14262 bgp->peer_self->hostname
14263 ? bgp->peer_self->hostname
14264 : "n/a",
14265 bgp->peer_self->domainname
14266 ? bgp->peer_self->domainname
14267 : "n/a");
14268 } else {
14269 vty_out(vty, " not advertised");
14270 }
d77114b7 14271
10711563
DA
14272 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
14273 vty_out(vty,
14274 " received (name: %s,domain name: %s)",
14275 p->hostname ? p->hostname : "n/a",
14276 p->domainname ? p->domainname : "n/a");
14277 } else {
14278 vty_out(vty, " not received");
d62a17ae 14279 }
d62a17ae 14280
10711563 14281 vty_out(vty, "\n");
d77114b7 14282
10711563
DA
14283 /* Graceful Restart */
14284 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
14285 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
14286 vty_out(vty,
14287 " Graceful Restart Capability:");
14288 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV))
14289 vty_out(vty, " advertised");
14290 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
14291 vty_out(vty, " %sreceived",
14292 CHECK_FLAG(p->cap,
14293 PEER_CAP_RESTART_ADV)
14294 ? "and "
14295 : "");
d77114b7
MK
14296 vty_out(vty, "\n");
14297
10711563
DA
14298 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14299 int restart_af_count = 0;
d62a17ae 14300
10711563
DA
14301 vty_out(vty,
14302 " Remote Restart timer is %d seconds\n",
14303 p->v_gr_restart);
14304 vty_out(vty,
14305 " Address families by peer:\n ");
d62a17ae 14306
10711563
DA
14307 FOREACH_AFI_SAFI (afi, safi)
14308 if (CHECK_FLAG(
14309 p->af_cap[afi]
14310 [safi],
14311 PEER_CAP_RESTART_AF_RCV)) {
14312 vty_out(vty, "%s%s(%s)",
14313 restart_af_count
14314 ? ", "
14315 : "",
14316 get_afi_safi_str(
14317 afi,
14318 safi,
14319 false),
14320 CHECK_FLAG(
14321 p->af_cap
14322 [afi]
14323 [safi],
14324 PEER_CAP_RESTART_AF_PRESERVE_RCV)
14325 ? "preserved"
14326 : "not preserved");
14327 restart_af_count++;
14328 }
14329 if (!restart_af_count)
14330 vty_out(vty, "none");
14331 vty_out(vty, "\n");
14332 }
17be83bf 14333 } /* Graceful Restart */
d62a17ae 14334 }
14335 }
14336
14337 /* graceful restart information */
10711563
DA
14338 json_object *json_grace = NULL;
14339 json_object *json_grace_send = NULL;
14340 json_object *json_grace_recv = NULL;
14341 int eor_send_af_count = 0;
14342 int eor_receive_af_count = 0;
d62a17ae 14343
10711563
DA
14344 if (use_json) {
14345 json_grace = json_object_new_object();
14346 json_grace_send = json_object_new_object();
14347 json_grace_recv = json_object_new_object();
14348
14349 if ((peer_established(p)) &&
14350 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14351 FOREACH_AFI_SAFI (afi, safi) {
14352 if (CHECK_FLAG(p->af_sflags[afi][safi],
14353 PEER_STATUS_EOR_SEND)) {
14354 json_object_boolean_true_add(
14355 json_grace_send,
14356 get_afi_safi_str(afi, safi,
14357 true));
14358 eor_send_af_count++;
d62a17ae 14359 }
10711563
DA
14360 }
14361 FOREACH_AFI_SAFI (afi, safi) {
14362 if (CHECK_FLAG(p->af_sflags[afi][safi],
14363 PEER_STATUS_EOR_RECEIVED)) {
14364 json_object_boolean_true_add(
14365 json_grace_recv,
14366 get_afi_safi_str(afi, safi,
14367 true));
14368 eor_receive_af_count++;
d62a17ae 14369 }
14370 }
10711563
DA
14371 }
14372 json_object_object_add(json_grace, "endOfRibSend",
14373 json_grace_send);
14374 json_object_object_add(json_grace, "endOfRibRecv",
14375 json_grace_recv);
d62a17ae 14376
d62a17ae 14377
10711563
DA
14378 if (p->t_gr_restart)
14379 json_object_int_add(
14380 json_grace, "gracefulRestartTimerMsecs",
14381 thread_timer_remain_second(p->t_gr_restart) *
14382 1000);
2986cac2 14383
10711563
DA
14384 if (p->t_gr_stale)
14385 json_object_int_add(
14386 json_grace, "gracefulStalepathTimerMsecs",
14387 thread_timer_remain_second(p->t_gr_stale) *
14388 1000);
14389 /* more gr info in new format */
403e64f8 14390 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, json_grace);
10711563
DA
14391 json_object_object_add(json_neigh, "gracefulRestartInfo",
14392 json_grace);
14393 } else {
14394 vty_out(vty, " Graceful restart information:\n");
14395 if ((peer_established(p)) &&
14396 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14397
14398 vty_out(vty, " End-of-RIB send: ");
14399 FOREACH_AFI_SAFI (afi, safi) {
14400 if (CHECK_FLAG(p->af_sflags[afi][safi],
14401 PEER_STATUS_EOR_SEND)) {
14402 vty_out(vty, "%s%s",
14403 eor_send_af_count ? ", " : "",
14404 get_afi_safi_str(afi, safi,
14405 false));
14406 eor_send_af_count++;
d62a17ae 14407 }
10711563
DA
14408 }
14409 vty_out(vty, "\n");
14410 vty_out(vty, " End-of-RIB received: ");
14411 FOREACH_AFI_SAFI (afi, safi) {
14412 if (CHECK_FLAG(p->af_sflags[afi][safi],
14413 PEER_STATUS_EOR_RECEIVED)) {
14414 vty_out(vty, "%s%s",
14415 eor_receive_af_count ? ", "
14416 : "",
14417 get_afi_safi_str(afi, safi,
14418 false));
14419 eor_receive_af_count++;
d62a17ae 14420 }
d62a17ae 14421 }
10711563
DA
14422 vty_out(vty, "\n");
14423 }
d62a17ae 14424
10711563
DA
14425 if (p->t_gr_restart)
14426 vty_out(vty,
14427 " The remaining time of restart timer is %ld\n",
14428 thread_timer_remain_second(p->t_gr_restart));
d62a17ae 14429
10711563
DA
14430 if (p->t_gr_stale)
14431 vty_out(vty,
14432 " The remaining time of stalepath timer is %ld\n",
14433 thread_timer_remain_second(p->t_gr_stale));
2986cac2 14434
10711563 14435 /* more gr info in new format */
403e64f8 14436 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, NULL);
10711563 14437 }
2986cac2 14438
d62a17ae 14439 if (use_json) {
14440 json_object *json_stat = NULL;
14441 json_stat = json_object_new_object();
14442 /* Packet counts. */
43aa5965
QY
14443
14444 atomic_size_t outq_count, inq_count;
14445 outq_count = atomic_load_explicit(&p->obuf->count,
14446 memory_order_relaxed);
14447 inq_count = atomic_load_explicit(&p->ibuf->count,
14448 memory_order_relaxed);
14449
14450 json_object_int_add(json_stat, "depthInq",
14451 (unsigned long)inq_count);
d62a17ae 14452 json_object_int_add(json_stat, "depthOutq",
43aa5965 14453 (unsigned long)outq_count);
0112e9e0
QY
14454 json_object_int_add(json_stat, "opensSent",
14455 atomic_load_explicit(&p->open_out,
14456 memory_order_relaxed));
14457 json_object_int_add(json_stat, "opensRecv",
14458 atomic_load_explicit(&p->open_in,
14459 memory_order_relaxed));
d62a17ae 14460 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
14461 atomic_load_explicit(&p->notify_out,
14462 memory_order_relaxed));
d62a17ae 14463 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
14464 atomic_load_explicit(&p->notify_in,
14465 memory_order_relaxed));
14466 json_object_int_add(json_stat, "updatesSent",
14467 atomic_load_explicit(&p->update_out,
14468 memory_order_relaxed));
14469 json_object_int_add(json_stat, "updatesRecv",
14470 atomic_load_explicit(&p->update_in,
14471 memory_order_relaxed));
d62a17ae 14472 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
14473 atomic_load_explicit(&p->keepalive_out,
14474 memory_order_relaxed));
d62a17ae 14475 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
14476 atomic_load_explicit(&p->keepalive_in,
14477 memory_order_relaxed));
d62a17ae 14478 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
14479 atomic_load_explicit(&p->refresh_out,
14480 memory_order_relaxed));
d62a17ae 14481 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
14482 atomic_load_explicit(&p->refresh_in,
14483 memory_order_relaxed));
d62a17ae 14484 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
14485 atomic_load_explicit(&p->dynamic_cap_out,
14486 memory_order_relaxed));
d62a17ae 14487 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
14488 atomic_load_explicit(&p->dynamic_cap_in,
14489 memory_order_relaxed));
14490 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
14491 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 14492 json_object_object_add(json_neigh, "messageStats", json_stat);
14493 } else {
cb93e0a2
IS
14494 atomic_size_t outq_count, inq_count, open_out, open_in,
14495 notify_out, notify_in, update_out, update_in,
14496 keepalive_out, keepalive_in, refresh_out, refresh_in,
14497 dynamic_cap_out, dynamic_cap_in;
43aa5965
QY
14498 outq_count = atomic_load_explicit(&p->obuf->count,
14499 memory_order_relaxed);
14500 inq_count = atomic_load_explicit(&p->ibuf->count,
14501 memory_order_relaxed);
cb93e0a2
IS
14502 open_out = atomic_load_explicit(&p->open_out,
14503 memory_order_relaxed);
14504 open_in =
14505 atomic_load_explicit(&p->open_in, memory_order_relaxed);
14506 notify_out = atomic_load_explicit(&p->notify_out,
14507 memory_order_relaxed);
14508 notify_in = atomic_load_explicit(&p->notify_in,
14509 memory_order_relaxed);
14510 update_out = atomic_load_explicit(&p->update_out,
14511 memory_order_relaxed);
14512 update_in = atomic_load_explicit(&p->update_in,
14513 memory_order_relaxed);
14514 keepalive_out = atomic_load_explicit(&p->keepalive_out,
14515 memory_order_relaxed);
14516 keepalive_in = atomic_load_explicit(&p->keepalive_in,
14517 memory_order_relaxed);
14518 refresh_out = atomic_load_explicit(&p->refresh_out,
14519 memory_order_relaxed);
14520 refresh_in = atomic_load_explicit(&p->refresh_in,
14521 memory_order_relaxed);
14522 dynamic_cap_out = atomic_load_explicit(&p->dynamic_cap_out,
14523 memory_order_relaxed);
14524 dynamic_cap_in = atomic_load_explicit(&p->dynamic_cap_in,
14525 memory_order_relaxed);
43aa5965 14526
d62a17ae 14527 /* Packet counts. */
14528 vty_out(vty, " Message statistics:\n");
43aa5965
QY
14529 vty_out(vty, " Inq depth is %zu\n", inq_count);
14530 vty_out(vty, " Outq depth is %zu\n", outq_count);
d62a17ae 14531 vty_out(vty, " Sent Rcvd\n");
cb93e0a2
IS
14532 vty_out(vty, " Opens: %10zu %10zu\n", open_out,
14533 open_in);
14534 vty_out(vty, " Notifications: %10zu %10zu\n", notify_out,
14535 notify_in);
14536 vty_out(vty, " Updates: %10zu %10zu\n", update_out,
14537 update_in);
14538 vty_out(vty, " Keepalives: %10zu %10zu\n", keepalive_out,
14539 keepalive_in);
14540 vty_out(vty, " Route Refresh: %10zu %10zu\n", refresh_out,
14541 refresh_in);
14542 vty_out(vty, " Capability: %10zu %10zu\n",
14543 dynamic_cap_out, dynamic_cap_in);
14544 vty_out(vty, " Total: %10u %10u\n",
14545 (uint32_t)PEER_TOTAL_TX(p), (uint32_t)PEER_TOTAL_RX(p));
d62a17ae 14546 }
14547
14548 if (use_json) {
14549 /* advertisement-interval */
14550 json_object_int_add(json_neigh,
14551 "minBtwnAdvertisementRunsTimerMsecs",
14552 p->v_routeadv * 1000);
14553
14554 /* Update-source. */
14555 if (p->update_if || p->update_source) {
14556 if (p->update_if)
14557 json_object_string_add(json_neigh,
14558 "updateSource",
14559 p->update_if);
14560 else if (p->update_source)
47e12884
DA
14561 json_object_string_addf(json_neigh,
14562 "updateSource", "%pSU",
14563 p->update_source);
d62a17ae 14564 }
14565 } else {
14566 /* advertisement-interval */
14567 vty_out(vty,
14568 " Minimum time between advertisement runs is %d seconds\n",
14569 p->v_routeadv);
14570
14571 /* Update-source. */
14572 if (p->update_if || p->update_source) {
14573 vty_out(vty, " Update source is ");
14574 if (p->update_if)
14575 vty_out(vty, "%s", p->update_if);
14576 else if (p->update_source)
47e12884 14577 vty_out(vty, "%pSU", p->update_source);
d62a17ae 14578 vty_out(vty, "\n");
14579 }
14580
14581 vty_out(vty, "\n");
14582 }
14583
14584 /* Address Family Information */
14585 json_object *json_hold = NULL;
14586
14587 if (use_json)
14588 json_hold = json_object_new_object();
14589
05c7a1cc
QY
14590 FOREACH_AFI_SAFI (afi, safi)
14591 if (p->afc[afi][safi])
14592 bgp_show_peer_afi(vty, p, afi, safi, use_json,
14593 json_hold);
d62a17ae 14594
14595 if (use_json) {
14596 json_object_object_add(json_neigh, "addressFamilyInfo",
14597 json_hold);
14598 json_object_int_add(json_neigh, "connectionsEstablished",
14599 p->established);
14600 json_object_int_add(json_neigh, "connectionsDropped",
14601 p->dropped);
14602 } else
14603 vty_out(vty, " Connections established %d; dropped %d\n",
14604 p->established, p->dropped);
14605
14606 if (!p->last_reset) {
14607 if (use_json)
14608 json_object_string_add(json_neigh, "lastReset",
14609 "never");
14610 else
14611 vty_out(vty, " Last reset never\n");
14612 } else {
14613 if (use_json) {
14614 time_t uptime;
a2700b50 14615 struct tm tm;
d62a17ae 14616
083ec940 14617 uptime = monotime(NULL);
d62a17ae 14618 uptime -= p->resettime;
a2700b50
MS
14619 gmtime_r(&uptime, &tm);
14620
d62a17ae 14621 json_object_int_add(json_neigh, "lastResetTimerMsecs",
a2700b50
MS
14622 (tm.tm_sec * 1000)
14623 + (tm.tm_min * 60000)
14624 + (tm.tm_hour * 3600000));
3577f1c5 14625 bgp_show_peer_reset(NULL, p, json_neigh, true);
d62a17ae 14626 } else {
14627 vty_out(vty, " Last reset %s, ",
14628 peer_uptime(p->resettime, timebuf,
14629 BGP_UPTIME_LEN, 0, NULL));
14630
3577f1c5 14631 bgp_show_peer_reset(vty, p, NULL, false);
d62a17ae 14632 if (p->last_reset_cause_size) {
14633 msg = p->last_reset_cause;
14634 vty_out(vty,
14635 " Message received that caused BGP to send a NOTIFICATION:\n ");
14636 for (i = 1; i <= p->last_reset_cause_size;
14637 i++) {
14638 vty_out(vty, "%02X", *msg++);
14639
14640 if (i != p->last_reset_cause_size) {
14641 if (i % 16 == 0) {
14642 vty_out(vty, "\n ");
14643 } else if (i % 4 == 0) {
14644 vty_out(vty, " ");
14645 }
14646 }
14647 }
14648 vty_out(vty, "\n");
14649 }
14650 }
14651 }
14652
14653 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
14654 if (use_json)
14655 json_object_boolean_true_add(json_neigh,
14656 "prefixesConfigExceedMax");
14657 else
14658 vty_out(vty,
14659 " Peer had exceeded the max. no. of prefixes configured.\n");
14660
14661 if (p->t_pmax_restart) {
14662 if (use_json) {
14663 json_object_boolean_true_add(
14664 json_neigh, "reducePrefixNumFrom");
14665 json_object_int_add(json_neigh,
14666 "restartInTimerMsec",
14667 thread_timer_remain_second(
14668 p->t_pmax_restart)
14669 * 1000);
14670 } else
14671 vty_out(vty,
14672 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
14673 p->host, thread_timer_remain_second(
14674 p->t_pmax_restart));
d62a17ae 14675 } else {
14676 if (use_json)
14677 json_object_boolean_true_add(
14678 json_neigh,
14679 "reducePrefixNumAndClearIpBgp");
14680 else
14681 vty_out(vty,
14682 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
14683 p->host);
14684 }
14685 }
14686
14687 /* EBGP Multihop and GTSM */
14688 if (p->sort != BGP_PEER_IBGP) {
14689 if (use_json) {
e2521429 14690 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14691 json_object_int_add(json_neigh,
14692 "externalBgpNbrMaxHopsAway",
14693 p->gtsm_hops);
be8d1733 14694 else
d62a17ae 14695 json_object_int_add(json_neigh,
14696 "externalBgpNbrMaxHopsAway",
14697 p->ttl);
14698 } else {
e2521429 14699 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14700 vty_out(vty,
14701 " External BGP neighbor may be up to %d hops away.\n",
14702 p->gtsm_hops);
be8d1733 14703 else
d62a17ae 14704 vty_out(vty,
14705 " External BGP neighbor may be up to %d hops away.\n",
14706 p->ttl);
14707 }
14708 } else {
be8d1733
DA
14709 if (use_json) {
14710 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14711 json_object_int_add(json_neigh,
14712 "internalBgpNbrMaxHopsAway",
14713 p->gtsm_hops);
14714 else
be8d1733
DA
14715 json_object_int_add(json_neigh,
14716 "internalBgpNbrMaxHopsAway",
14717 p->ttl);
14718 } else {
14719 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14720 vty_out(vty,
14721 " Internal BGP neighbor may be up to %d hops away.\n",
14722 p->gtsm_hops);
be8d1733
DA
14723 else
14724 vty_out(vty,
14725 " Internal BGP neighbor may be up to %d hops away.\n",
14726 p->ttl);
d62a17ae 14727 }
14728 }
14729
14730 /* Local address. */
14731 if (p->su_local) {
14732 if (use_json) {
47e12884
DA
14733 json_object_string_addf(json_neigh, "hostLocal", "%pSU",
14734 p->su_local);
d62a17ae 14735 json_object_int_add(json_neigh, "portLocal",
14736 ntohs(p->su_local->sin.sin_port));
14737 } else
47e12884
DA
14738 vty_out(vty, "Local host: %pSU, Local port: %d\n",
14739 p->su_local, ntohs(p->su_local->sin.sin_port));
1e592331
DS
14740 } else {
14741 if (use_json) {
14742 json_object_string_add(json_neigh, "hostLocal",
14743 "Unknown");
14744 json_object_int_add(json_neigh, "portLocal", -1);
14745 }
d62a17ae 14746 }
14747
14748 /* Remote address. */
14749 if (p->su_remote) {
14750 if (use_json) {
47e12884
DA
14751 json_object_string_addf(json_neigh, "hostForeign",
14752 "%pSU", p->su_remote);
d62a17ae 14753 json_object_int_add(json_neigh, "portForeign",
14754 ntohs(p->su_remote->sin.sin_port));
14755 } else
47e12884
DA
14756 vty_out(vty, "Foreign host: %pSU, Foreign port: %d\n",
14757 p->su_remote,
d62a17ae 14758 ntohs(p->su_remote->sin.sin_port));
1e592331
DS
14759 } else {
14760 if (use_json) {
14761 json_object_string_add(json_neigh, "hostForeign",
14762 "Unknown");
14763 json_object_int_add(json_neigh, "portForeign", -1);
14764 }
d62a17ae 14765 }
14766
14767 /* Nexthop display. */
14768 if (p->su_local) {
14769 if (use_json) {
c949c771
DA
14770 json_object_string_addf(json_neigh, "nexthop", "%pI4",
14771 &p->nexthop.v4);
14772 json_object_string_addf(json_neigh, "nexthopGlobal",
14773 "%pI6", &p->nexthop.v6_global);
14774 json_object_string_addf(json_neigh, "nexthopLocal",
14775 "%pI6", &p->nexthop.v6_local);
d62a17ae 14776 if (p->shared_network)
14777 json_object_string_add(json_neigh,
14778 "bgpConnection",
14779 "sharedNetwork");
14780 else
14781 json_object_string_add(json_neigh,
14782 "bgpConnection",
14783 "nonSharedNetwork");
14784 } else {
07380148
DA
14785 vty_out(vty, "Nexthop: %pI4\n", &p->nexthop.v4);
14786 vty_out(vty, "Nexthop global: %pI6\n",
14787 &p->nexthop.v6_global);
14788 vty_out(vty, "Nexthop local: %pI6\n",
14789 &p->nexthop.v6_local);
d62a17ae 14790 vty_out(vty, "BGP connection: %s\n",
14791 p->shared_network ? "shared network"
14792 : "non shared network");
14793 }
432e7e46
KQ
14794 } else {
14795 if (use_json) {
14796 json_object_string_add(json_neigh, "nexthop",
14797 "Unknown");
14798 json_object_string_add(json_neigh, "nexthopGlobal",
14799 "Unknown");
14800 json_object_string_add(json_neigh, "nexthopLocal",
14801 "Unknown");
14802 json_object_string_add(json_neigh, "bgpConnection",
14803 "Unknown");
14804 }
d62a17ae 14805 }
14806
14807 /* Timer information. */
14808 if (use_json) {
14809 json_object_int_add(json_neigh, "connectRetryTimer",
14810 p->v_connect);
f41255a0 14811 if (peer_established(p)) {
d62a17ae 14812 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14813 p->rtt);
f41255a0
DA
14814 if (CHECK_FLAG(p->flags, PEER_FLAG_RTT_SHUTDOWN)) {
14815 json_object_int_add(json_neigh,
14816 "shutdownRttInMsecs",
14817 p->rtt_expected);
14818 json_object_int_add(json_neigh,
14819 "shutdownRttAfterCount",
14820 p->rtt_keepalive_rcv);
14821 }
14822 }
d62a17ae 14823 if (p->t_start)
14824 json_object_int_add(
14825 json_neigh, "nextStartTimerDueInMsecs",
14826 thread_timer_remain_second(p->t_start) * 1000);
14827 if (p->t_connect)
14828 json_object_int_add(
14829 json_neigh, "nextConnectTimerDueInMsecs",
14830 thread_timer_remain_second(p->t_connect)
14831 * 1000);
14832 if (p->t_routeadv) {
14833 json_object_int_add(json_neigh, "mraiInterval",
14834 p->v_routeadv);
14835 json_object_int_add(
14836 json_neigh, "mraiTimerExpireInMsecs",
14837 thread_timer_remain_second(p->t_routeadv)
14838 * 1000);
14839 }
14840 if (p->password)
14841 json_object_int_add(json_neigh, "authenticationEnabled",
14842 1);
14843
14844 if (p->t_read)
14845 json_object_string_add(json_neigh, "readThread", "on");
14846 else
14847 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
14848
14849 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 14850 json_object_string_add(json_neigh, "writeThread", "on");
14851 else
14852 json_object_string_add(json_neigh, "writeThread",
14853 "off");
14854 } else {
14855 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14856 p->v_connect);
f41255a0 14857 if (peer_established(p)) {
d62a17ae 14858 vty_out(vty, "Estimated round trip time: %d ms\n",
14859 p->rtt);
f41255a0
DA
14860 if (CHECK_FLAG(p->flags, PEER_FLAG_RTT_SHUTDOWN))
14861 vty_out(vty,
14862 "Shutdown when RTT > %dms, count > %u\n",
14863 p->rtt_expected, p->rtt_keepalive_rcv);
14864 }
d62a17ae 14865 if (p->t_start)
14866 vty_out(vty, "Next start timer due in %ld seconds\n",
14867 thread_timer_remain_second(p->t_start));
14868 if (p->t_connect)
14869 vty_out(vty, "Next connect timer due in %ld seconds\n",
14870 thread_timer_remain_second(p->t_connect));
14871 if (p->t_routeadv)
14872 vty_out(vty,
14873 "MRAI (interval %u) timer expires in %ld seconds\n",
14874 p->v_routeadv,
14875 thread_timer_remain_second(p->t_routeadv));
14876 if (p->password)
14877 vty_out(vty, "Peer Authentication Enabled\n");
14878
cac9e917 14879 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
49507a6f
QY
14880 p->t_read ? "on" : "off",
14881 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14882 ? "on"
cac9e917 14883 : "off", p->fd);
d62a17ae 14884 }
14885
14886 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14887 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14888 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14889
14890 if (!use_json)
14891 vty_out(vty, "\n");
14892
14893 /* BFD information. */
21bfce98
RZ
14894 if (p->bfd_config)
14895 bgp_bfd_show_info(vty, p, json_neigh);
d62a17ae 14896
14897 if (use_json) {
14898 if (p->conf_if) /* Configured interface name. */
14899 json_object_object_add(json, p->conf_if, json_neigh);
14900 else /* Configured IP address. */
14901 json_object_object_add(json, p->host, json_neigh);
14902 }
14903}
14904
36235319
QY
14905static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14906 enum show_type type,
14907 union sockunion *su,
14908 const char *conf_if, afi_t afi,
403e64f8 14909 json_object *json)
2986cac2 14910{
14911 struct listnode *node, *nnode;
14912 struct peer *peer;
5a59e9b2 14913 bool found = false;
2986cac2 14914 safi_t safi = SAFI_UNICAST;
14915 json_object *json_neighbor = NULL;
14916
14917 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14918
14919 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14920 continue;
14921
14922 if ((peer->afc[afi][safi]) == 0)
14923 continue;
14924
403e64f8
DA
14925 if (json)
14926 json_neighbor = json_object_new_object();
14927
2ba1fe69 14928 if (type == show_all) {
403e64f8 14929 bgp_show_peer_gr_status(vty, peer, json_neighbor);
2986cac2 14930
403e64f8 14931 if (json)
13909c4f
DS
14932 json_object_object_add(json, peer->host,
14933 json_neighbor);
2986cac2 14934
2ba1fe69 14935 } else if (type == show_peer) {
2986cac2 14936 if (conf_if) {
14937 if ((peer->conf_if
13909c4f
DS
14938 && !strcmp(peer->conf_if, conf_if))
14939 || (peer->hostname
2986cac2 14940 && !strcmp(peer->hostname, conf_if))) {
5a59e9b2 14941 found = true;
13909c4f 14942 bgp_show_peer_gr_status(vty, peer,
13909c4f 14943 json_neighbor);
2986cac2 14944 }
14945 } else {
14946 if (sockunion_same(&peer->su, su)) {
5a59e9b2 14947 found = true;
13909c4f 14948 bgp_show_peer_gr_status(vty, peer,
13909c4f 14949 json_neighbor);
2986cac2 14950 }
14951 }
5a59e9b2
DS
14952 if (json) {
14953 if (found)
14954 json_object_object_add(json, peer->host,
14955 json_neighbor);
14956 else
14957 json_object_free(json_neighbor);
14958 }
2986cac2 14959 }
14960
5a59e9b2 14961 if (found)
2986cac2 14962 break;
14963 }
14964
5a59e9b2 14965 if (type == show_peer && !found) {
403e64f8 14966 if (json)
13909c4f 14967 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
2986cac2 14968 else
14969 vty_out(vty, "%% No such neighbor\n");
14970 }
403e64f8
DA
14971
14972 if (!json)
2986cac2 14973 vty_out(vty, "\n");
2986cac2 14974
14975 return CMD_SUCCESS;
14976}
14977
d62a17ae 14978static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14979 enum show_type type, union sockunion *su,
9f049418 14980 const char *conf_if, bool use_json,
d62a17ae 14981 json_object *json)
14982{
14983 struct listnode *node, *nnode;
14984 struct peer *peer;
14985 int find = 0;
9f049418 14986 bool nbr_output = false;
d1927ebe
AS
14987 afi_t afi = AFI_MAX;
14988 safi_t safi = SAFI_MAX;
14989
14990 if (type == show_ipv4_peer || type == show_ipv4_all) {
14991 afi = AFI_IP;
14992 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14993 afi = AFI_IP6;
14994 }
d62a17ae 14995
14996 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14997 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14998 continue;
14999
15000 switch (type) {
15001 case show_all:
15002 bgp_show_peer(vty, peer, use_json, json);
9f049418 15003 nbr_output = true;
d62a17ae 15004 break;
15005 case show_peer:
15006 if (conf_if) {
15007 if ((peer->conf_if
15008 && !strcmp(peer->conf_if, conf_if))
15009 || (peer->hostname
15010 && !strcmp(peer->hostname, conf_if))) {
15011 find = 1;
15012 bgp_show_peer(vty, peer, use_json,
15013 json);
15014 }
15015 } else {
15016 if (sockunion_same(&peer->su, su)) {
15017 find = 1;
15018 bgp_show_peer(vty, peer, use_json,
15019 json);
15020 }
15021 }
15022 break;
d1927ebe
AS
15023 case show_ipv4_peer:
15024 case show_ipv6_peer:
15025 FOREACH_SAFI (safi) {
15026 if (peer->afc[afi][safi]) {
15027 if (conf_if) {
15028 if ((peer->conf_if
15029 && !strcmp(peer->conf_if, conf_if))
15030 || (peer->hostname
15031 && !strcmp(peer->hostname, conf_if))) {
15032 find = 1;
15033 bgp_show_peer(vty, peer, use_json,
15034 json);
15035 break;
15036 }
15037 } else {
15038 if (sockunion_same(&peer->su, su)) {
15039 find = 1;
15040 bgp_show_peer(vty, peer, use_json,
15041 json);
15042 break;
15043 }
15044 }
15045 }
15046 }
15047 break;
15048 case show_ipv4_all:
15049 case show_ipv6_all:
15050 FOREACH_SAFI (safi) {
15051 if (peer->afc[afi][safi]) {
15052 bgp_show_peer(vty, peer, use_json, json);
15053 nbr_output = true;
15054 break;
15055 }
15056 }
15057 break;
d62a17ae 15058 }
15059 }
15060
d1927ebe
AS
15061 if ((type == show_peer || type == show_ipv4_peer ||
15062 type == show_ipv6_peer) && !find) {
d62a17ae 15063 if (use_json)
15064 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
15065 else
88b7d255 15066 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 15067 }
15068
d1927ebe
AS
15069 if (type != show_peer && type != show_ipv4_peer &&
15070 type != show_ipv6_peer && !nbr_output && !use_json)
94d4c685 15071 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 15072
d62a17ae 15073 if (use_json) {
996c9314
LB
15074 vty_out(vty, "%s\n", json_object_to_json_string_ext(
15075 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 15076 } else {
15077 vty_out(vty, "\n");
15078 }
15079
15080 return CMD_SUCCESS;
15081}
15082
36235319
QY
15083static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
15084 enum show_type type,
15085 const char *ip_str,
403e64f8 15086 afi_t afi, json_object *json)
2986cac2 15087{
15088
15089 int ret;
15090 struct bgp *bgp;
15091 union sockunion su;
2986cac2 15092
15093 bgp = bgp_get_default();
15094
13909c4f
DS
15095 if (!bgp)
15096 return;
2986cac2 15097
403e64f8
DA
15098 if (!json)
15099 bgp_show_global_graceful_restart_mode_vty(vty, bgp);
2986cac2 15100
13909c4f
DS
15101 if (ip_str) {
15102 ret = str2sockunion(ip_str, &su);
15103 if (ret < 0)
403e64f8
DA
15104 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL,
15105 ip_str, afi, json);
74a630b6
NT
15106 else
15107 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
403e64f8 15108 NULL, afi, json);
13909c4f
DS
15109 } else
15110 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
403e64f8 15111 afi, json);
2986cac2 15112}
15113
d62a17ae 15114static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
15115 enum show_type type,
15116 const char *ip_str,
9f049418 15117 bool use_json)
d62a17ae 15118{
0291c246
MK
15119 struct listnode *node, *nnode;
15120 struct bgp *bgp;
71aedaa3 15121 union sockunion su;
0291c246 15122 json_object *json = NULL;
71aedaa3 15123 int ret, is_first = 1;
9f049418 15124 bool nbr_output = false;
d62a17ae 15125
15126 if (use_json)
15127 vty_out(vty, "{\n");
15128
15129 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 15130 nbr_output = true;
d62a17ae 15131 if (use_json) {
15132 if (!(json = json_object_new_object())) {
af4c2728 15133 flog_err(
e50f7cfd 15134 EC_BGP_JSON_MEM_ERROR,
d62a17ae 15135 "Unable to allocate memory for JSON object");
15136 vty_out(vty,
15137 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
15138 return;
15139 }
15140
15141 json_object_int_add(json, "vrfId",
15142 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
15143 ? -1
15144 : (int64_t)bgp->vrf_id);
d62a17ae 15145 json_object_string_add(
15146 json, "vrfName",
15147 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 15148 ? VRF_DEFAULT_NAME
d62a17ae 15149 : bgp->name);
15150
15151 if (!is_first)
15152 vty_out(vty, ",\n");
15153 else
15154 is_first = 0;
15155
15156 vty_out(vty, "\"%s\":",
15157 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 15158 ? VRF_DEFAULT_NAME
d62a17ae 15159 : bgp->name);
15160 } else {
15161 vty_out(vty, "\nInstance %s:\n",
15162 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 15163 ? VRF_DEFAULT_NAME
d62a17ae 15164 : bgp->name);
15165 }
71aedaa3 15166
d1927ebe
AS
15167 if (type == show_peer || type == show_ipv4_peer ||
15168 type == show_ipv6_peer) {
71aedaa3
DS
15169 ret = str2sockunion(ip_str, &su);
15170 if (ret < 0)
15171 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
15172 use_json, json);
15173 else
15174 bgp_show_neighbor(vty, bgp, type, &su, NULL,
15175 use_json, json);
15176 } else {
d1927ebe 15177 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
71aedaa3
DS
15178 use_json, json);
15179 }
b77004d6 15180 json_object_free(json);
121067e9 15181 json = NULL;
d62a17ae 15182 }
15183
3e78a6ce 15184 if (use_json)
d62a17ae 15185 vty_out(vty, "}\n");
9f049418
DS
15186 else if (!nbr_output)
15187 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 15188}
15189
15190static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
15191 enum show_type type, const char *ip_str,
9f049418 15192 bool use_json)
d62a17ae 15193{
15194 int ret;
15195 struct bgp *bgp;
15196 union sockunion su;
15197 json_object *json = NULL;
15198
15199 if (name) {
15200 if (strmatch(name, "all")) {
71aedaa3
DS
15201 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
15202 use_json);
d62a17ae 15203 return CMD_SUCCESS;
15204 } else {
15205 bgp = bgp_lookup_by_name(name);
15206 if (!bgp) {
15207 if (use_json) {
15208 json = json_object_new_object();
75eeda93 15209 vty_json(vty, json);
d62a17ae 15210 } else
15211 vty_out(vty,
9f049418 15212 "%% BGP instance not found\n");
d62a17ae 15213
15214 return CMD_WARNING;
15215 }
15216 }
15217 } else {
15218 bgp = bgp_get_default();
15219 }
15220
15221 if (bgp) {
15222 json = json_object_new_object();
15223 if (ip_str) {
15224 ret = str2sockunion(ip_str, &su);
15225 if (ret < 0)
15226 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
15227 use_json, json);
15228 else
15229 bgp_show_neighbor(vty, bgp, type, &su, NULL,
15230 use_json, json);
15231 } else {
15232 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
15233 json);
15234 }
15235 json_object_free(json);
ca61fd25
DS
15236 } else {
15237 if (use_json)
15238 vty_out(vty, "{}\n");
15239 else
15240 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 15241 }
15242
15243 return CMD_SUCCESS;
4fb25c53
DW
15244}
15245
2986cac2 15246
15247
15248/* "show [ip] bgp neighbors graceful-restart" commands. */
dcab9012 15249DEFUN (show_ip_bgp_neighbors_graceful_restart,
2986cac2 15250 show_ip_bgp_neighbors_graceful_restart_cmd,
15251 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
15252 SHOW_STR
15253 BGP_STR
15254 IP_STR
15255 IPV6_STR
15256 NEIGHBOR_STR
15257 "Neighbor to display information about\n"
15258 "Neighbor to display information about\n"
15259 "Neighbor on BGP configured interface\n"
15260 GR_SHOW
15261 JSON_STR)
15262{
15263 char *sh_arg = NULL;
15264 enum show_type sh_type;
15265 int idx = 0;
15266 afi_t afi = AFI_MAX;
2986cac2 15267 bool uj = use_json(argc, argv);
15268
36235319 15269 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
2986cac2 15270 afi = AFI_MAX;
15271
15272 idx++;
15273
15274 if (argv_find(argv, argc, "A.B.C.D", &idx)
15275 || argv_find(argv, argc, "X:X::X:X", &idx)
15276 || argv_find(argv, argc, "WORD", &idx)) {
15277 sh_type = show_peer;
15278 sh_arg = argv[idx]->arg;
15279 } else
15280 sh_type = show_all;
15281
15282 if (!argv_find(argv, argc, "graceful-restart", &idx))
15283 return CMD_SUCCESS;
15284
15285
36235319
QY
15286 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
15287 afi, uj);
2986cac2 15288}
15289
716b2d8a 15290/* "show [ip] bgp neighbors" commands. */
718e3744 15291DEFUN (show_ip_bgp_neighbors,
15292 show_ip_bgp_neighbors_cmd,
24345e82 15293 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 15294 SHOW_STR
15295 IP_STR
15296 BGP_STR
f2a8972b 15297 BGP_INSTANCE_HELP_STR
00e6edb9
DA
15298 BGP_AF_STR
15299 BGP_AF_STR
718e3744 15300 "Detailed information on TCP and BGP neighbor connections\n"
15301 "Neighbor to display information about\n"
a80beece 15302 "Neighbor to display information about\n"
91d37724 15303 "Neighbor on BGP configured interface\n"
9973d184 15304 JSON_STR)
718e3744 15305{
d62a17ae 15306 char *vrf = NULL;
15307 char *sh_arg = NULL;
15308 enum show_type sh_type;
d1927ebe 15309 afi_t afi = AFI_MAX;
718e3744 15310
9f049418 15311 bool uj = use_json(argc, argv);
718e3744 15312
d62a17ae 15313 int idx = 0;
718e3744 15314
9a8bdf1c
PG
15315 /* [<vrf> VIEWVRFNAME] */
15316 if (argv_find(argv, argc, "vrf", &idx)) {
15317 vrf = argv[idx + 1]->arg;
15318 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15319 vrf = NULL;
15320 } else if (argv_find(argv, argc, "view", &idx))
15321 /* [<view> VIEWVRFNAME] */
d62a17ae 15322 vrf = argv[idx + 1]->arg;
718e3744 15323
d62a17ae 15324 idx++;
d1927ebe
AS
15325
15326 if (argv_find(argv, argc, "ipv4", &idx)) {
15327 sh_type = show_ipv4_all;
15328 afi = AFI_IP;
15329 } else if (argv_find(argv, argc, "ipv6", &idx)) {
15330 sh_type = show_ipv6_all;
15331 afi = AFI_IP6;
15332 } else {
15333 sh_type = show_all;
15334 }
15335
d62a17ae 15336 if (argv_find(argv, argc, "A.B.C.D", &idx)
15337 || argv_find(argv, argc, "X:X::X:X", &idx)
15338 || argv_find(argv, argc, "WORD", &idx)) {
15339 sh_type = show_peer;
15340 sh_arg = argv[idx]->arg;
d1927ebe
AS
15341 }
15342
15343 if (sh_type == show_peer && afi == AFI_IP) {
15344 sh_type = show_ipv4_peer;
15345 } else if (sh_type == show_peer && afi == AFI_IP6) {
15346 sh_type = show_ipv6_peer;
15347 }
856ca177 15348
d62a17ae 15349 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 15350}
15351
716b2d8a 15352/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 15353 paths' and `show ip mbgp paths'. Those functions results are the
15354 same.*/
f412b39a 15355DEFUN (show_ip_bgp_paths,
718e3744 15356 show_ip_bgp_paths_cmd,
46f296b4 15357 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 15358 SHOW_STR
15359 IP_STR
15360 BGP_STR
46f296b4 15361 BGP_SAFI_HELP_STR
718e3744 15362 "Path information\n")
15363{
d62a17ae 15364 vty_out(vty, "Address Refcnt Path\n");
15365 aspath_print_all_vty(vty);
15366 return CMD_SUCCESS;
718e3744 15367}
15368
718e3744 15369#include "hash.h"
15370
e3b78da8 15371static void community_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 15372 struct vty *vty)
718e3744 15373{
d62a17ae 15374 struct community *com;
718e3744 15375
e3b78da8 15376 com = (struct community *)bucket->data;
3f65c5b1 15377 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
c0945b78 15378 community_str(com, false, false));
718e3744 15379}
15380
15381/* Show BGP's community internal data. */
f412b39a 15382DEFUN (show_ip_bgp_community_info,
718e3744 15383 show_ip_bgp_community_info_cmd,
bec37ba5 15384 "show [ip] bgp community-info",
718e3744 15385 SHOW_STR
15386 IP_STR
15387 BGP_STR
15388 "List all bgp community information\n")
15389{
d62a17ae 15390 vty_out(vty, "Address Refcnt Community\n");
718e3744 15391
d62a17ae 15392 hash_iterate(community_hash(),
e3b78da8 15393 (void (*)(struct hash_bucket *,
d62a17ae 15394 void *))community_show_all_iterator,
15395 vty);
718e3744 15396
d62a17ae 15397 return CMD_SUCCESS;
718e3744 15398}
15399
e3b78da8 15400static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 15401 struct vty *vty)
57d187bc 15402{
d62a17ae 15403 struct lcommunity *lcom;
57d187bc 15404
e3b78da8 15405 lcom = (struct lcommunity *)bucket->data;
3f65c5b1 15406 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
c0945b78 15407 lcommunity_str(lcom, false, false));
57d187bc
JS
15408}
15409
15410/* Show BGP's community internal data. */
15411DEFUN (show_ip_bgp_lcommunity_info,
15412 show_ip_bgp_lcommunity_info_cmd,
15413 "show ip bgp large-community-info",
15414 SHOW_STR
15415 IP_STR
15416 BGP_STR
15417 "List all bgp large-community information\n")
15418{
d62a17ae 15419 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 15420
d62a17ae 15421 hash_iterate(lcommunity_hash(),
e3b78da8 15422 (void (*)(struct hash_bucket *,
d62a17ae 15423 void *))lcommunity_show_all_iterator,
15424 vty);
57d187bc 15425
d62a17ae 15426 return CMD_SUCCESS;
57d187bc 15427}
2986cac2 15428/* Graceful Restart */
15429
15430static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
403e64f8 15431 struct bgp *bgp)
2986cac2 15432{
57d187bc
JS
15433
15434
2986cac2 15435 vty_out(vty, "\n%s", SHOW_GR_HEADER);
15436
7318ae88 15437 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
2986cac2 15438
15439 switch (bgp_global_gr_mode) {
15440
15441 case GLOBAL_HELPER:
13909c4f 15442 vty_out(vty, "Global BGP GR Mode : Helper\n");
2986cac2 15443 break;
15444
15445 case GLOBAL_GR:
13909c4f 15446 vty_out(vty, "Global BGP GR Mode : Restart\n");
2986cac2 15447 break;
15448
15449 case GLOBAL_DISABLE:
13909c4f 15450 vty_out(vty, "Global BGP GR Mode : Disable\n");
2986cac2 15451 break;
15452
15453 case GLOBAL_INVALID:
2986cac2 15454 vty_out(vty,
2ba1fe69 15455 "Global BGP GR Mode Invalid\n");
2986cac2 15456 break;
15457 }
15458 vty_out(vty, "\n");
15459}
15460
36235319
QY
15461static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
15462 enum show_type type,
15463 const char *ip_str,
15464 afi_t afi, bool use_json)
2986cac2 15465{
403e64f8
DA
15466 json_object *json = NULL;
15467
15468 if (use_json)
15469 json = json_object_new_object();
15470
2986cac2 15471 if ((afi == AFI_MAX) && (ip_str == NULL)) {
15472 afi = AFI_IP;
15473
15474 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
15475
36235319 15476 bgp_show_neighbor_graceful_restart_vty(
403e64f8 15477 vty, type, ip_str, afi, json);
2986cac2 15478 afi++;
15479 }
15480 } else if (afi != AFI_MAX) {
36235319 15481 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
403e64f8 15482 json);
2986cac2 15483 } else {
403e64f8
DA
15484 if (json)
15485 json_object_free(json);
2986cac2 15486 return CMD_ERR_INCOMPLETE;
15487 }
15488
403e64f8
DA
15489 if (json)
15490 vty_json(vty, json);
15491
2986cac2 15492 return CMD_SUCCESS;
15493}
15494/* Graceful Restart */
15495
f412b39a 15496DEFUN (show_ip_bgp_attr_info,
718e3744 15497 show_ip_bgp_attr_info_cmd,
bec37ba5 15498 "show [ip] bgp attribute-info",
718e3744 15499 SHOW_STR
15500 IP_STR
15501 BGP_STR
15502 "List all bgp attribute information\n")
15503{
d62a17ae 15504 attr_show_all(vty);
15505 return CMD_SUCCESS;
718e3744 15506}
6b0655a2 15507
03915806
CS
15508static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
15509 afi_t afi, safi_t safi,
15510 bool use_json, json_object *json)
53089bec 15511{
15512 struct bgp *bgp;
15513 struct listnode *node;
15514 char *vname;
53089bec 15515 char *ecom_str;
9c2fd3fe 15516 enum vpn_policy_direction dir;
53089bec 15517
03915806 15518 if (json) {
b46dfd20
DS
15519 json_object *json_import_vrfs = NULL;
15520 json_object *json_export_vrfs = NULL;
15521
b46dfd20
DS
15522 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15523
53089bec 15524 if (!bgp) {
75eeda93 15525 vty_json(vty, json);
b46dfd20 15526
53089bec 15527 return CMD_WARNING;
15528 }
b46dfd20 15529
94d4c685
DS
15530 /* Provide context for the block */
15531 json_object_string_add(json, "vrf", name ? name : "default");
15532 json_object_string_add(json, "afiSafi",
5cb5f4d0 15533 get_afi_safi_str(afi, safi, true));
94d4c685 15534
b46dfd20
DS
15535 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15536 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
15537 json_object_string_add(json, "importFromVrfs", "none");
15538 json_object_string_add(json, "importRts", "none");
15539 } else {
6ce24e52
DS
15540 json_import_vrfs = json_object_new_array();
15541
b46dfd20
DS
15542 for (ALL_LIST_ELEMENTS_RO(
15543 bgp->vpn_policy[afi].import_vrf,
15544 node, vname))
15545 json_object_array_add(json_import_vrfs,
15546 json_object_new_string(vname));
15547
b20875ea
CS
15548 json_object_object_add(json, "importFromVrfs",
15549 json_import_vrfs);
b46dfd20 15550 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
15551 if (bgp->vpn_policy[afi].rtlist[dir]) {
15552 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15553 bgp->vpn_policy[afi].rtlist[dir],
15554 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
15555 json_object_string_add(json, "importRts",
15556 ecom_str);
15557 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15558 } else
15559 json_object_string_add(json, "importRts",
15560 "none");
b46dfd20
DS
15561 }
15562
15563 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15564 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
15565 json_object_string_add(json, "exportToVrfs", "none");
15566 json_object_string_add(json, "routeDistinguisher",
15567 "none");
15568 json_object_string_add(json, "exportRts", "none");
15569 } else {
6ce24e52
DS
15570 json_export_vrfs = json_object_new_array();
15571
b46dfd20
DS
15572 for (ALL_LIST_ELEMENTS_RO(
15573 bgp->vpn_policy[afi].export_vrf,
15574 node, vname))
15575 json_object_array_add(json_export_vrfs,
15576 json_object_new_string(vname));
15577 json_object_object_add(json, "exportToVrfs",
15578 json_export_vrfs);
c4f64ea9
DA
15579 json_object_string_addf(json, "routeDistinguisher",
15580 "%pRD",
15581 &bgp->vpn_policy[afi].tovpn_rd);
b46dfd20
DS
15582
15583 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
15584 if (bgp->vpn_policy[afi].rtlist[dir]) {
15585 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15586 bgp->vpn_policy[afi].rtlist[dir],
15587 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
15588 json_object_string_add(json, "exportRts",
15589 ecom_str);
15590 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15591 } else
15592 json_object_string_add(json, "exportRts",
15593 "none");
b46dfd20
DS
15594 }
15595
03915806 15596 if (use_json) {
75eeda93 15597 vty_json(vty, json);
03915806 15598 }
53089bec 15599 } else {
b46dfd20
DS
15600 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15601
53089bec 15602 if (!bgp) {
b46dfd20 15603 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 15604 return CMD_WARNING;
15605 }
53089bec 15606
b46dfd20
DS
15607 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15608 BGP_CONFIG_VRF_TO_VRF_IMPORT))
15609 vty_out(vty,
15610 "This VRF is not importing %s routes from any other VRF\n",
5cb5f4d0 15611 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15612 else {
15613 vty_out(vty,
15614 "This VRF is importing %s routes from the following VRFs:\n",
5cb5f4d0 15615 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15616
15617 for (ALL_LIST_ELEMENTS_RO(
15618 bgp->vpn_policy[afi].import_vrf,
15619 node, vname))
15620 vty_out(vty, " %s\n", vname);
15621
15622 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
15623 ecom_str = NULL;
15624 if (bgp->vpn_policy[afi].rtlist[dir]) {
15625 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15626 bgp->vpn_policy[afi].rtlist[dir],
15627 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea 15628 vty_out(vty, "Import RT(s): %s\n", ecom_str);
b46dfd20 15629
b20875ea
CS
15630 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15631 } else
15632 vty_out(vty, "Import RT(s):\n");
53089bec 15633 }
53089bec 15634
b46dfd20
DS
15635 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15636 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15637 vty_out(vty,
15638 "This VRF is not exporting %s routes to any other VRF\n",
5cb5f4d0 15639 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15640 else {
15641 vty_out(vty,
04c9077f 15642 "This VRF is exporting %s routes to the following VRFs:\n",
5cb5f4d0 15643 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15644
15645 for (ALL_LIST_ELEMENTS_RO(
15646 bgp->vpn_policy[afi].export_vrf,
15647 node, vname))
15648 vty_out(vty, " %s\n", vname);
15649
c4f64ea9
DA
15650 vty_out(vty, "RD: %pRD\n",
15651 &bgp->vpn_policy[afi].tovpn_rd);
b46dfd20
DS
15652
15653 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
15654 if (bgp->vpn_policy[afi].rtlist[dir]) {
15655 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15656 bgp->vpn_policy[afi].rtlist[dir],
15657 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
15658 vty_out(vty, "Export RT: %s\n", ecom_str);
15659 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15660 } else
15661 vty_out(vty, "Import RT(s):\n");
53089bec 15662 }
53089bec 15663 }
15664
15665 return CMD_SUCCESS;
15666}
15667
03915806
CS
15668static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
15669 safi_t safi, bool use_json)
15670{
15671 struct listnode *node, *nnode;
15672 struct bgp *bgp;
15673 char *vrf_name = NULL;
15674 json_object *json = NULL;
15675 json_object *json_vrf = NULL;
15676 json_object *json_vrfs = NULL;
15677
15678 if (use_json) {
15679 json = json_object_new_object();
15680 json_vrfs = json_object_new_object();
15681 }
15682
15683 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15684
15685 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
15686 vrf_name = bgp->name;
15687
15688 if (use_json) {
15689 json_vrf = json_object_new_object();
15690 } else {
15691 vty_out(vty, "\nInstance %s:\n",
15692 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15693 ? VRF_DEFAULT_NAME : bgp->name);
15694 }
15695 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
15696 if (use_json) {
15697 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15698 json_object_object_add(json_vrfs,
15699 VRF_DEFAULT_NAME, json_vrf);
15700 else
15701 json_object_object_add(json_vrfs, vrf_name,
15702 json_vrf);
15703 }
15704 }
15705
15706 if (use_json) {
15707 json_object_object_add(json, "vrfs", json_vrfs);
75eeda93 15708 vty_json(vty, json);
03915806
CS
15709 }
15710
15711 return CMD_SUCCESS;
15712}
15713
53089bec 15714/* "show [ip] bgp route-leak" command. */
15715DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
15716 show_ip_bgp_route_leak_cmd,
15717 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
15718 SHOW_STR
15719 IP_STR
15720 BGP_STR
15721 BGP_INSTANCE_HELP_STR
15722 BGP_AFI_HELP_STR
15723 BGP_SAFI_HELP_STR
15724 "Route leaking information\n"
15725 JSON_STR)
53089bec 15726{
15727 char *vrf = NULL;
15728 afi_t afi = AFI_MAX;
15729 safi_t safi = SAFI_MAX;
15730
9f049418 15731 bool uj = use_json(argc, argv);
53089bec 15732 int idx = 0;
03915806 15733 json_object *json = NULL;
53089bec 15734
15735 /* show [ip] bgp */
15736 if (argv_find(argv, argc, "ip", &idx)) {
15737 afi = AFI_IP;
15738 safi = SAFI_UNICAST;
15739 }
15740 /* [vrf VIEWVRFNAME] */
15741 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
15742 vty_out(vty,
15743 "%% This command is not applicable to BGP views\n");
53089bec 15744 return CMD_WARNING;
15745 }
15746
9a8bdf1c
PG
15747 if (argv_find(argv, argc, "vrf", &idx)) {
15748 vrf = argv[idx + 1]->arg;
15749 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15750 vrf = NULL;
15751 }
53089bec 15752 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
c48349e3 15753 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
53089bec 15754 argv_find_and_parse_safi(argv, argc, &idx, &safi);
53089bec 15755
15756 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
15757 vty_out(vty,
15758 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 15759 return CMD_WARNING;
15760 }
15761
03915806
CS
15762 if (vrf && strmatch(vrf, "all"))
15763 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15764
15765 if (uj)
15766 json = json_object_new_object();
15767
15768 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
53089bec 15769}
15770
d62a17ae 15771static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
fa5a9276 15772 safi_t safi, bool uj)
f186de26 15773{
d62a17ae 15774 struct listnode *node, *nnode;
15775 struct bgp *bgp;
f186de26 15776
d62a17ae 15777 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
fa5a9276
AR
15778 if (!uj)
15779 vty_out(vty, "\nInstance %s:\n",
15780 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15781 ? VRF_DEFAULT_NAME
15782 : bgp->name);
15783
15784 update_group_show(bgp, afi, safi, vty, 0, uj);
d62a17ae 15785 }
f186de26 15786}
15787
d62a17ae 15788static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
fa5a9276 15789 int safi, uint64_t subgrp_id, bool uj)
4fb25c53 15790{
d62a17ae 15791 struct bgp *bgp;
4fb25c53 15792
d62a17ae 15793 if (name) {
15794 if (strmatch(name, "all")) {
fa5a9276 15795 bgp_show_all_instances_updgrps_vty(vty, afi, safi, uj);
d62a17ae 15796 return CMD_SUCCESS;
15797 } else {
15798 bgp = bgp_lookup_by_name(name);
15799 }
15800 } else {
15801 bgp = bgp_get_default();
15802 }
4fb25c53 15803
d62a17ae 15804 if (bgp)
fa5a9276 15805 update_group_show(bgp, afi, safi, vty, subgrp_id, uj);
d62a17ae 15806 return CMD_SUCCESS;
4fb25c53
DW
15807}
15808
8fe8a7f6
DS
15809DEFUN (show_ip_bgp_updgrps,
15810 show_ip_bgp_updgrps_cmd,
fa5a9276 15811 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID] [json]",
8386ac43 15812 SHOW_STR
15813 IP_STR
15814 BGP_STR
15815 BGP_INSTANCE_HELP_STR
c9e571b4 15816 BGP_AFI_HELP_STR
9bedbb1e 15817 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956 15818 "Detailed info about dynamic update groups\n"
fa5a9276
AR
15819 "Specific subgroup to display detailed info for\n"
15820 JSON_STR)
8386ac43 15821{
d62a17ae 15822 char *vrf = NULL;
15823 afi_t afi = AFI_IP6;
15824 safi_t safi = SAFI_UNICAST;
15825 uint64_t subgrp_id = 0;
15826
15827 int idx = 0;
15828
fa5a9276
AR
15829 bool uj = use_json(argc, argv);
15830
d62a17ae 15831 /* show [ip] bgp */
15832 if (argv_find(argv, argc, "ip", &idx))
15833 afi = AFI_IP;
9a8bdf1c
PG
15834 /* [<vrf> VIEWVRFNAME] */
15835 if (argv_find(argv, argc, "vrf", &idx)) {
15836 vrf = argv[idx + 1]->arg;
15837 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15838 vrf = NULL;
15839 } else if (argv_find(argv, argc, "view", &idx))
15840 /* [<view> VIEWVRFNAME] */
15841 vrf = argv[idx + 1]->arg;
d62a17ae 15842 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15843 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15844 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15845 }
5bf15956 15846
d62a17ae 15847 /* get subgroup id, if provided */
15848 idx = argc - 1;
15849 if (argv[idx]->type == VARIABLE_TKN)
15850 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 15851
fa5a9276 15852 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id, uj));
8fe8a7f6
DS
15853}
15854
f186de26 15855DEFUN (show_bgp_instance_all_ipv6_updgrps,
15856 show_bgp_instance_all_ipv6_updgrps_cmd,
fa5a9276 15857 "show [ip] bgp <view|vrf> all update-groups [json]",
f186de26 15858 SHOW_STR
716b2d8a 15859 IP_STR
f186de26 15860 BGP_STR
15861 BGP_INSTANCE_ALL_HELP_STR
fa5a9276
AR
15862 "Detailed info about dynamic update groups\n"
15863 JSON_STR)
f186de26 15864{
fa5a9276
AR
15865 bool uj = use_json(argc, argv);
15866
15867 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST, uj);
d62a17ae 15868 return CMD_SUCCESS;
f186de26 15869}
15870
43d3f4fc
DS
15871DEFUN (show_bgp_l2vpn_evpn_updgrps,
15872 show_bgp_l2vpn_evpn_updgrps_cmd,
15873 "show [ip] bgp l2vpn evpn update-groups",
15874 SHOW_STR
15875 IP_STR
15876 BGP_STR
15877 "l2vpn address family\n"
15878 "evpn sub-address family\n"
15879 "Detailed info about dynamic update groups\n")
15880{
15881 char *vrf = NULL;
15882 uint64_t subgrp_id = 0;
15883
fa5a9276 15884 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id, 0);
43d3f4fc
DS
15885 return CMD_SUCCESS;
15886}
15887
5bf15956
DW
15888DEFUN (show_bgp_updgrps_stats,
15889 show_bgp_updgrps_stats_cmd,
716b2d8a 15890 "show [ip] bgp update-groups statistics",
3f9c7369 15891 SHOW_STR
716b2d8a 15892 IP_STR
3f9c7369 15893 BGP_STR
0c7b1b01 15894 "Detailed info about dynamic update groups\n"
3f9c7369
DS
15895 "Statistics\n")
15896{
d62a17ae 15897 struct bgp *bgp;
3f9c7369 15898
d62a17ae 15899 bgp = bgp_get_default();
15900 if (bgp)
15901 update_group_show_stats(bgp, vty);
3f9c7369 15902
d62a17ae 15903 return CMD_SUCCESS;
3f9c7369
DS
15904}
15905
8386ac43 15906DEFUN (show_bgp_instance_updgrps_stats,
15907 show_bgp_instance_updgrps_stats_cmd,
18c57037 15908 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 15909 SHOW_STR
716b2d8a 15910 IP_STR
8386ac43 15911 BGP_STR
15912 BGP_INSTANCE_HELP_STR
0c7b1b01 15913 "Detailed info about dynamic update groups\n"
8386ac43 15914 "Statistics\n")
15915{
d62a17ae 15916 int idx_word = 3;
15917 struct bgp *bgp;
8386ac43 15918
d62a17ae 15919 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15920 if (bgp)
15921 update_group_show_stats(bgp, vty);
8386ac43 15922
d62a17ae 15923 return CMD_SUCCESS;
8386ac43 15924}
15925
d62a17ae 15926static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15927 afi_t afi, safi_t safi,
15928 const char *what, uint64_t subgrp_id)
3f9c7369 15929{
d62a17ae 15930 struct bgp *bgp;
8386ac43 15931
d62a17ae 15932 if (name)
15933 bgp = bgp_lookup_by_name(name);
15934 else
15935 bgp = bgp_get_default();
8386ac43 15936
d62a17ae 15937 if (bgp) {
15938 if (!strcmp(what, "advertise-queue"))
15939 update_group_show_adj_queue(bgp, afi, safi, vty,
15940 subgrp_id);
15941 else if (!strcmp(what, "advertised-routes"))
15942 update_group_show_advertised(bgp, afi, safi, vty,
15943 subgrp_id);
15944 else if (!strcmp(what, "packet-queue"))
15945 update_group_show_packet_queue(bgp, afi, safi, vty,
15946 subgrp_id);
15947 }
3f9c7369
DS
15948}
15949
dc64bdec
QY
15950DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15951 show_ip_bgp_instance_updgrps_adj_s_cmd,
15952 "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",
15953 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15954 BGP_SAFI_HELP_STR
15955 "Detailed info about dynamic update groups\n"
15956 "Specific subgroup to display info for\n"
15957 "Advertisement queue\n"
15958 "Announced routes\n"
15959 "Packet queue\n")
3f9c7369 15960{
dc64bdec
QY
15961 uint64_t subgrp_id = 0;
15962 afi_t afiz;
15963 safi_t safiz;
15964 if (sgid)
15965 subgrp_id = strtoull(sgid, NULL, 10);
15966
15967 if (!ip && !afi)
15968 afiz = AFI_IP6;
15969 if (!ip && afi)
15970 afiz = bgp_vty_afi_from_str(afi);
15971 if (ip && !afi)
15972 afiz = AFI_IP;
15973 if (ip && afi) {
15974 afiz = bgp_vty_afi_from_str(afi);
15975 if (afiz != AFI_IP)
15976 vty_out(vty,
15977 "%% Cannot specify both 'ip' and 'ipv6'\n");
15978 return CMD_WARNING;
15979 }
d62a17ae 15980
dc64bdec 15981 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 15982
dc64bdec 15983 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 15984 return CMD_SUCCESS;
15985}
15986
6f4eacf3
DA
15987static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
15988 json_object *json)
d62a17ae 15989{
15990 struct listnode *node, *nnode;
15991 struct prefix *range;
15992 struct peer *conf;
15993 struct peer *peer;
d62a17ae 15994 afi_t afi;
15995 safi_t safi;
15996 const char *peer_status;
d62a17ae 15997 int lr_count;
15998 int dynamic;
6f4eacf3
DA
15999 bool af_cfgd;
16000 json_object *json_peer_group = NULL;
16001 json_object *json_peer_group_afc = NULL;
16002 json_object *json_peer_group_members = NULL;
16003 json_object *json_peer_group_dynamic = NULL;
16004 json_object *json_peer_group_dynamic_af = NULL;
16005 json_object *json_peer_group_ranges = NULL;
d62a17ae 16006
16007 conf = group->conf;
16008
6f4eacf3
DA
16009 if (json) {
16010 json_peer_group = json_object_new_object();
16011 json_peer_group_afc = json_object_new_array();
16012 }
16013
d62a17ae 16014 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
6f4eacf3 16015 if (json)
44a4d55e
PG
16016 asn_asn2json(json_peer_group, "remoteAs", conf->as,
16017 bgp_get_asnotation(conf->bgp));
16018 else {
16019 vty_out(vty, "\nBGP peer-group %s, remote AS ",
16020 group->name);
16021 vty_out(vty, ASN_FORMAT(bgp_get_asnotation(conf->bgp)),
16022 &conf->as);
16023 vty_out(vty, "\n");
16024 }
d62a17ae 16025 } else if (conf->as_type == AS_INTERNAL) {
6f4eacf3 16026 if (json)
e84c7c12
PG
16027 asn_asn2json(json, "remoteAs", group->bgp->as,
16028 group->bgp->asnotation);
6f4eacf3 16029 else
9eb11997
PG
16030 vty_out(vty, "\nBGP peer-group %s, remote AS %s\n",
16031 group->name, group->bgp->as_pretty);
d62a17ae 16032 } else {
6f4eacf3
DA
16033 if (!json)
16034 vty_out(vty, "\nBGP peer-group %s\n", group->name);
d62a17ae 16035 }
f14e6fdb 16036
6f4eacf3
DA
16037 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
16038 if (json)
16039 json_object_string_add(json_peer_group, "type",
16040 "internal");
16041 else
16042 vty_out(vty, " Peer-group type is internal\n");
16043 } else {
16044 if (json)
16045 json_object_string_add(json_peer_group, "type",
16046 "external");
16047 else
16048 vty_out(vty, " Peer-group type is external\n");
16049 }
d62a17ae 16050
16051 /* Display AFs configured. */
6f4eacf3
DA
16052 if (!json)
16053 vty_out(vty, " Configured address-families:");
16054
05c7a1cc
QY
16055 FOREACH_AFI_SAFI (afi, safi) {
16056 if (conf->afc[afi][safi]) {
6f4eacf3
DA
16057 af_cfgd = true;
16058 if (json)
16059 json_object_array_add(
16060 json_peer_group_afc,
16061 json_object_new_string(get_afi_safi_str(
16062 afi, safi, false)));
16063 else
16064 vty_out(vty, " %s;",
16065 get_afi_safi_str(afi, safi, false));
d62a17ae 16066 }
05c7a1cc 16067 }
6f4eacf3
DA
16068
16069 if (json) {
16070 json_object_object_add(json_peer_group,
16071 "addressFamiliesConfigured",
16072 json_peer_group_afc);
16073 } else {
16074 if (!af_cfgd)
16075 vty_out(vty, " none\n");
16076 else
16077 vty_out(vty, "\n");
16078 }
d62a17ae 16079
16080 /* Display listen ranges (for dynamic neighbors), if any */
16081 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
d62a17ae 16082 lr_count = listcount(group->listen_range[afi]);
16083 if (lr_count) {
6f4eacf3
DA
16084 if (json) {
16085 if (!json_peer_group_dynamic)
16086 json_peer_group_dynamic =
16087 json_object_new_object();
16088
16089 json_peer_group_dynamic_af =
16090 json_object_new_object();
16091 json_peer_group_ranges =
16092 json_object_new_array();
16093 json_object_int_add(json_peer_group_dynamic_af,
16094 "count", lr_count);
16095 } else {
16096 vty_out(vty, " %d %s listen range(s)\n",
16097 lr_count, afi2str(afi));
16098 }
d62a17ae 16099
16100 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
6f4eacf3
DA
16101 nnode, range)) {
16102 if (json) {
16103 char buf[BUFSIZ];
16104
16105 snprintfrr(buf, sizeof(buf), "%pFX",
16106 range);
16107
16108 json_object_array_add(
16109 json_peer_group_ranges,
16110 json_object_new_string(buf));
16111 } else {
16112 vty_out(vty, " %pFX\n", range);
16113 }
16114 }
16115
16116 if (json) {
16117 json_object_object_add(
16118 json_peer_group_dynamic_af, "ranges",
16119 json_peer_group_ranges);
16120
16121 json_object_object_add(
16122 json_peer_group_dynamic, afi2str(afi),
16123 json_peer_group_dynamic_af);
16124 }
d62a17ae 16125 }
16126 }
f14e6fdb 16127
6f4eacf3
DA
16128 if (json_peer_group_dynamic)
16129 json_object_object_add(json_peer_group, "dynamicRanges",
16130 json_peer_group_dynamic);
16131
d62a17ae 16132 /* Display group members and their status */
16133 if (listcount(group->peer)) {
6f4eacf3
DA
16134 if (json)
16135 json_peer_group_members = json_object_new_object();
16136 else
16137 vty_out(vty, " Peer-group members:\n");
d62a17ae 16138 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
cb9196e7
DS
16139 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
16140 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 16141 peer_status = "Idle (Admin)";
16142 else if (CHECK_FLAG(peer->sflags,
16143 PEER_STATUS_PREFIX_OVERFLOW))
16144 peer_status = "Idle (PfxCt)";
16145 else
16146 peer_status = lookup_msg(bgp_status_msg,
16147 peer->status, NULL);
16148
16149 dynamic = peer_dynamic_neighbor(peer);
6f4eacf3
DA
16150
16151 if (json) {
16152 json_object *json_peer_group_member =
16153 json_object_new_object();
16154
16155 json_object_string_add(json_peer_group_member,
16156 "status", peer_status);
16157
16158 if (dynamic)
16159 json_object_boolean_true_add(
16160 json_peer_group_member,
16161 "dynamic");
16162
16163 json_object_object_add(json_peer_group_members,
16164 peer->host,
16165 json_peer_group_member);
16166 } else {
16167 vty_out(vty, " %s %s %s \n", peer->host,
16168 dynamic ? "(dynamic)" : "",
16169 peer_status);
16170 }
d62a17ae 16171 }
6f4eacf3
DA
16172 if (json)
16173 json_object_object_add(json_peer_group, "members",
16174 json_peer_group_members);
d62a17ae 16175 }
f14e6fdb 16176
6f4eacf3
DA
16177 if (json)
16178 json_object_object_add(json, group->name, json_peer_group);
16179
d62a17ae 16180 return CMD_SUCCESS;
16181}
16182
ff9959b0 16183static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
6f4eacf3 16184 const char *group_name, bool uj)
d62a17ae 16185{
ff9959b0 16186 struct bgp *bgp;
d62a17ae 16187 struct listnode *node, *nnode;
16188 struct peer_group *group;
ff9959b0 16189 bool found = false;
6f4eacf3
DA
16190 json_object *json = NULL;
16191
16192 if (uj)
16193 json = json_object_new_object();
ff9959b0
QY
16194
16195 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
16196
16197 if (!bgp) {
c48349e3 16198 if (uj)
75eeda93 16199 vty_json(vty, json);
c48349e3 16200 else
6f4eacf3 16201 vty_out(vty, "%% BGP instance not found\n");
6f4eacf3 16202
ff9959b0
QY
16203 return CMD_WARNING;
16204 }
d62a17ae 16205
16206 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
16207 if (group_name) {
16208 if (strmatch(group->name, group_name)) {
6f4eacf3 16209 bgp_show_one_peer_group(vty, group, json);
ff9959b0
QY
16210 found = true;
16211 break;
d62a17ae 16212 }
ff9959b0 16213 } else {
6f4eacf3 16214 bgp_show_one_peer_group(vty, group, json);
d62a17ae 16215 }
f14e6fdb 16216 }
f14e6fdb 16217
6f4eacf3 16218 if (group_name && !found && !uj)
d62a17ae 16219 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 16220
c48349e3 16221 if (uj)
75eeda93 16222 vty_json(vty, json);
6f4eacf3 16223
d62a17ae 16224 return CMD_SUCCESS;
f14e6fdb
DS
16225}
16226
6f4eacf3
DA
16227DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
16228 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
16229 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
16230 "Detailed information on BGP peer groups\n"
16231 "Peer group name\n" JSON_STR)
f14e6fdb 16232{
d62a17ae 16233 char *vrf, *pg;
d62a17ae 16234 int idx = 0;
6f4eacf3 16235 bool uj = use_json(argc, argv);
f14e6fdb 16236
a4d82a8a
PZ
16237 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
16238 : NULL;
d62a17ae 16239 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 16240
6f4eacf3 16241 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
f14e6fdb 16242}
3f9c7369 16243
d6e3c605 16244
718e3744 16245/* Redistribute VTY commands. */
16246
585f1adc
IR
16247DEFUN (bgp_redistribute_ipv4,
16248 bgp_redistribute_ipv4_cmd,
16249 "redistribute " FRR_IP_REDIST_STR_BGPD,
16250 "Redistribute information from another routing protocol\n"
16251 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 16252{
585f1adc 16253 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16254 int idx_protocol = 1;
585f1adc 16255 int type;
37a87b8f 16256
585f1adc
IR
16257 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16258 if (type < 0) {
16259 vty_out(vty, "%% Invalid route type\n");
16260 return CMD_WARNING_CONFIG_FAILED;
16261 }
7f323236 16262
585f1adc
IR
16263 bgp_redist_add(bgp, AFI_IP, type, 0);
16264 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
718e3744 16265}
16266
d62a17ae 16267ALIAS_HIDDEN(
16268 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
16269 "redistribute " FRR_IP_REDIST_STR_BGPD,
16270 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 16271
585f1adc
IR
16272DEFUN (bgp_redistribute_ipv4_rmap,
16273 bgp_redistribute_ipv4_rmap_cmd,
70dd370f 16274 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
585f1adc
IR
16275 "Redistribute information from another routing protocol\n"
16276 FRR_IP_REDIST_HELP_STR_BGPD
16277 "Route map reference\n"
16278 "Pointer to route-map entries\n")
718e3744 16279{
585f1adc 16280 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16281 int idx_protocol = 1;
16282 int idx_word = 3;
585f1adc
IR
16283 int type;
16284 struct bgp_redist *red;
16285 bool changed;
16286 struct route_map *route_map = route_map_lookup_warn_noexist(
16287 vty, argv[idx_word]->arg);
16288
16289 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16290 if (type < 0) {
16291 vty_out(vty, "%% Invalid route type\n");
16292 return CMD_WARNING_CONFIG_FAILED;
16293 }
37a87b8f 16294
585f1adc
IR
16295 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16296 changed =
16297 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16298 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
718e3744 16299}
16300
d62a17ae 16301ALIAS_HIDDEN(
16302 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
70dd370f 16303 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
d62a17ae 16304 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16305 "Route map reference\n"
16306 "Pointer to route-map entries\n")
596c17ba 16307
585f1adc
IR
16308DEFUN (bgp_redistribute_ipv4_metric,
16309 bgp_redistribute_ipv4_metric_cmd,
16310 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
16311 "Redistribute information from another routing protocol\n"
16312 FRR_IP_REDIST_HELP_STR_BGPD
16313 "Metric for redistributed routes\n"
16314 "Default metric\n")
718e3744 16315{
585f1adc 16316 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16317 int idx_protocol = 1;
16318 int idx_number = 3;
585f1adc
IR
16319 int type;
16320 uint32_t metric;
16321 struct bgp_redist *red;
16322 bool changed;
16323
16324 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16325 if (type < 0) {
16326 vty_out(vty, "%% Invalid route type\n");
16327 return CMD_WARNING_CONFIG_FAILED;
16328 }
16329 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 16330
585f1adc
IR
16331 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16332 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16333 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 16334}
16335
16336ALIAS_HIDDEN(
16337 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
16338 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
16339 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16340 "Metric for redistributed routes\n"
16341 "Default metric\n")
596c17ba 16342
585f1adc
IR
16343DEFUN (bgp_redistribute_ipv4_rmap_metric,
16344 bgp_redistribute_ipv4_rmap_metric_cmd,
70dd370f 16345 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
585f1adc
IR
16346 "Redistribute information from another routing protocol\n"
16347 FRR_IP_REDIST_HELP_STR_BGPD
16348 "Route map reference\n"
16349 "Pointer to route-map entries\n"
16350 "Metric for redistributed routes\n"
16351 "Default metric\n")
718e3744 16352{
585f1adc 16353 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16354 int idx_protocol = 1;
16355 int idx_word = 3;
16356 int idx_number = 5;
585f1adc
IR
16357 int type;
16358 uint32_t metric;
16359 struct bgp_redist *red;
16360 bool changed;
16361 struct route_map *route_map =
16362 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16363
16364 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16365 if (type < 0) {
16366 vty_out(vty, "%% Invalid route type\n");
16367 return CMD_WARNING_CONFIG_FAILED;
16368 }
16369 metric = strtoul(argv[idx_number]->arg, NULL, 10);
d62a17ae 16370
585f1adc
IR
16371 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16372 changed =
16373 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16374 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16375 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 16376}
16377
16378ALIAS_HIDDEN(
16379 bgp_redistribute_ipv4_rmap_metric,
16380 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
16381 "redistribute " FRR_IP_REDIST_STR_BGPD
70dd370f 16382 " route-map RMAP_NAME metric (0-4294967295)",
d62a17ae 16383 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16384 "Route map reference\n"
16385 "Pointer to route-map entries\n"
16386 "Metric for redistributed routes\n"
16387 "Default metric\n")
596c17ba 16388
585f1adc
IR
16389DEFUN (bgp_redistribute_ipv4_metric_rmap,
16390 bgp_redistribute_ipv4_metric_rmap_cmd,
70dd370f 16391 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
585f1adc
IR
16392 "Redistribute information from another routing protocol\n"
16393 FRR_IP_REDIST_HELP_STR_BGPD
16394 "Metric for redistributed routes\n"
16395 "Default metric\n"
16396 "Route map reference\n"
16397 "Pointer to route-map entries\n")
718e3744 16398{
585f1adc 16399 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16400 int idx_protocol = 1;
37a87b8f 16401 int idx_number = 3;
585f1adc
IR
16402 int idx_word = 5;
16403 int type;
16404 uint32_t metric;
16405 struct bgp_redist *red;
16406 bool changed;
16407 struct route_map *route_map =
16408 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16409
16410 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16411 if (type < 0) {
16412 vty_out(vty, "%% Invalid route type\n");
16413 return CMD_WARNING_CONFIG_FAILED;
16414 }
16415 metric = strtoul(argv[idx_number]->arg, NULL, 10);
d62a17ae 16416
585f1adc
IR
16417 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16418 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16419 changed |=
16420 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16421 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 16422}
16423
16424ALIAS_HIDDEN(
16425 bgp_redistribute_ipv4_metric_rmap,
16426 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
16427 "redistribute " FRR_IP_REDIST_STR_BGPD
70dd370f 16428 " metric (0-4294967295) route-map RMAP_NAME",
d62a17ae 16429 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16430 "Metric for redistributed routes\n"
16431 "Default metric\n"
16432 "Route map reference\n"
16433 "Pointer to route-map entries\n")
596c17ba 16434
585f1adc
IR
16435DEFUN (bgp_redistribute_ipv4_ospf,
16436 bgp_redistribute_ipv4_ospf_cmd,
16437 "redistribute <ospf|table> (1-65535)",
16438 "Redistribute information from another routing protocol\n"
16439 "Open Shortest Path First (OSPFv2)\n"
16440 "Non-main Kernel Routing Table\n"
16441 "Instance ID/Table ID\n")
7c8ff89e 16442{
585f1adc
IR
16443 VTY_DECLVAR_CONTEXT(bgp, bgp);
16444 int idx_ospf_table = 1;
d62a17ae 16445 int idx_number = 2;
585f1adc
IR
16446 unsigned short instance;
16447 unsigned short protocol;
7c8ff89e 16448
585f1adc 16449 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 16450
585f1adc
IR
16451 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16452 protocol = ZEBRA_ROUTE_OSPF;
16453 else
16454 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 16455
585f1adc
IR
16456 bgp_redist_add(bgp, AFI_IP, protocol, instance);
16457 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
7c8ff89e
DS
16458}
16459
d62a17ae 16460ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
16461 "redistribute <ospf|table> (1-65535)",
16462 "Redistribute information from another routing protocol\n"
16463 "Open Shortest Path First (OSPFv2)\n"
16464 "Non-main Kernel Routing Table\n"
16465 "Instance ID/Table ID\n")
596c17ba 16466
585f1adc
IR
16467DEFUN (bgp_redistribute_ipv4_ospf_rmap,
16468 bgp_redistribute_ipv4_ospf_rmap_cmd,
70dd370f 16469 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
585f1adc
IR
16470 "Redistribute information from another routing protocol\n"
16471 "Open Shortest Path First (OSPFv2)\n"
16472 "Non-main Kernel Routing Table\n"
16473 "Instance ID/Table ID\n"
16474 "Route map reference\n"
16475 "Pointer to route-map entries\n")
7c8ff89e 16476{
585f1adc
IR
16477 VTY_DECLVAR_CONTEXT(bgp, bgp);
16478 int idx_ospf_table = 1;
d62a17ae 16479 int idx_number = 2;
16480 int idx_word = 4;
585f1adc
IR
16481 struct bgp_redist *red;
16482 unsigned short instance;
16483 int protocol;
16484 bool changed;
16485 struct route_map *route_map =
16486 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16487
16488 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16489 protocol = ZEBRA_ROUTE_OSPF;
16490 else
16491 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 16492
585f1adc
IR
16493 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16494 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16495 changed =
16496 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16497 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 16498}
16499
16500ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
16501 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
70dd370f 16502 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
d62a17ae 16503 "Redistribute information from another routing protocol\n"
16504 "Open Shortest Path First (OSPFv2)\n"
16505 "Non-main Kernel Routing Table\n"
16506 "Instance ID/Table ID\n"
16507 "Route map reference\n"
16508 "Pointer to route-map entries\n")
596c17ba 16509
585f1adc
IR
16510DEFUN (bgp_redistribute_ipv4_ospf_metric,
16511 bgp_redistribute_ipv4_ospf_metric_cmd,
16512 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16513 "Redistribute information from another routing protocol\n"
16514 "Open Shortest Path First (OSPFv2)\n"
16515 "Non-main Kernel Routing Table\n"
16516 "Instance ID/Table ID\n"
16517 "Metric for redistributed routes\n"
16518 "Default metric\n")
7c8ff89e 16519{
585f1adc
IR
16520 VTY_DECLVAR_CONTEXT(bgp, bgp);
16521 int idx_ospf_table = 1;
d62a17ae 16522 int idx_number = 2;
16523 int idx_number_2 = 4;
585f1adc
IR
16524 uint32_t metric;
16525 struct bgp_redist *red;
16526 unsigned short instance;
16527 int protocol;
16528 bool changed;
16529
16530 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16531 protocol = ZEBRA_ROUTE_OSPF;
16532 else
16533 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 16534
585f1adc
IR
16535 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16536 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 16537
585f1adc
IR
16538 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16539 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16540 metric);
16541 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 16542}
16543
16544ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
16545 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
16546 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16547 "Redistribute information from another routing protocol\n"
16548 "Open Shortest Path First (OSPFv2)\n"
16549 "Non-main Kernel Routing Table\n"
16550 "Instance ID/Table ID\n"
16551 "Metric for redistributed routes\n"
16552 "Default metric\n")
596c17ba 16553
585f1adc
IR
16554DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
16555 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
70dd370f 16556 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
585f1adc
IR
16557 "Redistribute information from another routing protocol\n"
16558 "Open Shortest Path First (OSPFv2)\n"
16559 "Non-main Kernel Routing Table\n"
16560 "Instance ID/Table ID\n"
16561 "Route map reference\n"
16562 "Pointer to route-map entries\n"
16563 "Metric for redistributed routes\n"
16564 "Default metric\n")
7c8ff89e 16565{
585f1adc
IR
16566 VTY_DECLVAR_CONTEXT(bgp, bgp);
16567 int idx_ospf_table = 1;
d62a17ae 16568 int idx_number = 2;
16569 int idx_word = 4;
16570 int idx_number_2 = 6;
585f1adc
IR
16571 uint32_t metric;
16572 struct bgp_redist *red;
16573 unsigned short instance;
16574 int protocol;
16575 bool changed;
16576 struct route_map *route_map =
16577 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16578
16579 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16580 protocol = ZEBRA_ROUTE_OSPF;
16581 else
16582 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 16583
585f1adc
IR
16584 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16585 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 16586
585f1adc
IR
16587 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16588 changed =
16589 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16590 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16591 metric);
16592 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 16593}
16594
16595ALIAS_HIDDEN(
16596 bgp_redistribute_ipv4_ospf_rmap_metric,
16597 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
70dd370f 16598 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
d62a17ae 16599 "Redistribute information from another routing protocol\n"
16600 "Open Shortest Path First (OSPFv2)\n"
16601 "Non-main Kernel Routing Table\n"
16602 "Instance ID/Table ID\n"
16603 "Route map reference\n"
16604 "Pointer to route-map entries\n"
16605 "Metric for redistributed routes\n"
16606 "Default metric\n")
596c17ba 16607
585f1adc
IR
16608DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
16609 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
70dd370f 16610 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
585f1adc
IR
16611 "Redistribute information from another routing protocol\n"
16612 "Open Shortest Path First (OSPFv2)\n"
16613 "Non-main Kernel Routing Table\n"
16614 "Instance ID/Table ID\n"
16615 "Metric for redistributed routes\n"
16616 "Default metric\n"
16617 "Route map reference\n"
16618 "Pointer to route-map entries\n")
7c8ff89e 16619{
585f1adc
IR
16620 VTY_DECLVAR_CONTEXT(bgp, bgp);
16621 int idx_ospf_table = 1;
d62a17ae 16622 int idx_number = 2;
16623 int idx_number_2 = 4;
16624 int idx_word = 6;
585f1adc
IR
16625 uint32_t metric;
16626 struct bgp_redist *red;
16627 unsigned short instance;
16628 int protocol;
16629 bool changed;
16630 struct route_map *route_map =
16631 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16632
16633 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16634 protocol = ZEBRA_ROUTE_OSPF;
16635 else
16636 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 16637
585f1adc
IR
16638 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16639 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 16640
585f1adc
IR
16641 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16642 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16643 metric);
16644 changed |=
16645 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16646 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 16647}
16648
16649ALIAS_HIDDEN(
16650 bgp_redistribute_ipv4_ospf_metric_rmap,
16651 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
70dd370f 16652 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
d62a17ae 16653 "Redistribute information from another routing protocol\n"
16654 "Open Shortest Path First (OSPFv2)\n"
16655 "Non-main Kernel Routing Table\n"
16656 "Instance ID/Table ID\n"
16657 "Metric for redistributed routes\n"
16658 "Default metric\n"
16659 "Route map reference\n"
16660 "Pointer to route-map entries\n")
596c17ba 16661
585f1adc
IR
16662DEFUN (no_bgp_redistribute_ipv4_ospf,
16663 no_bgp_redistribute_ipv4_ospf_cmd,
70dd370f 16664 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
585f1adc
IR
16665 NO_STR
16666 "Redistribute information from another routing protocol\n"
16667 "Open Shortest Path First (OSPFv2)\n"
16668 "Non-main Kernel Routing Table\n"
16669 "Instance ID/Table ID\n"
16670 "Metric for redistributed routes\n"
16671 "Default metric\n"
16672 "Route map reference\n"
16673 "Pointer to route-map entries\n")
7c8ff89e 16674{
585f1adc
IR
16675 VTY_DECLVAR_CONTEXT(bgp, bgp);
16676 int idx_ospf_table = 2;
d62a17ae 16677 int idx_number = 3;
585f1adc
IR
16678 unsigned short instance;
16679 int protocol;
37a87b8f 16680
585f1adc
IR
16681 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16682 protocol = ZEBRA_ROUTE_OSPF;
16683 else
16684 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 16685
585f1adc
IR
16686 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16687 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
d62a17ae 16688}
16689
16690ALIAS_HIDDEN(
16691 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
70dd370f 16692 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
d62a17ae 16693 NO_STR
16694 "Redistribute information from another routing protocol\n"
16695 "Open Shortest Path First (OSPFv2)\n"
16696 "Non-main Kernel Routing Table\n"
16697 "Instance ID/Table ID\n"
16698 "Metric for redistributed routes\n"
16699 "Default metric\n"
16700 "Route map reference\n"
16701 "Pointer to route-map entries\n")
596c17ba 16702
585f1adc
IR
16703DEFUN (no_bgp_redistribute_ipv4,
16704 no_bgp_redistribute_ipv4_cmd,
70dd370f 16705 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
585f1adc
IR
16706 NO_STR
16707 "Redistribute information from another routing protocol\n"
16708 FRR_IP_REDIST_HELP_STR_BGPD
16709 "Metric for redistributed routes\n"
16710 "Default metric\n"
16711 "Route map reference\n"
16712 "Pointer to route-map entries\n")
718e3744 16713{
585f1adc 16714 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16715 int idx_protocol = 2;
585f1adc 16716 int type;
d62a17ae 16717
585f1adc
IR
16718 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16719 if (type < 0) {
16720 vty_out(vty, "%% Invalid route type\n");
16721 return CMD_WARNING_CONFIG_FAILED;
16722 }
16723 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
d62a17ae 16724}
16725
16726ALIAS_HIDDEN(
16727 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
16728 "no redistribute " FRR_IP_REDIST_STR_BGPD
70dd370f 16729 " [{metric (0-4294967295)|route-map RMAP_NAME}]",
d62a17ae 16730 NO_STR
16731 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16732 "Metric for redistributed routes\n"
16733 "Default metric\n"
16734 "Route map reference\n"
16735 "Pointer to route-map entries\n")
596c17ba 16736
585f1adc
IR
16737DEFUN (bgp_redistribute_ipv6,
16738 bgp_redistribute_ipv6_cmd,
16739 "redistribute " FRR_IP6_REDIST_STR_BGPD,
16740 "Redistribute information from another routing protocol\n"
16741 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 16742{
585f1adc 16743 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16744 int idx_protocol = 1;
585f1adc 16745 int type;
718e3744 16746
585f1adc
IR
16747 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16748 if (type < 0) {
16749 vty_out(vty, "%% Invalid route type\n");
16750 return CMD_WARNING_CONFIG_FAILED;
16751 }
718e3744 16752
585f1adc
IR
16753 bgp_redist_add(bgp, AFI_IP6, type, 0);
16754 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
718e3744 16755}
16756
585f1adc
IR
16757DEFUN (bgp_redistribute_ipv6_rmap,
16758 bgp_redistribute_ipv6_rmap_cmd,
70dd370f 16759 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME",
585f1adc
IR
16760 "Redistribute information from another routing protocol\n"
16761 FRR_IP6_REDIST_HELP_STR_BGPD
16762 "Route map reference\n"
16763 "Pointer to route-map entries\n")
718e3744 16764{
585f1adc 16765 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16766 int idx_protocol = 1;
16767 int idx_word = 3;
585f1adc
IR
16768 int type;
16769 struct bgp_redist *red;
16770 bool changed;
16771 struct route_map *route_map =
16772 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16773
16774 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16775 if (type < 0) {
16776 vty_out(vty, "%% Invalid route type\n");
16777 return CMD_WARNING_CONFIG_FAILED;
16778 }
37a87b8f 16779
585f1adc
IR
16780 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16781 changed =
16782 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16783 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 16784}
16785
585f1adc 16786DEFUN (bgp_redistribute_ipv6_metric,
718e3744 16787 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 16788 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 16789 "Redistribute information from another routing protocol\n"
ab0181ee 16790 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 16791 "Metric for redistributed routes\n"
16792 "Default metric\n")
16793{
585f1adc 16794 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16795 int idx_protocol = 1;
16796 int idx_number = 3;
585f1adc
IR
16797 int type;
16798 uint32_t metric;
16799 struct bgp_redist *red;
16800 bool changed;
16801
16802 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16803 if (type < 0) {
16804 vty_out(vty, "%% Invalid route type\n");
16805 return CMD_WARNING_CONFIG_FAILED;
16806 }
16807 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 16808
585f1adc
IR
16809 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16810 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
16811 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 16812}
16813
585f1adc
IR
16814DEFUN (bgp_redistribute_ipv6_rmap_metric,
16815 bgp_redistribute_ipv6_rmap_metric_cmd,
70dd370f 16816 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
585f1adc
IR
16817 "Redistribute information from another routing protocol\n"
16818 FRR_IP6_REDIST_HELP_STR_BGPD
16819 "Route map reference\n"
16820 "Pointer to route-map entries\n"
16821 "Metric for redistributed routes\n"
16822 "Default metric\n")
718e3744 16823{
585f1adc 16824 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16825 int idx_protocol = 1;
16826 int idx_word = 3;
16827 int idx_number = 5;
585f1adc
IR
16828 int type;
16829 uint32_t metric;
16830 struct bgp_redist *red;
16831 bool changed;
16832 struct route_map *route_map =
16833 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16834
16835 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16836 if (type < 0) {
16837 vty_out(vty, "%% Invalid route type\n");
16838 return CMD_WARNING_CONFIG_FAILED;
16839 }
16840 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 16841
585f1adc
IR
16842 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16843 changed =
16844 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16845 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
16846 metric);
16847 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 16848}
16849
585f1adc
IR
16850DEFUN (bgp_redistribute_ipv6_metric_rmap,
16851 bgp_redistribute_ipv6_metric_rmap_cmd,
70dd370f 16852 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
585f1adc
IR
16853 "Redistribute information from another routing protocol\n"
16854 FRR_IP6_REDIST_HELP_STR_BGPD
16855 "Metric for redistributed routes\n"
16856 "Default metric\n"
16857 "Route map reference\n"
16858 "Pointer to route-map entries\n")
718e3744 16859{
585f1adc 16860 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16861 int idx_protocol = 1;
37a87b8f 16862 int idx_number = 3;
585f1adc
IR
16863 int idx_word = 5;
16864 int type;
16865 uint32_t metric;
16866 struct bgp_redist *red;
16867 bool changed;
16868 struct route_map *route_map =
16869 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16870
16871 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16872 if (type < 0) {
16873 vty_out(vty, "%% Invalid route type\n");
16874 return CMD_WARNING_CONFIG_FAILED;
16875 }
16876 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 16877
585f1adc
IR
16878 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16879 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
16880 metric);
16881 changed |=
16882 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16883 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 16884}
16885
585f1adc
IR
16886DEFUN (no_bgp_redistribute_ipv6,
16887 no_bgp_redistribute_ipv6_cmd,
70dd370f 16888 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
585f1adc
IR
16889 NO_STR
16890 "Redistribute information from another routing protocol\n"
16891 FRR_IP6_REDIST_HELP_STR_BGPD
16892 "Metric for redistributed routes\n"
16893 "Default metric\n"
16894 "Route map reference\n"
16895 "Pointer to route-map entries\n")
718e3744 16896{
585f1adc 16897 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16898 int idx_protocol = 2;
585f1adc 16899 int type;
37a87b8f 16900
585f1adc
IR
16901 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16902 if (type < 0) {
16903 vty_out(vty, "%% Invalid route type\n");
16904 return CMD_WARNING_CONFIG_FAILED;
16905 }
718e3744 16906
585f1adc 16907 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
d62a17ae 16908}
16909
4ab46701
AR
16910/* Neighbor update tcp-mss. */
16911static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
16912 const char *tcp_mss_str)
16913{
16914 struct peer *peer;
16915 uint32_t tcp_mss_val = 0;
16916
16917 peer = peer_and_group_lookup_vty(vty, peer_str);
16918 if (!peer)
16919 return CMD_WARNING_CONFIG_FAILED;
16920
16921 if (tcp_mss_str) {
16922 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
16923 peer_tcp_mss_set(peer, tcp_mss_val);
16924 } else {
16925 peer_tcp_mss_unset(peer);
16926 }
16927
16928 return CMD_SUCCESS;
16929}
16930
16931DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
16932 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
16933 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16934 "TCP max segment size\n"
16935 "TCP MSS value\n")
16936{
16937 int peer_index = 1;
16938 int mss_index = 3;
16939
16940 vty_out(vty,
16941 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16942 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
16943 argv[mss_index]->arg);
16944}
16945
16946DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
16947 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
16948 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16949 "TCP max segment size\n"
16950 "TCP MSS value\n")
16951{
16952 int peer_index = 2;
16953
16954 vty_out(vty,
16955 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16956 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
16957}
16958
a486300b
PG
16959DEFPY(bgp_retain_route_target, bgp_retain_route_target_cmd,
16960 "[no$no] bgp retain route-target all",
16961 NO_STR BGP_STR
16962 "Retain BGP updates\n"
16963 "Retain BGP updates based on route-target values\n"
16964 "Retain all BGP updates\n")
16965{
16966 bool check;
16967 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
16968
16969 check = CHECK_FLAG(bgp->af_flags[bgp_node_afi(vty)][bgp_node_safi(vty)],
16970 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16971 if (check != !no) {
16972 if (!no)
16973 SET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16974 [bgp_node_safi(vty)],
16975 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16976 else
16977 UNSET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16978 [bgp_node_safi(vty)],
16979 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16980 /* trigger a flush to re-sync with ADJ-RIB-in */
16981 bgp_clear(vty, bgp, bgp_node_afi(vty), bgp_node_safi(vty),
16982 clear_all, BGP_CLEAR_SOFT_IN, NULL);
16983 }
16984 return CMD_SUCCESS;
16985}
16986
dd65f45e
DL
16987static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16988 afi_t afi, safi_t safi)
d62a17ae 16989{
16990 int i;
16991
16992 /* Unicast redistribution only. */
16993 if (safi != SAFI_UNICAST)
2b791107 16994 return;
d62a17ae 16995
16996 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16997 /* Redistribute BGP does not make sense. */
16998 if (i != ZEBRA_ROUTE_BGP) {
16999 struct list *red_list;
17000 struct listnode *node;
17001 struct bgp_redist *red;
17002
17003 red_list = bgp->redist[afi][i];
17004 if (!red_list)
17005 continue;
17006
17007 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 17008 /* "redistribute" configuration. */
17009 vty_out(vty, " redistribute %s",
17010 zebra_route_string(i));
17011 if (red->instance)
17012 vty_out(vty, " %d", red->instance);
17013 if (red->redist_metric_flag)
17014 vty_out(vty, " metric %u",
17015 red->redist_metric);
17016 if (red->rmap.name)
17017 vty_out(vty, " route-map %s",
17018 red->rmap.name);
17019 vty_out(vty, "\n");
17020 }
17021 }
17022 }
718e3744 17023}
6b0655a2 17024
dd65f45e
DL
17025/* peer-group helpers for config-write */
17026
83194f39 17027static bool peergroup_flag_check(struct peer *peer, uint64_t flag)
dd65f45e
DL
17028{
17029 if (!peer_group_active(peer)) {
17030 if (CHECK_FLAG(peer->flags_invert, flag))
17031 return !CHECK_FLAG(peer->flags, flag);
17032 else
17033 return !!CHECK_FLAG(peer->flags, flag);
17034 }
17035
17036 return !!CHECK_FLAG(peer->flags_override, flag);
17037}
17038
17039static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
da5e1a58 17040 uint64_t flag)
dd65f45e
DL
17041{
17042 if (!peer_group_active(peer)) {
17043 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
17044 return !peer_af_flag_check(peer, afi, safi, flag);
17045 else
17046 return !!peer_af_flag_check(peer, afi, safi, flag);
17047 }
17048
17049 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
17050}
17051
17052static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
17053 uint8_t type, int direct)
17054{
17055 struct bgp_filter *filter;
17056
17057 if (peer_group_active(peer))
17058 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
17059 type);
17060
17061 filter = &peer->filter[afi][safi];
17062 switch (type) {
17063 case PEER_FT_DISTRIBUTE_LIST:
17064 return !!(filter->dlist[direct].name);
17065 case PEER_FT_FILTER_LIST:
17066 return !!(filter->aslist[direct].name);
17067 case PEER_FT_PREFIX_LIST:
17068 return !!(filter->plist[direct].name);
17069 case PEER_FT_ROUTE_MAP:
17070 return !!(filter->map[direct].name);
17071 case PEER_FT_UNSUPPRESS_MAP:
17072 return !!(filter->usmap.name);
7f7940e6
MK
17073 case PEER_FT_ADVERTISE_MAP:
17074 return !!(filter->advmap.aname
17075 && ((filter->advmap.condition == direct)
17076 && filter->advmap.cname));
dd65f45e
DL
17077 default:
17078 return false;
17079 }
17080}
17081
17082/* Return true if the addpath type is set for peer and different from
17083 * peer-group.
17084 */
3dc339cd
DA
17085static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
17086 safi_t safi)
dd65f45e
DL
17087{
17088 enum bgp_addpath_strat type, g_type;
17089
17090 type = peer->addpath_type[afi][safi];
17091
17092 if (type != BGP_ADDPATH_NONE) {
17093 if (peer_group_active(peer)) {
17094 g_type = peer->group->conf->addpath_type[afi][safi];
17095
17096 if (type != g_type)
3dc339cd 17097 return true;
dd65f45e 17098 else
3dc339cd 17099 return false;
dd65f45e
DL
17100 }
17101
3dc339cd 17102 return true;
dd65f45e
DL
17103 }
17104
3dc339cd 17105 return false;
dd65f45e
DL
17106}
17107
b9c7bc5a 17108/* This is part of the address-family block (unicast only) */
dd65f45e 17109static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
17110 afi_t afi)
17111{
b9c7bc5a 17112 int indent = 2;
53970de3 17113 uint32_t tovpn_sid_index = 0;
ddb5b488 17114
8a066a70 17115 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
ae6a6fb4
DS
17116 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
17117 BGP_CONFIG_VRF_TO_VRF_IMPORT))
8a066a70
PG
17118 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
17119 bgp->vpn_policy[afi]
bb4f6190 17120 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
17121 else
17122 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
17123 bgp->vpn_policy[afi]
17124 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
17125 }
12a844a5
DS
17126 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
17127 BGP_CONFIG_VRF_TO_VRF_IMPORT)
17128 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
17129 BGP_CONFIG_VRF_TO_VRF_EXPORT))
17130 return;
17131
e70e9f8e
PZ
17132 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17133 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
17134
17135 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
17136
17137 } else {
17138 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
17139 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
17140 bgp->vpn_policy[afi].tovpn_label);
17141 }
ddb5b488 17142 }
53970de3
RS
17143
17144 tovpn_sid_index = bgp->vpn_policy[afi].tovpn_sid_index;
17145 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17146 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
17147 vty_out(vty, "%*ssid vpn export %s\n", indent, "", "auto");
17148 } else if (tovpn_sid_index != 0) {
17149 vty_out(vty, "%*ssid vpn export %d\n", indent, "",
17150 tovpn_sid_index);
17151 }
17152
c4f64ea9
DA
17153 if (CHECK_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_RD_SET))
17154 vty_out(vty, "%*srd vpn export %pRD\n", indent, "",
17155 &bgp->vpn_policy[afi].tovpn_rd);
17156
ddb5b488
PZ
17157 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17158 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
17159
17160 char buf[PREFIX_STRLEN];
17161 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
17162 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
17163 sizeof(buf))) {
17164
b9c7bc5a
PZ
17165 vty_out(vty, "%*snexthop vpn export %s\n",
17166 indent, "", buf);
ddb5b488
PZ
17167 }
17168 }
17169 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
17170 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
17171 && ecommunity_cmp(
17172 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
17173 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
17174
17175 char *b = ecommunity_ecom2str(
17176 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
17177 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 17178 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
17179 XFREE(MTYPE_ECOMMUNITY_STR, b);
17180 } else {
17181 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
17182 char *b = ecommunity_ecom2str(
17183 bgp->vpn_policy[afi]
17184 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
17185 ECOMMUNITY_FORMAT_ROUTE_MAP,
17186 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 17187 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
17188 XFREE(MTYPE_ECOMMUNITY_STR, b);
17189 }
17190 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
17191 char *b = ecommunity_ecom2str(
17192 bgp->vpn_policy[afi]
17193 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
17194 ECOMMUNITY_FORMAT_ROUTE_MAP,
17195 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 17196 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
17197 XFREE(MTYPE_ECOMMUNITY_STR, b);
17198 }
17199 }
bb4f6190
DS
17200
17201 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 17202 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
17203 bgp->vpn_policy[afi]
17204 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 17205
301ad80a
PG
17206 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
17207 char *b = ecommunity_ecom2str(
17208 bgp->vpn_policy[afi]
17209 .import_redirect_rtlist,
17210 ECOMMUNITY_FORMAT_ROUTE_MAP,
17211 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 17212
9a659715
PG
17213 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
17214 != ECOMMUNITY_SIZE)
c6423c31 17215 vty_out(vty, "%*srt6 redirect import %s\n",
9a659715
PG
17216 indent, "", b);
17217 else
17218 vty_out(vty, "%*srt redirect import %s\n",
17219 indent, "", b);
301ad80a
PG
17220 XFREE(MTYPE_ECOMMUNITY_STR, b);
17221 }
ddb5b488
PZ
17222}
17223
dd65f45e
DL
17224static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
17225 afi_t afi, safi_t safi)
17226{
17227 struct bgp_filter *filter;
17228 char *addr;
17229
17230 addr = peer->host;
17231 filter = &peer->filter[afi][safi];
17232
17233 /* distribute-list. */
17234 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
17235 FILTER_IN))
17236 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
17237 filter->dlist[FILTER_IN].name);
17238
17239 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
17240 FILTER_OUT))
17241 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
17242 filter->dlist[FILTER_OUT].name);
17243
17244 /* prefix-list. */
17245 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
17246 FILTER_IN))
17247 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
17248 filter->plist[FILTER_IN].name);
17249
17250 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
17251 FILTER_OUT))
17252 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
17253 filter->plist[FILTER_OUT].name);
17254
17255 /* route-map. */
17256 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
17257 vty_out(vty, " neighbor %s route-map %s in\n", addr,
17258 filter->map[RMAP_IN].name);
17259
17260 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
17261 RMAP_OUT))
17262 vty_out(vty, " neighbor %s route-map %s out\n", addr,
17263 filter->map[RMAP_OUT].name);
17264
17265 /* unsuppress-map */
17266 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
17267 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
17268 filter->usmap.name);
17269
7f7940e6
MK
17270 /* advertise-map : always applied in OUT direction*/
17271 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
17272 CONDITION_NON_EXIST))
17273 vty_out(vty,
17274 " neighbor %s advertise-map %s non-exist-map %s\n",
17275 addr, filter->advmap.aname, filter->advmap.cname);
17276
17277 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
17278 CONDITION_EXIST))
17279 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
17280 addr, filter->advmap.aname, filter->advmap.cname);
17281
dd65f45e
DL
17282 /* filter-list. */
17283 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
17284 FILTER_IN))
17285 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
17286 filter->aslist[FILTER_IN].name);
17287
17288 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
17289 FILTER_OUT))
17290 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
17291 filter->aslist[FILTER_OUT].name);
17292}
17293
17294/* BGP peer configuration display function. */
17295static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
17296 struct peer *peer)
17297{
17298 struct peer *g_peer = NULL;
dd65f45e
DL
17299 char *addr;
17300 int if_pg_printed = false;
17301 int if_ras_printed = false;
17302
17303 /* Skip dynamic neighbors. */
17304 if (peer_dynamic_neighbor(peer))
17305 return;
17306
17307 if (peer->conf_if)
17308 addr = peer->conf_if;
17309 else
17310 addr = peer->host;
17311
17312 /************************************
17313 ****** Global to the neighbor ******
17314 ************************************/
17315 if (peer->conf_if) {
17316 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
17317 vty_out(vty, " neighbor %s interface v6only", addr);
17318 else
17319 vty_out(vty, " neighbor %s interface", addr);
17320
17321 if (peer_group_active(peer)) {
17322 vty_out(vty, " peer-group %s", peer->group->name);
17323 if_pg_printed = true;
17324 } else if (peer->as_type == AS_SPECIFIED) {
de76ed8a 17325 vty_out(vty, " remote-as %s", peer->as_pretty);
dd65f45e
DL
17326 if_ras_printed = true;
17327 } else if (peer->as_type == AS_INTERNAL) {
17328 vty_out(vty, " remote-as internal");
17329 if_ras_printed = true;
17330 } else if (peer->as_type == AS_EXTERNAL) {
17331 vty_out(vty, " remote-as external");
17332 if_ras_printed = true;
17333 }
17334
17335 vty_out(vty, "\n");
17336 }
17337
17338 /* remote-as and peer-group */
17339 /* peer is a member of a peer-group */
17340 if (peer_group_active(peer)) {
17341 g_peer = peer->group->conf;
17342
17343 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
17344 if (peer->as_type == AS_SPECIFIED) {
de76ed8a
PG
17345 vty_out(vty, " neighbor %s remote-as %s\n",
17346 addr, peer->as_pretty);
dd65f45e
DL
17347 } else if (peer->as_type == AS_INTERNAL) {
17348 vty_out(vty,
17349 " neighbor %s remote-as internal\n",
17350 addr);
17351 } else if (peer->as_type == AS_EXTERNAL) {
17352 vty_out(vty,
17353 " neighbor %s remote-as external\n",
17354 addr);
17355 }
17356 }
17357
17358 /* For swpX peers we displayed the peer-group
17359 * via 'neighbor swpX interface peer-group PGNAME' */
17360 if (!if_pg_printed)
17361 vty_out(vty, " neighbor %s peer-group %s\n", addr,
17362 peer->group->name);
17363 }
17364
17365 /* peer is NOT a member of a peer-group */
17366 else {
17367 /* peer is a peer-group, declare the peer-group */
17368 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
17369 vty_out(vty, " neighbor %s peer-group\n", addr);
17370 }
17371
17372 if (!if_ras_printed) {
17373 if (peer->as_type == AS_SPECIFIED) {
de76ed8a
PG
17374 vty_out(vty, " neighbor %s remote-as %s\n",
17375 addr, peer->as_pretty);
dd65f45e
DL
17376 } else if (peer->as_type == AS_INTERNAL) {
17377 vty_out(vty,
17378 " neighbor %s remote-as internal\n",
17379 addr);
17380 } else if (peer->as_type == AS_EXTERNAL) {
17381 vty_out(vty,
17382 " neighbor %s remote-as external\n",
17383 addr);
17384 }
17385 }
17386 }
17387
17388 /* local-as */
17389 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
de76ed8a
PG
17390 vty_out(vty, " neighbor %s local-as %s", addr,
17391 peer->change_local_as_pretty);
dd65f45e
DL
17392 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
17393 vty_out(vty, " no-prepend");
17394 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
17395 vty_out(vty, " replace-as");
17396 vty_out(vty, "\n");
17397 }
17398
17399 /* description */
17400 if (peer->desc) {
17401 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
17402 }
17403
17404 /* shutdown */
17405 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
17406 if (peer->tx_shutdown_message)
17407 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
17408 peer->tx_shutdown_message);
17409 else
17410 vty_out(vty, " neighbor %s shutdown\n", addr);
17411 }
17412
8336c896
DA
17413 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
17414 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
17415 peer->rtt_expected, peer->rtt_keepalive_conf);
17416
dd65f45e 17417 /* bfd */
21bfce98
RZ
17418 if (peer->bfd_config)
17419 bgp_bfd_peer_config_write(vty, peer, addr);
dd65f45e
DL
17420
17421 /* password */
17422 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
17423 vty_out(vty, " neighbor %s password %s\n", addr,
17424 peer->password);
17425
17426 /* neighbor solo */
17427 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
17428 if (!peer_group_active(peer)) {
17429 vty_out(vty, " neighbor %s solo\n", addr);
17430 }
17431 }
17432
17433 /* BGP port */
17434 if (peer->port != BGP_PORT_DEFAULT) {
17435 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
17436 }
17437
17438 /* Local interface name */
17439 if (peer->ifname) {
17440 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
17441 }
17442
4ab46701
AR
17443 /* TCP max segment size */
17444 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
17445 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
17446
dd65f45e
DL
17447 /* passive */
17448 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
17449 vty_out(vty, " neighbor %s passive\n", addr);
17450
17451 /* ebgp-multihop */
17452 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
e2521429
DA
17453 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
17454 && peer->ttl == MAXTTL)) {
dd65f45e
DL
17455 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
17456 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
17457 peer->ttl);
17458 }
17459 }
17460
97a52c82
DA
17461 /* aigp */
17462 if (peergroup_flag_check(peer, PEER_FLAG_AIGP))
17463 vty_out(vty, " neighbor %s aigp\n", addr);
17464
4f770cf1
DA
17465 /* graceful-shutdown */
17466 if (peergroup_flag_check(peer, PEER_FLAG_GRACEFUL_SHUTDOWN))
17467 vty_out(vty, " neighbor %s graceful-shutdown\n", addr);
17468
d864dd9e 17469 /* role */
7dddd1f7
DA
17470 if (peergroup_flag_check(peer, PEER_FLAG_ROLE) &&
17471 peer->local_role != ROLE_UNDEFINED)
d864dd9e 17472 vty_out(vty, " neighbor %s local-role %s%s\n", addr,
8f2d6021 17473 bgp_get_name_by_role(peer->local_role),
7dddd1f7 17474 CHECK_FLAG(peer->flags, PEER_FLAG_ROLE_STRICT_MODE)
d864dd9e
EB
17475 ? " strict-mode"
17476 : "");
d864dd9e 17477
dd65f45e 17478 /* ttl-security hops */
e2521429 17479 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
dd65f45e
DL
17480 if (!peer_group_active(peer)
17481 || g_peer->gtsm_hops != peer->gtsm_hops) {
17482 vty_out(vty, " neighbor %s ttl-security hops %d\n",
17483 addr, peer->gtsm_hops);
17484 }
17485 }
17486
17487 /* disable-connected-check */
17488 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
17489 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
17490
27aa23a4
DA
17491 /* link-bw-encoding-ieee */
17492 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE))
17493 vty_out(vty, " neighbor %s disable-link-bw-encoding-ieee\n",
17494 addr);
17495
d08c0c80
DA
17496 /* extended-optional-parameters */
17497 if (peergroup_flag_check(peer, PEER_FLAG_EXTENDED_OPT_PARAMS))
17498 vty_out(vty, " neighbor %s extended-optional-parameters\n",
17499 addr);
17500
dd65f45e
DL
17501 /* enforce-first-as */
17502 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
17503 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
17504
17505 /* update-source */
17506 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
17507 if (peer->update_source)
47e12884
DA
17508 vty_out(vty, " neighbor %s update-source %pSU\n", addr,
17509 peer->update_source);
dd65f45e
DL
17510 else if (peer->update_if)
17511 vty_out(vty, " neighbor %s update-source %s\n", addr,
17512 peer->update_if);
17513 }
17514
17515 /* advertisement-interval */
17516 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
17517 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
17518 peer->routeadv);
17519
17520 /* timers */
17521 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
17522 vty_out(vty, " neighbor %s timers %u %u\n", addr,
17523 peer->keepalive, peer->holdtime);
17524
17525 /* timers connect */
17526 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
17527 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17528 peer->connect);
5d5393b9
DL
17529 /* need special-case handling for changed default values due to
17530 * config profile / version (because there is no "timers bgp connect"
17531 * command, we need to save this per-peer :/)
17532 */
17533 else if (!peer_group_active(peer) && !peer->connect &&
17534 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
17535 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17536 peer->bgp->default_connect_retry);
dd65f45e 17537
d43114f3
DS
17538 /* timers delayopen */
17539 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
17540 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17541 peer->delayopen);
17542 /* Save config even though flag is not set if default values have been
17543 * changed
17544 */
17545 else if (!peer_group_active(peer) && !peer->delayopen
17546 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
17547 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17548 peer->bgp->default_delayopen);
17549
dd65f45e
DL
17550 /* capability dynamic */
17551 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
17552 vty_out(vty, " neighbor %s capability dynamic\n", addr);
17553
17554 /* capability extended-nexthop */
17555 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
8e89adc1
DS
17556 if (CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE) &&
17557 !peer->conf_if)
843770f6
DA
17558 vty_out(vty,
17559 " no neighbor %s capability extended-nexthop\n",
17560 addr);
17561 else if (!peer->conf_if)
17562 vty_out(vty,
17563 " neighbor %s capability extended-nexthop\n",
17564 addr);
dd65f45e
DL
17565 }
17566
17567 /* dont-capability-negotiation */
17568 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
17569 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
17570
17571 /* override-capability */
17572 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
17573 vty_out(vty, " neighbor %s override-capability\n", addr);
17574
17575 /* strict-capability-match */
17576 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
17577 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
17578
17579 /* Sender side AS path loop detection. */
17580 if (peer->as_path_loop_detection)
17581 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
17582 addr);
cfd47646 17583
a5c6a9b1
DA
17584 /* path-attribute discard */
17585 char discard_attrs_str[BUFSIZ] = {0};
17586 bool discard_attrs = bgp_path_attribute_discard(
17587 peer, discard_attrs_str, sizeof(discard_attrs_str));
17588
17589 if (discard_attrs)
17590 vty_out(vty, " neighbor %s path-attribute discard %s\n", addr,
17591 discard_attrs_str);
17592
cfd47646 17593 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 17594 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
cfd47646 17595
17596 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 17597 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
cfd47646 17598 vty_out(vty,
17599 " neighbor %s graceful-restart-helper\n", addr);
13909c4f
DS
17600 } else if (CHECK_FLAG(
17601 peer->peer_gr_new_status_flag,
17602 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
cfd47646 17603 vty_out(vty,
17604 " neighbor %s graceful-restart\n", addr);
13909c4f
DS
17605 } else if (
17606 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
17607 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
17608 && !(CHECK_FLAG(
17609 peer->peer_gr_new_status_flag,
17610 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
17611 vty_out(vty, " neighbor %s graceful-restart-disable\n",
17612 addr);
cfd47646 17613 }
17614 }
dd65f45e
DL
17615}
17616
17617/* BGP peer configuration display function. */
17618static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
17619 struct peer *peer, afi_t afi, safi_t safi)
17620{
17621 struct peer *g_peer = NULL;
17622 char *addr;
17623 bool flag_scomm, flag_secomm, flag_slcomm;
17624
17625 /* Skip dynamic neighbors. */
17626 if (peer_dynamic_neighbor(peer))
17627 return;
17628
17629 if (peer->conf_if)
17630 addr = peer->conf_if;
17631 else
17632 addr = peer->host;
17633
17634 /************************************
17635 ****** Per AF to the neighbor ******
17636 ************************************/
17637 if (peer_group_active(peer)) {
17638 g_peer = peer->group->conf;
17639
17640 /* If the peer-group is active but peer is not, print a 'no
17641 * activate' */
17642 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
17643 vty_out(vty, " no neighbor %s activate\n", addr);
17644 }
17645
17646 /* If the peer-group is not active but peer is, print an
17647 'activate' */
17648 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
17649 vty_out(vty, " neighbor %s activate\n", addr);
17650 }
17651 } else {
17652 if (peer->afc[afi][safi]) {
38d11af5
TA
17653 if (safi == SAFI_ENCAP)
17654 vty_out(vty, " neighbor %s activate\n", addr);
17655 else if (!bgp->default_af[afi][safi])
dd65f45e
DL
17656 vty_out(vty, " neighbor %s activate\n", addr);
17657 } else {
38d11af5
TA
17658 if (bgp->default_af[afi][safi])
17659 vty_out(vty, " no neighbor %s activate\n",
17660 addr);
dd65f45e
DL
17661 }
17662 }
17663
17664 /* addpath TX knobs */
17665 if (peergroup_af_addpath_check(peer, afi, safi)) {
17666 switch (peer->addpath_type[afi][safi]) {
17667 case BGP_ADDPATH_ALL:
17668 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
17669 addr);
17670 break;
17671 case BGP_ADDPATH_BEST_PER_AS:
17672 vty_out(vty,
17673 " neighbor %s addpath-tx-bestpath-per-AS\n",
17674 addr);
17675 break;
17676 case BGP_ADDPATH_MAX:
17677 case BGP_ADDPATH_NONE:
17678 break;
17679 }
17680 }
17681
7c0e4312
DA
17682 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DISABLE_ADDPATH_RX))
17683 vty_out(vty, " neighbor %s disable-addpath-rx\n", addr);
17684
dd65f45e
DL
17685 /* ORF capability. */
17686 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
17687 || peergroup_af_flag_check(peer, afi, safi,
17688 PEER_FLAG_ORF_PREFIX_RM)) {
17689 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
17690
17691 if (peergroup_af_flag_check(peer, afi, safi,
17692 PEER_FLAG_ORF_PREFIX_SM)
17693 && peergroup_af_flag_check(peer, afi, safi,
17694 PEER_FLAG_ORF_PREFIX_RM))
17695 vty_out(vty, " both");
17696 else if (peergroup_af_flag_check(peer, afi, safi,
17697 PEER_FLAG_ORF_PREFIX_SM))
17698 vty_out(vty, " send");
17699 else
17700 vty_out(vty, " receive");
17701 vty_out(vty, "\n");
17702 }
17703
dd65f45e
DL
17704 /* Route reflector client. */
17705 if (peergroup_af_flag_check(peer, afi, safi,
17706 PEER_FLAG_REFLECTOR_CLIENT)) {
17707 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
17708 }
17709
17710 /* next-hop-self force */
17711 if (peergroup_af_flag_check(peer, afi, safi,
17712 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
17713 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
17714 }
17715
17716 /* next-hop-self */
17717 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
17718 vty_out(vty, " neighbor %s next-hop-self\n", addr);
17719 }
17720
17721 /* remove-private-AS */
17722 if (peergroup_af_flag_check(peer, afi, safi,
17723 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
17724 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
17725 addr);
17726 }
17727
17728 else if (peergroup_af_flag_check(peer, afi, safi,
17729 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
17730 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
17731 addr);
17732 }
17733
17734 else if (peergroup_af_flag_check(peer, afi, safi,
17735 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
17736 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
17737 }
17738
17739 else if (peergroup_af_flag_check(peer, afi, safi,
17740 PEER_FLAG_REMOVE_PRIVATE_AS)) {
17741 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
17742 }
17743
17744 /* as-override */
17745 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
17746 vty_out(vty, " neighbor %s as-override\n", addr);
17747 }
17748
17749 /* send-community print. */
17750 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
17751 PEER_FLAG_SEND_COMMUNITY);
17752 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
17753 PEER_FLAG_SEND_EXT_COMMUNITY);
17754 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
17755 PEER_FLAG_SEND_LARGE_COMMUNITY);
17756
17757 if (flag_scomm && flag_secomm && flag_slcomm) {
17758 vty_out(vty, " no neighbor %s send-community all\n", addr);
17759 } else {
17760 if (flag_scomm)
17761 vty_out(vty, " no neighbor %s send-community\n", addr);
17762 if (flag_secomm)
17763 vty_out(vty,
17764 " no neighbor %s send-community extended\n",
17765 addr);
17766
17767 if (flag_slcomm)
17768 vty_out(vty, " no neighbor %s send-community large\n",
17769 addr);
17770 }
17771
17772 /* Default information */
17773 if (peergroup_af_flag_check(peer, afi, safi,
17774 PEER_FLAG_DEFAULT_ORIGINATE)) {
17775 vty_out(vty, " neighbor %s default-originate", addr);
17776
17777 if (peer->default_rmap[afi][safi].name)
17778 vty_out(vty, " route-map %s",
17779 peer->default_rmap[afi][safi].name);
17780
17781 vty_out(vty, "\n");
17782 }
17783
17784 /* Soft reconfiguration inbound. */
17785 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
17786 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
17787 addr);
17788 }
17789
17790 /* maximum-prefix. */
17791 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
6cde4b45 17792 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
dd65f45e
DL
17793 peer->pmax[afi][safi]);
17794
17795 if (peer->pmax_threshold[afi][safi]
17796 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
17797 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
17798 if (peer_af_flag_check(peer, afi, safi,
17799 PEER_FLAG_MAX_PREFIX_WARNING))
17800 vty_out(vty, " warning-only");
17801 if (peer->pmax_restart[afi][safi])
17802 vty_out(vty, " restart %u",
17803 peer->pmax_restart[afi][safi]);
9cbd06e0
DA
17804 if (peer_af_flag_check(peer, afi, safi,
17805 PEER_FLAG_MAX_PREFIX_FORCE))
17806 vty_out(vty, " force");
dd65f45e
DL
17807
17808 vty_out(vty, "\n");
17809 }
17810
fde246e8
DA
17811 /* maximum-prefix-out */
17812 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
6cde4b45 17813 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
fde246e8
DA
17814 addr, peer->pmax_out[afi][safi]);
17815
dd65f45e
DL
17816 /* Route server client. */
17817 if (peergroup_af_flag_check(peer, afi, safi,
17818 PEER_FLAG_RSERVER_CLIENT)) {
17819 vty_out(vty, " neighbor %s route-server-client\n", addr);
17820 }
17821
17822 /* Nexthop-local unchanged. */
17823 if (peergroup_af_flag_check(peer, afi, safi,
17824 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
17825 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
17826 }
17827
17828 /* allowas-in <1-10> */
17829 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
17830 if (peer_af_flag_check(peer, afi, safi,
17831 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
17832 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
17833 } else if (peer->allowas_in[afi][safi] == 3) {
17834 vty_out(vty, " neighbor %s allowas-in\n", addr);
17835 } else {
17836 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
17837 peer->allowas_in[afi][safi]);
17838 }
17839 }
17840
46dbf9d0
DA
17841 /* accept-own */
17842 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ACCEPT_OWN))
17843 vty_out(vty, " neighbor %s accept-own\n", addr);
17844
01da2d26
DA
17845 /* soo */
17846 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOO)) {
17847 char *soo_str = ecommunity_ecom2str(
17848 peer->soo[afi][safi], ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
17849
17850 vty_out(vty, " neighbor %s soo %s\n", addr, soo_str);
17851 XFREE(MTYPE_ECOMMUNITY_STR, soo_str);
17852 }
17853
dd65f45e
DL
17854 /* weight */
17855 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
17856 vty_out(vty, " neighbor %s weight %lu\n", addr,
17857 peer->weight[afi][safi]);
17858
17859 /* Filter. */
17860 bgp_config_write_filter(vty, peer, afi, safi);
17861
17862 /* atribute-unchanged. */
17863 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
17864 || (safi != SAFI_EVPN
17865 && peer_af_flag_check(peer, afi, safi,
17866 PEER_FLAG_NEXTHOP_UNCHANGED))
17867 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
17868
17869 if (!peer_group_active(peer)
17870 || peergroup_af_flag_check(peer, afi, safi,
17871 PEER_FLAG_AS_PATH_UNCHANGED)
17872 || peergroup_af_flag_check(peer, afi, safi,
17873 PEER_FLAG_NEXTHOP_UNCHANGED)
17874 || peergroup_af_flag_check(peer, afi, safi,
17875 PEER_FLAG_MED_UNCHANGED)) {
17876
17877 vty_out(vty,
17878 " neighbor %s attribute-unchanged%s%s%s\n",
17879 addr,
17880 peer_af_flag_check(peer, afi, safi,
17881 PEER_FLAG_AS_PATH_UNCHANGED)
17882 ? " as-path"
17883 : "",
17884 peer_af_flag_check(peer, afi, safi,
17885 PEER_FLAG_NEXTHOP_UNCHANGED)
17886 ? " next-hop"
17887 : "",
17888 peer_af_flag_check(peer, afi, safi,
17889 PEER_FLAG_MED_UNCHANGED)
17890 ? " med"
17891 : "");
17892 }
17893 }
17894}
17895
a486300b
PG
17896static void bgp_vpn_config_write(struct vty *vty, struct bgp *bgp, afi_t afi,
17897 safi_t safi)
17898{
17899 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
17900 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL))
17901 vty_out(vty, " no bgp retain route-target all\n");
17902}
17903
dd65f45e
DL
17904/* Address family based peer configuration display. */
17905static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
17906 safi_t safi)
17907{
17908 struct peer *peer;
17909 struct peer_group *group;
17910 struct listnode *node, *nnode;
17911
17912
17913 vty_frame(vty, " !\n address-family ");
17914 if (afi == AFI_IP) {
17915 if (safi == SAFI_UNICAST)
17916 vty_frame(vty, "ipv4 unicast");
17917 else if (safi == SAFI_LABELED_UNICAST)
17918 vty_frame(vty, "ipv4 labeled-unicast");
17919 else if (safi == SAFI_MULTICAST)
17920 vty_frame(vty, "ipv4 multicast");
17921 else if (safi == SAFI_MPLS_VPN)
17922 vty_frame(vty, "ipv4 vpn");
17923 else if (safi == SAFI_ENCAP)
17924 vty_frame(vty, "ipv4 encap");
17925 else if (safi == SAFI_FLOWSPEC)
17926 vty_frame(vty, "ipv4 flowspec");
17927 } else if (afi == AFI_IP6) {
17928 if (safi == SAFI_UNICAST)
17929 vty_frame(vty, "ipv6 unicast");
17930 else if (safi == SAFI_LABELED_UNICAST)
17931 vty_frame(vty, "ipv6 labeled-unicast");
17932 else if (safi == SAFI_MULTICAST)
17933 vty_frame(vty, "ipv6 multicast");
17934 else if (safi == SAFI_MPLS_VPN)
17935 vty_frame(vty, "ipv6 vpn");
17936 else if (safi == SAFI_ENCAP)
17937 vty_frame(vty, "ipv6 encap");
17938 else if (safi == SAFI_FLOWSPEC)
17939 vty_frame(vty, "ipv6 flowspec");
17940 } else if (afi == AFI_L2VPN) {
17941 if (safi == SAFI_EVPN)
17942 vty_frame(vty, "l2vpn evpn");
17943 }
17944 vty_frame(vty, "\n");
17945
17946 bgp_config_write_distance(vty, bgp, afi, safi);
17947
17948 bgp_config_write_network(vty, bgp, afi, safi);
17949
17950 bgp_config_write_redistribute(vty, bgp, afi, safi);
17951
8a4e7fe6
DA
17952 /* BGP flag dampening. */
17953 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
6c75f4b3 17954 bgp_config_write_damp(vty, afi, safi);
8a4e7fe6 17955
dd65f45e
DL
17956 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
17957 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
17958
17959 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dd65f45e
DL
17960 /* Do not display doppelganger peers */
17961 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17962 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
17963 }
17964
17965 bgp_config_write_maxpaths(vty, bgp, afi, safi);
17966 bgp_config_write_table_map(vty, bgp, afi, safi);
17967
17968 if (safi == SAFI_EVPN)
17969 bgp_config_write_evpn_info(vty, bgp, afi, safi);
17970
17971 if (safi == SAFI_FLOWSPEC)
17972 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
17973
a486300b
PG
17974 if (safi == SAFI_MPLS_VPN)
17975 bgp_vpn_config_write(vty, bgp, afi, safi);
17976
dd65f45e
DL
17977 if (safi == SAFI_UNICAST) {
17978 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
17979 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17980 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
17981
17982 vty_out(vty, " export vpn\n");
17983 }
17984 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17985 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
17986
17987 vty_out(vty, " import vpn\n");
17988 }
17989 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17990 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
17991 char *name;
17992
17993 for (ALL_LIST_ELEMENTS_RO(
17994 bgp->vpn_policy[afi].import_vrf, node,
17995 name))
17996 vty_out(vty, " import vrf %s\n", name);
17997 }
17998 }
17999
18000 vty_endframe(vty, " exit-address-family\n");
18001}
18002
18003int bgp_config_write(struct vty *vty)
18004{
18005 struct bgp *bgp;
18006 struct peer_group *group;
18007 struct peer *peer;
18008 struct listnode *node, *nnode;
18009 struct listnode *mnode, *mnnode;
b16bcbba
TA
18010 afi_t afi;
18011 safi_t safi;
efc9b57d 18012 uint32_t tovpn_sid_index = 0;
dd65f45e
DL
18013
18014 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
18015 vty_out(vty, "bgp route-map delay-timer %u\n",
18016 bm->rmap_update_timer);
18017
d70583f7
D
18018 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
18019 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
18020 if (bm->v_update_delay != bm->v_establish_wait)
18021 vty_out(vty, " %d", bm->v_establish_wait);
18022 vty_out(vty, "\n");
18023 }
18024
9acb67cb
DS
18025 if (bm->wait_for_fib)
18026 vty_out(vty, "bgp suppress-fib-pending\n");
18027
05bd726c 18028 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
18029 vty_out(vty, "bgp graceful-shutdown\n");
18030
c163f297
DS
18031 /* No-RIB (Zebra) option flag configuration */
18032 if (bgp_option_check(BGP_OPT_NO_FIB))
18033 vty_out(vty, "bgp no-rib\n");
18034
870791a3
IR
18035 if (CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
18036 vty_out(vty, "bgp send-extra-data zebra\n");
e46723a5 18037
425bd64b
PS
18038 /* BGP session DSCP value */
18039 if (bm->tcp_dscp != IPTOS_PREC_INTERNETCONTROL)
18040 vty_out(vty, "bgp session-dscp %u\n", bm->tcp_dscp >> 2);
18041
a0b937de 18042 /* BGP InQ limit */
963b7ee4 18043 if (bm->inq_limit != BM_DEFAULT_Q_LIMIT)
a0b937de
SW
18044 vty_out(vty, "bgp input-queue-limit %u\n", bm->inq_limit);
18045
963b7ee4
DS
18046 if (bm->outq_limit != BM_DEFAULT_Q_LIMIT)
18047 vty_out(vty, "bgp output-queue-limit %u\n", bm->outq_limit);
18048
dd65f45e
DL
18049 /* BGP configuration. */
18050 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
18051
18052 /* skip all auto created vrf as they dont have user config */
18053 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
18054 continue;
18055
18056 /* Router bgp ASN */
9eb11997 18057 vty_out(vty, "router bgp %s", bgp->as_pretty);
dd65f45e
DL
18058
18059 if (bgp->name)
18060 vty_out(vty, " %s %s",
18061 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
18062 ? "view" : "vrf", bgp->name);
e55b0883
PG
18063 if (CHECK_FLAG(bgp->config, BGP_CONFIG_ASNOTATION))
18064 vty_out(vty, " as-notation %s",
18065 asn_mode2str(bgp->asnotation));
18066
dd65f45e
DL
18067 vty_out(vty, "\n");
18068
18069 /* BGP fast-external-failover. */
18070 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
18071 vty_out(vty, " no bgp fast-external-failover\n");
18072
18073 /* BGP router ID. */
3a6290bd 18074 if (bgp->router_id_static.s_addr != INADDR_ANY)
23d0a753
DA
18075 vty_out(vty, " bgp router-id %pI4\n",
18076 &bgp->router_id_static);
dd65f45e 18077
c208c586
S
18078 /* Suppress fib pending */
18079 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
18080 vty_out(vty, " bgp suppress-fib-pending\n");
18081
dd65f45e 18082 /* BGP log-neighbor-changes. */
892fedb6 18083 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
5d5393b9 18084 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
dd65f45e 18085 vty_out(vty, " %sbgp log-neighbor-changes\n",
892fedb6
DA
18086 CHECK_FLAG(bgp->flags,
18087 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
dd65f45e
DL
18088 ? ""
18089 : "no ");
18090
18091 /* BGP configuration. */
892fedb6 18092 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
dd65f45e
DL
18093 vty_out(vty, " bgp always-compare-med\n");
18094
18095 /* RFC8212 default eBGP policy. */
1d3fdccf
DA
18096 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
18097 != SAVE_BGP_EBGP_REQUIRES_POLICY)
18098 vty_out(vty, " %sbgp ebgp-requires-policy\n",
18099 CHECK_FLAG(bgp->flags,
18100 BGP_FLAG_EBGP_REQUIRES_POLICY)
18101 ? ""
18102 : "no ");
dd65f45e
DL
18103
18104 /* draft-ietf-idr-deprecate-as-set-confed-set */
7f972cd8 18105 if (bgp->reject_as_sets)
dd65f45e
DL
18106 vty_out(vty, " bgp reject-as-sets\n");
18107
2adac256
DA
18108 /* Suppress duplicate updates if the route actually not changed
18109 */
18110 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
18111 != SAVE_BGP_SUPPRESS_DUPLICATES)
18112 vty_out(vty, " %sbgp suppress-duplicates\n",
18113 CHECK_FLAG(bgp->flags,
18114 BGP_FLAG_SUPPRESS_DUPLICATES)
18115 ? ""
18116 : "no ");
18117
1ae314be
DA
18118 /* Send Hard Reset CEASE Notification for 'Administrative Reset'
18119 */
18120 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET) !=
18121 SAVE_BGP_HARD_ADMIN_RESET)
18122 vty_out(vty, " %sbgp hard-administrative-reset\n",
18123 CHECK_FLAG(bgp->flags,
18124 BGP_FLAG_HARD_ADMIN_RESET)
18125 ? ""
18126 : "no ");
18127
b16bcbba
TA
18128 /* BGP default <afi>-<safi> */
18129 FOREACH_AFI_SAFI (afi, safi) {
18130 if (afi == AFI_IP && safi == SAFI_UNICAST) {
18131 if (!bgp->default_af[afi][safi])
18132 vty_out(vty, " no bgp default %s\n",
18133 get_bgp_default_af_flag(afi,
18134 safi));
18135 } else if (bgp->default_af[afi][safi])
18136 vty_out(vty, " bgp default %s\n",
18137 get_bgp_default_af_flag(afi, safi));
18138 }
e84c59af 18139
dd65f45e
DL
18140 /* BGP default local-preference. */
18141 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
18142 vty_out(vty, " bgp default local-preference %u\n",
18143 bgp->default_local_pref);
18144
18145 /* BGP default show-hostname */
892fedb6 18146 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
5d5393b9 18147 != SAVE_BGP_SHOW_HOSTNAME)
dd65f45e 18148 vty_out(vty, " %sbgp default show-hostname\n",
892fedb6 18149 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
dd65f45e
DL
18150 ? ""
18151 : "no ");
18152
aef999a2
DA
18153 /* BGP default show-nexthop-hostname */
18154 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
18155 != SAVE_BGP_SHOW_HOSTNAME)
18156 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
18157 CHECK_FLAG(bgp->flags,
18158 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
18159 ? ""
18160 : "no ");
18161
dd65f45e
DL
18162 /* BGP default subgroup-pkt-queue-max. */
18163 if (bgp->default_subgroup_pkt_queue_max
18164 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
18165 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
18166 bgp->default_subgroup_pkt_queue_max);
18167
18168 /* BGP client-to-client reflection. */
892fedb6 18169 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
dd65f45e
DL
18170 vty_out(vty, " no bgp client-to-client reflection\n");
18171
18172 /* BGP cluster ID. */
18173 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
23d0a753
DA
18174 vty_out(vty, " bgp cluster-id %pI4\n",
18175 &bgp->cluster_id);
dd65f45e
DL
18176
18177 /* Disable ebgp connected nexthop check */
892fedb6 18178 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
dd65f45e
DL
18179 vty_out(vty,
18180 " bgp disable-ebgp-connected-route-check\n");
18181
18182 /* Confederation identifier*/
18183 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
7e14d0fa
PG
18184 vty_out(vty, " bgp confederation identifier %s\n",
18185 bgp->confed_id_pretty);
dd65f45e
DL
18186
18187 /* Confederation peer */
18188 if (bgp->confed_peers_cnt > 0) {
18189 int i;
18190
18191 vty_out(vty, " bgp confederation peers");
18192
18193 for (i = 0; i < bgp->confed_peers_cnt; i++)
7e14d0fa
PG
18194 vty_out(vty, " %s",
18195 bgp->confed_peers[i].as_pretty);
dd65f45e
DL
18196
18197 vty_out(vty, "\n");
18198 }
18199
18200 /* BGP deterministic-med. */
892fedb6 18201 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
5d5393b9 18202 != SAVE_BGP_DETERMINISTIC_MED)
dd65f45e 18203 vty_out(vty, " %sbgp deterministic-med\n",
892fedb6
DA
18204 CHECK_FLAG(bgp->flags,
18205 BGP_FLAG_DETERMINISTIC_MED)
dd65f45e
DL
18206 ? ""
18207 : "no ");
18208
18209 /* BGP update-delay. */
18210 bgp_config_write_update_delay(vty, bgp);
18211
18212 if (bgp->v_maxmed_onstartup
18213 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
18214 vty_out(vty, " bgp max-med on-startup %u",
18215 bgp->v_maxmed_onstartup);
18216 if (bgp->maxmed_onstartup_value
18217 != BGP_MAXMED_VALUE_DEFAULT)
18218 vty_out(vty, " %u",
18219 bgp->maxmed_onstartup_value);
18220 vty_out(vty, "\n");
18221 }
18222 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
18223 vty_out(vty, " bgp max-med administrative");
18224 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
18225 vty_out(vty, " %u", bgp->maxmed_admin_value);
18226 vty_out(vty, "\n");
18227 }
18228
18229 /* write quanta */
18230 bgp_config_write_wpkt_quanta(vty, bgp);
18231 /* read quanta */
18232 bgp_config_write_rpkt_quanta(vty, bgp);
18233
18234 /* coalesce time */
18235 bgp_config_write_coalesce_time(vty, bgp);
18236
05bd726c 18237 /* BGP per-instance graceful-shutdown */
18238 /* BGP-wide settings and per-instance settings are mutually
18239 * exclusive.
18240 */
18241 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
18242 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
18243 vty_out(vty, " bgp graceful-shutdown\n");
18244
8606be87
DA
18245 /* Long-lived Graceful Restart */
18246 if (bgp->llgr_stale_time != BGP_DEFAULT_LLGR_STALE_TIME)
18247 vty_out(vty,
18248 " bgp long-lived-graceful-restart stale-time %u\n",
18249 bgp->llgr_stale_time);
18250
dd65f45e
DL
18251 /* BGP graceful-restart. */
18252 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
18253 vty_out(vty,
18254 " bgp graceful-restart stalepath-time %u\n",
18255 bgp->stalepath_time);
cfd47646 18256
dd65f45e
DL
18257 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
18258 vty_out(vty, " bgp graceful-restart restart-time %u\n",
18259 bgp->restart_time);
cfd47646 18260
f2ca5c5b
DA
18261 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION) !=
18262 SAVE_BGP_GRACEFUL_NOTIFICATION)
18263 vty_out(vty, " %sbgp graceful-restart notification\n",
18264 CHECK_FLAG(bgp->flags,
18265 BGP_FLAG_GRACEFUL_NOTIFICATION)
18266 ? ""
18267 : "no ");
18268
cfd47646 18269 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
18270 vty_out(vty,
18271 " bgp graceful-restart select-defer-time %u\n",
18272 bgp->select_defer_time);
18273
18274 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
dd65f45e
DL
18275 vty_out(vty, " bgp graceful-restart\n");
18276
cfd47646 18277 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
18278 vty_out(vty, " bgp graceful-restart-disable\n");
18279
dd65f45e 18280 /* BGP graceful-restart Preserve State F bit. */
892fedb6 18281 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
dd65f45e
DL
18282 vty_out(vty,
18283 " bgp graceful-restart preserve-fw-state\n");
18284
d1adb448
PG
18285 /* BGP TCP keepalive */
18286 bgp_config_tcp_keepalive(vty, bgp);
18287
dc95985f 18288 /* Stale timer for RIB */
18289 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
18290 vty_out(vty,
18291 " bgp graceful-restart rib-stale-time %u\n",
18292 bgp->rib_stale_time);
18293
dd65f45e 18294 /* BGP bestpath method. */
892fedb6 18295 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
dd65f45e 18296 vty_out(vty, " bgp bestpath as-path ignore\n");
892fedb6 18297 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
dd65f45e
DL
18298 vty_out(vty, " bgp bestpath as-path confed\n");
18299
892fedb6
DA
18300 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
18301 if (CHECK_FLAG(bgp->flags,
18302 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
dd65f45e
DL
18303 vty_out(vty,
18304 " bgp bestpath as-path multipath-relax as-set\n");
18305 } else {
18306 vty_out(vty,
18307 " bgp bestpath as-path multipath-relax\n");
18308 }
18309 }
18310
892fedb6 18311 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
dd65f45e
DL
18312 vty_out(vty,
18313 " bgp route-reflector allow-outbound-policy\n");
18314 }
892fedb6 18315 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
dd65f45e 18316 vty_out(vty, " bgp bestpath compare-routerid\n");
97a52c82
DA
18317 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_AIGP))
18318 vty_out(vty, " bgp bestpath aigp\n");
892fedb6
DA
18319 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
18320 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
dd65f45e 18321 vty_out(vty, " bgp bestpath med");
892fedb6 18322 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
dd65f45e 18323 vty_out(vty, " confed");
892fedb6
DA
18324 if (CHECK_FLAG(bgp->flags,
18325 BGP_FLAG_MED_MISSING_AS_WORST))
dd65f45e
DL
18326 vty_out(vty, " missing-as-worst");
18327 vty_out(vty, "\n");
18328 }
18329
ee88563a
JM
18330 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
18331 vty_out(vty,
18332 " bgp bestpath peer-type multipath-relax\n");
18333
f7e1c681 18334 /* Link bandwidth handling. */
18335 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
18336 vty_out(vty, " bgp bestpath bandwidth ignore\n");
18337 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
18338 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
18339 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
18340 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
18341
dd65f45e 18342 /* BGP network import check. */
892fedb6 18343 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
5d5393b9 18344 != SAVE_BGP_IMPORT_CHECK)
dd65f45e 18345 vty_out(vty, " %sbgp network import-check\n",
892fedb6 18346 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
dd65f45e
DL
18347 ? ""
18348 : "no ");
18349
18350 /* BGP timers configuration. */
5d5393b9 18351 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
9800cfff 18352 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
dd65f45e
DL
18353 vty_out(vty, " timers bgp %u %u\n",
18354 bgp->default_keepalive, bgp->default_holdtime);
18355
b042667a
TI
18356 /* BGP minimum holdtime configuration. */
18357 if (bgp->default_min_holdtime != SAVE_BGP_HOLDTIME
18358 && bgp->default_min_holdtime != 0)
18359 vty_out(vty, " bgp minimum-holdtime %u\n",
18360 bgp->default_min_holdtime);
18361
389e4f92
QY
18362 /* Conditional advertisement timer configuration */
18363 if (bgp->condition_check_period
18364 != DEFAULT_CONDITIONAL_ROUTES_POLL_TIME)
18365 vty_out(vty,
18366 " bgp conditional-advertisement timer %u\n",
18367 bgp->condition_check_period);
18368
dd65f45e
DL
18369 /* peer-group */
18370 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
18371 bgp_config_write_peer_global(vty, bgp, group->conf);
18372 }
18373
18374 /* Normal neighbor configuration. */
18375 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
18376 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
18377 bgp_config_write_peer_global(vty, bgp, peer);
18378 }
18379
18380 /* listen range and limit for dynamic BGP neighbors */
18381 bgp_config_write_listen(vty, bgp);
18382
18383 /*
18384 * BGP default autoshutdown neighbors
18385 *
18386 * This must be placed after any peer and peer-group
18387 * configuration, to avoid setting all peers to shutdown after
18388 * a daemon restart, which is undesired behavior. (see #2286)
18389 */
18390 if (bgp->autoshutdown)
18391 vty_out(vty, " bgp default shutdown\n");
18392
9cf59432
DS
18393 /* BGP instance administrative shutdown */
18394 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
18395 vty_out(vty, " bgp shutdown\n");
18396
8666265e
DS
18397 if (bgp->allow_martian)
18398 vty_out(vty, " bgp allow-martian-nexthop\n");
18399
f852eb98
PG
18400 if (bgp->fast_convergence)
18401 vty_out(vty, " bgp fast-convergence\n");
18402
a0281b2e
HS
18403 if (bgp->srv6_enabled) {
18404 vty_frame(vty, " !\n segment-routing srv6\n");
96db4340 18405 if (strlen(bgp->srv6_locator_name))
a0281b2e
HS
18406 vty_out(vty, " locator %s\n",
18407 bgp->srv6_locator_name);
ff7c3ee1 18408 vty_endframe(vty, " exit\n");
a0281b2e
HS
18409 }
18410
efc9b57d
CS
18411 tovpn_sid_index = bgp->tovpn_sid_index;
18412 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)) {
18413 vty_out(vty, " sid vpn per-vrf export auto\n");
18414 } else if (tovpn_sid_index != 0) {
18415 vty_out(vty, " sid vpn per-vrf export %d\n",
18416 tovpn_sid_index);
18417 }
a0281b2e 18418
dd65f45e
DL
18419 /* IPv4 unicast configuration. */
18420 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
18421
18422 /* IPv4 multicast configuration. */
18423 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
18424
18425 /* IPv4 labeled-unicast configuration. */
18426 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
18427
18428 /* IPv4 VPN configuration. */
18429 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
18430
18431 /* ENCAPv4 configuration. */
18432 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
18433
18434 /* FLOWSPEC v4 configuration. */
18435 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
18436
18437 /* IPv6 unicast configuration. */
18438 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
18439
18440 /* IPv6 multicast configuration. */
18441 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
18442
18443 /* IPv6 labeled-unicast configuration. */
18444 bgp_config_write_family(vty, bgp, AFI_IP6,
18445 SAFI_LABELED_UNICAST);
18446
18447 /* IPv6 VPN configuration. */
18448 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
18449
18450 /* ENCAPv6 configuration. */
18451 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
18452
18453 /* FLOWSPEC v6 configuration. */
18454 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
18455
18456 /* EVPN configuration. */
18457 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
18458
18459 hook_call(bgp_inst_config_write, bgp, vty);
18460
49e5a4a0 18461#ifdef ENABLE_BGP_VNC
dd65f45e
DL
18462 bgp_rfapi_cfg_write(vty, bgp);
18463#endif
18464
07679ad9 18465 vty_out(vty, "exit\n");
dd65f45e
DL
18466 vty_out(vty, "!\n");
18467 }
18468 return 0;
18469}
18470
ddb5b488 18471
718e3744 18472/* BGP node structure. */
d62a17ae 18473static struct cmd_node bgp_node = {
f4b8291f 18474 .name = "bgp",
62b346ee 18475 .node = BGP_NODE,
24389580 18476 .parent_node = CONFIG_NODE,
62b346ee 18477 .prompt = "%s(config-router)# ",
612c2c15 18478 .config_write = bgp_config_write,
718e3744 18479};
18480
d62a17ae 18481static struct cmd_node bgp_ipv4_unicast_node = {
f4b8291f 18482 .name = "bgp ipv4 unicast",
62b346ee 18483 .node = BGP_IPV4_NODE,
24389580 18484 .parent_node = BGP_NODE,
62b346ee 18485 .prompt = "%s(config-router-af)# ",
dd2c81b8 18486 .no_xpath = true,
718e3744 18487};
18488
d62a17ae 18489static struct cmd_node bgp_ipv4_multicast_node = {
f4b8291f 18490 .name = "bgp ipv4 multicast",
62b346ee 18491 .node = BGP_IPV4M_NODE,
24389580 18492 .parent_node = BGP_NODE,
62b346ee 18493 .prompt = "%s(config-router-af)# ",
dd2c81b8 18494 .no_xpath = true,
718e3744 18495};
18496
d62a17ae 18497static struct cmd_node bgp_ipv4_labeled_unicast_node = {
f4b8291f 18498 .name = "bgp ipv4 labeled unicast",
62b346ee 18499 .node = BGP_IPV4L_NODE,
24389580 18500 .parent_node = BGP_NODE,
62b346ee 18501 .prompt = "%s(config-router-af)# ",
dd2c81b8 18502 .no_xpath = true,
f51bae9c
DS
18503};
18504
d62a17ae 18505static struct cmd_node bgp_ipv6_unicast_node = {
a17cfb3f 18506 .name = "bgp ipv6 unicast",
62b346ee 18507 .node = BGP_IPV6_NODE,
24389580 18508 .parent_node = BGP_NODE,
62b346ee 18509 .prompt = "%s(config-router-af)# ",
dd2c81b8 18510 .no_xpath = true,
718e3744 18511};
18512
d62a17ae 18513static struct cmd_node bgp_ipv6_multicast_node = {
f4b8291f 18514 .name = "bgp ipv6 multicast",
62b346ee 18515 .node = BGP_IPV6M_NODE,
24389580 18516 .parent_node = BGP_NODE,
62b346ee 18517 .prompt = "%s(config-router-af)# ",
dd2c81b8 18518 .no_xpath = true,
25ffbdc1 18519};
18520
d62a17ae 18521static struct cmd_node bgp_ipv6_labeled_unicast_node = {
f4b8291f 18522 .name = "bgp ipv6 labeled unicast",
62b346ee 18523 .node = BGP_IPV6L_NODE,
24389580 18524 .parent_node = BGP_NODE,
62b346ee 18525 .prompt = "%s(config-router-af)# ",
dd2c81b8 18526 .no_xpath = true,
f51bae9c
DS
18527};
18528
62b346ee 18529static struct cmd_node bgp_vpnv4_node = {
f4b8291f 18530 .name = "bgp vpnv4",
62b346ee 18531 .node = BGP_VPNV4_NODE,
24389580 18532 .parent_node = BGP_NODE,
62b346ee 18533 .prompt = "%s(config-router-af)# ",
dd2c81b8 18534 .no_xpath = true,
62b346ee 18535};
6b0655a2 18536
62b346ee 18537static struct cmd_node bgp_vpnv6_node = {
f4b8291f 18538 .name = "bgp vpnv6",
62b346ee 18539 .node = BGP_VPNV6_NODE,
24389580 18540 .parent_node = BGP_NODE,
62b346ee 18541 .prompt = "%s(config-router-af-vpnv6)# ",
dd2c81b8 18542 .no_xpath = true,
62b346ee 18543};
8ecd3266 18544
62b346ee 18545static struct cmd_node bgp_evpn_node = {
f4b8291f 18546 .name = "bgp evpn",
62b346ee 18547 .node = BGP_EVPN_NODE,
24389580 18548 .parent_node = BGP_NODE,
62b346ee 18549 .prompt = "%s(config-router-evpn)# ",
dd2c81b8 18550 .no_xpath = true,
62b346ee 18551};
4e0b7b6d 18552
62b346ee 18553static struct cmd_node bgp_evpn_vni_node = {
f4b8291f 18554 .name = "bgp evpn vni",
62b346ee 18555 .node = BGP_EVPN_VNI_NODE,
24389580 18556 .parent_node = BGP_EVPN_NODE,
62b346ee 18557 .prompt = "%s(config-router-af-vni)# ",
62b346ee 18558};
90e60aa7 18559
62b346ee 18560static struct cmd_node bgp_flowspecv4_node = {
f4b8291f 18561 .name = "bgp ipv4 flowspec",
62b346ee 18562 .node = BGP_FLOWSPECV4_NODE,
24389580 18563 .parent_node = BGP_NODE,
62b346ee 18564 .prompt = "%s(config-router-af)# ",
dd2c81b8 18565 .no_xpath = true,
62b346ee 18566};
7c40bf39 18567
62b346ee 18568static struct cmd_node bgp_flowspecv6_node = {
f4b8291f 18569 .name = "bgp ipv6 flowspec",
62b346ee 18570 .node = BGP_FLOWSPECV6_NODE,
24389580 18571 .parent_node = BGP_NODE,
62b346ee 18572 .prompt = "%s(config-router-af-vpnv6)# ",
dd2c81b8 18573 .no_xpath = true,
62b346ee 18574};
7c40bf39 18575
bfaab44d
HS
18576static struct cmd_node bgp_srv6_node = {
18577 .name = "bgp srv6",
18578 .node = BGP_SRV6_NODE,
18579 .parent_node = BGP_NODE,
18580 .prompt = "%s(config-router-srv6)# ",
18581};
18582
d62a17ae 18583static void community_list_vty(void);
1f8ae70b 18584
8c20061f
DA
18585static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
18586{
18587 struct bgp *bgp;
18588 struct peer_group *group;
18589 struct listnode *lnbgp, *lnpeer;
18590
18591 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18592 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
18593 vector_set(comps,
18594 XSTRDUP(MTYPE_COMPLETION, group->name));
18595 }
18596}
18597
18598static void bgp_ac_peer(vector comps, struct cmd_token *token)
b8a815e5 18599{
d62a17ae 18600 struct bgp *bgp;
18601 struct peer *peer;
d62a17ae 18602 struct listnode *lnbgp, *lnpeer;
b8a815e5 18603
d62a17ae 18604 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18605 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
18606 /* only provide suggestions on the appropriate input
18607 * token type,
18608 * they'll otherwise show up multiple times */
18609 enum cmd_token_type match_type;
18610 char *name = peer->host;
d48ed3e0 18611
d62a17ae 18612 if (peer->conf_if) {
18613 match_type = VARIABLE_TKN;
18614 name = peer->conf_if;
18615 } else if (strchr(peer->host, ':'))
18616 match_type = IPV6_TKN;
18617 else
18618 match_type = IPV4_TKN;
d48ed3e0 18619
d62a17ae 18620 if (token->type != match_type)
18621 continue;
d48ed3e0 18622
d62a17ae 18623 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
18624 }
d62a17ae 18625 }
b8a815e5
DL
18626}
18627
8c20061f
DA
18628static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
18629{
18630 bgp_ac_peer(comps, token);
84de1483
DA
18631
18632 if (token->type == VARIABLE_TKN)
18633 bgp_ac_peergroup(comps, token);
8c20061f
DA
18634}
18635
b8a815e5 18636static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 18637 {.varname = "neighbor", .completions = bgp_ac_neighbor},
18638 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 18639 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 18640 {.completions = NULL}};
18641
47a306a0
DS
18642static const struct cmd_variable_handler bgp_var_peergroup[] = {
18643 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
18644 {.completions = NULL} };
18645
aa24a36a
DA
18646DEFINE_HOOK(bgp_config_end, (struct bgp *bgp), (bgp));
18647
18648static struct thread *t_bgp_cfg;
18649
18650bool bgp_config_inprocess(void)
18651{
18652 return thread_is_scheduled(t_bgp_cfg);
18653}
18654
18655static void bgp_config_finish(struct thread *t)
18656{
18657 struct listnode *node;
18658 struct bgp *bgp;
18659
18660 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp))
18661 hook_call(bgp_config_end, bgp);
18662}
18663
18664static void bgp_config_start(void)
18665{
18666#define BGP_PRE_CONFIG_MAX_WAIT_SECONDS 600
18667 THREAD_OFF(t_bgp_cfg);
18668 thread_add_timer(bm->master, bgp_config_finish, NULL,
18669 BGP_PRE_CONFIG_MAX_WAIT_SECONDS, &t_bgp_cfg);
18670}
18671
18672/* When we receive a hook the configuration is read,
18673 * we start a timer to make sure we postpone sending
18674 * EoR before route-maps are processed.
18675 * This is especially valid if using `bgp route-map delay-timer`.
18676 */
18677static void bgp_config_end(void)
18678{
18679#define BGP_POST_CONFIG_DELAY_SECONDS 1
18680 uint32_t bgp_post_config_delay =
18681 thread_is_scheduled(bm->t_rmap_update)
18682 ? thread_timer_remain_second(bm->t_rmap_update)
18683 : BGP_POST_CONFIG_DELAY_SECONDS;
18684
18685 /* If BGP config processing thread isn't running, then
18686 * we can return and rely it's properly handled.
18687 */
18688 if (!bgp_config_inprocess())
18689 return;
18690
18691 THREAD_OFF(t_bgp_cfg);
18692
18693 /* Start a new timer to make sure we don't send EoR
18694 * before route-maps are processed.
18695 */
18696 thread_add_timer(bm->master, bgp_config_finish, NULL,
18697 bgp_post_config_delay, &t_bgp_cfg);
18698}
18699
4cd690ae
PG
18700static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
18701{
18702 int write = 0;
18703 struct interface *ifp;
18704 struct bgp_interface *iifp;
18705
18706 FOR_ALL_INTERFACES (vrf, ifp) {
18707 iifp = ifp->info;
18708 if (!iifp)
18709 continue;
18710
18711 if_vty_config_start(vty, ifp);
18712
18713 if (CHECK_FLAG(iifp->flags,
18714 BGP_INTERFACE_MPLS_BGP_FORWARDING)) {
18715 vty_out(vty, " mpls bgp forwarding\n");
18716 write++;
18717 }
18718
18719 if_vty_config_end(vty);
18720 }
18721
18722 return write;
18723}
18724
18725/* Configuration write function for bgpd. */
18726static int config_write_interface(struct vty *vty)
18727{
18728 int write = 0;
18729 struct vrf *vrf = NULL;
18730
18731 /* Display all VRF aware OSPF interface configuration */
18732 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
18733 write += config_write_interface_one(vty, vrf);
18734 }
18735
18736 return write;
18737}
18738
18739DEFPY(mpls_bgp_forwarding, mpls_bgp_forwarding_cmd,
18740 "[no$no] mpls bgp forwarding",
18741 NO_STR MPLS_STR BGP_STR
18742 "Enable MPLS forwarding for eBGP directly connected peers\n")
18743{
18744 bool check;
18745 struct bgp_interface *iifp;
18746
18747 VTY_DECLVAR_CONTEXT(interface, ifp);
18748 iifp = ifp->info;
18749 if (!iifp) {
18750 vty_out(vty, "Interface %s not available\n", ifp->name);
18751 return CMD_WARNING_CONFIG_FAILED;
18752 }
18753 check = CHECK_FLAG(iifp->flags, BGP_INTERFACE_MPLS_BGP_FORWARDING);
18754 if (check != !no) {
18755 if (no)
18756 UNSET_FLAG(iifp->flags,
18757 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18758 else
18759 SET_FLAG(iifp->flags,
18760 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18761 /* trigger a nht update on eBGP sessions */
18762 if (if_is_operative(ifp))
18763 bgp_nht_ifp_up(ifp);
18764 }
18765 return CMD_SUCCESS;
18766}
18767
a0b937de
SW
18768DEFPY (bgp_inq_limit,
18769 bgp_inq_limit_cmd,
18770 "bgp input-queue-limit (1-4294967295)$limit",
18771 BGP_STR
18772 "Set the BGP Input Queue limit for all peers when message parsing\n"
18773 "Input-Queue limit\n")
18774{
18775 bm->inq_limit = limit;
18776
18777 return CMD_SUCCESS;
18778}
18779
18780DEFPY (no_bgp_inq_limit,
18781 no_bgp_inq_limit_cmd,
18782 "no bgp input-queue-limit [(1-4294967295)$limit]",
18783 NO_STR
18784 BGP_STR
18785 "Set the BGP Input Queue limit for all peers when message parsing\n"
18786 "Input-Queue limit\n")
18787{
963b7ee4
DS
18788 bm->inq_limit = BM_DEFAULT_Q_LIMIT;
18789
18790 return CMD_SUCCESS;
18791}
18792
18793DEFPY (bgp_outq_limit,
18794 bgp_outq_limit_cmd,
18795 "bgp output-queue-limit (1-4294967295)$limit",
18796 BGP_STR
18797 "Set the BGP Output Queue limit for all peers when message parsing\n"
18798 "Output-Queue limit\n")
18799{
18800 bm->outq_limit = limit;
a0b937de
SW
18801
18802 return CMD_SUCCESS;
18803}
18804
963b7ee4
DS
18805DEFPY (no_bgp_outq_limit,
18806 no_bgp_outq_limit_cmd,
18807 "no bgp output-queue-limit [(1-4294967295)$limit]",
18808 NO_STR
18809 BGP_STR
18810 "Set the BGP Output Queue limit for all peers when message parsing\n"
18811 "Output-Queue limit\n")
18812{
18813 bm->outq_limit = BM_DEFAULT_Q_LIMIT;
a0b937de
SW
18814
18815 return CMD_SUCCESS;
18816}
18817
963b7ee4 18818
4cd690ae
PG
18819/* Initialization of BGP interface. */
18820static void bgp_vty_if_init(void)
18821{
18822 /* Install interface node. */
18823 if_cmd_init(config_write_interface);
18824
18825 /* "mpls bgp forwarding" commands. */
18826 install_element(INTERFACE_NODE, &mpls_bgp_forwarding_cmd);
18827}
18828
d62a17ae 18829void bgp_vty_init(void)
18830{
18831 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 18832 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 18833
aa24a36a
DA
18834 cmd_init_config_callbacks(bgp_config_start, bgp_config_end);
18835
d62a17ae 18836 /* Install bgp top node. */
612c2c15
DL
18837 install_node(&bgp_node);
18838 install_node(&bgp_ipv4_unicast_node);
18839 install_node(&bgp_ipv4_multicast_node);
18840 install_node(&bgp_ipv4_labeled_unicast_node);
18841 install_node(&bgp_ipv6_unicast_node);
18842 install_node(&bgp_ipv6_multicast_node);
18843 install_node(&bgp_ipv6_labeled_unicast_node);
18844 install_node(&bgp_vpnv4_node);
18845 install_node(&bgp_vpnv6_node);
18846 install_node(&bgp_evpn_node);
18847 install_node(&bgp_evpn_vni_node);
18848 install_node(&bgp_flowspecv4_node);
18849 install_node(&bgp_flowspecv6_node);
bfaab44d 18850 install_node(&bgp_srv6_node);
d62a17ae 18851
18852 /* Install default VTY commands to new nodes. */
18853 install_default(BGP_NODE);
18854 install_default(BGP_IPV4_NODE);
18855 install_default(BGP_IPV4M_NODE);
18856 install_default(BGP_IPV4L_NODE);
18857 install_default(BGP_IPV6_NODE);
18858 install_default(BGP_IPV6M_NODE);
18859 install_default(BGP_IPV6L_NODE);
18860 install_default(BGP_VPNV4_NODE);
18861 install_default(BGP_VPNV6_NODE);
7c40bf39 18862 install_default(BGP_FLOWSPECV4_NODE);
18863 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 18864 install_default(BGP_EVPN_NODE);
18865 install_default(BGP_EVPN_VNI_NODE);
bfaab44d 18866 install_default(BGP_SRV6_NODE);
d62a17ae 18867
a0b937de
SW
18868 /* "global bgp inq-limit command */
18869 install_element(CONFIG_NODE, &bgp_inq_limit_cmd);
18870 install_element(CONFIG_NODE, &no_bgp_inq_limit_cmd);
963b7ee4
DS
18871 install_element(CONFIG_NODE, &bgp_outq_limit_cmd);
18872 install_element(CONFIG_NODE, &no_bgp_outq_limit_cmd);
a0b937de 18873
8029b216
AK
18874 /* "bgp local-mac" hidden commands. */
18875 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
18876 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
18877
9acb67cb
DS
18878 /* "bgp suppress-fib-pending" global */
18879 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
18880
d62a17ae 18881 /* bgp route-map delay-timer commands. */
18882 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
18883 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18884
8666265e
DS
18885 install_element(BGP_NODE, &bgp_allow_martian_cmd);
18886
f852eb98
PG
18887 /* bgp fast-convergence command */
18888 install_element(BGP_NODE, &bgp_fast_convergence_cmd);
18889 install_element(BGP_NODE, &no_bgp_fast_convergence_cmd);
18890
d70583f7
D
18891 /* global bgp update-delay command */
18892 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
18893 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
18894
05bd726c 18895 /* global bgp graceful-shutdown command */
18896 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
18897 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
18898
d62a17ae 18899 /* Dummy commands (Currently not supported) */
18900 install_element(BGP_NODE, &no_synchronization_cmd);
18901 install_element(BGP_NODE, &no_auto_summary_cmd);
18902
18903 /* "router bgp" commands. */
18904 install_element(CONFIG_NODE, &router_bgp_cmd);
18905
18906 /* "no router bgp" commands. */
18907 install_element(CONFIG_NODE, &no_router_bgp_cmd);
18908
425bd64b
PS
18909 /* "bgp session-dscp command */
18910 install_element(CONFIG_NODE, &bgp_session_dscp_cmd);
18911 install_element(CONFIG_NODE, &no_bgp_session_dscp_cmd);
18912
d62a17ae 18913 /* "bgp router-id" commands. */
18914 install_element(BGP_NODE, &bgp_router_id_cmd);
18915 install_element(BGP_NODE, &no_bgp_router_id_cmd);
18916
c208c586
S
18917 /* "bgp suppress-fib-pending" command */
18918 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
18919
d62a17ae 18920 /* "bgp cluster-id" commands. */
18921 install_element(BGP_NODE, &bgp_cluster_id_cmd);
18922 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
18923
c163f297
DS
18924 /* "bgp no-rib" commands. */
18925 install_element(CONFIG_NODE, &bgp_norib_cmd);
18926 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
18927
e46723a5
DS
18928 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
18929
d62a17ae 18930 /* "bgp confederation" commands. */
18931 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
18932 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
18933
18934 /* "bgp confederation peers" commands. */
18935 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
18936 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
18937
18938 /* bgp max-med command */
18939 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
18940 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
18941 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
18942 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
18943 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
18944
d864dd9e
EB
18945 /* "neighbor role" commands. */
18946 install_element(BGP_NODE, &neighbor_role_cmd);
18947 install_element(BGP_NODE, &neighbor_role_strict_cmd);
18948 install_element(BGP_NODE, &no_neighbor_role_cmd);
18949
97a52c82
DA
18950 /* "neighbor aigp" commands. */
18951 install_element(BGP_NODE, &neighbor_aigp_cmd);
18952
4f770cf1
DA
18953 /* "neighbor graceful-shutdown" command */
18954 install_element(BGP_NODE, &neighbor_graceful_shutdown_cmd);
18955
d62a17ae 18956 /* bgp disable-ebgp-connected-nh-check */
18957 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
18958 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
18959
18960 /* bgp update-delay command */
18961 install_element(BGP_NODE, &bgp_update_delay_cmd);
18962 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
d62a17ae 18963
18964 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
555e09d4 18965 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
d62a17ae 18966
18967 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
18968 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
18969
18970 /* "maximum-paths" commands. */
18971 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
18972 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
18973 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
18974 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
18975 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
18976 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
18977 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
18978 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
18979 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
18980 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
18981 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18982 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
18983 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
18984 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18985 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
18986
39edabac
PG
18987 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
18988 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
18989 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
18990 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18991 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
d62a17ae 18992 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
18993 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
18994 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
18995 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18996 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18997
18998 /* "timers bgp" commands. */
18999 install_element(BGP_NODE, &bgp_timers_cmd);
19000 install_element(BGP_NODE, &no_bgp_timers_cmd);
19001
b042667a
TI
19002 /* "minimum-holdtime" commands. */
19003 install_element(BGP_NODE, &bgp_minimum_holdtime_cmd);
19004 install_element(BGP_NODE, &no_bgp_minimum_holdtime_cmd);
19005
d62a17ae 19006 /* route-map delay-timer commands - per instance for backwards compat.
19007 */
19008 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
19009 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
19010
19011 /* "bgp client-to-client reflection" commands */
19012 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
19013 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
19014
19015 /* "bgp always-compare-med" commands */
19016 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
19017 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
19018
9dac9fc8
DA
19019 /* bgp ebgp-requires-policy */
19020 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
19021 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
19022
2adac256
DA
19023 /* bgp suppress-duplicates */
19024 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
19025 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
19026
fb29348a
DA
19027 /* bgp reject-as-sets */
19028 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
19029 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
19030
d62a17ae 19031 /* "bgp deterministic-med" commands */
19032 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
19033 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
19034
055679e9 19035 /* "bgp graceful-restart" command */
36235319
QY
19036 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
19037 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
055679e9 19038
19039 /* "bgp graceful-restart-disable" command */
36235319
QY
19040 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
19041 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
055679e9 19042
19043 /* "neighbor a:b:c:d graceful-restart" command */
36235319
QY
19044 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
19045 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
055679e9 19046
19047 /* "neighbor a:b:c:d graceful-restart-disable" command */
19048 install_element(BGP_NODE,
19049 &bgp_neighbor_graceful_restart_disable_set_cmd);
19050 install_element(BGP_NODE,
19051 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
19052
19053 /* "neighbor a:b:c:d graceful-restart-helper" command */
19054 install_element(BGP_NODE,
19055 &bgp_neighbor_graceful_restart_helper_set_cmd);
19056 install_element(BGP_NODE,
19057 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
19058
d62a17ae 19059 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
19060 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
19061 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
19062 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
cfd47646 19063 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
f009ff26 19064 install_element(BGP_NODE,
19065 &no_bgp_graceful_restart_select_defer_time_cmd);
d62a17ae 19066 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
19067 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
f2ca5c5b 19068 install_element(BGP_NODE, &bgp_graceful_restart_notification_cmd);
d62a17ae 19069
d6e3c15b 19070 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
19071 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
dc95985f 19072 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
19073 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
d6e3c15b 19074
7f323236
DW
19075 /* "bgp graceful-shutdown" commands */
19076 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
19077 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
19078
1ae314be
DA
19079 /* "bgp hard-administrative-reset" commands */
19080 install_element(BGP_NODE, &bgp_administrative_reset_cmd);
19081
8606be87
DA
19082 /* "bgp long-lived-graceful-restart" commands */
19083 install_element(BGP_NODE, &bgp_llgr_stalepath_time_cmd);
19084 install_element(BGP_NODE, &no_bgp_llgr_stalepath_time_cmd);
19085
d62a17ae 19086 /* "bgp fast-external-failover" commands */
19087 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
19088 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
19089
97a52c82
DA
19090 /* "bgp bestpath aigp" commands */
19091 install_element(BGP_NODE, &bgp_bestpath_aigp_cmd);
19092
d62a17ae 19093 /* "bgp bestpath compare-routerid" commands */
19094 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
19095 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
19096
19097 /* "bgp bestpath as-path ignore" commands */
19098 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
19099 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
19100
19101 /* "bgp bestpath as-path confed" commands */
19102 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
19103 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
19104
19105 /* "bgp bestpath as-path multipath-relax" commands */
19106 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
19107 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
19108
ee88563a
JM
19109 /* "bgp bestpath peer-type multipath-relax" commands */
19110 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
19111 install_element(BGP_NODE,
19112 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
19113
d62a17ae 19114 /* "bgp log-neighbor-changes" commands */
19115 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
19116 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
19117
19118 /* "bgp bestpath med" commands */
19119 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
19120 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
19121
f7e1c681 19122 /* "bgp bestpath bandwidth" commands */
19123 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
ad36d216 19124 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
f7e1c681 19125
b16bcbba
TA
19126 /* "no bgp default <afi>-<safi>" commands. */
19127 install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
e84c59af 19128
d62a17ae 19129 /* "bgp network import-check" commands. */
19130 install_element(BGP_NODE, &bgp_network_import_check_cmd);
19131 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
19132 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
19133
19134 /* "bgp default local-preference" commands. */
19135 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
19136 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
19137
19138 /* bgp default show-hostname */
19139 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
19140 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
19141
aef999a2
DA
19142 /* bgp default show-nexthop-hostname */
19143 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
19144 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
19145
d62a17ae 19146 /* "bgp default subgroup-pkt-queue-max" commands. */
19147 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
19148 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
19149
19150 /* bgp ibgp-allow-policy-mods command */
19151 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
19152 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
19153
19154 /* "bgp listen limit" commands. */
19155 install_element(BGP_NODE, &bgp_listen_limit_cmd);
19156 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
19157
19158 /* "bgp listen range" commands. */
19159 install_element(BGP_NODE, &bgp_listen_range_cmd);
19160 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
19161
8175f54a 19162 /* "bgp default shutdown" command */
f26845f9 19163 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
9cf59432
DS
19164
19165 /* "bgp shutdown" commands */
19166 install_element(BGP_NODE, &bgp_shutdown_cmd);
8389c83a 19167 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
9cf59432 19168 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
1b6e7a88 19169 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
f26845f9 19170
d62a17ae 19171 /* "neighbor remote-as" commands. */
19172 install_element(BGP_NODE, &neighbor_remote_as_cmd);
19173 install_element(BGP_NODE, &neighbor_interface_config_cmd);
19174 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
19175 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
19176 install_element(BGP_NODE,
19177 &neighbor_interface_v6only_config_remote_as_cmd);
19178 install_element(BGP_NODE, &no_neighbor_cmd);
19179 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
19180
19181 /* "neighbor peer-group" commands. */
19182 install_element(BGP_NODE, &neighbor_peer_group_cmd);
19183 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
19184 install_element(BGP_NODE,
19185 &no_neighbor_interface_peer_group_remote_as_cmd);
19186
19187 /* "neighbor local-as" commands. */
19188 install_element(BGP_NODE, &neighbor_local_as_cmd);
19189 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
19190 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
19191 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
19192
19193 /* "neighbor solo" commands. */
19194 install_element(BGP_NODE, &neighbor_solo_cmd);
19195 install_element(BGP_NODE, &no_neighbor_solo_cmd);
19196
19197 /* "neighbor password" commands. */
19198 install_element(BGP_NODE, &neighbor_password_cmd);
19199 install_element(BGP_NODE, &no_neighbor_password_cmd);
19200
19201 /* "neighbor activate" commands. */
19202 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
19203 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
19204 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
19205 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
19206 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
19207 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
19208 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
19209 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
19210 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 19211 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
19212 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 19213 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
19214
19215 /* "no neighbor activate" commands. */
19216 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
19217 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
19218 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
19219 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
19220 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
19221 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
19222 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
19223 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
19224 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 19225 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
19226 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 19227 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
19228
19229 /* "neighbor peer-group" set commands. */
19230 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
19231 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
19232 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
19233 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
19234 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
19235 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
19236 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
19237 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 19238 install_element(BGP_FLOWSPECV4_NODE,
19239 &neighbor_set_peer_group_hidden_cmd);
19240 install_element(BGP_FLOWSPECV6_NODE,
19241 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 19242
19243 /* "no neighbor peer-group unset" commands. */
19244 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
19245 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19246 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19247 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19248 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19249 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19250 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19251 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 19252 install_element(BGP_FLOWSPECV4_NODE,
19253 &no_neighbor_set_peer_group_hidden_cmd);
19254 install_element(BGP_FLOWSPECV6_NODE,
19255 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 19256
19257 /* "neighbor softreconfiguration inbound" commands.*/
19258 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
19259 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
19260 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
19261 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
19262 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
19263 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
19264 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
19265 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
19266 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
19267 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
19268 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
19269 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
19270 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
19271 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
19272 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
19273 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
19274 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
19275 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 19276 install_element(BGP_FLOWSPECV4_NODE,
19277 &neighbor_soft_reconfiguration_cmd);
19278 install_element(BGP_FLOWSPECV4_NODE,
19279 &no_neighbor_soft_reconfiguration_cmd);
19280 install_element(BGP_FLOWSPECV6_NODE,
19281 &neighbor_soft_reconfiguration_cmd);
19282 install_element(BGP_FLOWSPECV6_NODE,
19283 &no_neighbor_soft_reconfiguration_cmd);
616c6ee8
PG
19284 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
19285 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 19286
19287 /* "neighbor attribute-unchanged" commands. */
19288 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
19289 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
19290 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
19291 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
19292 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
19293 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
19294 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
19295 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
19296 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
19297 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
19298 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
19299 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
19300 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
19301 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
19302 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
19303 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
19304 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
19305 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
19306
19307 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
19308 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
19309
b8ad84d2
PG
19310 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
19311 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
19312 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
19313 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
19314
d62a17ae 19315 /* "nexthop-local unchanged" commands */
19316 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
19317 install_element(BGP_IPV6_NODE,
19318 &no_neighbor_nexthop_local_unchanged_cmd);
19319
19320 /* "neighbor next-hop-self" commands. */
19321 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
19322 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
19323 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
19324 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
19325 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
19326 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
19327 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
19328 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
19329 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
19330 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
19331 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
19332 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
19333 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
19334 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
19335 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
19336 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
19337 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
19338 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
19339 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
19340 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 19341
19342 /* "neighbor next-hop-self force" commands. */
19343 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
19344 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
1bc4e531
DA
19345 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19346 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19347 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
19348 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19349 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19350 install_element(BGP_IPV4_NODE,
19351 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19352 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
19353 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19354 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19355 install_element(BGP_IPV4M_NODE,
19356 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19357 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
19358 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19359 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19360 install_element(BGP_IPV4L_NODE,
19361 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19362 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
19363 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19364 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19365 install_element(BGP_IPV6_NODE,
19366 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19367 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
19368 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19369 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19370 install_element(BGP_IPV6M_NODE,
19371 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19372 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
19373 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19374 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19375 install_element(BGP_IPV6L_NODE,
19376 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19377 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
19378 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19379 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19380 install_element(BGP_VPNV4_NODE,
19381 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19382 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
19383 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19384 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19385 install_element(BGP_VPNV6_NODE,
19386 &no_neighbor_nexthop_self_all_hidden_cmd);
be7e1fa3
MS
19387 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
19388 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
d62a17ae 19389
19390 /* "neighbor as-override" commands. */
19391 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
19392 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
19393 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
19394 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
19395 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
19396 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
19397 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
19398 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
19399 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
19400 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
19401 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
19402 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
19403 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
19404 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
19405 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
19406 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
19407 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
19408 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
19409
19410 /* "neighbor remove-private-AS" commands. */
19411 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
19412 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
19413 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
19414 install_element(BGP_NODE,
19415 &no_neighbor_remove_private_as_all_hidden_cmd);
19416 install_element(BGP_NODE,
19417 &neighbor_remove_private_as_replace_as_hidden_cmd);
19418 install_element(BGP_NODE,
19419 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
19420 install_element(BGP_NODE,
19421 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
19422 install_element(
19423 BGP_NODE,
19424 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
19425 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
19426 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
19427 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
19428 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
19429 install_element(BGP_IPV4_NODE,
19430 &neighbor_remove_private_as_replace_as_cmd);
19431 install_element(BGP_IPV4_NODE,
19432 &no_neighbor_remove_private_as_replace_as_cmd);
19433 install_element(BGP_IPV4_NODE,
19434 &neighbor_remove_private_as_all_replace_as_cmd);
19435 install_element(BGP_IPV4_NODE,
19436 &no_neighbor_remove_private_as_all_replace_as_cmd);
19437 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
19438 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
19439 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
19440 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
19441 install_element(BGP_IPV4M_NODE,
19442 &neighbor_remove_private_as_replace_as_cmd);
19443 install_element(BGP_IPV4M_NODE,
19444 &no_neighbor_remove_private_as_replace_as_cmd);
19445 install_element(BGP_IPV4M_NODE,
19446 &neighbor_remove_private_as_all_replace_as_cmd);
19447 install_element(BGP_IPV4M_NODE,
19448 &no_neighbor_remove_private_as_all_replace_as_cmd);
19449 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
19450 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
19451 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
19452 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
19453 install_element(BGP_IPV4L_NODE,
19454 &neighbor_remove_private_as_replace_as_cmd);
19455 install_element(BGP_IPV4L_NODE,
19456 &no_neighbor_remove_private_as_replace_as_cmd);
19457 install_element(BGP_IPV4L_NODE,
19458 &neighbor_remove_private_as_all_replace_as_cmd);
19459 install_element(BGP_IPV4L_NODE,
19460 &no_neighbor_remove_private_as_all_replace_as_cmd);
19461 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
19462 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
19463 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
19464 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
19465 install_element(BGP_IPV6_NODE,
19466 &neighbor_remove_private_as_replace_as_cmd);
19467 install_element(BGP_IPV6_NODE,
19468 &no_neighbor_remove_private_as_replace_as_cmd);
19469 install_element(BGP_IPV6_NODE,
19470 &neighbor_remove_private_as_all_replace_as_cmd);
19471 install_element(BGP_IPV6_NODE,
19472 &no_neighbor_remove_private_as_all_replace_as_cmd);
19473 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
19474 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
19475 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
19476 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
19477 install_element(BGP_IPV6M_NODE,
19478 &neighbor_remove_private_as_replace_as_cmd);
19479 install_element(BGP_IPV6M_NODE,
19480 &no_neighbor_remove_private_as_replace_as_cmd);
19481 install_element(BGP_IPV6M_NODE,
19482 &neighbor_remove_private_as_all_replace_as_cmd);
19483 install_element(BGP_IPV6M_NODE,
19484 &no_neighbor_remove_private_as_all_replace_as_cmd);
19485 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
19486 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
19487 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
19488 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
19489 install_element(BGP_IPV6L_NODE,
19490 &neighbor_remove_private_as_replace_as_cmd);
19491 install_element(BGP_IPV6L_NODE,
19492 &no_neighbor_remove_private_as_replace_as_cmd);
19493 install_element(BGP_IPV6L_NODE,
19494 &neighbor_remove_private_as_all_replace_as_cmd);
19495 install_element(BGP_IPV6L_NODE,
19496 &no_neighbor_remove_private_as_all_replace_as_cmd);
19497 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
19498 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
19499 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
19500 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
19501 install_element(BGP_VPNV4_NODE,
19502 &neighbor_remove_private_as_replace_as_cmd);
19503 install_element(BGP_VPNV4_NODE,
19504 &no_neighbor_remove_private_as_replace_as_cmd);
19505 install_element(BGP_VPNV4_NODE,
19506 &neighbor_remove_private_as_all_replace_as_cmd);
19507 install_element(BGP_VPNV4_NODE,
19508 &no_neighbor_remove_private_as_all_replace_as_cmd);
19509 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
19510 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
19511 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
19512 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
19513 install_element(BGP_VPNV6_NODE,
19514 &neighbor_remove_private_as_replace_as_cmd);
19515 install_element(BGP_VPNV6_NODE,
19516 &no_neighbor_remove_private_as_replace_as_cmd);
19517 install_element(BGP_VPNV6_NODE,
19518 &neighbor_remove_private_as_all_replace_as_cmd);
19519 install_element(BGP_VPNV6_NODE,
19520 &no_neighbor_remove_private_as_all_replace_as_cmd);
19521
19522 /* "neighbor send-community" commands.*/
19523 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
19524 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
19525 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
19526 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
19527 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
19528 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
19529 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
19530 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
19531 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
19532 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
19533 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
19534 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
19535 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
19536 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
19537 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
19538 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
19539 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
19540 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
19541 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
19542 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
19543 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
19544 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
19545 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
19546 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
19547 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
19548 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
19549 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
19550 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
19551 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
19552 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
19553 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
19554 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
19555 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
19556 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
19557 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
19558 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
19559
19560 /* "neighbor route-reflector" commands.*/
19561 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
19562 install_element(BGP_NODE,
19563 &no_neighbor_route_reflector_client_hidden_cmd);
19564 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
19565 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
19566 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
19567 install_element(BGP_IPV4M_NODE,
19568 &no_neighbor_route_reflector_client_cmd);
19569 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
19570 install_element(BGP_IPV4L_NODE,
19571 &no_neighbor_route_reflector_client_cmd);
19572 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
19573 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
19574 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
19575 install_element(BGP_IPV6M_NODE,
19576 &no_neighbor_route_reflector_client_cmd);
19577 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
19578 install_element(BGP_IPV6L_NODE,
19579 &no_neighbor_route_reflector_client_cmd);
19580 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
19581 install_element(BGP_VPNV4_NODE,
19582 &no_neighbor_route_reflector_client_cmd);
19583 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
19584 install_element(BGP_VPNV6_NODE,
19585 &no_neighbor_route_reflector_client_cmd);
7c40bf39 19586 install_element(BGP_FLOWSPECV4_NODE,
19587 &neighbor_route_reflector_client_cmd);
19588 install_element(BGP_FLOWSPECV4_NODE,
19589 &no_neighbor_route_reflector_client_cmd);
19590 install_element(BGP_FLOWSPECV6_NODE,
19591 &neighbor_route_reflector_client_cmd);
19592 install_element(BGP_FLOWSPECV6_NODE,
19593 &no_neighbor_route_reflector_client_cmd);
d62a17ae 19594 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
19595 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
19596
19597 /* "neighbor route-server" commands.*/
19598 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
19599 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
19600 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
19601 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
19602 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
19603 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
19604 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
19605 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
19606 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
19607 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
19608 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
19609 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
19610 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
19611 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
19612 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
19613 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
19614 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
19615 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
19616 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
19617 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 19618 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
19619 install_element(BGP_FLOWSPECV4_NODE,
19620 &no_neighbor_route_server_client_cmd);
19621 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
19622 install_element(BGP_FLOWSPECV6_NODE,
19623 &no_neighbor_route_server_client_cmd);
d62a17ae 19624
7c0e4312
DA
19625 /* "neighbor disable-addpath-rx" commands. */
19626 install_element(BGP_IPV4_NODE, &neighbor_disable_addpath_rx_cmd);
19627 install_element(BGP_IPV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19628 install_element(BGP_IPV4M_NODE, &neighbor_disable_addpath_rx_cmd);
19629 install_element(BGP_IPV4M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19630 install_element(BGP_IPV4L_NODE, &neighbor_disable_addpath_rx_cmd);
19631 install_element(BGP_IPV4L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19632 install_element(BGP_IPV6_NODE, &neighbor_disable_addpath_rx_cmd);
19633 install_element(BGP_IPV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19634 install_element(BGP_IPV6M_NODE, &neighbor_disable_addpath_rx_cmd);
19635 install_element(BGP_IPV6M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19636 install_element(BGP_IPV6L_NODE, &neighbor_disable_addpath_rx_cmd);
19637 install_element(BGP_IPV6L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19638 install_element(BGP_VPNV4_NODE, &neighbor_disable_addpath_rx_cmd);
19639 install_element(BGP_VPNV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19640 install_element(BGP_VPNV6_NODE, &neighbor_disable_addpath_rx_cmd);
19641 install_element(BGP_VPNV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19642
d62a17ae 19643 /* "neighbor addpath-tx-all-paths" commands.*/
19644 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
19645 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
19646 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19647 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19648 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19649 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19650 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19651 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19652 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19653 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19654 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19655 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19656 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19657 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19658 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19659 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19660 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19661 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19662
19663 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
19664 install_element(BGP_NODE,
19665 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19666 install_element(BGP_NODE,
19667 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19668 install_element(BGP_IPV4_NODE,
19669 &neighbor_addpath_tx_bestpath_per_as_cmd);
19670 install_element(BGP_IPV4_NODE,
19671 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19672 install_element(BGP_IPV4M_NODE,
19673 &neighbor_addpath_tx_bestpath_per_as_cmd);
19674 install_element(BGP_IPV4M_NODE,
19675 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19676 install_element(BGP_IPV4L_NODE,
19677 &neighbor_addpath_tx_bestpath_per_as_cmd);
19678 install_element(BGP_IPV4L_NODE,
19679 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19680 install_element(BGP_IPV6_NODE,
19681 &neighbor_addpath_tx_bestpath_per_as_cmd);
19682 install_element(BGP_IPV6_NODE,
19683 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19684 install_element(BGP_IPV6M_NODE,
19685 &neighbor_addpath_tx_bestpath_per_as_cmd);
19686 install_element(BGP_IPV6M_NODE,
19687 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19688 install_element(BGP_IPV6L_NODE,
19689 &neighbor_addpath_tx_bestpath_per_as_cmd);
19690 install_element(BGP_IPV6L_NODE,
19691 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19692 install_element(BGP_VPNV4_NODE,
19693 &neighbor_addpath_tx_bestpath_per_as_cmd);
19694 install_element(BGP_VPNV4_NODE,
19695 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19696 install_element(BGP_VPNV6_NODE,
19697 &neighbor_addpath_tx_bestpath_per_as_cmd);
19698 install_element(BGP_VPNV6_NODE,
19699 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19700
2b31007c
RZ
19701 /* "neighbor sender-as-path-loop-detection" commands. */
19702 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
19703 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
19704
a5c6a9b1
DA
19705 /* "neighbor path-attribute discard" commands. */
19706 install_element(BGP_NODE, &neighbor_path_attribute_discard_cmd);
b986d7f4 19707 install_element(BGP_NODE, &no_neighbor_path_attribute_discard_cmd);
a5c6a9b1 19708
d62a17ae 19709 /* "neighbor passive" commands. */
19710 install_element(BGP_NODE, &neighbor_passive_cmd);
19711 install_element(BGP_NODE, &no_neighbor_passive_cmd);
19712
19713
19714 /* "neighbor shutdown" commands. */
19715 install_element(BGP_NODE, &neighbor_shutdown_cmd);
19716 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
19717 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
19718 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
8336c896
DA
19719 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
19720 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
d62a17ae 19721
19722 /* "neighbor capability extended-nexthop" commands.*/
19723 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
19724 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
19725
19726 /* "neighbor capability orf prefix-list" commands.*/
19727 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
19728 install_element(BGP_NODE,
19729 &no_neighbor_capability_orf_prefix_hidden_cmd);
19730 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
19731 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
19732 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
19733 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19734 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
19735 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19736 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
19737 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
19738 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
19739 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19740 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
19741 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19742
19743 /* "neighbor capability dynamic" commands.*/
19744 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
19745 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
19746
19747 /* "neighbor dont-capability-negotiate" commands. */
19748 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
19749 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
19750
19751 /* "neighbor ebgp-multihop" commands. */
19752 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
19753 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
19754 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
19755
19756 /* "neighbor disable-connected-check" commands. */
19757 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
19758 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
19759
7ab294ea
DA
19760 /* "neighbor disable-link-bw-encoding-ieee" commands. */
19761 install_element(BGP_NODE, &neighbor_disable_link_bw_encoding_ieee_cmd);
19762 install_element(BGP_NODE,
19763 &no_neighbor_disable_link_bw_encoding_ieee_cmd);
27aa23a4 19764
d08c0c80
DA
19765 /* "neighbor extended-optional-parameters" commands. */
19766 install_element(BGP_NODE, &neighbor_extended_optional_parameters_cmd);
19767 install_element(BGP_NODE,
19768 &no_neighbor_extended_optional_parameters_cmd);
19769
47cbc09b
PM
19770 /* "neighbor enforce-first-as" commands. */
19771 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
19772 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
19773
d62a17ae 19774 /* "neighbor description" commands. */
19775 install_element(BGP_NODE, &neighbor_description_cmd);
19776 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 19777 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 19778
19779 /* "neighbor update-source" commands. "*/
19780 install_element(BGP_NODE, &neighbor_update_source_cmd);
19781 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
19782
19783 /* "neighbor default-originate" commands. */
19784 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
19785 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
19786 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
19787 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
19788 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
19789 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
19790 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
19791 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
19792 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
19793 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
19794 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
19795 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
19796 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
19797 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
19798 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
19799 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
19800 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
19801 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
19802 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
19803 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
19804 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
19805
19806 /* "neighbor port" commands. */
19807 install_element(BGP_NODE, &neighbor_port_cmd);
19808 install_element(BGP_NODE, &no_neighbor_port_cmd);
19809
19810 /* "neighbor weight" commands. */
19811 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
19812 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
19813
19814 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
19815 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
19816 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
19817 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
19818 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
19819 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
19820 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
19821 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
19822 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
19823 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
19824 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
19825 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
19826 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
19827 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
19828 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
19829 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
19830
19831 /* "neighbor override-capability" commands. */
19832 install_element(BGP_NODE, &neighbor_override_capability_cmd);
19833 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
19834
19835 /* "neighbor strict-capability-match" commands. */
19836 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
19837 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
19838
19839 /* "neighbor timers" commands. */
19840 install_element(BGP_NODE, &neighbor_timers_cmd);
19841 install_element(BGP_NODE, &no_neighbor_timers_cmd);
19842
19843 /* "neighbor timers connect" commands. */
19844 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
19845 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
19846
d43114f3
DS
19847 /* "neighbor timers delayopen" commands. */
19848 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
19849 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
19850
d62a17ae 19851 /* "neighbor advertisement-interval" commands. */
19852 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
19853 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
19854
19855 /* "neighbor interface" commands. */
19856 install_element(BGP_NODE, &neighbor_interface_cmd);
19857 install_element(BGP_NODE, &no_neighbor_interface_cmd);
19858
19859 /* "neighbor distribute" commands. */
19860 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
19861 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
19862 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
19863 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
19864 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
19865 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
19866 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
19867 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
19868 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
19869 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
19870 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
19871 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
19872 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
19873 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
19874 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
19875 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
19876 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
19877 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
19878
19879 /* "neighbor prefix-list" commands. */
19880 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
642ef664 19881 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
d62a17ae 19882 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
642ef664 19883 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 19884 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
642ef664 19885 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 19886 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
642ef664 19887 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 19888 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
642ef664 19889 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 19890 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
642ef664 19891 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 19892 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
642ef664 19893 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 19894 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
642ef664 19895 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 19896 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
642ef664 19897 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 19898 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
642ef664 19899 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 19900 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
642ef664 19901 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 19902
19903 /* "neighbor filter-list" commands. */
19904 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
19905 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
19906 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
19907 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
19908 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
19909 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
19910 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
19911 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
19912 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
19913 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
19914 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
19915 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
19916 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
19917 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
19918 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
19919 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
19920 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
19921 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 19922 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
19923 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
19924 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
19925 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 19926
19927 /* "neighbor route-map" commands. */
d6d7ed37
IR
19928 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
19929 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
d62a17ae 19930 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
0ea8d871 19931 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
d62a17ae 19932 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
0ea8d871 19933 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
d62a17ae 19934 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
0ea8d871 19935 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
d62a17ae 19936 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
0ea8d871 19937 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
d62a17ae 19938 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
0ea8d871 19939 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
d62a17ae 19940 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
0ea8d871 19941 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
d62a17ae 19942 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
0ea8d871 19943 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
d62a17ae 19944 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
0ea8d871 19945 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 19946 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
0ea8d871 19947 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
7c40bf39 19948 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
0ea8d871 19949 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549 19950 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
0ea8d871 19951 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 19952
19953 /* "neighbor unsuppress-map" commands. */
19954 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
19955 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
19956 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
19957 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
19958 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
19959 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
19960 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
19961 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
19962 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
19963 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
19964 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
19965 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
19966 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
19967 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
19968 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
19969 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
19970 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
19971 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
19972
7f7940e6 19973 /* "neighbor advertise-map" commands. */
389e4f92 19974 install_element(BGP_NODE, &bgp_condadv_period_cmd);
7f7940e6 19975 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
7f7940e6 19976 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19977 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19978 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19979 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19980 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19981 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19982 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19983 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19984
fde246e8
DA
19985 /* neighbor maximum-prefix-out commands. */
19986 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
19987 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
19988 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
19989 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19990 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
19991 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19992 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
19993 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19994 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
19995 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19996 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
19997 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19998 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
19999 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
20000 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
20001 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
20002 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
20003 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
20004
d62a17ae 20005 /* "neighbor maximum-prefix" commands. */
20006 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
20007 install_element(BGP_NODE,
20008 &neighbor_maximum_prefix_threshold_hidden_cmd);
20009 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
20010 install_element(BGP_NODE,
20011 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
20012 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
20013 install_element(BGP_NODE,
20014 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
20015 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
20016 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
20017 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
20018 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
20019 install_element(BGP_IPV4_NODE,
20020 &neighbor_maximum_prefix_threshold_warning_cmd);
20021 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
20022 install_element(BGP_IPV4_NODE,
20023 &neighbor_maximum_prefix_threshold_restart_cmd);
20024 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
20025 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
20026 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
20027 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
20028 install_element(BGP_IPV4M_NODE,
20029 &neighbor_maximum_prefix_threshold_warning_cmd);
20030 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
20031 install_element(BGP_IPV4M_NODE,
20032 &neighbor_maximum_prefix_threshold_restart_cmd);
20033 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
20034 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
20035 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
20036 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
20037 install_element(BGP_IPV4L_NODE,
20038 &neighbor_maximum_prefix_threshold_warning_cmd);
20039 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
20040 install_element(BGP_IPV4L_NODE,
20041 &neighbor_maximum_prefix_threshold_restart_cmd);
20042 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
20043 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
20044 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
20045 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
20046 install_element(BGP_IPV6_NODE,
20047 &neighbor_maximum_prefix_threshold_warning_cmd);
20048 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
20049 install_element(BGP_IPV6_NODE,
20050 &neighbor_maximum_prefix_threshold_restart_cmd);
20051 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
20052 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
20053 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
20054 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
20055 install_element(BGP_IPV6M_NODE,
20056 &neighbor_maximum_prefix_threshold_warning_cmd);
20057 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
20058 install_element(BGP_IPV6M_NODE,
20059 &neighbor_maximum_prefix_threshold_restart_cmd);
20060 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
20061 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
20062 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
20063 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
20064 install_element(BGP_IPV6L_NODE,
20065 &neighbor_maximum_prefix_threshold_warning_cmd);
20066 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
20067 install_element(BGP_IPV6L_NODE,
20068 &neighbor_maximum_prefix_threshold_restart_cmd);
20069 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
20070 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
20071 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
20072 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
20073 install_element(BGP_VPNV4_NODE,
20074 &neighbor_maximum_prefix_threshold_warning_cmd);
20075 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
20076 install_element(BGP_VPNV4_NODE,
20077 &neighbor_maximum_prefix_threshold_restart_cmd);
20078 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
20079 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
20080 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
20081 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
20082 install_element(BGP_VPNV6_NODE,
20083 &neighbor_maximum_prefix_threshold_warning_cmd);
20084 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
20085 install_element(BGP_VPNV6_NODE,
20086 &neighbor_maximum_prefix_threshold_restart_cmd);
20087 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
20088
20089 /* "neighbor allowas-in" */
20090 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
20091 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
20092 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
20093 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
20094 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
20095 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
20096 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
20097 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
20098 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
20099 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
20100 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
20101 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
20102 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
20103 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
20104 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
20105 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
20106 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
20107 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
20108 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
20109 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
20110
46dbf9d0
DA
20111 /* neighbor accept-own */
20112 install_element(BGP_VPNV4_NODE, &neighbor_accept_own_cmd);
20113 install_element(BGP_VPNV6_NODE, &neighbor_accept_own_cmd);
20114
01da2d26
DA
20115 /* "neighbor soo" */
20116 install_element(BGP_IPV4_NODE, &neighbor_soo_cmd);
20117 install_element(BGP_IPV4_NODE, &no_neighbor_soo_cmd);
20118 install_element(BGP_IPV4M_NODE, &neighbor_soo_cmd);
20119 install_element(BGP_IPV4M_NODE, &no_neighbor_soo_cmd);
20120 install_element(BGP_IPV4L_NODE, &neighbor_soo_cmd);
20121 install_element(BGP_IPV4L_NODE, &no_neighbor_soo_cmd);
20122 install_element(BGP_IPV6_NODE, &neighbor_soo_cmd);
20123 install_element(BGP_IPV6_NODE, &no_neighbor_soo_cmd);
20124 install_element(BGP_IPV6M_NODE, &neighbor_soo_cmd);
20125 install_element(BGP_IPV6M_NODE, &no_neighbor_soo_cmd);
20126 install_element(BGP_IPV6L_NODE, &neighbor_soo_cmd);
20127 install_element(BGP_IPV6L_NODE, &no_neighbor_soo_cmd);
20128 install_element(BGP_VPNV4_NODE, &neighbor_soo_cmd);
20129 install_element(BGP_VPNV4_NODE, &no_neighbor_soo_cmd);
20130 install_element(BGP_VPNV6_NODE, &neighbor_soo_cmd);
20131 install_element(BGP_VPNV6_NODE, &no_neighbor_soo_cmd);
20132 install_element(BGP_EVPN_NODE, &neighbor_soo_cmd);
20133 install_element(BGP_EVPN_NODE, &no_neighbor_soo_cmd);
20134
d62a17ae 20135 /* address-family commands. */
20136 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
20137 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 20138#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 20139 install_element(BGP_NODE, &address_family_vpnv4_cmd);
20140 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 20141#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 20142
d62a17ae 20143 install_element(BGP_NODE, &address_family_evpn_cmd);
20144
20145 /* "exit-address-family" command. */
20146 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
20147 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
20148 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
20149 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
20150 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
20151 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
20152 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
20153 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 20154 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
20155 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 20156 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
20157
a486300b
PG
20158 /* BGP retain all route-target */
20159 install_element(BGP_VPNV4_NODE, &bgp_retain_route_target_cmd);
20160 install_element(BGP_VPNV6_NODE, &bgp_retain_route_target_cmd);
20161
d62a17ae 20162 /* "clear ip bgp commands" */
20163 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
20164
20165 /* clear ip bgp prefix */
20166 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
20167 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
20168 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
20169
20170 /* "show [ip] bgp summary" commands. */
20171 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 20172 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 20173 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 20174 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 20175 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
20176 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 20177 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
20178
20179 /* "show [ip] bgp neighbors" commands. */
20180 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
20181
36235319 20182 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
2986cac2 20183
d62a17ae 20184 /* "show [ip] bgp peer-group" commands. */
20185 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
20186
20187 /* "show [ip] bgp paths" commands. */
20188 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
20189
20190 /* "show [ip] bgp community" commands. */
20191 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
20192
20193 /* "show ip bgp large-community" commands. */
20194 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
20195 /* "show [ip] bgp attribute-info" commands. */
20196 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 20197 /* "show [ip] bgp route-leak" command */
20198 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 20199
20200 /* "redistribute" commands. */
20201 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
20202 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
20203 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
20204 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
20205 install_element(BGP_NODE,
20206 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
20207 install_element(BGP_NODE,
20208 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
20209 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
20210 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
20211 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
20212 install_element(BGP_NODE,
20213 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
20214 install_element(BGP_NODE,
20215 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
20216 install_element(BGP_NODE,
20217 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
20218 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
20219 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
20220 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
20221 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
20222 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
20223 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
20224 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
20225 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
20226 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
20227 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
20228 install_element(BGP_IPV4_NODE,
20229 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
20230 install_element(BGP_IPV4_NODE,
20231 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
20232 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
20233 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
20234 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
20235 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
20236 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
20237 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
20238
70dd370f 20239 /* import|export vpn [route-map RMAP_NAME] */
b9c7bc5a
PZ
20240 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
20241 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 20242
12a844a5
DS
20243 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
20244 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
20245
d62a17ae 20246 /* ttl_security commands */
20247 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
20248 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
20249
d1adb448
PG
20250 /* "bgp tcp-keepalive" commands */
20251 install_element(BGP_NODE, &bgp_tcp_keepalive_cmd);
20252 install_element(BGP_NODE, &no_bgp_tcp_keepalive_cmd);
20253
d62a17ae 20254 /* "show [ip] bgp memory" commands. */
20255 install_element(VIEW_NODE, &show_bgp_memory_cmd);
20256
acf71666
MK
20257 /* "show bgp martian next-hop" */
20258 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
20259
48ecf8f5
DS
20260 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
20261
d62a17ae 20262 /* "show [ip] bgp views" commands. */
20263 install_element(VIEW_NODE, &show_bgp_views_cmd);
20264
20265 /* "show [ip] bgp vrfs" commands. */
20266 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
20267
20268 /* Community-list. */
20269 community_list_vty();
ddb5b488 20270
ed0e57e3
DA
20271 community_alias_vty();
20272
ddb5b488 20273 /* vpn-policy commands */
b9c7bc5a
PZ
20274 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
20275 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
20276 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
20277 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
20278 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
20279 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
20280 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
20281 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
20282 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
20283 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
20284 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
20285 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 20286
301ad80a
PG
20287 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
20288 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
20289
b9c7bc5a
PZ
20290 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
20291 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
20292 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
20293 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
b9c7bc5a
PZ
20294 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
20295 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
20296 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
20297 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
20298 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
20299 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
4ab46701
AR
20300
20301 /* tcp-mss command */
20302 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
20303 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
bfaab44d
HS
20304
20305 /* srv6 commands */
ea372e81 20306 install_element(VIEW_NODE, &show_bgp_srv6_cmd);
bfaab44d 20307 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
0249b8b6 20308 install_element(BGP_NODE, &no_bgp_segment_routing_srv6_cmd);
a0281b2e 20309 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
0249b8b6 20310 install_element(BGP_SRV6_NODE, &no_bgp_srv6_locator_cmd);
b72c9e14
HS
20311 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
20312 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
527588aa 20313 install_element(BGP_NODE, &bgp_sid_vpn_export_cmd);
e606d8ec 20314 install_element(BGP_NODE, &no_bgp_sid_vpn_export_cmd);
4cd690ae
PG
20315
20316 bgp_vty_if_init();
718e3744 20317}
6b0655a2 20318
718e3744 20319#include "memory.h"
20320#include "bgp_regex.h"
20321#include "bgp_clist.h"
20322#include "bgp_ecommunity.h"
20323
20324/* VTY functions. */
20325
20326/* Direction value to string conversion. */
d62a17ae 20327static const char *community_direct_str(int direct)
20328{
20329 switch (direct) {
20330 case COMMUNITY_DENY:
20331 return "deny";
20332 case COMMUNITY_PERMIT:
20333 return "permit";
20334 default:
20335 return "unknown";
20336 }
718e3744 20337}
20338
20339/* Display error string. */
d62a17ae 20340static void community_list_perror(struct vty *vty, int ret)
20341{
20342 switch (ret) {
20343 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
20344 vty_out(vty, "%% Can't find community-list\n");
20345 break;
20346 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
20347 vty_out(vty, "%% Malformed community-list value\n");
20348 break;
20349 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
20350 vty_out(vty,
20351 "%% Community name conflict, previously defined as standard community\n");
20352 break;
20353 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
20354 vty_out(vty,
20355 "%% Community name conflict, previously defined as expanded community\n");
20356 break;
20357 }
718e3744 20358}
20359
5bf15956
DW
20360/* "community-list" keyword help string. */
20361#define COMMUNITY_LIST_STR "Add a community list entry\n"
20362
7336e101
SP
20363/*community-list standard */
20364DEFUN (community_list_standard,
20365 bgp_community_list_standard_cmd,
a2099c1d 20366 "bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 20367 BGP_STR
718e3744 20368 COMMUNITY_LIST_STR
20369 "Community list number (standard)\n"
5bf15956 20370 "Add an standard community-list entry\n"
718e3744 20371 "Community list name\n"
2f8cc0e5
DA
20372 "Sequence number of an entry\n"
20373 "Sequence number\n"
718e3744 20374 "Specify community to reject\n"
20375 "Specify community to accept\n"
20376 COMMUNITY_VAL_STR)
20377{
d62a17ae 20378 char *cl_name_or_number = NULL;
2f8cc0e5 20379 char *seq = NULL;
d62a17ae 20380 int direct = 0;
20381 int style = COMMUNITY_LIST_STANDARD;
d62a17ae 20382 int idx = 0;
7336e101 20383
e34627f9 20384 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20385 seq = argv[idx]->arg;
20386
20387 idx = 0;
d62a17ae 20388 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 20389 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 20390 cl_name_or_number = argv[idx]->arg;
20391 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20392 : COMMUNITY_DENY;
20393 argv_find(argv, argc, "AA:NN", &idx);
20394 char *str = argv_concat(argv, argc, idx);
42f914d4 20395
2f8cc0e5
DA
20396 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
20397 direct, style);
42f914d4 20398
d62a17ae 20399 XFREE(MTYPE_TMP, str);
42f914d4 20400
d62a17ae 20401 if (ret < 0) {
20402 /* Display error string. */
20403 community_list_perror(vty, ret);
20404 return CMD_WARNING_CONFIG_FAILED;
20405 }
42f914d4 20406
d62a17ae 20407 return CMD_SUCCESS;
718e3744 20408}
20409
7336e101
SP
20410DEFUN (no_community_list_standard_all,
20411 no_bgp_community_list_standard_all_cmd,
a2099c1d 20412 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
20413 NO_STR
20414 BGP_STR
20415 COMMUNITY_LIST_STR
20416 "Community list number (standard)\n"
20417 "Add an standard community-list entry\n"
20418 "Community list name\n"
2f8cc0e5
DA
20419 "Sequence number of an entry\n"
20420 "Sequence number\n"
7336e101
SP
20421 "Specify community to reject\n"
20422 "Specify community to accept\n"
20423 COMMUNITY_VAL_STR)
718e3744 20424{
d62a17ae 20425 char *cl_name_or_number = NULL;
174b5cb9 20426 char *str = NULL;
d62a17ae 20427 int direct = 0;
20428 int style = COMMUNITY_LIST_STANDARD;
2f8cc0e5 20429 char *seq = NULL;
d62a17ae 20430 int idx = 0;
7336e101 20431
e34627f9 20432 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20433 seq = argv[idx]->arg;
20434
20435 idx = 0;
174b5cb9
DA
20436 argv_find(argv, argc, "permit", &idx);
20437 argv_find(argv, argc, "deny", &idx);
20438
20439 if (idx) {
20440 direct = argv_find(argv, argc, "permit", &idx)
20441 ? COMMUNITY_PERMIT
20442 : COMMUNITY_DENY;
20443
20444 idx = 0;
20445 argv_find(argv, argc, "AA:NN", &idx);
20446 str = argv_concat(argv, argc, idx);
20447 }
20448
20449 idx = 0;
d62a17ae 20450 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 20451 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 20452 cl_name_or_number = argv[idx]->arg;
42f914d4 20453
2f8cc0e5 20454 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 20455 direct, style);
42f914d4 20456
d62a17ae 20457 XFREE(MTYPE_TMP, str);
daf9ddbb 20458
d62a17ae 20459 if (ret < 0) {
20460 community_list_perror(vty, ret);
20461 return CMD_WARNING_CONFIG_FAILED;
20462 }
42f914d4 20463
d62a17ae 20464 return CMD_SUCCESS;
718e3744 20465}
7336e101 20466
174b5cb9 20467ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
a2099c1d 20468 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME>",
174b5cb9
DA
20469 NO_STR BGP_STR COMMUNITY_LIST_STR
20470 "Community list number (standard)\n"
20471 "Add an standard community-list entry\n"
20472 "Community list name\n")
20473
7336e101
SP
20474/*community-list expanded */
20475DEFUN (community_list_expanded_all,
20476 bgp_community_list_expanded_all_cmd,
a2099c1d 20477 "bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
20478 BGP_STR
20479 COMMUNITY_LIST_STR
718e3744 20480 "Community list number (expanded)\n"
5bf15956 20481 "Add an expanded community-list entry\n"
718e3744 20482 "Community list name\n"
2f8cc0e5
DA
20483 "Sequence number of an entry\n"
20484 "Sequence number\n"
718e3744 20485 "Specify community to reject\n"
20486 "Specify community to accept\n"
20487 COMMUNITY_VAL_STR)
20488{
d62a17ae 20489 char *cl_name_or_number = NULL;
2f8cc0e5 20490 char *seq = NULL;
d62a17ae 20491 int direct = 0;
20492 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 20493 int idx = 0;
7b9a4750 20494
e34627f9 20495 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20496 seq = argv[idx]->arg;
20497
20498 idx = 0;
20499
d62a17ae 20500 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 20501 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 20502 cl_name_or_number = argv[idx]->arg;
20503 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20504 : COMMUNITY_DENY;
20505 argv_find(argv, argc, "AA:NN", &idx);
20506 char *str = argv_concat(argv, argc, idx);
42f914d4 20507
2f8cc0e5
DA
20508 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
20509 direct, style);
42f914d4 20510
d62a17ae 20511 XFREE(MTYPE_TMP, str);
42f914d4 20512
d62a17ae 20513 if (ret < 0) {
20514 /* Display error string. */
20515 community_list_perror(vty, ret);
20516 return CMD_WARNING_CONFIG_FAILED;
20517 }
42f914d4 20518
d62a17ae 20519 return CMD_SUCCESS;
718e3744 20520}
20521
7336e101
SP
20522DEFUN (no_community_list_expanded_all,
20523 no_bgp_community_list_expanded_all_cmd,
a2099c1d 20524 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
20525 NO_STR
20526 BGP_STR
20527 COMMUNITY_LIST_STR
20528 "Community list number (expanded)\n"
20529 "Add an expanded community-list entry\n"
20530 "Community list name\n"
2f8cc0e5
DA
20531 "Sequence number of an entry\n"
20532 "Sequence number\n"
7336e101
SP
20533 "Specify community to reject\n"
20534 "Specify community to accept\n"
20535 COMMUNITY_VAL_STR)
718e3744 20536{
d62a17ae 20537 char *cl_name_or_number = NULL;
2f8cc0e5 20538 char *seq = NULL;
174b5cb9 20539 char *str = NULL;
d62a17ae 20540 int direct = 0;
20541 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 20542 int idx = 0;
174b5cb9 20543
e34627f9 20544 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20545 seq = argv[idx]->arg;
20546
20547 idx = 0;
174b5cb9
DA
20548 argv_find(argv, argc, "permit", &idx);
20549 argv_find(argv, argc, "deny", &idx);
20550
20551 if (idx) {
20552 direct = argv_find(argv, argc, "permit", &idx)
20553 ? COMMUNITY_PERMIT
20554 : COMMUNITY_DENY;
20555
20556 idx = 0;
20557 argv_find(argv, argc, "AA:NN", &idx);
20558 str = argv_concat(argv, argc, idx);
7336e101 20559 }
174b5cb9
DA
20560
20561 idx = 0;
d62a17ae 20562 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 20563 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 20564 cl_name_or_number = argv[idx]->arg;
42f914d4 20565
2f8cc0e5 20566 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 20567 direct, style);
42f914d4 20568
d62a17ae 20569 XFREE(MTYPE_TMP, str);
daf9ddbb 20570
d62a17ae 20571 if (ret < 0) {
20572 community_list_perror(vty, ret);
20573 return CMD_WARNING_CONFIG_FAILED;
20574 }
42f914d4 20575
d62a17ae 20576 return CMD_SUCCESS;
718e3744 20577}
20578
36d4bb44
EB
20579ALIAS(no_community_list_expanded_all,
20580 no_bgp_community_list_expanded_all_list_cmd,
a2099c1d 20581 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME>",
36d4bb44 20582 NO_STR BGP_STR COMMUNITY_LIST_STR
174b5cb9
DA
20583 "Community list number (expanded)\n"
20584 "Add an expanded community-list entry\n"
20585 "Community list name\n")
20586
8d9b8ed9
PM
20587/* Return configuration string of community-list entry. */
20588static const char *community_list_config_str(struct community_entry *entry)
20589{
20590 const char *str;
20591
20592 if (entry->any)
20593 str = "";
20594 else {
20595 if (entry->style == COMMUNITY_LIST_STANDARD)
c0945b78 20596 str = community_str(entry->u.com, false, false);
8d9b8ed9 20597 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
c0945b78 20598 str = lcommunity_str(entry->u.lcom, false, false);
8d9b8ed9
PM
20599 else
20600 str = entry->config;
20601 }
20602 return str;
20603}
20604
d62a17ae 20605static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 20606{
d62a17ae 20607 struct community_entry *entry;
718e3744 20608
d62a17ae 20609 for (entry = list->head; entry; entry = entry->next) {
20610 if (entry == list->head) {
20611 if (all_digit(list->name))
20612 vty_out(vty, "Community %s list %s\n",
20613 entry->style == COMMUNITY_LIST_STANDARD
20614 ? "standard"
20615 : "(expanded) access",
20616 list->name);
20617 else
20618 vty_out(vty, "Named Community %s list %s\n",
20619 entry->style == COMMUNITY_LIST_STANDARD
20620 ? "standard"
20621 : "expanded",
20622 list->name);
20623 }
20624 if (entry->any)
20625 vty_out(vty, " %s\n",
20626 community_direct_str(entry->direct));
20627 else
20628 vty_out(vty, " %s %s\n",
20629 community_direct_str(entry->direct),
8d9b8ed9 20630 community_list_config_str(entry));
d62a17ae 20631 }
718e3744 20632}
20633
7336e101
SP
20634DEFUN (show_community_list,
20635 show_bgp_community_list_cmd,
20636 "show bgp community-list",
718e3744 20637 SHOW_STR
7336e101 20638 BGP_STR
718e3744 20639 "List community-list\n")
20640{
d62a17ae 20641 struct community_list *list;
20642 struct community_list_master *cm;
718e3744 20643
d62a17ae 20644 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20645 if (!cm)
20646 return CMD_SUCCESS;
718e3744 20647
d62a17ae 20648 for (list = cm->num.head; list; list = list->next)
20649 community_list_show(vty, list);
718e3744 20650
d62a17ae 20651 for (list = cm->str.head; list; list = list->next)
20652 community_list_show(vty, list);
718e3744 20653
d62a17ae 20654 return CMD_SUCCESS;
718e3744 20655}
20656
7336e101
SP
20657DEFUN (show_community_list_arg,
20658 show_bgp_community_list_arg_cmd,
a2099c1d 20659 "show bgp community-list <(1-500)|COMMUNITY_LIST_NAME> detail",
7336e101
SP
20660 SHOW_STR
20661 BGP_STR
718e3744 20662 "List community-list\n"
20663 "Community-list number\n"
960b69b9 20664 "Community-list name\n"
20665 "Detailed information on community-list\n")
718e3744 20666{
d62a17ae 20667 int idx_comm_list = 3;
20668 struct community_list *list;
718e3744 20669
e237b0d2 20670 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 20671 COMMUNITY_LIST_MASTER);
20672 if (!list) {
20673 vty_out(vty, "%% Can't find community-list\n");
20674 return CMD_WARNING;
20675 }
718e3744 20676
d62a17ae 20677 community_list_show(vty, list);
718e3744 20678
d62a17ae 20679 return CMD_SUCCESS;
718e3744 20680}
6b0655a2 20681
57d187bc
JS
20682/*
20683 * Large Community code.
20684 */
d62a17ae 20685static int lcommunity_list_set_vty(struct vty *vty, int argc,
20686 struct cmd_token **argv, int style,
20687 int reject_all_digit_name)
20688{
20689 int ret;
20690 int direct;
20691 char *str;
20692 int idx = 0;
20693 char *cl_name;
2f8cc0e5
DA
20694 char *seq = NULL;
20695
a08032fe 20696 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 20697 seq = argv[idx]->arg;
d62a17ae 20698
2f8cc0e5 20699 idx = 0;
d62a17ae 20700 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20701 : COMMUNITY_DENY;
20702
20703 /* All digit name check. */
20704 idx = 0;
a2099c1d 20705 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
d62a17ae 20706 argv_find(argv, argc, "(1-99)", &idx);
20707 argv_find(argv, argc, "(100-500)", &idx);
20708 cl_name = argv[idx]->arg;
20709 if (reject_all_digit_name && all_digit(cl_name)) {
20710 vty_out(vty, "%% Community name cannot have all digits\n");
20711 return CMD_WARNING_CONFIG_FAILED;
20712 }
20713
20714 idx = 0;
20715 argv_find(argv, argc, "AA:BB:CC", &idx);
20716 argv_find(argv, argc, "LINE", &idx);
20717 /* Concat community string argument. */
20718 if (idx)
20719 str = argv_concat(argv, argc, idx);
20720 else
20721 str = NULL;
20722
2f8cc0e5 20723 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
d62a17ae 20724
20725 /* Free temporary community list string allocated by
20726 argv_concat(). */
0a22ddfb 20727 XFREE(MTYPE_TMP, str);
d62a17ae 20728
20729 if (ret < 0) {
20730 community_list_perror(vty, ret);
20731 return CMD_WARNING_CONFIG_FAILED;
20732 }
20733 return CMD_SUCCESS;
20734}
20735
20736static int lcommunity_list_unset_vty(struct vty *vty, int argc,
20737 struct cmd_token **argv, int style)
20738{
20739 int ret;
20740 int direct = 0;
20741 char *str = NULL;
20742 int idx = 0;
2f8cc0e5 20743 char *seq = NULL;
d62a17ae 20744
a08032fe 20745 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 20746 seq = argv[idx]->arg;
d62a17ae 20747
2f8cc0e5 20748 idx = 0;
d62a17ae 20749 argv_find(argv, argc, "permit", &idx);
20750 argv_find(argv, argc, "deny", &idx);
20751
20752 if (idx) {
20753 /* Check the list direct. */
20754 if (strncmp(argv[idx]->arg, "p", 1) == 0)
20755 direct = COMMUNITY_PERMIT;
20756 else
20757 direct = COMMUNITY_DENY;
20758
20759 idx = 0;
20760 argv_find(argv, argc, "LINE", &idx);
20761 argv_find(argv, argc, "AA:AA:NN", &idx);
20762 /* Concat community string argument. */
20763 str = argv_concat(argv, argc, idx);
20764 }
20765
20766 idx = 0;
20767 argv_find(argv, argc, "(1-99)", &idx);
20768 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 20769 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
d62a17ae 20770
20771 /* Unset community list. */
2f8cc0e5 20772 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
d62a17ae 20773 style);
20774
20775 /* Free temporary community list string allocated by
20776 argv_concat(). */
0a22ddfb 20777 XFREE(MTYPE_TMP, str);
d62a17ae 20778
20779 if (ret < 0) {
20780 community_list_perror(vty, ret);
20781 return CMD_WARNING_CONFIG_FAILED;
20782 }
20783
20784 return CMD_SUCCESS;
57d187bc
JS
20785}
20786
20787/* "large-community-list" keyword help string. */
20788#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
20789#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
20790
7336e101
SP
20791DEFUN (lcommunity_list_standard,
20792 bgp_lcommunity_list_standard_cmd,
a08032fe 20793 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
20794 BGP_STR
20795 LCOMMUNITY_LIST_STR
20796 "Large Community list number (standard)\n"
2f8cc0e5
DA
20797 "Sequence number of an entry\n"
20798 "Sequence number\n"
7336e101
SP
20799 "Specify large community to reject\n"
20800 "Specify large community to accept\n"
20801 LCOMMUNITY_VAL_STR)
52951b63 20802{
d62a17ae 20803 return lcommunity_list_set_vty(vty, argc, argv,
20804 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
20805}
20806
7336e101
SP
20807DEFUN (lcommunity_list_expanded,
20808 bgp_lcommunity_list_expanded_cmd,
a08032fe 20809 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20810 BGP_STR
20811 LCOMMUNITY_LIST_STR
20812 "Large Community list number (expanded)\n"
2f8cc0e5
DA
20813 "Sequence number of an entry\n"
20814 "Sequence number\n"
7336e101
SP
20815 "Specify large community to reject\n"
20816 "Specify large community to accept\n"
20817 "An ordered list as a regular-expression\n")
57d187bc 20818{
d62a17ae 20819 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 20820 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
20821}
20822
7336e101
SP
20823DEFUN (lcommunity_list_name_standard,
20824 bgp_lcommunity_list_name_standard_cmd,
a2099c1d 20825 "bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
20826 BGP_STR
20827 LCOMMUNITY_LIST_STR
20828 "Specify standard large-community-list\n"
20829 "Large Community list name\n"
2f8cc0e5
DA
20830 "Sequence number of an entry\n"
20831 "Sequence number\n"
7336e101
SP
20832 "Specify large community to reject\n"
20833 "Specify large community to accept\n"
20834 LCOMMUNITY_VAL_STR)
52951b63 20835{
d62a17ae 20836 return lcommunity_list_set_vty(vty, argc, argv,
20837 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
20838}
20839
7336e101
SP
20840DEFUN (lcommunity_list_name_expanded,
20841 bgp_lcommunity_list_name_expanded_cmd,
a2099c1d 20842 "bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20843 BGP_STR
20844 LCOMMUNITY_LIST_STR
20845 "Specify expanded large-community-list\n"
20846 "Large Community list name\n"
2f8cc0e5
DA
20847 "Sequence number of an entry\n"
20848 "Sequence number\n"
7336e101
SP
20849 "Specify large community to reject\n"
20850 "Specify large community to accept\n"
20851 "An ordered list as a regular-expression\n")
57d187bc 20852{
d62a17ae 20853 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 20854 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
20855}
20856
4378f57c
DA
20857DEFUN (no_lcommunity_list_all,
20858 no_bgp_lcommunity_list_all_cmd,
a2099c1d 20859 "no bgp large-community-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME>",
7336e101
SP
20860 NO_STR
20861 BGP_STR
20862 LCOMMUNITY_LIST_STR
20863 "Large Community list number (standard)\n"
20864 "Large Community list number (expanded)\n"
20865 "Large Community list name\n")
57d187bc 20866{
7336e101
SP
20867 return lcommunity_list_unset_vty(vty, argc, argv,
20868 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
20869}
20870
4378f57c
DA
20871DEFUN (no_lcommunity_list_name_standard_all,
20872 no_bgp_lcommunity_list_name_standard_all_cmd,
a2099c1d 20873 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME",
4378f57c
DA
20874 NO_STR
20875 BGP_STR
20876 LCOMMUNITY_LIST_STR
20877 "Specify standard large-community-list\n"
20878 "Large Community list name\n")
20879{
20880 return lcommunity_list_unset_vty(vty, argc, argv,
20881 LARGE_COMMUNITY_LIST_STANDARD);
20882}
20883
7336e101
SP
20884DEFUN (no_lcommunity_list_name_expanded_all,
20885 no_bgp_lcommunity_list_name_expanded_all_cmd,
a2099c1d 20886 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME",
7336e101
SP
20887 NO_STR
20888 BGP_STR
20889 LCOMMUNITY_LIST_STR
20890 "Specify expanded large-community-list\n"
20891 "Large Community list name\n")
57d187bc 20892{
d62a17ae 20893 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 20894 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
20895}
20896
7336e101
SP
20897DEFUN (no_lcommunity_list_standard,
20898 no_bgp_lcommunity_list_standard_cmd,
a08032fe 20899 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
20900 NO_STR
20901 BGP_STR
20902 LCOMMUNITY_LIST_STR
20903 "Large Community list number (standard)\n"
2f8cc0e5
DA
20904 "Sequence number of an entry\n"
20905 "Sequence number\n"
7336e101
SP
20906 "Specify large community to reject\n"
20907 "Specify large community to accept\n"
20908 LCOMMUNITY_VAL_STR)
57d187bc 20909{
d62a17ae 20910 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 20911 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
20912}
20913
7336e101
SP
20914DEFUN (no_lcommunity_list_expanded,
20915 no_bgp_lcommunity_list_expanded_cmd,
a08032fe 20916 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20917 NO_STR
20918 BGP_STR
20919 LCOMMUNITY_LIST_STR
20920 "Large Community list number (expanded)\n"
2f8cc0e5
DA
20921 "Sequence number of an entry\n"
20922 "Sequence number\n"
7336e101
SP
20923 "Specify large community to reject\n"
20924 "Specify large community to accept\n"
20925 "An ordered list as a regular-expression\n")
57d187bc 20926{
d62a17ae 20927 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 20928 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
20929}
20930
7336e101
SP
20931DEFUN (no_lcommunity_list_name_standard,
20932 no_bgp_lcommunity_list_name_standard_cmd,
a2099c1d 20933 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
20934 NO_STR
20935 BGP_STR
20936 LCOMMUNITY_LIST_STR
20937 "Specify standard large-community-list\n"
20938 "Large Community list name\n"
2f8cc0e5
DA
20939 "Sequence number of an entry\n"
20940 "Sequence number\n"
7336e101
SP
20941 "Specify large community to reject\n"
20942 "Specify large community to accept\n"
20943 LCOMMUNITY_VAL_STR)
57d187bc 20944{
d62a17ae 20945 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 20946 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
20947}
20948
7336e101
SP
20949DEFUN (no_lcommunity_list_name_expanded,
20950 no_bgp_lcommunity_list_name_expanded_cmd,
a2099c1d 20951 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20952 NO_STR
20953 BGP_STR
20954 LCOMMUNITY_LIST_STR
20955 "Specify expanded large-community-list\n"
20956 "Large community list name\n"
2f8cc0e5
DA
20957 "Sequence number of an entry\n"
20958 "Sequence number\n"
7336e101
SP
20959 "Specify large community to reject\n"
20960 "Specify large community to accept\n"
20961 "An ordered list as a regular-expression\n")
57d187bc 20962{
d62a17ae 20963 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 20964 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
20965}
20966
d62a17ae 20967static void lcommunity_list_show(struct vty *vty, struct community_list *list)
20968{
20969 struct community_entry *entry;
20970
20971 for (entry = list->head; entry; entry = entry->next) {
20972 if (entry == list->head) {
20973 if (all_digit(list->name))
20974 vty_out(vty, "Large community %s list %s\n",
169b72c8 20975 entry->style ==
20976 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 20977 ? "standard"
20978 : "(expanded) access",
20979 list->name);
20980 else
20981 vty_out(vty,
20982 "Named large community %s list %s\n",
169b72c8 20983 entry->style ==
20984 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 20985 ? "standard"
20986 : "expanded",
20987 list->name);
20988 }
20989 if (entry->any)
20990 vty_out(vty, " %s\n",
20991 community_direct_str(entry->direct));
20992 else
20993 vty_out(vty, " %s %s\n",
20994 community_direct_str(entry->direct),
8d9b8ed9 20995 community_list_config_str(entry));
d62a17ae 20996 }
57d187bc
JS
20997}
20998
7336e101
SP
20999DEFUN (show_lcommunity_list,
21000 show_bgp_lcommunity_list_cmd,
21001 "show bgp large-community-list",
57d187bc 21002 SHOW_STR
7336e101 21003 BGP_STR
57d187bc
JS
21004 "List large-community list\n")
21005{
d62a17ae 21006 struct community_list *list;
21007 struct community_list_master *cm;
57d187bc 21008
d62a17ae 21009 cm = community_list_master_lookup(bgp_clist,
21010 LARGE_COMMUNITY_LIST_MASTER);
21011 if (!cm)
21012 return CMD_SUCCESS;
57d187bc 21013
d62a17ae 21014 for (list = cm->num.head; list; list = list->next)
21015 lcommunity_list_show(vty, list);
57d187bc 21016
d62a17ae 21017 for (list = cm->str.head; list; list = list->next)
21018 lcommunity_list_show(vty, list);
57d187bc 21019
d62a17ae 21020 return CMD_SUCCESS;
57d187bc
JS
21021}
21022
7336e101
SP
21023DEFUN (show_lcommunity_list_arg,
21024 show_bgp_lcommunity_list_arg_cmd,
a2099c1d 21025 "show bgp large-community-list <(1-500)|LCOMMUNITY_LIST_NAME> detail",
7336e101
SP
21026 SHOW_STR
21027 BGP_STR
57d187bc 21028 "List large-community list\n"
960b69b9 21029 "Large-community-list number\n"
21030 "Large-community-list name\n"
21031 "Detailed information on large-community-list\n")
57d187bc 21032{
d62a17ae 21033 struct community_list *list;
57d187bc 21034
e237b0d2 21035 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
d62a17ae 21036 LARGE_COMMUNITY_LIST_MASTER);
21037 if (!list) {
960b69b9 21038 vty_out(vty, "%% Can't find large-community-list\n");
d62a17ae 21039 return CMD_WARNING;
21040 }
57d187bc 21041
d62a17ae 21042 lcommunity_list_show(vty, list);
57d187bc 21043
d62a17ae 21044 return CMD_SUCCESS;
57d187bc
JS
21045}
21046
718e3744 21047/* "extcommunity-list" keyword help string. */
21048#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
21049#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
21050
7336e101
SP
21051DEFUN (extcommunity_list_standard,
21052 bgp_extcommunity_list_standard_cmd,
a2099c1d 21053 "bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 21054 BGP_STR
718e3744 21055 EXTCOMMUNITY_LIST_STR
21056 "Extended Community list number (standard)\n"
718e3744 21057 "Specify standard extcommunity-list\n"
5bf15956 21058 "Community list name\n"
2f8cc0e5
DA
21059 "Sequence number of an entry\n"
21060 "Sequence number\n"
718e3744 21061 "Specify community to reject\n"
21062 "Specify community to accept\n"
21063 EXTCOMMUNITY_VAL_STR)
21064{
d62a17ae 21065 int style = EXTCOMMUNITY_LIST_STANDARD;
21066 int direct = 0;
21067 char *cl_number_or_name = NULL;
2f8cc0e5 21068 char *seq = NULL;
42f914d4 21069
d62a17ae 21070 int idx = 0;
7b9a4750 21071
d62a17ae 21072 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 21073 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 21074 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 21075
a08032fe 21076 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
21077 seq = argv[idx]->arg;
21078
d62a17ae 21079 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
21080 : COMMUNITY_DENY;
21081 argv_find(argv, argc, "AA:NN", &idx);
21082 char *str = argv_concat(argv, argc, idx);
42f914d4 21083
2f8cc0e5 21084 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 21085 direct, style);
42f914d4 21086
d62a17ae 21087 XFREE(MTYPE_TMP, str);
42f914d4 21088
d62a17ae 21089 if (ret < 0) {
21090 community_list_perror(vty, ret);
21091 return CMD_WARNING_CONFIG_FAILED;
21092 }
42f914d4 21093
d62a17ae 21094 return CMD_SUCCESS;
718e3744 21095}
21096
7336e101
SP
21097DEFUN (extcommunity_list_name_expanded,
21098 bgp_extcommunity_list_name_expanded_cmd,
a2099c1d 21099 "bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
21100 BGP_STR
21101 EXTCOMMUNITY_LIST_STR
5bf15956 21102 "Extended Community list number (expanded)\n"
718e3744 21103 "Specify expanded extcommunity-list\n"
21104 "Extended Community list name\n"
2f8cc0e5
DA
21105 "Sequence number of an entry\n"
21106 "Sequence number\n"
718e3744 21107 "Specify community to reject\n"
21108 "Specify community to accept\n"
21109 "An ordered list as a regular-expression\n")
21110{
d62a17ae 21111 int style = EXTCOMMUNITY_LIST_EXPANDED;
21112 int direct = 0;
21113 char *cl_number_or_name = NULL;
2f8cc0e5 21114 char *seq = NULL;
d62a17ae 21115 int idx = 0;
7336e101 21116
d62a17ae 21117 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 21118 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 21119 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 21120
a08032fe 21121 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
21122 seq = argv[idx]->arg;
21123
d62a17ae 21124 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
21125 : COMMUNITY_DENY;
21126 argv_find(argv, argc, "LINE", &idx);
21127 char *str = argv_concat(argv, argc, idx);
42f914d4 21128
2f8cc0e5 21129 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 21130 direct, style);
42f914d4 21131
d62a17ae 21132 XFREE(MTYPE_TMP, str);
42f914d4 21133
d62a17ae 21134 if (ret < 0) {
21135 community_list_perror(vty, ret);
21136 return CMD_WARNING_CONFIG_FAILED;
21137 }
42f914d4 21138
d62a17ae 21139 return CMD_SUCCESS;
718e3744 21140}
21141
7336e101
SP
21142DEFUN (no_extcommunity_list_standard_all,
21143 no_bgp_extcommunity_list_standard_all_cmd,
a2099c1d 21144 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
21145 NO_STR
21146 BGP_STR
21147 EXTCOMMUNITY_LIST_STR
813d4307 21148 "Extended Community list number (standard)\n"
718e3744 21149 "Specify standard extcommunity-list\n"
5bf15956 21150 "Community list name\n"
2f8cc0e5
DA
21151 "Sequence number of an entry\n"
21152 "Sequence number\n"
718e3744 21153 "Specify community to reject\n"
21154 "Specify community to accept\n"
21155 EXTCOMMUNITY_VAL_STR)
21156{
d62a17ae 21157 int style = EXTCOMMUNITY_LIST_STANDARD;
21158 int direct = 0;
21159 char *cl_number_or_name = NULL;
d4455c89 21160 char *str = NULL;
2f8cc0e5 21161 char *seq = NULL;
d62a17ae 21162 int idx = 0;
d4455c89 21163
a08032fe 21164 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
21165 seq = argv[idx]->arg;
21166
21167 idx = 0;
d4455c89
DA
21168 argv_find(argv, argc, "permit", &idx);
21169 argv_find(argv, argc, "deny", &idx);
d4455c89
DA
21170 if (idx) {
21171 direct = argv_find(argv, argc, "permit", &idx)
21172 ? COMMUNITY_PERMIT
21173 : COMMUNITY_DENY;
21174
21175 idx = 0;
21176 argv_find(argv, argc, "AA:NN", &idx);
21177 str = argv_concat(argv, argc, idx);
21178 }
21179
21180 idx = 0;
d62a17ae 21181 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 21182 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 21183 cl_number_or_name = argv[idx]->arg;
42f914d4 21184
d62a17ae 21185 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 21186 seq, direct, style);
42f914d4 21187
d62a17ae 21188 XFREE(MTYPE_TMP, str);
42f914d4 21189
d62a17ae 21190 if (ret < 0) {
21191 community_list_perror(vty, ret);
21192 return CMD_WARNING_CONFIG_FAILED;
21193 }
42f914d4 21194
d62a17ae 21195 return CMD_SUCCESS;
718e3744 21196}
21197
d4455c89
DA
21198ALIAS(no_extcommunity_list_standard_all,
21199 no_bgp_extcommunity_list_standard_all_list_cmd,
a2099c1d 21200 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME>",
36d4bb44 21201 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
21202 "Extended Community list number (standard)\n"
21203 "Specify standard extcommunity-list\n"
21204 "Community list name\n")
21205
7336e101
SP
21206DEFUN (no_extcommunity_list_expanded_all,
21207 no_bgp_extcommunity_list_expanded_all_cmd,
a2099c1d 21208 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
21209 NO_STR
21210 BGP_STR
21211 EXTCOMMUNITY_LIST_STR
718e3744 21212 "Extended Community list number (expanded)\n"
718e3744 21213 "Specify expanded extcommunity-list\n"
5bf15956 21214 "Extended Community list name\n"
2f8cc0e5
DA
21215 "Sequence number of an entry\n"
21216 "Sequence number\n"
718e3744 21217 "Specify community to reject\n"
21218 "Specify community to accept\n"
21219 "An ordered list as a regular-expression\n")
21220{
d62a17ae 21221 int style = EXTCOMMUNITY_LIST_EXPANDED;
21222 int direct = 0;
21223 char *cl_number_or_name = NULL;
d4455c89 21224 char *str = NULL;
2f8cc0e5 21225 char *seq = NULL;
d62a17ae 21226 int idx = 0;
d4455c89 21227
a08032fe 21228 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
21229 seq = argv[idx]->arg;
21230
21231 idx = 0;
d4455c89
DA
21232 argv_find(argv, argc, "permit", &idx);
21233 argv_find(argv, argc, "deny", &idx);
21234
21235 if (idx) {
21236 direct = argv_find(argv, argc, "permit", &idx)
21237 ? COMMUNITY_PERMIT
21238 : COMMUNITY_DENY;
21239
21240 idx = 0;
21241 argv_find(argv, argc, "LINE", &idx);
21242 str = argv_concat(argv, argc, idx);
21243 }
21244
21245 idx = 0;
d62a17ae 21246 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 21247 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 21248 cl_number_or_name = argv[idx]->arg;
42f914d4 21249
d62a17ae 21250 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 21251 seq, direct, style);
42f914d4 21252
d62a17ae 21253 XFREE(MTYPE_TMP, str);
42f914d4 21254
d62a17ae 21255 if (ret < 0) {
21256 community_list_perror(vty, ret);
21257 return CMD_WARNING_CONFIG_FAILED;
21258 }
42f914d4 21259
d62a17ae 21260 return CMD_SUCCESS;
718e3744 21261}
21262
d4455c89
DA
21263ALIAS(no_extcommunity_list_expanded_all,
21264 no_bgp_extcommunity_list_expanded_all_list_cmd,
a2099c1d 21265 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME>",
36d4bb44 21266 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
21267 "Extended Community list number (expanded)\n"
21268 "Specify expanded extcommunity-list\n"
21269 "Extended Community list name\n")
21270
d62a17ae 21271static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 21272{
d62a17ae 21273 struct community_entry *entry;
718e3744 21274
d62a17ae 21275 for (entry = list->head; entry; entry = entry->next) {
21276 if (entry == list->head) {
21277 if (all_digit(list->name))
21278 vty_out(vty, "Extended community %s list %s\n",
21279 entry->style == EXTCOMMUNITY_LIST_STANDARD
21280 ? "standard"
21281 : "(expanded) access",
21282 list->name);
21283 else
21284 vty_out(vty,
21285 "Named extended community %s list %s\n",
21286 entry->style == EXTCOMMUNITY_LIST_STANDARD
21287 ? "standard"
21288 : "expanded",
21289 list->name);
21290 }
21291 if (entry->any)
21292 vty_out(vty, " %s\n",
21293 community_direct_str(entry->direct));
21294 else
21295 vty_out(vty, " %s %s\n",
21296 community_direct_str(entry->direct),
8d9b8ed9 21297 community_list_config_str(entry));
d62a17ae 21298 }
718e3744 21299}
21300
7336e101
SP
21301DEFUN (show_extcommunity_list,
21302 show_bgp_extcommunity_list_cmd,
21303 "show bgp extcommunity-list",
718e3744 21304 SHOW_STR
7336e101 21305 BGP_STR
718e3744 21306 "List extended-community list\n")
21307{
d62a17ae 21308 struct community_list *list;
21309 struct community_list_master *cm;
718e3744 21310
d62a17ae 21311 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
21312 if (!cm)
21313 return CMD_SUCCESS;
718e3744 21314
d62a17ae 21315 for (list = cm->num.head; list; list = list->next)
21316 extcommunity_list_show(vty, list);
718e3744 21317
d62a17ae 21318 for (list = cm->str.head; list; list = list->next)
21319 extcommunity_list_show(vty, list);
718e3744 21320
d62a17ae 21321 return CMD_SUCCESS;
718e3744 21322}
21323
7336e101
SP
21324DEFUN (show_extcommunity_list_arg,
21325 show_bgp_extcommunity_list_arg_cmd,
a2099c1d 21326 "show bgp extcommunity-list <(1-500)|EXTCOMMUNITY_LIST_NAME> detail",
7336e101
SP
21327 SHOW_STR
21328 BGP_STR
718e3744 21329 "List extended-community list\n"
21330 "Extcommunity-list number\n"
960b69b9 21331 "Extcommunity-list name\n"
21332 "Detailed information on extcommunity-list\n")
718e3744 21333{
d62a17ae 21334 int idx_comm_list = 3;
21335 struct community_list *list;
718e3744 21336
e237b0d2 21337 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 21338 EXTCOMMUNITY_LIST_MASTER);
21339 if (!list) {
21340 vty_out(vty, "%% Can't find extcommunity-list\n");
21341 return CMD_WARNING;
21342 }
718e3744 21343
d62a17ae 21344 extcommunity_list_show(vty, list);
718e3744 21345
d62a17ae 21346 return CMD_SUCCESS;
718e3744 21347}
6b0655a2 21348
718e3744 21349/* Display community-list and extcommunity-list configuration. */
d62a17ae 21350static int community_list_config_write(struct vty *vty)
21351{
21352 struct community_list *list;
21353 struct community_entry *entry;
21354 struct community_list_master *cm;
21355 int write = 0;
21356
21357 /* Community-list. */
21358 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
21359
21360 for (list = cm->num.head; list; list = list->next)
21361 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
21362 vty_out(vty,
21363 "bgp community-list %s seq %" PRId64 " %s %s\n",
21364 list->name, entry->seq,
d62a17ae 21365 community_direct_str(entry->direct),
21366 community_list_config_str(entry));
21367 write++;
21368 }
21369 for (list = cm->str.head; list; list = list->next)
21370 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
21371 vty_out(vty,
21372 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
d62a17ae 21373 entry->style == COMMUNITY_LIST_STANDARD
21374 ? "standard"
21375 : "expanded",
2f8cc0e5
DA
21376 list->name, entry->seq,
21377 community_direct_str(entry->direct),
d62a17ae 21378 community_list_config_str(entry));
21379 write++;
21380 }
21381
21382 /* Extcommunity-list. */
21383 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
21384
21385 for (list = cm->num.head; list; list = list->next)
21386 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
21387 vty_out(vty,
21388 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
21389 list->name, entry->seq,
21390 community_direct_str(entry->direct),
d62a17ae 21391 community_list_config_str(entry));
21392 write++;
21393 }
21394 for (list = cm->str.head; list; list = list->next)
21395 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 21396 vty_out(vty,
6cde4b45 21397 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
d62a17ae 21398 entry->style == EXTCOMMUNITY_LIST_STANDARD
21399 ? "standard"
21400 : "expanded",
2f8cc0e5
DA
21401 list->name, entry->seq,
21402 community_direct_str(entry->direct),
d62a17ae 21403 community_list_config_str(entry));
21404 write++;
21405 }
21406
21407
21408 /* lcommunity-list. */
21409 cm = community_list_master_lookup(bgp_clist,
21410 LARGE_COMMUNITY_LIST_MASTER);
21411
21412 for (list = cm->num.head; list; list = list->next)
21413 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 21414 vty_out(vty,
6cde4b45 21415 "bgp large-community-list %s seq %" PRId64" %s %s\n",
2f8cc0e5
DA
21416 list->name, entry->seq,
21417 community_direct_str(entry->direct),
d62a17ae 21418 community_list_config_str(entry));
21419 write++;
21420 }
21421 for (list = cm->str.head; list; list = list->next)
21422 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 21423 vty_out(vty,
6cde4b45 21424 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
2f8cc0e5 21425
d62a17ae 21426 entry->style == LARGE_COMMUNITY_LIST_STANDARD
21427 ? "standard"
21428 : "expanded",
2f8cc0e5 21429 list->name, entry->seq, community_direct_str(entry->direct),
d62a17ae 21430 community_list_config_str(entry));
21431 write++;
21432 }
21433
21434 return write;
21435}
21436
612c2c15 21437static int community_list_config_write(struct vty *vty);
d62a17ae 21438static struct cmd_node community_list_node = {
f4b8291f 21439 .name = "community list",
62b346ee
DL
21440 .node = COMMUNITY_LIST_NODE,
21441 .prompt = "",
612c2c15 21442 .config_write = community_list_config_write,
718e3744 21443};
21444
d62a17ae 21445static void community_list_vty(void)
21446{
612c2c15 21447 install_node(&community_list_node);
d62a17ae 21448
21449 /* Community-list. */
7336e101
SP
21450 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
21451 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
21452 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 21453 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 21454 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 21455 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
21456 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
21457 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 21458
21459 /* Extcommunity-list. */
7336e101
SP
21460 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
21461 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
21462 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
d4455c89
DA
21463 install_element(CONFIG_NODE,
21464 &no_bgp_extcommunity_list_standard_all_list_cmd);
7336e101 21465 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
d4455c89
DA
21466 install_element(CONFIG_NODE,
21467 &no_bgp_extcommunity_list_expanded_all_list_cmd);
7336e101
SP
21468 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
21469 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 21470
21471 /* Large Community List */
7336e101 21472 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
7336e101
SP
21473 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
21474 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
7336e101 21475 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
4378f57c
DA
21476 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
21477 install_element(CONFIG_NODE,
21478 &no_bgp_lcommunity_list_name_standard_all_cmd);
7336e101
SP
21479 install_element(CONFIG_NODE,
21480 &no_bgp_lcommunity_list_name_expanded_all_cmd);
21481 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
21482 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
21483 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
21484 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
21485 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
21486 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
225096bc
DA
21487
21488 bgp_community_list_command_completion_setup();
5bf15956 21489}
ed0e57e3
DA
21490
21491static struct cmd_node community_alias_node = {
21492 .name = "community alias",
21493 .node = COMMUNITY_ALIAS_NODE,
21494 .prompt = "",
21495 .config_write = bgp_community_alias_write,
21496};
21497
21498void community_alias_vty(void)
21499{
21500 install_node(&community_alias_node);
21501
21502 /* Community-list. */
21503 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
b4ad2fae
DS
21504
21505 bgp_community_alias_command_completion_setup();
ed0e57e3 21506}