]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
Merge pull request #12375 from chiragshah6/fdev1
[mirror_frr.git] / bgpd / bgp_vty.c
CommitLineData
718e3744 1/* BGP VTY interface.
896014f4
DL
2 * Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
718e3744 20
21#include <zebra.h>
22
23#include "command.h"
afec25d9 24#include "lib/json.h"
4ab46701 25#include "lib/sockopt.h"
5cb5f4d0 26#include "lib_errors.h"
ec0ab544 27#include "lib/zclient.h"
6f4eacf3 28#include "lib/printfrr.h"
718e3744 29#include "prefix.h"
30#include "plist.h"
31#include "buffer.h"
32#include "linklist.h"
33#include "stream.h"
34#include "thread.h"
35#include "log.h"
3b8b1855 36#include "memory.h"
1c0d8808 37#include "lib_vty.h"
4bf6a362 38#include "hash.h"
3f9c7369 39#include "queue.h"
039f3a34 40#include "filter.h"
5d5ba018 41#include "frrstr.h"
718e3744 42
43#include "bgpd/bgpd.h"
48ecf8f5 44#include "bgpd/bgp_attr_evpn.h"
4bf6a362 45#include "bgpd/bgp_advertise.h"
718e3744 46#include "bgpd/bgp_attr.h"
47#include "bgpd/bgp_aspath.h"
48#include "bgpd/bgp_community.h"
ed0e57e3 49#include "bgpd/bgp_community_alias.h"
4bf6a362 50#include "bgpd/bgp_ecommunity.h"
57d187bc 51#include "bgpd/bgp_lcommunity.h"
4bf6a362 52#include "bgpd/bgp_damp.h"
718e3744 53#include "bgpd/bgp_debug.h"
14454c9f 54#include "bgpd/bgp_errors.h"
e0701b79 55#include "bgpd/bgp_fsm.h"
4cd690ae 56#include "bgpd/bgp_nht.h"
4bf6a362 57#include "bgpd/bgp_nexthop.h"
4122b697 58#include "bgpd/bgp_network.h"
718e3744 59#include "bgpd/bgp_open.h"
4bf6a362 60#include "bgpd/bgp_regex.h"
718e3744 61#include "bgpd/bgp_route.h"
c016b6c7 62#include "bgpd/bgp_mplsvpn.h"
718e3744 63#include "bgpd/bgp_zebra.h"
fee0f4c6 64#include "bgpd/bgp_table.h"
94f2b392 65#include "bgpd/bgp_vty.h"
165b5fff 66#include "bgpd/bgp_mpath.h"
cb1faec9 67#include "bgpd/bgp_packet.h"
3f9c7369 68#include "bgpd/bgp_updgrp.h"
c43ed2e4 69#include "bgpd/bgp_bfd.h"
555e09d4 70#include "bgpd/bgp_io.h"
94c2f693 71#include "bgpd/bgp_evpn.h"
dd65f45e 72#include "bgpd/bgp_evpn_vty.h"
b5e140c8 73#include "bgpd/bgp_evpn_mh.h"
dcc68b5e 74#include "bgpd/bgp_addpath.h"
48ecf8f5 75#include "bgpd/bgp_mac.h"
dd65f45e 76#include "bgpd/bgp_flowspec.h"
389e4f92 77#include "bgpd/bgp_conditional_adv.h"
49e5a4a0 78#ifdef ENABLE_BGP_VNC
dd65f45e
DL
79#include "bgpd/rfapi/bgp_rfapi_cfg.h"
80#endif
70cd87ca
MK
81#include "bgpd/bgp_orr.h"
82
dd65f45e 83
5d5393b9 84FRR_CFG_DEFAULT_BOOL(BGP_IMPORT_CHECK,
62282e83
DS
85 {
86 .val_bool = false,
87 .match_profile = "traditional",
88 .match_version = "< 7.4",
89 },
90 { .val_bool = true },
67b0f40c 91);
5d5393b9 92FRR_CFG_DEFAULT_BOOL(BGP_SHOW_HOSTNAME,
4c1458b5
DL
93 { .val_bool = true, .match_profile = "datacenter", },
94 { .val_bool = false },
67b0f40c 95);
aef999a2
DA
96FRR_CFG_DEFAULT_BOOL(BGP_SHOW_NEXTHOP_HOSTNAME,
97 { .val_bool = true, .match_profile = "datacenter", },
98 { .val_bool = false },
67b0f40c 99);
5d5393b9 100FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
4c1458b5
DL
101 { .val_bool = true, .match_profile = "datacenter", },
102 { .val_bool = false },
67b0f40c 103);
5d5393b9 104FRR_CFG_DEFAULT_BOOL(BGP_DETERMINISTIC_MED,
4c1458b5
DL
105 { .val_bool = true, .match_profile = "datacenter", },
106 { .val_bool = false },
67b0f40c 107);
5d5393b9
DL
108FRR_CFG_DEFAULT_ULONG(BGP_CONNECT_RETRY,
109 { .val_ulong = 10, .match_profile = "datacenter", },
110 { .val_ulong = 120 },
67b0f40c 111);
5d5393b9
DL
112FRR_CFG_DEFAULT_ULONG(BGP_HOLDTIME,
113 { .val_ulong = 9, .match_profile = "datacenter", },
114 { .val_ulong = 180 },
67b0f40c 115);
5d5393b9
DL
116FRR_CFG_DEFAULT_ULONG(BGP_KEEPALIVE,
117 { .val_ulong = 3, .match_profile = "datacenter", },
118 { .val_ulong = 60 },
67b0f40c 119);
1d3fdccf
DA
120FRR_CFG_DEFAULT_BOOL(BGP_EBGP_REQUIRES_POLICY,
121 { .val_bool = false, .match_profile = "datacenter", },
122 { .val_bool = false, .match_version = "< 7.4", },
123 { .val_bool = true },
67b0f40c 124);
2adac256
DA
125FRR_CFG_DEFAULT_BOOL(BGP_SUPPRESS_DUPLICATES,
126 { .val_bool = false, .match_version = "< 7.6", },
127 { .val_bool = true },
67b0f40c 128);
f2ca5c5b
DA
129FRR_CFG_DEFAULT_BOOL(BGP_GRACEFUL_NOTIFICATION,
130 { .val_bool = false, .match_version = "< 8.3", },
131 { .val_bool = true },
132);
1ae314be
DA
133FRR_CFG_DEFAULT_BOOL(BGP_HARD_ADMIN_RESET,
134 { .val_bool = false, .match_version = "< 8.3", },
135 { .val_bool = true },
136);
5d5393b9 137
dd65f45e
DL
138DEFINE_HOOK(bgp_inst_config_write,
139 (struct bgp *bgp, struct vty *vty),
8451921b
DL
140 (bgp, vty));
141DEFINE_HOOK(bgp_snmp_update_last_changed, (struct bgp *bgp), (bgp));
1ca2fd11 142DEFINE_HOOK(bgp_snmp_init_stats, (struct bgp *bgp), (bgp));
718e3744 143
d62a17ae 144static struct peer_group *listen_range_exists(struct bgp *bgp,
145 struct prefix *range, int exact);
146
055679e9 147/* Show BGP peer's information. */
148enum show_type {
149 show_all,
150 show_peer,
151 show_ipv4_all,
152 show_ipv6_all,
153 show_ipv4_peer,
154 show_ipv6_peer
155};
156
36235319
QY
157static struct peer_group *listen_range_exists(struct bgp *bgp,
158 struct prefix *range, int exact);
2986cac2 159
36235319
QY
160static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
161 struct bgp *bgp,
162 bool use_json,
163 json_object *json);
2986cac2 164
36235319
QY
165static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
166 enum show_type type,
167 const char *ip_str,
168 afi_t afi, bool use_json);
2986cac2 169
d62a17ae 170static enum node_type bgp_node_type(afi_t afi, safi_t safi)
171{
172 switch (afi) {
173 case AFI_IP:
174 switch (safi) {
175 case SAFI_UNICAST:
176 return BGP_IPV4_NODE;
d62a17ae 177 case SAFI_MULTICAST:
178 return BGP_IPV4M_NODE;
d62a17ae 179 case SAFI_LABELED_UNICAST:
180 return BGP_IPV4L_NODE;
d62a17ae 181 case SAFI_MPLS_VPN:
182 return BGP_VPNV4_NODE;
7c40bf39 183 case SAFI_FLOWSPEC:
184 return BGP_FLOWSPECV4_NODE;
5c525538
RW
185 default:
186 /* not expected */
187 return BGP_IPV4_NODE;
d62a17ae 188 }
d62a17ae 189 case AFI_IP6:
190 switch (safi) {
191 case SAFI_UNICAST:
192 return BGP_IPV6_NODE;
d62a17ae 193 case SAFI_MULTICAST:
194 return BGP_IPV6M_NODE;
d62a17ae 195 case SAFI_LABELED_UNICAST:
196 return BGP_IPV6L_NODE;
d62a17ae 197 case SAFI_MPLS_VPN:
198 return BGP_VPNV6_NODE;
7c40bf39 199 case SAFI_FLOWSPEC:
200 return BGP_FLOWSPECV6_NODE;
5c525538
RW
201 default:
202 /* not expected */
203 return BGP_IPV4_NODE;
d62a17ae 204 }
d62a17ae 205 case AFI_L2VPN:
206 return BGP_EVPN_NODE;
b26f891d 207 case AFI_UNSPEC:
d62a17ae 208 case AFI_MAX:
209 // We should never be here but to clarify the switch statement..
210 return BGP_IPV4_NODE;
d62a17ae 211 }
212
213 // Impossible to happen
214 return BGP_IPV4_NODE;
f51bae9c 215}
20eb8864 216
5cb5f4d0
DD
217static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
218{
7d0d37de
DS
219 if (afi == AFI_IP) {
220 if (safi == SAFI_UNICAST)
221 return "IPv4 Unicast";
222 if (safi == SAFI_MULTICAST)
223 return "IPv4 Multicast";
224 if (safi == SAFI_LABELED_UNICAST)
225 return "IPv4 Labeled Unicast";
226 if (safi == SAFI_MPLS_VPN)
227 return "IPv4 VPN";
228 if (safi == SAFI_ENCAP)
229 return "IPv4 Encap";
230 if (safi == SAFI_FLOWSPEC)
231 return "IPv4 Flowspec";
232 } else if (afi == AFI_IP6) {
233 if (safi == SAFI_UNICAST)
234 return "IPv6 Unicast";
235 if (safi == SAFI_MULTICAST)
236 return "IPv6 Multicast";
237 if (safi == SAFI_LABELED_UNICAST)
238 return "IPv6 Labeled Unicast";
239 if (safi == SAFI_MPLS_VPN)
240 return "IPv6 VPN";
241 if (safi == SAFI_ENCAP)
242 return "IPv6 Encap";
243 if (safi == SAFI_FLOWSPEC)
244 return "IPv6 Flowspec";
245 } else if (afi == AFI_L2VPN) {
246 if (safi == SAFI_EVPN)
247 return "L2VPN EVPN";
248 }
249
250 return "Unknown";
5cb5f4d0
DD
251}
252
253/*
254 * Please note that we have intentionally camelCased
255 * the return strings here. So if you want
256 * to use this function, please ensure you
257 * are doing this within json output
258 */
259static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
260{
7d0d37de
DS
261 if (afi == AFI_IP) {
262 if (safi == SAFI_UNICAST)
263 return "ipv4Unicast";
264 if (safi == SAFI_MULTICAST)
265 return "ipv4Multicast";
266 if (safi == SAFI_LABELED_UNICAST)
267 return "ipv4LabeledUnicast";
268 if (safi == SAFI_MPLS_VPN)
269 return "ipv4Vpn";
270 if (safi == SAFI_ENCAP)
271 return "ipv4Encap";
272 if (safi == SAFI_FLOWSPEC)
273 return "ipv4Flowspec";
274 } else if (afi == AFI_IP6) {
275 if (safi == SAFI_UNICAST)
276 return "ipv6Unicast";
277 if (safi == SAFI_MULTICAST)
278 return "ipv6Multicast";
279 if (safi == SAFI_LABELED_UNICAST)
280 return "ipv6LabeledUnicast";
281 if (safi == SAFI_MPLS_VPN)
282 return "ipv6Vpn";
283 if (safi == SAFI_ENCAP)
284 return "ipv6Encap";
285 if (safi == SAFI_FLOWSPEC)
286 return "ipv6Flowspec";
287 } else if (afi == AFI_L2VPN) {
288 if (safi == SAFI_EVPN)
289 return "l2VpnEvpn";
290 }
291
292 return "Unknown";
5cb5f4d0
DD
293}
294
0249b8b6
HS
295/* unset srv6 locator */
296static int bgp_srv6_locator_unset(struct bgp *bgp)
297{
298 int ret;
299 struct listnode *node, *nnode;
efae8c26 300 struct srv6_locator_chunk *chunk;
0249b8b6
HS
301 struct bgp_srv6_function *func;
302 struct bgp *bgp_vrf;
0249b8b6
HS
303
304 /* release chunk notification via ZAPI */
305 ret = bgp_zebra_srv6_manager_release_locator_chunk(
306 bgp->srv6_locator_name);
307 if (ret < 0)
308 return -1;
309
310 /* refresh chunks */
03852f67 311 for (ALL_LIST_ELEMENTS(bgp->srv6_locator_chunks, node, nnode, chunk)) {
0249b8b6 312 listnode_delete(bgp->srv6_locator_chunks, chunk);
69467313 313 srv6_locator_chunk_free(&chunk);
03852f67 314 }
0249b8b6
HS
315
316 /* refresh functions */
bda15542 317 for (ALL_LIST_ELEMENTS(bgp->srv6_functions, node, nnode, func)) {
0249b8b6 318 listnode_delete(bgp->srv6_functions, func);
bda15542
CS
319 XFREE(MTYPE_BGP_SRV6_FUNCTION, func);
320 }
0249b8b6
HS
321
322 /* refresh tovpn_sid */
323 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
324 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
325 continue;
326
327 /* refresh vpnv4 tovpn_sid */
944909f4
CS
328 XFREE(MTYPE_BGP_SRV6_SID,
329 bgp_vrf->vpn_policy[AFI_IP].tovpn_sid);
0249b8b6
HS
330
331 /* refresh vpnv6 tovpn_sid */
944909f4
CS
332 XFREE(MTYPE_BGP_SRV6_SID,
333 bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid);
527588aa
CS
334
335 /* refresh per-vrf tovpn_sid */
336 XFREE(MTYPE_BGP_SRV6_SID, bgp_vrf->tovpn_sid);
0249b8b6
HS
337 }
338
339 /* update vpn bgp processes */
340 vpn_leak_postchange_all();
341
f8e9c702
CS
342 /* refresh tovpn_sid_locator */
343 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
344 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
345 continue;
346
347 /* refresh vpnv4 tovpn_sid_locator */
efae8c26
CS
348 srv6_locator_chunk_free(
349 &bgp_vrf->vpn_policy[AFI_IP].tovpn_sid_locator);
f8e9c702
CS
350
351 /* refresh vpnv6 tovpn_sid_locator */
efae8c26
CS
352 srv6_locator_chunk_free(
353 &bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid_locator);
527588aa
CS
354
355 /* refresh per-vrf tovpn_sid_locator */
69467313 356 srv6_locator_chunk_free(&bgp_vrf->tovpn_sid_locator);
f8e9c702
CS
357 }
358
0249b8b6
HS
359 /* clear locator name */
360 memset(bgp->srv6_locator_name, 0, sizeof(bgp->srv6_locator_name));
361
362 return 0;
363}
364
718e3744 365/* Utility function to get address family from current node. */
d62a17ae 366afi_t bgp_node_afi(struct vty *vty)
367{
368 afi_t afi;
369 switch (vty->node) {
370 case BGP_IPV6_NODE:
371 case BGP_IPV6M_NODE:
372 case BGP_IPV6L_NODE:
373 case BGP_VPNV6_NODE:
7c40bf39 374 case BGP_FLOWSPECV6_NODE:
d62a17ae 375 afi = AFI_IP6;
376 break;
377 case BGP_EVPN_NODE:
378 afi = AFI_L2VPN;
379 break;
380 default:
381 afi = AFI_IP;
382 break;
383 }
384 return afi;
718e3744 385}
386
387/* Utility function to get subsequent address family from current
388 node. */
d62a17ae 389safi_t bgp_node_safi(struct vty *vty)
390{
391 safi_t safi;
392 switch (vty->node) {
393 case BGP_VPNV4_NODE:
394 case BGP_VPNV6_NODE:
395 safi = SAFI_MPLS_VPN;
396 break;
397 case BGP_IPV4M_NODE:
398 case BGP_IPV6M_NODE:
399 safi = SAFI_MULTICAST;
400 break;
401 case BGP_EVPN_NODE:
402 safi = SAFI_EVPN;
403 break;
404 case BGP_IPV4L_NODE:
405 case BGP_IPV6L_NODE:
406 safi = SAFI_LABELED_UNICAST;
407 break;
7c40bf39 408 case BGP_FLOWSPECV4_NODE:
409 case BGP_FLOWSPECV6_NODE:
410 safi = SAFI_FLOWSPEC;
411 break;
d62a17ae 412 default:
413 safi = SAFI_UNICAST;
414 break;
415 }
416 return safi;
718e3744 417}
418
55f91488
QY
419/**
420 * Converts an AFI in string form to afi_t
421 *
422 * @param afi string, one of
423 * - "ipv4"
424 * - "ipv6"
81cf0de5 425 * - "l2vpn"
55f91488
QY
426 * @return the corresponding afi_t
427 */
d62a17ae 428afi_t bgp_vty_afi_from_str(const char *afi_str)
429{
430 afi_t afi = AFI_MAX; /* unknown */
431 if (strmatch(afi_str, "ipv4"))
432 afi = AFI_IP;
433 else if (strmatch(afi_str, "ipv6"))
434 afi = AFI_IP6;
81cf0de5
CS
435 else if (strmatch(afi_str, "l2vpn"))
436 afi = AFI_L2VPN;
d62a17ae 437 return afi;
438}
439
440int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
441 afi_t *afi)
442{
443 int ret = 0;
444 if (argv_find(argv, argc, "ipv4", index)) {
445 ret = 1;
446 if (afi)
447 *afi = AFI_IP;
448 } else if (argv_find(argv, argc, "ipv6", index)) {
449 ret = 1;
450 if (afi)
451 *afi = AFI_IP6;
8688b3e7
DS
452 } else if (argv_find(argv, argc, "l2vpn", index)) {
453 ret = 1;
454 if (afi)
455 *afi = AFI_L2VPN;
d62a17ae 456 }
457 return ret;
46f296b4
LB
458}
459
375a2e67 460/* supports <unicast|multicast|vpn|labeled-unicast> */
d62a17ae 461safi_t bgp_vty_safi_from_str(const char *safi_str)
462{
463 safi_t safi = SAFI_MAX; /* unknown */
464 if (strmatch(safi_str, "multicast"))
465 safi = SAFI_MULTICAST;
466 else if (strmatch(safi_str, "unicast"))
467 safi = SAFI_UNICAST;
468 else if (strmatch(safi_str, "vpn"))
469 safi = SAFI_MPLS_VPN;
81cf0de5
CS
470 else if (strmatch(safi_str, "evpn"))
471 safi = SAFI_EVPN;
d62a17ae 472 else if (strmatch(safi_str, "labeled-unicast"))
473 safi = SAFI_LABELED_UNICAST;
7c40bf39 474 else if (strmatch(safi_str, "flowspec"))
475 safi = SAFI_FLOWSPEC;
d62a17ae 476 return safi;
477}
478
479int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
480 safi_t *safi)
481{
482 int ret = 0;
483 if (argv_find(argv, argc, "unicast", index)) {
484 ret = 1;
485 if (safi)
486 *safi = SAFI_UNICAST;
487 } else if (argv_find(argv, argc, "multicast", index)) {
488 ret = 1;
489 if (safi)
490 *safi = SAFI_MULTICAST;
491 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
492 ret = 1;
493 if (safi)
494 *safi = SAFI_LABELED_UNICAST;
495 } else if (argv_find(argv, argc, "vpn", index)) {
496 ret = 1;
497 if (safi)
498 *safi = SAFI_MPLS_VPN;
8688b3e7
DS
499 } else if (argv_find(argv, argc, "evpn", index)) {
500 ret = 1;
501 if (safi)
502 *safi = SAFI_EVPN;
7c40bf39 503 } else if (argv_find(argv, argc, "flowspec", index)) {
504 ret = 1;
505 if (safi)
506 *safi = SAFI_FLOWSPEC;
d62a17ae 507 }
508 return ret;
46f296b4
LB
509}
510
b16bcbba
TA
511/*
512 * Convert an afi_t/safi_t pair to matching BGP_DEFAULT_AF* flag.
513 *
514 * afi
515 * address-family identifier
516 *
517 * safi
518 * subsequent address-family identifier
519 *
520 * Returns:
521 * default_af string corresponding to the supplied afi/safi pair.
522 * If afi/safi is invalid or if flag for afi/safi doesn't exist,
523 * return -1.
524 */
525static const char *get_bgp_default_af_flag(afi_t afi, safi_t safi)
526{
527 switch (afi) {
528 case AFI_IP:
529 switch (safi) {
530 case SAFI_UNICAST:
531 return "ipv4-unicast";
532 case SAFI_MULTICAST:
533 return "ipv4-multicast";
534 case SAFI_MPLS_VPN:
535 return "ipv4-vpn";
536 case SAFI_ENCAP:
537 return "ipv4-encap";
538 case SAFI_LABELED_UNICAST:
539 return "ipv4-labeled-unicast";
540 case SAFI_FLOWSPEC:
541 return "ipv4-flowspec";
542 default:
543 return "unknown-afi/safi";
544 }
545 break;
546 case AFI_IP6:
547 switch (safi) {
548 case SAFI_UNICAST:
549 return "ipv6-unicast";
550 case SAFI_MULTICAST:
551 return "ipv6-multicast";
552 case SAFI_MPLS_VPN:
553 return "ipv6-vpn";
554 case SAFI_ENCAP:
555 return "ipv6-encap";
556 case SAFI_LABELED_UNICAST:
557 return "ipv6-labeled-unicast";
558 case SAFI_FLOWSPEC:
559 return "ipv6-flowspec";
560 default:
561 return "unknown-afi/safi";
562 }
563 break;
564 case AFI_L2VPN:
565 switch (safi) {
566 case SAFI_EVPN:
567 return "l2vpn-evpn";
568 default:
569 return "unknown-afi/safi";
570 }
571 case AFI_UNSPEC:
572 case AFI_MAX:
573 return "unknown-afi/safi";
574 }
575 /* all AFIs are accounted for above, so this shouldn't happen */
576 return "unknown-afi/safi";
577}
578
5d5393b9
DL
579int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
580 enum bgp_instance_type inst_type)
581{
582 int ret = bgp_get(bgp, as, name, inst_type);
583
584 if (ret == BGP_CREATED) {
585 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
d43114f3 586 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
5d5393b9
DL
587
588 if (DFLT_BGP_IMPORT_CHECK)
892fedb6 589 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
5d5393b9 590 if (DFLT_BGP_SHOW_HOSTNAME)
892fedb6 591 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
aef999a2
DA
592 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
593 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
5d5393b9 594 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
892fedb6 595 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
5d5393b9 596 if (DFLT_BGP_DETERMINISTIC_MED)
892fedb6 597 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
1d3fdccf
DA
598 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
599 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2adac256
DA
600 if (DFLT_BGP_SUPPRESS_DUPLICATES)
601 SET_FLAG((*bgp)->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
f2ca5c5b
DA
602 if (DFLT_BGP_GRACEFUL_NOTIFICATION)
603 SET_FLAG((*bgp)->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
1ae314be
DA
604 if (DFLT_BGP_HARD_ADMIN_RESET)
605 SET_FLAG((*bgp)->flags, BGP_FLAG_HARD_ADMIN_RESET);
5d5393b9
DL
606
607 ret = BGP_SUCCESS;
608 }
609 return ret;
610}
611
7eeee51e 612/*
f212a857 613 * bgp_vty_find_and_parse_afi_safi_bgp
7eeee51e 614 *
f212a857
DS
615 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
616 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
7eeee51e
DS
617 * to appropriate values for the calling function. This is to allow the
618 * calling function to make decisions appropriate for the show command
619 * that is being parsed.
620 *
621 * The show commands are generally of the form:
d62a17ae 622 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
623 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
7eeee51e
DS
624 *
625 * Since we use argv_find if the show command in particular doesn't have:
626 * [ip]
18c57037 627 * [<view|vrf> VIEWVRFNAME]
375a2e67 628 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
7eeee51e
DS
629 * The command parsing should still be ok.
630 *
631 * vty -> The vty for the command so we can output some useful data in
632 * the event of a parse error in the vrf.
633 * argv -> The command tokens
634 * argc -> How many command tokens we have
d62a17ae 635 * idx -> The current place in the command, generally should be 0 for this
636 * function
7eeee51e
DS
637 * afi -> The parsed afi if it was included in the show command, returned here
638 * safi -> The parsed safi if it was included in the show command, returned here
f212a857 639 * bgp -> Pointer to the bgp data structure we need to fill in.
52e5b8c4 640 * use_json -> json is configured or not
7eeee51e
DS
641 *
642 * The function returns the correct location in the parse tree for the
643 * last token found.
0e37c258
DS
644 *
645 * Returns 0 for failure to parse correctly, else the idx position of where
646 * it found the last token.
7eeee51e 647 */
d62a17ae 648int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
649 struct cmd_token **argv, int argc,
650 int *idx, afi_t *afi, safi_t *safi,
9f049418 651 struct bgp **bgp, bool use_json)
d62a17ae 652{
653 char *vrf_name = NULL;
654
655 assert(afi);
656 assert(safi);
657 assert(bgp);
658
659 if (argv_find(argv, argc, "ip", idx))
660 *afi = AFI_IP;
661
9a8bdf1c 662 if (argv_find(argv, argc, "view", idx))
d62a17ae 663 vrf_name = argv[*idx + 1]->arg;
9a8bdf1c
PG
664 else if (argv_find(argv, argc, "vrf", idx)) {
665 vrf_name = argv[*idx + 1]->arg;
666 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
667 vrf_name = NULL;
668 }
669 if (vrf_name) {
d62a17ae 670 if (strmatch(vrf_name, "all"))
671 *bgp = NULL;
672 else {
673 *bgp = bgp_lookup_by_name(vrf_name);
674 if (!*bgp) {
52e5b8c4
SP
675 if (use_json) {
676 json_object *json = NULL;
677 json = json_object_new_object();
678 json_object_string_add(
679 json, "warning",
680 "View/Vrf is unknown");
75eeda93 681 vty_json(vty, json);
52e5b8c4 682 }
ca61fd25
DS
683 else
684 vty_out(vty, "View/Vrf %s is unknown\n",
685 vrf_name);
d62a17ae 686 *idx = 0;
687 return 0;
688 }
689 }
690 } else {
691 *bgp = bgp_get_default();
692 if (!*bgp) {
52e5b8c4
SP
693 if (use_json) {
694 json_object *json = NULL;
695 json = json_object_new_object();
696 json_object_string_add(
697 json, "warning",
698 "Default BGP instance not found");
75eeda93 699 vty_json(vty, json);
52e5b8c4 700 }
ca61fd25
DS
701 else
702 vty_out(vty,
703 "Default BGP instance not found\n");
d62a17ae 704 *idx = 0;
705 return 0;
706 }
707 }
708
709 if (argv_find_and_parse_afi(argv, argc, idx, afi))
710 argv_find_and_parse_safi(argv, argc, idx, safi);
711
712 *idx += 1;
713 return *idx;
714}
715
28c6e247 716static bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
d62a17ae 717{
718 struct interface *ifp = NULL;
4122b697
DA
719 struct listnode *node;
720 struct bgp_listener *listener;
721 union sockunion all_su;
d62a17ae 722
4122b697 723 if (su->sa.sa_family == AF_INET) {
3d2a2725 724 (void)str2sockunion("0.0.0.0", &all_su);
d62a17ae 725 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
4122b697 726 } else if (su->sa.sa_family == AF_INET6) {
3d2a2725 727 (void)str2sockunion("::", &all_su);
d62a17ae 728 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
729 su->sin6.sin6_scope_id,
730 bgp->vrf_id);
4122b697 731 }
d62a17ae 732
4122b697
DA
733 if (ifp) {
734 for (ALL_LIST_ELEMENTS_RO(bm->listen_sockets, node, listener)) {
735 if (sockunion_family(su) !=
736 sockunion_family(&listener->su))
737 continue;
738
739 /* If 0.0.0.0/:: is a listener, then treat as self and
740 * reject.
741 */
742 if (!sockunion_cmp(&listener->su, su) ||
743 !sockunion_cmp(&listener->su, &all_su))
744 return true;
745 }
746 }
d62a17ae 747
3dc339cd 748 return false;
718e3744 749}
750
28c6e247
IR
751/* Utility function for looking up peer from VTY. */
752/* This is used only for configuration, so disallow if attempted on
753 * a dynamic neighbor.
754 */
755static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
756{
757 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
758 int ret;
759 union sockunion su;
760 struct peer *peer;
761
762 if (!bgp) {
763 return NULL;
764 }
765
766 ret = str2sockunion(ip_str, &su);
767 if (ret < 0) {
768 peer = peer_lookup_by_conf_if(bgp, ip_str);
769 if (!peer) {
770 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
771 == NULL) {
772 vty_out(vty,
773 "%% Malformed address or name: %s\n",
774 ip_str);
775 return NULL;
776 }
777 }
778 } else {
779 peer = peer_lookup(bgp, &su);
780 if (!peer) {
781 vty_out(vty,
782 "%% Specify remote-as or peer-group commands first\n");
783 return NULL;
784 }
785 if (peer_dynamic_neighbor(peer)) {
786 vty_out(vty,
787 "%% Operation not allowed on a dynamic neighbor\n");
788 return NULL;
789 }
790 }
791 return peer;
792}
793
718e3744 794/* Utility function for looking up peer or peer group. */
f14e6fdb
DS
795/* This is used only for configuration, so disallow if attempted on
796 * a dynamic neighbor.
797 */
d62a17ae 798struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
799{
800 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
801 int ret;
802 union sockunion su;
803 struct peer *peer = NULL;
804 struct peer_group *group = NULL;
805
806 if (!bgp) {
807 return NULL;
808 }
809
810 ret = str2sockunion(peer_str, &su);
811 if (ret == 0) {
812 /* IP address, locate peer. */
813 peer = peer_lookup(bgp, &su);
814 } else {
815 /* Not IP, could match either peer configured on interface or a
816 * group. */
817 peer = peer_lookup_by_conf_if(bgp, peer_str);
818 if (!peer)
819 group = peer_group_lookup(bgp, peer_str);
820 }
821
822 if (peer) {
823 if (peer_dynamic_neighbor(peer)) {
824 vty_out(vty,
825 "%% Operation not allowed on a dynamic neighbor\n");
826 return NULL;
827 }
828
829 return peer;
830 }
831
832 if (group)
833 return group->conf;
834
835 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
836
837 return NULL;
838}
839
4b7e23e9 840int bgp_vty_return(struct vty *vty, enum bgp_create_error_code ret)
d62a17ae 841{
842 const char *str = NULL;
843
844 switch (ret) {
4b7e23e9
DS
845 case BGP_SUCCESS:
846 case BGP_CREATED:
847 case BGP_GR_NO_OPERATION:
848 break;
d62a17ae 849 case BGP_ERR_INVALID_VALUE:
850 str = "Invalid value";
851 break;
852 case BGP_ERR_INVALID_FLAG:
853 str = "Invalid flag";
854 break;
855 case BGP_ERR_PEER_GROUP_SHUTDOWN:
856 str = "Peer-group has been shutdown. Activate the peer-group first";
857 break;
858 case BGP_ERR_PEER_FLAG_CONFLICT:
859 str = "Can't set override-capability and strict-capability-match at the same time";
860 break;
861 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
862 str = "Specify remote-as or peer-group remote AS first";
863 break;
864 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
865 str = "Cannot change the peer-group. Deconfigure first";
866 break;
867 case BGP_ERR_PEER_GROUP_MISMATCH:
868 str = "Peer is not a member of this peer-group";
869 break;
870 case BGP_ERR_PEER_FILTER_CONFLICT:
871 str = "Prefix/distribute list can not co-exist";
872 break;
873 case BGP_ERR_NOT_INTERNAL_PEER:
874 str = "Invalid command. Not an internal neighbor";
875 break;
876 case BGP_ERR_REMOVE_PRIVATE_AS:
877 str = "remove-private-AS cannot be configured for IBGP peers";
878 break;
d62a17ae 879 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
880 str = "Cannot have local-as same as BGP AS number";
881 break;
882 case BGP_ERR_TCPSIG_FAILED:
883 str = "Error while applying TCP-Sig to session(s)";
884 break;
885 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
886 str = "ebgp-multihop and ttl-security cannot be configured together";
887 break;
888 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
889 str = "ttl-security only allowed for EBGP peers";
890 break;
891 case BGP_ERR_AS_OVERRIDE:
892 str = "as-override cannot be configured for IBGP peers";
893 break;
894 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
895 str = "Invalid limit for number of dynamic neighbors";
896 break;
897 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
898 str = "Dynamic neighbor listen range already exists";
899 break;
900 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
901 str = "Operation not allowed on a dynamic neighbor";
902 break;
903 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
904 str = "Operation not allowed on a directly connected neighbor";
905 break;
906 case BGP_ERR_PEER_SAFI_CONFLICT:
a59803d0 907 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
055679e9 908 break;
909 case BGP_ERR_GR_INVALID_CMD:
910 str = "The Graceful Restart command used is not valid at this moment.";
911 break;
912 case BGP_ERR_GR_OPERATION_FAILED:
913 str = "The Graceful Restart Operation failed due to an err.";
914 break;
6dcea6fe
DS
915 case BGP_ERR_PEER_GROUP_MEMBER:
916 str = "Peer-group member cannot override remote-as of peer-group.";
917 break;
918 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
919 str = "Peer-group members must be all internal or all external.";
920 break;
4b7e23e9
DS
921 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_NOT_FOUND:
922 str = "Range specified cannot be deleted because it is not part of current config.";
923 break;
924 case BGP_ERR_INSTANCE_MISMATCH:
925 str = "Instance specified does not match the current instance.";
926 break;
927 case BGP_ERR_NO_INTERFACE_CONFIG:
928 str = "Interface specified is not being used for interface based peer.";
929 break;
930 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
931 str = "No configuration already specified for soft reconfiguration.";
932 break;
933 case BGP_ERR_AS_MISMATCH:
934 str = "BGP is already running.";
935 break;
936 case BGP_ERR_AF_UNCONFIGURED:
937 str = "AFI/SAFI specified is not currently configured.";
938 break;
4b7e23e9
DS
939 case BGP_ERR_INVALID_AS:
940 str = "Confederation AS specified is the same AS as our AS.";
941 break;
d864dd9e
EB
942 case BGP_ERR_INVALID_ROLE_NAME:
943 str = "Invalid role name";
944 break;
945 case BGP_ERR_INVALID_INTERNAL_ROLE:
8f2d6021 946 str = "External roles can be set only on eBGP session";
d864dd9e 947 break;
70cd87ca 948 case BGP_ERR_PEER_ORR_CONFIGURED:
d6b27611 949 str = "Deconfigure optimal-route-reflection on this peer first";
70cd87ca 950 break;
d62a17ae 951 }
952 if (str) {
953 vty_out(vty, "%% %s\n", str);
954 return CMD_WARNING_CONFIG_FAILED;
955 }
956 return CMD_SUCCESS;
718e3744 957}
958
7aafcaca 959/* BGP clear sort. */
d62a17ae 960enum clear_sort {
961 clear_all,
962 clear_peer,
963 clear_group,
964 clear_external,
965 clear_as
7aafcaca
DS
966};
967
1ca2fd11
IR
968static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
969 safi_t safi, int error)
d62a17ae 970{
971 switch (error) {
972 case BGP_ERR_AF_UNCONFIGURED:
a486300b
PG
973 if (vty)
974 vty_out(vty,
975 "%% BGP: Enable %s address family for the neighbor %s\n",
976 get_afi_safi_str(afi, safi, false), peer->host);
977 else
978 zlog_warn(
1af6e82b 979 "%% BGP: Enable %s address family for the neighbor %s",
a486300b 980 get_afi_safi_str(afi, safi, false), peer->host);
d62a17ae 981 break;
982 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
a486300b
PG
983 if (vty)
984 vty_out(vty,
985 "%% BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
986 peer->host);
987 else
988 zlog_warn(
1af6e82b 989 "%% BGP: Inbound soft reconfig for %s not possible as it has neither refresh capability, nor inbound soft reconfig",
a486300b 990 peer->host);
d62a17ae 991 break;
992 default:
993 break;
994 }
7aafcaca
DS
995}
996
dc912615 997static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
c368171c 998 struct listnode **nnode, enum bgp_clear_type stype)
dc912615
DS
999{
1000 int ret = 0;
2adac256 1001 struct peer_af *paf;
dc912615
DS
1002
1003 /* if afi/.safi not specified, spin thru all of them */
1004 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
1005 afi_t tmp_afi;
1006 safi_t tmp_safi;
0e5cdd59
DS
1007 enum bgp_af_index index;
1008
1009 for (index = BGP_AF_START; index < BGP_AF_MAX; index++) {
1010 paf = peer->peer_af_array[index];
1011 if (!paf)
1012 continue;
dc912615 1013
2adac256
DA
1014 if (paf && paf->subgroup)
1015 SET_FLAG(paf->subgroup->sflags,
1016 SUBGRP_STATUS_FORCE_UPDATES);
1017
0e5cdd59
DS
1018 tmp_afi = paf->afi;
1019 tmp_safi = paf->safi;
dc912615
DS
1020 if (!peer->afc[tmp_afi][tmp_safi])
1021 continue;
1022
1023 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 1024 ret = peer_clear(peer, nnode);
dc912615
DS
1025 else
1026 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
1027 stype);
1028 }
1029 /* if afi specified and safi not, spin thru safis on this afi */
1030 } else if (safi == SAFI_UNSPEC) {
1031 safi_t tmp_safi;
1032
1033 for (tmp_safi = SAFI_UNICAST;
1034 tmp_safi < SAFI_MAX; tmp_safi++) {
1035 if (!peer->afc[afi][tmp_safi])
1036 continue;
1037
2adac256
DA
1038 paf = peer_af_find(peer, afi, tmp_safi);
1039 if (paf && paf->subgroup)
1040 SET_FLAG(paf->subgroup->sflags,
1041 SUBGRP_STATUS_FORCE_UPDATES);
1042
dc912615 1043 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 1044 ret = peer_clear(peer, nnode);
dc912615
DS
1045 else
1046 ret = peer_clear_soft(peer, afi,
1047 tmp_safi, stype);
1048 }
1049 /* both afi/safi specified, let the caller know if not defined */
1050 } else {
1051 if (!peer->afc[afi][safi])
1052 return 1;
1053
2adac256
DA
1054 paf = peer_af_find(peer, afi, safi);
1055 if (paf && paf->subgroup)
1056 SET_FLAG(paf->subgroup->sflags,
1057 SUBGRP_STATUS_FORCE_UPDATES);
1058
dc912615 1059 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 1060 ret = peer_clear(peer, nnode);
dc912615
DS
1061 else
1062 ret = peer_clear_soft(peer, afi, safi, stype);
1063 }
1064
1065 return ret;
1066}
1067
7aafcaca 1068/* `clear ip bgp' functions. */
1ca2fd11 1069static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
d62a17ae 1070 enum clear_sort sort, enum bgp_clear_type stype,
1ca2fd11 1071 const char *arg)
d62a17ae 1072{
dc912615 1073 int ret = 0;
3ae8bfa5 1074 bool found = false;
d62a17ae 1075 struct peer *peer;
dc95985f 1076
1077 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
d62a17ae 1078
1079 /* Clear all neighbors. */
1080 /*
1081 * Pass along pointer to next node to peer_clear() when walking all
3ae8bfa5
PM
1082 * nodes on the BGP instance as that may get freed if it is a
1083 * doppelganger
d62a17ae 1084 */
1085 if (sort == clear_all) {
1086 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dc95985f 1087
1088 bgp_peer_gr_flags_update(peer);
1089
36235319 1090 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
dc95985f 1091 gr_router_detected = true;
1092
c368171c 1093 ret = bgp_peer_clear(peer, afi, safi, &nnode,
dc912615 1094 stype);
d62a17ae 1095
1096 if (ret < 0)
1ca2fd11 1097 bgp_clear_vty_error(vty, peer, afi, safi, ret);
dc95985f 1098 }
1099
36235319
QY
1100 if (gr_router_detected
1101 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1102 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1103 } else if (!gr_router_detected
1104 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1105 bgp_zebra_send_capabilities(bgp, true);
04b6bdc0 1106 }
d62a17ae 1107
1108 /* This is to apply read-only mode on this clear. */
1109 if (stype == BGP_CLEAR_SOFT_NONE)
1110 bgp->update_delay_over = 0;
1111
1112 return CMD_SUCCESS;
7aafcaca
DS
1113 }
1114
3ae8bfa5 1115 /* Clear specified neighbor. */
d62a17ae 1116 if (sort == clear_peer) {
1117 union sockunion su;
d62a17ae 1118
1119 /* Make sockunion for lookup. */
1120 ret = str2sockunion(arg, &su);
1121 if (ret < 0) {
1122 peer = peer_lookup_by_conf_if(bgp, arg);
1123 if (!peer) {
1124 peer = peer_lookup_by_hostname(bgp, arg);
1125 if (!peer) {
1ca2fd11
IR
1126 vty_out(vty,
1127 "Malformed address or name: %s\n",
d62a17ae 1128 arg);
1129 return CMD_WARNING;
1130 }
1131 }
1132 } else {
1133 peer = peer_lookup(bgp, &su);
1134 if (!peer) {
1ca2fd11 1135 vty_out(vty,
664b6f18 1136 "%% BGP: Unknown neighbor - \"%s\"\n",
1ca2fd11 1137 arg);
d62a17ae 1138 return CMD_WARNING;
1139 }
1140 }
7aafcaca 1141
dc95985f 1142 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1143 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1144
dc912615
DS
1145 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1146
1147 /* if afi/safi not defined for this peer, let caller know */
1148 if (ret == 1)
3ae8bfa5 1149 ret = BGP_ERR_AF_UNCONFIGURED;
7aafcaca 1150
d62a17ae 1151 if (ret < 0)
1ca2fd11 1152 bgp_clear_vty_error(vty, peer, afi, safi, ret);
7aafcaca 1153
d62a17ae 1154 return CMD_SUCCESS;
7aafcaca 1155 }
7aafcaca 1156
3ae8bfa5 1157 /* Clear all neighbors belonging to a specific peer-group. */
d62a17ae 1158 if (sort == clear_group) {
1159 struct peer_group *group;
7aafcaca 1160
d62a17ae 1161 group = peer_group_lookup(bgp, arg);
1162 if (!group) {
664b6f18 1163 vty_out(vty, "%% BGP: No such peer-group %s\n", arg);
d62a17ae 1164 return CMD_WARNING;
1165 }
1166
1167 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
c368171c 1168 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 1169
d62a17ae 1170 if (ret < 0)
1ca2fd11 1171 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
1172 else
1173 found = true;
d62a17ae 1174 }
3ae8bfa5
PM
1175
1176 if (!found)
1ca2fd11 1177 vty_out(vty,
664b6f18 1178 "%% BGP: No %s peer belonging to peer-group %s is configured\n",
5cb5f4d0 1179 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1180
d62a17ae 1181 return CMD_SUCCESS;
7aafcaca 1182 }
7aafcaca 1183
3ae8bfa5 1184 /* Clear all external (eBGP) neighbors. */
d62a17ae 1185 if (sort == clear_external) {
1186 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1187 if (peer->sort == BGP_PEER_IBGP)
1188 continue;
7aafcaca 1189
dc95985f 1190 bgp_peer_gr_flags_update(peer);
1191
36235319 1192 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 1193 gr_router_detected = true;
dc95985f 1194
c368171c 1195 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 1196
d62a17ae 1197 if (ret < 0)
1ca2fd11 1198 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
1199 else
1200 found = true;
d62a17ae 1201 }
3ae8bfa5 1202
36235319
QY
1203 if (gr_router_detected
1204 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1205 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1206 } else if (!gr_router_detected
1207 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1208 bgp_zebra_send_capabilities(bgp, true);
1209 }
1210
3ae8bfa5 1211 if (!found)
1ca2fd11 1212 vty_out(vty,
664b6f18 1213 "%% BGP: No external %s peer is configured\n",
1ca2fd11 1214 get_afi_safi_str(afi, safi, false));
3ae8bfa5 1215
d62a17ae 1216 return CMD_SUCCESS;
1217 }
1218
3ae8bfa5 1219 /* Clear all neighbors belonging to a specific AS. */
d62a17ae 1220 if (sort == clear_as) {
3ae8bfa5 1221 as_t as = strtoul(arg, NULL, 10);
d62a17ae 1222
1223 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1224 if (peer->as != as)
1225 continue;
1226
dc95985f 1227 bgp_peer_gr_flags_update(peer);
1228
36235319 1229 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 1230 gr_router_detected = true;
dc95985f 1231
c368171c 1232 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
d62a17ae 1233
1234 if (ret < 0)
1ca2fd11 1235 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
1236 else
1237 found = true;
d62a17ae 1238 }
3ae8bfa5 1239
36235319
QY
1240 if (gr_router_detected
1241 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1242 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1243 } else if (!gr_router_detected
1244 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1245 bgp_zebra_send_capabilities(bgp, true);
1246 }
1247
3ae8bfa5 1248 if (!found)
1ca2fd11 1249 vty_out(vty,
664b6f18 1250 "%% BGP: No %s peer is configured with AS %s\n",
1ca2fd11 1251 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1252
d62a17ae 1253 return CMD_SUCCESS;
1254 }
1255
1256 return CMD_SUCCESS;
1257}
1258
1ca2fd11
IR
1259static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
1260 safi_t safi, enum clear_sort sort,
1261 enum bgp_clear_type stype, const char *arg)
d62a17ae 1262{
1263 struct bgp *bgp;
1264
1265 /* BGP structure lookup. */
1266 if (name) {
1267 bgp = bgp_lookup_by_name(name);
1268 if (bgp == NULL) {
1ca2fd11 1269 vty_out(vty, "Can't find BGP instance %s\n", name);
d62a17ae 1270 return CMD_WARNING;
1271 }
1272 } else {
1273 bgp = bgp_get_default();
1274 if (bgp == NULL) {
1ca2fd11 1275 vty_out(vty, "No BGP process is configured\n");
d62a17ae 1276 return CMD_WARNING;
1277 }
1278 }
1279
1ca2fd11 1280 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
7aafcaca
DS
1281}
1282
1283/* clear soft inbound */
1ca2fd11 1284static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
7aafcaca 1285{
99b3ebd3
NS
1286 afi_t afi;
1287 safi_t safi;
1288
1ca2fd11
IR
1289 FOREACH_AFI_SAFI (afi, safi)
1290 bgp_clear_vty(vty, name, afi, safi, clear_all,
1291 BGP_CLEAR_SOFT_IN, NULL);
7aafcaca
DS
1292}
1293
1294/* clear soft outbound */
1ca2fd11 1295static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
7aafcaca 1296{
99b3ebd3
NS
1297 afi_t afi;
1298 safi_t safi;
1299
1ca2fd11
IR
1300 FOREACH_AFI_SAFI (afi, safi)
1301 bgp_clear_vty(vty, name, afi, safi, clear_all,
1302 BGP_CLEAR_SOFT_OUT, NULL);
7aafcaca
DS
1303}
1304
1305
a486300b
PG
1306void bgp_clear_soft_in(struct bgp *bgp, afi_t afi, safi_t safi)
1307{
1308 bgp_clear(NULL, bgp, afi, safi, clear_all, BGP_CLEAR_SOFT_IN, NULL);
1309}
1310
2e4c2296 1311#include "bgpd/bgp_vty_clippy.c"
f787d7a0 1312
8029b216
AK
1313DEFUN_HIDDEN (bgp_local_mac,
1314 bgp_local_mac_cmd,
093e3f23 1315 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
8029b216
AK
1316 BGP_STR
1317 "Local MAC config\n"
1318 "VxLAN Network Identifier\n"
1319 "VNI number\n"
1320 "local mac\n"
1321 "mac address\n"
1322 "mac-mobility sequence\n"
1323 "seq number\n")
1324{
1325 int rv;
1326 vni_t vni;
1327 struct ethaddr mac;
1328 struct ipaddr ip;
1329 uint32_t seq;
1330 struct bgp *bgp;
1331
1332 vni = strtoul(argv[3]->arg, NULL, 10);
1333 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1334 vty_out(vty, "%% Malformed MAC address\n");
1335 return CMD_WARNING;
1336 }
1337 memset(&ip, 0, sizeof(ip));
1338 seq = strtoul(argv[7]->arg, NULL, 10);
1339
1340 bgp = bgp_get_default();
1341 if (!bgp) {
1342 vty_out(vty, "Default BGP instance is not there\n");
1343 return CMD_WARNING;
1344 }
1345
b5e140c8
AK
1346 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1347 zero_esi);
8029b216
AK
1348 if (rv < 0) {
1349 vty_out(vty, "Internal error\n");
1350 return CMD_WARNING;
1351 }
1352
1353 return CMD_SUCCESS;
1354}
1355
1356DEFUN_HIDDEN (no_bgp_local_mac,
1357 no_bgp_local_mac_cmd,
093e3f23 1358 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
8029b216
AK
1359 NO_STR
1360 BGP_STR
1361 "Local MAC config\n"
1362 "VxLAN Network Identifier\n"
1363 "VNI number\n"
1364 "local mac\n"
1365 "mac address\n")
1366{
1367 int rv;
1368 vni_t vni;
1369 struct ethaddr mac;
1370 struct ipaddr ip;
1371 struct bgp *bgp;
1372
1373 vni = strtoul(argv[4]->arg, NULL, 10);
1374 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1375 vty_out(vty, "%% Malformed MAC address\n");
1376 return CMD_WARNING;
1377 }
1378 memset(&ip, 0, sizeof(ip));
1379
1380 bgp = bgp_get_default();
1381 if (!bgp) {
1382 vty_out(vty, "Default BGP instance is not there\n");
1383 return CMD_WARNING;
1384 }
1385
ec0ab544 1386 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
8029b216
AK
1387 if (rv < 0) {
1388 vty_out(vty, "Internal error\n");
1389 return CMD_WARNING;
1390 }
1391
1392 return CMD_SUCCESS;
1393}
1394
718e3744 1395DEFUN (no_synchronization,
1396 no_synchronization_cmd,
1397 "no synchronization",
1398 NO_STR
1399 "Perform IGP synchronization\n")
1400{
d62a17ae 1401 return CMD_SUCCESS;
718e3744 1402}
1403
1404DEFUN (no_auto_summary,
1405 no_auto_summary_cmd,
1406 "no auto-summary",
1407 NO_STR
1408 "Enable automatic network number summarization\n")
1409{
d62a17ae 1410 return CMD_SUCCESS;
718e3744 1411}
3d515fd9 1412
718e3744 1413/* "router bgp" commands. */
1ca2fd11
IR
1414DEFUN_NOSH (router_bgp,
1415 router_bgp_cmd,
1416 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1417 ROUTER_STR
1418 BGP_STR
1419 AS_STR
1420 BGP_INSTANCE_HELP_STR)
718e3744 1421{
d62a17ae 1422 int idx_asn = 2;
1423 int idx_view_vrf = 3;
1424 int idx_vrf = 4;
1ca2fd11
IR
1425 int is_new_bgp = 0;
1426 int ret;
d62a17ae 1427 as_t as;
1428 struct bgp *bgp;
1429 const char *name = NULL;
1430 enum bgp_instance_type inst_type;
1431
1432 // "router bgp" without an ASN
1433 if (argc == 2) {
1434 // Pending: Make VRF option available for ASN less config
1abef40f 1435 bgp = bgp_get_default();
d62a17ae 1436
1abef40f 1437 if (bgp == NULL) {
d62a17ae 1438 vty_out(vty, "%% No BGP process is configured\n");
1439 return CMD_WARNING_CONFIG_FAILED;
1440 }
1441
1442 if (listcount(bm->bgp) > 1) {
996c9314 1443 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1444 return CMD_WARNING_CONFIG_FAILED;
1445 }
1446 }
1447
1448 // "router bgp X"
1449 else {
ff8a8a7a 1450 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1ca2fd11 1451
cc413e2a
DA
1452 if (as == BGP_PRIVATE_AS_MAX || as == BGP_AS4_MAX)
1453 vty_out(vty, "Reserved AS used (%u|%u); AS is %u\n",
1454 BGP_PRIVATE_AS_MAX, BGP_AS4_MAX, as);
1455
d62a17ae 1456 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1457 if (argc > 3) {
1458 name = argv[idx_vrf]->arg;
1459
9a8bdf1c
PG
1460 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1461 if (strmatch(name, VRF_DEFAULT_NAME))
1462 name = NULL;
1463 else
1464 inst_type = BGP_INSTANCE_TYPE_VRF;
1ca2fd11 1465 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
d62a17ae 1466 inst_type = BGP_INSTANCE_TYPE_VIEW;
d62a17ae 1467 }
1468
1ca2fd11
IR
1469 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1470 is_new_bgp = (bgp_lookup(as, name) == NULL);
3bd70bf8 1471
1ca2fd11
IR
1472 ret = bgp_get_vty(&bgp, &as, name, inst_type);
1473 switch (ret) {
1474 case BGP_ERR_AS_MISMATCH:
1475 vty_out(vty, "BGP is already running; AS is %u\n", as);
1476 return CMD_WARNING_CONFIG_FAILED;
1477 case BGP_ERR_INSTANCE_MISMATCH:
1478 vty_out(vty,
1479 "BGP instance name and AS number mismatch\n");
1480 vty_out(vty,
1481 "BGP instance is already running; AS is %u\n",
1482 as);
1483 return CMD_WARNING_CONFIG_FAILED;
ff8a8a7a 1484 }
1ca2fd11
IR
1485
1486 /*
1487 * If we just instantiated the default instance, complete
1488 * any pending VRF-VPN leaking that was configured via
1489 * earlier "router bgp X vrf FOO" blocks.
1490 */
1491 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1492 vpn_leak_postchange_all();
1493
1494 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1495 bgp_vpn_leak_export(bgp);
1496 /* Pending: handle when user tries to change a view to vrf n vv.
1497 */
d62a17ae 1498 }
1499
1ca2fd11
IR
1500 /* unset the auto created flag as the user config is now present */
1501 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1502 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1503
1504 return CMD_SUCCESS;
718e3744 1505}
1506
718e3744 1507/* "no router bgp" commands. */
1ca2fd11
IR
1508DEFUN (no_router_bgp,
1509 no_router_bgp_cmd,
1510 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1511 NO_STR
1512 ROUTER_STR
1513 BGP_STR
1514 AS_STR
1515 BGP_INSTANCE_HELP_STR)
718e3744 1516{
4fd9919e 1517 int idx_asn = 3;
d62a17ae 1518 int idx_vrf = 5;
1ca2fd11 1519 as_t as;
4fd9919e 1520 struct bgp *bgp;
d62a17ae 1521 const char *name = NULL;
718e3744 1522
d62a17ae 1523 // "no router bgp" without an ASN
1524 if (argc == 3) {
1525 // Pending: Make VRF option available for ASN less config
8382083a 1526 bgp = bgp_get_default();
718e3744 1527
8382083a 1528 if (bgp == NULL) {
d62a17ae 1529 vty_out(vty, "%% No BGP process is configured\n");
1530 return CMD_WARNING_CONFIG_FAILED;
1531 }
7fb21a9f 1532
d62a17ae 1533 if (listcount(bm->bgp) > 1) {
996c9314 1534 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1535 return CMD_WARNING_CONFIG_FAILED;
1536 }
4fd9919e 1537
4fd9919e 1538 if (bgp->l3vni) {
be125e6f 1539 vty_out(vty, "%% Please unconfigure l3vni %u\n",
4fd9919e
IR
1540 bgp->l3vni);
1541 return CMD_WARNING_CONFIG_FAILED;
1542 }
d62a17ae 1543 } else {
4fd9919e
IR
1544 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1545
1ca42c8d 1546 if (argc > 4) {
d62a17ae 1547 name = argv[idx_vrf]->arg;
1ca42c8d
IR
1548 if (strmatch(argv[idx_vrf - 1]->text, "vrf")
1549 && strmatch(name, VRF_DEFAULT_NAME))
1550 name = NULL;
1551 }
7fb21a9f 1552
4fd9919e
IR
1553 /* Lookup bgp structure. */
1554 bgp = bgp_lookup(as, name);
1555 if (!bgp) {
1556 vty_out(vty, "%% Can't find BGP instance\n");
1557 return CMD_WARNING_CONFIG_FAILED;
1558 }
1559
1560 if (bgp->l3vni) {
1561 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1562 bgp->l3vni);
1563 return CMD_WARNING_CONFIG_FAILED;
1564 }
1565
1566 /* Cannot delete default instance if vrf instances exist */
1567 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1568 struct listnode *node;
1569 struct bgp *tmp_bgp;
1570
1571 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1572 if (tmp_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
1573 continue;
1574 if (CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1575 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1576 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1577 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1578 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1579 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1580 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1581 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1582 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1583 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1584 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1585 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1586 (bgp == bgp_get_evpn() &&
1587 (CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1588 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST) ||
1589 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1590 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP) ||
1591 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1592 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST) ||
1593 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1594 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))) ||
f33bf7c0 1595 (hashcount(tmp_bgp->vnihash))) {
4fd9919e
IR
1596 vty_out(vty,
1597 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1598 return CMD_WARNING_CONFIG_FAILED;
1599 }
1600 }
1601 }
d62a17ae 1602 }
718e3744 1603
1ca2fd11 1604 bgp_delete(bgp);
718e3744 1605
1ca2fd11 1606 return CMD_SUCCESS;
718e3744 1607}
1608
425bd64b
PS
1609/* bgp session-dscp */
1610
1611DEFPY (bgp_session_dscp,
1612 bgp_session_dscp_cmd,
1613 "bgp session-dscp (0-63)$dscp",
1614 BGP_STR
1615 "Override default (C6) bgp TCP session DSCP value\n"
1616 "Manually configured dscp parameter\n")
1617{
1618 bm->tcp_dscp = dscp << 2;
1619
1620 return CMD_SUCCESS;
1621}
1622
1623DEFPY (no_bgp_session_dscp,
1624 no_bgp_session_dscp_cmd,
1625 "no bgp session-dscp [(0-63)]",
1626 NO_STR
1627 BGP_STR
1628 "Override default (C6) bgp TCP session DSCP value\n"
1629 "Manually configured dscp parameter\n")
1630{
1631 bm->tcp_dscp = IPTOS_PREC_INTERNETCONTROL;
1632
1633 return CMD_SUCCESS;
1634}
718e3744 1635
ff8a8a7a
CS
1636/* BGP router-id. */
1637
1ca2fd11
IR
1638DEFPY (bgp_router_id,
1639 bgp_router_id_cmd,
1640 "bgp router-id A.B.C.D",
1641 BGP_STR
1642 "Override configured router identifier\n"
1643 "Manually configured router identifier\n")
718e3744 1644{
1ca2fd11
IR
1645 VTY_DECLVAR_CONTEXT(bgp, bgp);
1646 bgp_router_id_static_set(bgp, router_id);
1647 return CMD_SUCCESS;
ff8a8a7a 1648}
718e3744 1649
1ca2fd11
IR
1650DEFPY (no_bgp_router_id,
1651 no_bgp_router_id_cmd,
1652 "no bgp router-id [A.B.C.D]",
1653 NO_STR
1654 BGP_STR
1655 "Override configured router identifier\n"
1656 "Manually configured router identifier\n")
ff8a8a7a 1657{
1ca2fd11 1658 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1659
1ca2fd11
IR
1660 if (router_id_str) {
1661 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1662 vty_out(vty, "%% BGP router-id doesn't match\n");
1663 return CMD_WARNING_CONFIG_FAILED;
1664 }
1665 }
718e3744 1666
1ca2fd11
IR
1667 router_id.s_addr = 0;
1668 bgp_router_id_static_set(bgp, router_id);
1669
1670 return CMD_SUCCESS;
ff8a8a7a 1671}
6b0655a2 1672
ed0e57e3 1673DEFPY(bgp_community_alias, bgp_community_alias_cmd,
b4ad2fae 1674 "[no$no] bgp community alias WORD$community ALIAS_NAME$alias_name",
ed0e57e3
DA
1675 NO_STR BGP_STR
1676 "Add community specific parameters\n"
1677 "Create an alias for a community\n"
1678 "Community (AA:BB or AA:BB:CC)\n"
1679 "Alias name\n")
1680{
8cfa1e78 1681 struct community_alias ca = {};
ed0e57e3
DA
1682 struct community_alias *lookup_community;
1683 struct community_alias *lookup_alias;
d13d137a
DA
1684 struct community *comm;
1685 struct lcommunity *lcomm;
1686 uint8_t invalid = 0;
ed0e57e3 1687
d13d137a
DA
1688 comm = community_str2com(community);
1689 if (!comm)
1690 invalid++;
1691 community_free(&comm);
1692
1693 lcomm = lcommunity_str2com(community);
1694 if (!lcomm)
1695 invalid++;
1696 lcommunity_free(&lcomm);
1697
1698 if (invalid > 1) {
ed0e57e3
DA
1699 vty_out(vty, "Invalid community format\n");
1700 return CMD_WARNING;
1701 }
1702
8cfa1e78
DA
1703 strlcpy(ca.community, community, sizeof(ca.community));
1704 strlcpy(ca.alias, alias_name, sizeof(ca.alias));
ed0e57e3 1705
8cfa1e78
DA
1706 lookup_community = bgp_ca_community_lookup(&ca);
1707 lookup_alias = bgp_ca_alias_lookup(&ca);
ed0e57e3
DA
1708
1709 if (no) {
8cfa1e78
DA
1710 bgp_ca_alias_delete(&ca);
1711 bgp_ca_community_delete(&ca);
ed0e57e3
DA
1712 } else {
1713 if (lookup_alias) {
1714 /* Lookup if community hash table has an item
1715 * with the same alias name.
1716 */
8cfa1e78
DA
1717 strlcpy(ca.community, lookup_alias->community,
1718 sizeof(ca.community));
1719 if (bgp_ca_community_lookup(&ca)) {
ed0e57e3
DA
1720 vty_out(vty,
1721 "community (%s) already has this alias (%s)\n",
1722 lookup_alias->community,
1723 lookup_alias->alias);
1724 return CMD_WARNING;
1725 }
8cfa1e78 1726 bgp_ca_alias_delete(&ca);
ed0e57e3
DA
1727 }
1728
8cfa1e78
DA
1729 if (lookup_community) {
1730 /* Lookup if alias hash table has an item
1731 * with the same community.
1732 */
1733 strlcpy(ca.alias, lookup_community->alias,
1734 sizeof(ca.alias));
1735 if (bgp_ca_alias_lookup(&ca)) {
1736 vty_out(vty,
1737 "alias (%s) already has this community (%s)\n",
1738 lookup_community->alias,
1739 lookup_community->community);
1740 return CMD_WARNING;
1741 }
1742 bgp_ca_community_delete(&ca);
1743 }
ed0e57e3 1744
8cfa1e78
DA
1745 bgp_ca_alias_insert(&ca);
1746 bgp_ca_community_insert(&ca);
ed0e57e3
DA
1747 }
1748
1749 return CMD_SUCCESS;
1750}
1751
9acb67cb
DS
1752DEFPY (bgp_global_suppress_fib_pending,
1753 bgp_global_suppress_fib_pending_cmd,
1754 "[no] bgp suppress-fib-pending",
1755 NO_STR
1756 BGP_STR
1757 "Advertise only routes that are programmed in kernel to peers globally\n")
1758{
1759 bm_wait_for_fib_set(!no);
1760
1761 return CMD_SUCCESS;
1762}
1763
c208c586
S
1764DEFPY (bgp_suppress_fib_pending,
1765 bgp_suppress_fib_pending_cmd,
1766 "[no] bgp suppress-fib-pending",
1767 NO_STR
1768 BGP_STR
1769 "Advertise only routes that are programmed in kernel to peers\n")
1770{
1771 VTY_DECLVAR_CONTEXT(bgp, bgp);
1772
1773 bgp_suppress_fib_pending_set(bgp, !no);
1774 return CMD_SUCCESS;
1775}
1776
1777
718e3744 1778/* BGP Cluster ID. */
1ca2fd11
IR
1779DEFUN (bgp_cluster_id,
1780 bgp_cluster_id_cmd,
1781 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1782 BGP_STR
1783 "Configure Route-Reflector Cluster-id\n"
1784 "Route-Reflector Cluster-id in IP address format\n"
1785 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1786{
1ca2fd11 1787 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1788 int idx_ipv4 = 2;
1ca2fd11
IR
1789 int ret;
1790 struct in_addr cluster;
1791
1792 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1793 if (!ret) {
1794 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1795 return CMD_WARNING_CONFIG_FAILED;
1796 }
718e3744 1797
1ca2fd11
IR
1798 bgp_cluster_id_set(bgp, &cluster);
1799 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1800
1ca2fd11 1801 return CMD_SUCCESS;
718e3744 1802}
1803
1ca2fd11
IR
1804DEFUN (no_bgp_cluster_id,
1805 no_bgp_cluster_id_cmd,
1806 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1807 NO_STR
1808 BGP_STR
1809 "Configure Route-Reflector Cluster-id\n"
1810 "Route-Reflector Cluster-id in IP address format\n"
1811 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1812{
1ca2fd11
IR
1813 VTY_DECLVAR_CONTEXT(bgp, bgp);
1814 bgp_cluster_id_unset(bgp);
1815 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1816
1ca2fd11 1817 return CMD_SUCCESS;
718e3744 1818}
1819
c163f297
DS
1820DEFPY (bgp_norib,
1821 bgp_norib_cmd,
1822 "bgp no-rib",
1823 BGP_STR
1824 "Disable BGP route installation to RIB (Zebra)\n")
1825{
1826 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1827 vty_out(vty,
1828 "%% No-RIB option is already set, nothing to do here.\n");
1829 return CMD_SUCCESS;
1830 }
1831
1832 bgp_option_norib_set_runtime();
1833
1834 return CMD_SUCCESS;
1835}
1836
1837DEFPY (no_bgp_norib,
1838 no_bgp_norib_cmd,
1839 "no bgp no-rib",
1840 NO_STR
1841 BGP_STR
1842 "Disable BGP route installation to RIB (Zebra)\n")
1843{
1844 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1845 vty_out(vty,
1846 "%% No-RIB option is not set, nothing to do here.\n");
1847 return CMD_SUCCESS;
1848 }
1849
1850 bgp_option_norib_unset_runtime();
1851
1852 return CMD_SUCCESS;
1853}
1854
e46723a5
DS
1855DEFPY (no_bgp_send_extra_data,
1856 no_bgp_send_extra_data_cmd,
1857 "[no] bgp send-extra-data zebra",
1858 NO_STR
1859 BGP_STR
1860 "Extra data to Zebra for display/use\n"
1861 "To zebra\n")
1862{
ec0acb80
DA
1863 if (no)
1864 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1865 else
1866 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
e46723a5
DS
1867
1868 return CMD_SUCCESS;
1869}
1870
1ca2fd11
IR
1871DEFUN (bgp_confederation_identifier,
1872 bgp_confederation_identifier_cmd,
1873 "bgp confederation identifier (1-4294967295)",
e9273987 1874 BGP_STR
1ca2fd11
IR
1875 "AS confederation parameters\n"
1876 "AS number\n"
1877 "Set routing domain confederation AS\n")
718e3744 1878{
1ca2fd11 1879 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1880 int idx_number = 3;
1ca2fd11 1881 as_t as;
718e3744 1882
1ca2fd11 1883 as = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 1884
1ca2fd11 1885 bgp_confederation_id_set(bgp, as);
718e3744 1886
1ca2fd11 1887 return CMD_SUCCESS;
718e3744 1888}
1889
1ca2fd11
IR
1890DEFUN (no_bgp_confederation_identifier,
1891 no_bgp_confederation_identifier_cmd,
1892 "no bgp confederation identifier [(1-4294967295)]",
1893 NO_STR
e9273987 1894 BGP_STR
1ca2fd11
IR
1895 "AS confederation parameters\n"
1896 "AS number\n"
1897 "Set routing domain confederation AS\n")
ff8a8a7a 1898{
1ca2fd11
IR
1899 VTY_DECLVAR_CONTEXT(bgp, bgp);
1900 bgp_confederation_id_unset(bgp);
1901
1902 return CMD_SUCCESS;
ff8a8a7a
CS
1903}
1904
1ca2fd11
IR
1905DEFUN (bgp_confederation_peers,
1906 bgp_confederation_peers_cmd,
1907 "bgp confederation peers (1-4294967295)...",
e9273987 1908 BGP_STR
1ca2fd11
IR
1909 "AS confederation parameters\n"
1910 "Peer ASs in BGP confederation\n"
1911 AS_STR)
718e3744 1912{
1ca2fd11 1913 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1914 int idx_asn = 3;
1ca2fd11 1915 as_t as;
d62a17ae 1916 int i;
718e3744 1917
1ca2fd11
IR
1918 for (i = idx_asn; i < argc; i++) {
1919 as = strtoul(argv[i]->arg, NULL, 10);
718e3744 1920
1ca2fd11
IR
1921 if (bgp->as == as) {
1922 vty_out(vty,
1923 "%% Local member-AS not allowed in confed peer list\n");
1924 continue;
1925 }
1926
1927 bgp_confederation_peers_add(bgp, as);
1928 }
1929 return CMD_SUCCESS;
718e3744 1930}
1931
1ca2fd11
IR
1932DEFUN (no_bgp_confederation_peers,
1933 no_bgp_confederation_peers_cmd,
1934 "no bgp confederation peers (1-4294967295)...",
1935 NO_STR
e9273987 1936 BGP_STR
1ca2fd11
IR
1937 "AS confederation parameters\n"
1938 "Peer ASs in BGP confederation\n"
1939 AS_STR)
718e3744 1940{
1ca2fd11 1941 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1942 int idx_asn = 4;
1ca2fd11 1943 as_t as;
d62a17ae 1944 int i;
718e3744 1945
1ca2fd11
IR
1946 for (i = idx_asn; i < argc; i++) {
1947 as = strtoul(argv[i]->arg, NULL, 10);
ff8a8a7a 1948
1ca2fd11
IR
1949 bgp_confederation_peers_remove(bgp, as);
1950 }
1951 return CMD_SUCCESS;
718e3744 1952}
6b0655a2 1953
5e242b0d
DS
1954/**
1955 * Central routine for maximum-paths configuration.
1956 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1957 * @set: 1 for setting values, 0 for removing the max-paths config.
1958 */
585f1adc
IR
1959static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1960 const char *mpaths, uint16_t options,
1961 int set)
d62a17ae 1962{
585f1adc
IR
1963 VTY_DECLVAR_CONTEXT(bgp, bgp);
1964 uint16_t maxpaths = 0;
d62a17ae 1965 int ret;
585f1adc
IR
1966 afi_t afi;
1967 safi_t safi;
1968
1969 afi = bgp_node_afi(vty);
1970 safi = bgp_node_safi(vty);
d62a17ae 1971
1972 if (set) {
585f1adc 1973 maxpaths = strtol(mpaths, NULL, 10);
d62a17ae 1974 if (maxpaths > multipath_num) {
585f1adc 1975 vty_out(vty,
d62a17ae 1976 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1977 maxpaths, multipath_num);
1978 return CMD_WARNING_CONFIG_FAILED;
1979 }
1980 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1981 options);
1982 } else
1983 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1984
1985 if (ret < 0) {
585f1adc 1986 vty_out(vty,
d62a17ae 1987 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1988 (set == 1) ? "" : "un",
1989 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1990 maxpaths, afi, safi);
1991 return CMD_WARNING_CONFIG_FAILED;
1992 }
1993
1994 bgp_recalculate_all_bestpaths(bgp);
1995
1996 return CMD_SUCCESS;
165b5fff
JB
1997}
1998
1ca2fd11
IR
1999DEFUN (bgp_maxmed_admin,
2000 bgp_maxmed_admin_cmd,
2001 "bgp max-med administrative ",
2002 BGP_STR
2003 "Advertise routes with max-med\n"
2004 "Administratively applied, for an indefinite period\n")
abc920f8 2005{
1ca2fd11 2006 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 2007
1ca2fd11
IR
2008 bgp->v_maxmed_admin = 1;
2009 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
ff8a8a7a 2010
1ca2fd11 2011 bgp_maxmed_update(bgp);
abc920f8 2012
1ca2fd11 2013 return CMD_SUCCESS;
ff8a8a7a
CS
2014}
2015
1ca2fd11
IR
2016DEFUN (bgp_maxmed_admin_medv,
2017 bgp_maxmed_admin_medv_cmd,
2018 "bgp max-med administrative (0-4294967295)",
2019 BGP_STR
2020 "Advertise routes with max-med\n"
2021 "Administratively applied, for an indefinite period\n"
2022 "Max MED value to be used\n")
abc920f8 2023{
1ca2fd11 2024 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 2025 int idx_number = 3;
abc920f8 2026
1ca2fd11
IR
2027 bgp->v_maxmed_admin = 1;
2028 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
abc920f8 2029
1ca2fd11 2030 bgp_maxmed_update(bgp);
abc920f8 2031
1ca2fd11 2032 return CMD_SUCCESS;
abc920f8
DS
2033}
2034
1ca2fd11
IR
2035DEFUN (no_bgp_maxmed_admin,
2036 no_bgp_maxmed_admin_cmd,
2037 "no bgp max-med administrative [(0-4294967295)]",
2038 NO_STR
2039 BGP_STR
2040 "Advertise routes with max-med\n"
2041 "Administratively applied, for an indefinite period\n"
2042 "Max MED value to be used\n")
abc920f8 2043{
1ca2fd11
IR
2044 VTY_DECLVAR_CONTEXT(bgp, bgp);
2045 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
2046 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
2047 bgp_maxmed_update(bgp);
ff8a8a7a 2048
1ca2fd11 2049 return CMD_SUCCESS;
abc920f8
DS
2050}
2051
1ca2fd11
IR
2052DEFUN (bgp_maxmed_onstartup,
2053 bgp_maxmed_onstartup_cmd,
2054 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
2055 BGP_STR
2056 "Advertise routes with max-med\n"
2057 "Effective on a startup\n"
2058 "Time (seconds) period for max-med\n"
2059 "Max MED value to be used\n")
abc920f8 2060{
1ca2fd11 2061 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 2062 int idx = 0;
4668a151 2063
9b01d289
DA
2064 if (argv_find(argv, argc, "(5-86400)", &idx))
2065 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
d62a17ae 2066 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1ca2fd11 2067 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
d62a17ae 2068 else
1ca2fd11 2069 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 2070
1ca2fd11
IR
2071 bgp_maxmed_update(bgp);
2072
2073 return CMD_SUCCESS;
abc920f8
DS
2074}
2075
1ca2fd11
IR
2076DEFUN (no_bgp_maxmed_onstartup,
2077 no_bgp_maxmed_onstartup_cmd,
2078 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
2079 NO_STR
2080 BGP_STR
2081 "Advertise routes with max-med\n"
2082 "Effective on a startup\n"
2083 "Time (seconds) period for max-med\n"
2084 "Max MED value to be used\n")
abc920f8 2085{
1ca2fd11
IR
2086 VTY_DECLVAR_CONTEXT(bgp, bgp);
2087
2088 /* Cancel max-med onstartup if its on */
2089 if (bgp->t_maxmed_onstartup) {
c3aaa89a 2090 THREAD_OFF(bgp->t_maxmed_onstartup);
1ca2fd11
IR
2091 bgp->maxmed_onstartup_over = 1;
2092 }
abc920f8 2093
1ca2fd11
IR
2094 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
2095 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 2096
1ca2fd11
IR
2097 bgp_maxmed_update(bgp);
2098
2099 return CMD_SUCCESS;
abc920f8
DS
2100}
2101
d70583f7
D
2102static int bgp_global_update_delay_config_vty(struct vty *vty,
2103 uint16_t update_delay,
2104 uint16_t establish_wait)
2105{
2106 struct listnode *node, *nnode;
2107 struct bgp *bgp;
2108 bool vrf_cfg = false;
2109
2110 /*
2111 * See if update-delay is set per-vrf and warn user to delete it
2112 * Note that we only need to check this if this is the first time
2113 * setting the global config.
2114 */
2115 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
2116 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2117 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
2118 vty_out(vty,
2119 "%% update-delay configuration found in vrf %s\n",
2120 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
2121 ? VRF_DEFAULT_NAME
2122 : bgp->name);
2123 vrf_cfg = true;
2124 }
2125 }
2126 }
2127
2128 if (vrf_cfg) {
2129 vty_out(vty,
2130 "%%Failed: global update-delay config not permitted\n");
2131 return CMD_WARNING;
2132 }
2133
2134 if (!establish_wait) { /* update-delay <delay> */
2135 bm->v_update_delay = update_delay;
2136 bm->v_establish_wait = bm->v_update_delay;
2137 } else {
2138 /* update-delay <delay> <establish-wait> */
2139 if (update_delay < establish_wait) {
2140 vty_out(vty,
2141 "%%Failed: update-delay less than the establish-wait!\n");
2142 return CMD_WARNING_CONFIG_FAILED;
2143 }
2144
2145 bm->v_update_delay = update_delay;
2146 bm->v_establish_wait = establish_wait;
2147 }
2148
2149 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2150 bgp->v_update_delay = bm->v_update_delay;
2151 bgp->v_establish_wait = bm->v_establish_wait;
2152 }
2153
2154 return CMD_SUCCESS;
2155}
2156
2157static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
2158{
2159 struct listnode *node, *nnode;
2160 struct bgp *bgp;
2161
2162 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
2163 bm->v_establish_wait = bm->v_update_delay;
2164
2165 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2166 bgp->v_update_delay = bm->v_update_delay;
2167 bgp->v_establish_wait = bm->v_establish_wait;
2168 }
2169
2170 return CMD_SUCCESS;
2171}
2172
2173static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
2174 uint16_t establish_wait)
f188f2c4 2175{
d62a17ae 2176 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 2177
d70583f7
D
2178 /* if configured globally, per-instance config is not allowed */
2179 if (bm->v_update_delay) {
2180 vty_out(vty,
2181 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
2182 return CMD_WARNING_CONFIG_FAILED;
2183 }
2184
f188f2c4 2185
d70583f7 2186 if (!establish_wait) /* update-delay <delay> */
d62a17ae 2187 {
2188 bgp->v_update_delay = update_delay;
2189 bgp->v_establish_wait = bgp->v_update_delay;
2190 return CMD_SUCCESS;
2191 }
f188f2c4 2192
d62a17ae 2193 /* update-delay <delay> <establish-wait> */
d62a17ae 2194 if (update_delay < establish_wait) {
2195 vty_out(vty,
2196 "%%Failed: update-delay less than the establish-wait!\n");
2197 return CMD_WARNING_CONFIG_FAILED;
2198 }
f188f2c4 2199
d62a17ae 2200 bgp->v_update_delay = update_delay;
2201 bgp->v_establish_wait = establish_wait;
f188f2c4 2202
d62a17ae 2203 return CMD_SUCCESS;
f188f2c4
DS
2204}
2205
d62a17ae 2206static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 2207{
d62a17ae 2208 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 2209
d70583f7
D
2210 /* If configured globally, cannot remove from one bgp instance */
2211 if (bm->v_update_delay) {
2212 vty_out(vty,
2213 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2214 return CMD_WARNING_CONFIG_FAILED;
2215 }
d62a17ae 2216 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2217 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 2218
d62a17ae 2219 return CMD_SUCCESS;
f188f2c4
DS
2220}
2221
2b791107 2222void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 2223{
d70583f7
D
2224 /* If configured globally, no need to display per-instance value */
2225 if (bgp->v_update_delay != bm->v_update_delay) {
d62a17ae 2226 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2227 if (bgp->v_update_delay != bgp->v_establish_wait)
2228 vty_out(vty, " %d", bgp->v_establish_wait);
2229 vty_out(vty, "\n");
2230 }
f188f2c4
DS
2231}
2232
d70583f7
D
2233/* Global update-delay configuration */
2234DEFPY (bgp_global_update_delay,
2235 bgp_global_update_delay_cmd,
2236 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2237 BGP_STR
2238 "Force initial delay for best-path and updates for all bgp instances\n"
2239 "Max delay in seconds\n"
2240 "Establish wait in seconds\n")
2241{
2242 return bgp_global_update_delay_config_vty(vty, delay, wait);
2243}
f188f2c4 2244
d70583f7
D
2245/* Global update-delay deconfiguration */
2246DEFPY (no_bgp_global_update_delay,
2247 no_bgp_global_update_delay_cmd,
2248 "no bgp update-delay [(0-3600) [(1-3600)]]",
2249 NO_STR
2250 BGP_STR
f188f2c4 2251 "Force initial delay for best-path and updates\n"
d70583f7
D
2252 "Max delay in seconds\n"
2253 "Establish wait in seconds\n")
f188f2c4 2254{
d70583f7 2255 return bgp_global_update_delay_deconfig_vty(vty);
f188f2c4
DS
2256}
2257
d70583f7
D
2258/* Update-delay configuration */
2259
2260DEFPY (bgp_update_delay,
2261 bgp_update_delay_cmd,
2262 "update-delay (0-3600)$delay [(1-3600)$wait]",
f188f2c4 2263 "Force initial delay for best-path and updates\n"
d70583f7
D
2264 "Max delay in seconds\n"
2265 "Establish wait in seconds\n")
f188f2c4 2266{
d70583f7 2267 return bgp_update_delay_config_vty(vty, delay, wait);
f188f2c4
DS
2268}
2269
2270/* Update-delay deconfiguration */
d70583f7 2271DEFPY (no_bgp_update_delay,
f188f2c4 2272 no_bgp_update_delay_cmd,
838758ac
DW
2273 "no update-delay [(0-3600) [(1-3600)]]",
2274 NO_STR
f188f2c4 2275 "Force initial delay for best-path and updates\n"
d70583f7
D
2276 "Max delay in seconds\n"
2277 "Establish wait in seconds\n")
f188f2c4 2278{
d62a17ae 2279 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
2280}
2281
5e242b0d 2282
1ca2fd11
IR
2283static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2284 bool set)
cb1faec9 2285{
1ca2fd11
IR
2286 VTY_DECLVAR_CONTEXT(bgp, bgp);
2287
8fa7732f
QY
2288 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2289 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
555e09d4
QY
2290
2291 return CMD_SUCCESS;
2292}
2293
1ca2fd11
IR
2294static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2295 bool set)
555e09d4 2296{
1ca2fd11
IR
2297 VTY_DECLVAR_CONTEXT(bgp, bgp);
2298
8fa7732f
QY
2299 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2300 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
cb1faec9 2301
d62a17ae 2302 return CMD_SUCCESS;
cb1faec9
DS
2303}
2304
2b791107 2305void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 2306{
555e09d4
QY
2307 uint32_t quanta =
2308 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2309 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 2310 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
2311}
2312
555e09d4
QY
2313void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2314{
2315 uint32_t quanta =
2316 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2317 if (quanta != BGP_READ_PACKET_MAX)
152456fe 2318 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 2319}
cb1faec9 2320
8fa7732f
QY
2321/* Packet quanta configuration
2322 *
2323 * XXX: The value set here controls the size of a stack buffer in the IO
2324 * thread. When changing these limits be careful to prevent stack overflow.
2325 *
2326 * Furthermore, the maximums used here should correspond to
2327 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2328 */
1ca2fd11
IR
2329DEFPY (bgp_wpkt_quanta,
2330 bgp_wpkt_quanta_cmd,
2331 "[no] write-quanta (1-64)$quanta",
2332 NO_STR
2333 "How many packets to write to peer socket per run\n"
2334 "Number of packets\n")
2335{
2336 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
2337}
cb1faec9 2338
1ca2fd11
IR
2339DEFPY (bgp_rpkt_quanta,
2340 bgp_rpkt_quanta_cmd,
2341 "[no] read-quanta (1-10)$quanta",
2342 NO_STR
2343 "How many packets to read from peer socket per I/O cycle\n"
2344 "Number of packets\n")
2345{
2346 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
555e09d4
QY
2347}
2348
2b791107 2349void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 2350{
37a333fe 2351 if (!bgp->heuristic_coalesce)
d62a17ae 2352 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
2353}
2354
d1adb448
PG
2355/* BGP TCP keepalive */
2356static void bgp_config_tcp_keepalive(struct vty *vty, struct bgp *bgp)
2357{
2358 if (bgp->tcp_keepalive_idle) {
2359 vty_out(vty, " bgp tcp-keepalive %u %u %u\n",
2360 bgp->tcp_keepalive_idle, bgp->tcp_keepalive_intvl,
2361 bgp->tcp_keepalive_probes);
2362 }
2363}
4668a151 2364
1ca2fd11
IR
2365DEFUN (bgp_coalesce_time,
2366 bgp_coalesce_time_cmd,
2367 "coalesce-time (0-4294967295)",
2368 "Subgroup coalesce timer\n"
2369 "Subgroup coalesce timer value (in ms)\n")
ff8a8a7a 2370{
1ca2fd11 2371 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 2372
1ca2fd11 2373 int idx = 0;
9b01d289 2374
1ca2fd11 2375 bgp->heuristic_coalesce = false;
9b01d289
DA
2376
2377 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2378 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
2379
1ca2fd11 2380 return CMD_SUCCESS;
3f9c7369
DS
2381}
2382
1ca2fd11
IR
2383DEFUN (no_bgp_coalesce_time,
2384 no_bgp_coalesce_time_cmd,
2385 "no coalesce-time (0-4294967295)",
2386 NO_STR
2387 "Subgroup coalesce timer\n"
2388 "Subgroup coalesce timer value (in ms)\n")
3f9c7369 2389{
1ca2fd11 2390 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 2391
1ca2fd11
IR
2392 bgp->heuristic_coalesce = true;
2393 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
2394 return CMD_SUCCESS;
3f9c7369
DS
2395}
2396
5e242b0d 2397/* Maximum-paths configuration */
585f1adc
IR
2398DEFUN (bgp_maxpaths,
2399 bgp_maxpaths_cmd,
2400 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2401 "Forward packets over multiple paths\n"
2402 "Number of paths\n")
5e242b0d 2403{
d62a17ae 2404 int idx_number = 1;
585f1adc
IR
2405 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
2406 argv[idx_number]->arg, 0, 1);
5e242b0d
DS
2407}
2408
d62a17ae 2409ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2410 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2411 "Forward packets over multiple paths\n"
2412 "Number of paths\n")
596c17ba 2413
585f1adc
IR
2414DEFUN (bgp_maxpaths_ibgp,
2415 bgp_maxpaths_ibgp_cmd,
2416 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2417 "Forward packets over multiple paths\n"
2418 "iBGP-multipath\n"
2419 "Number of paths\n")
165b5fff 2420{
d62a17ae 2421 int idx_number = 2;
585f1adc
IR
2422 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2423 argv[idx_number]->arg, 0, 1);
5e242b0d 2424}
165b5fff 2425
d62a17ae 2426ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2427 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2428 "Forward packets over multiple paths\n"
2429 "iBGP-multipath\n"
2430 "Number of paths\n")
596c17ba 2431
585f1adc
IR
2432DEFUN (bgp_maxpaths_ibgp_cluster,
2433 bgp_maxpaths_ibgp_cluster_cmd,
2434 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2435 "Forward packets over multiple paths\n"
2436 "iBGP-multipath\n"
2437 "Number of paths\n"
2438 "Match the cluster length\n")
5e242b0d 2439{
d62a17ae 2440 int idx_number = 2;
aa53c036
DS
2441 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2442 argv[idx_number]->arg, true, 1);
165b5fff
JB
2443}
2444
d62a17ae 2445ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2446 "maximum-paths ibgp " CMD_RANGE_STR(
2447 1, MULTIPATH_NUM) " equal-cluster-length",
2448 "Forward packets over multiple paths\n"
2449 "iBGP-multipath\n"
2450 "Number of paths\n"
2451 "Match the cluster length\n")
596c17ba 2452
585f1adc
IR
2453DEFUN (no_bgp_maxpaths,
2454 no_bgp_maxpaths_cmd,
2455 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2456 NO_STR
2457 "Forward packets over multiple paths\n"
2458 "Number of paths\n")
165b5fff 2459{
585f1adc 2460 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
165b5fff
JB
2461}
2462
d62a17ae 2463ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 2464 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 2465 "Forward packets over multiple paths\n"
2466 "Number of paths\n")
596c17ba 2467
585f1adc
IR
2468DEFUN (no_bgp_maxpaths_ibgp,
2469 no_bgp_maxpaths_ibgp_cmd,
2470 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2471 NO_STR
2472 "Forward packets over multiple paths\n"
2473 "iBGP-multipath\n"
2474 "Number of paths\n"
2475 "Match the cluster length\n")
165b5fff 2476{
585f1adc 2477 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
2478}
2479
d62a17ae 2480ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2481 "no maximum-paths ibgp [" CMD_RANGE_STR(
2482 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2483 NO_STR
2484 "Forward packets over multiple paths\n"
2485 "iBGP-multipath\n"
2486 "Number of paths\n"
2487 "Match the cluster length\n")
596c17ba 2488
dd65f45e
DL
2489static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2490 afi_t afi, safi_t safi)
165b5fff 2491{
00908b7a 2492 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
d62a17ae 2493 vty_out(vty, " maximum-paths %d\n",
2494 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2495 }
165b5fff 2496
00908b7a 2497 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
d62a17ae 2498 vty_out(vty, " maximum-paths ibgp %d",
2499 bgp->maxpaths[afi][safi].maxpaths_ibgp);
aa53c036 2500 if (bgp->maxpaths[afi][safi].same_clusterlen)
d62a17ae 2501 vty_out(vty, " equal-cluster-length");
2502 vty_out(vty, "\n");
2503 }
165b5fff 2504}
6b0655a2 2505
718e3744 2506/* BGP timers. */
2507
1ca2fd11
IR
2508DEFUN (bgp_timers,
2509 bgp_timers_cmd,
2510 "timers bgp (0-65535) (0-65535)",
2511 "Adjust routing timers\n"
2512 "BGP timers\n"
2513 "Keepalive interval\n"
2514 "Holdtime\n")
718e3744 2515{
1ca2fd11 2516 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 2517 int idx_number = 2;
2518 int idx_number_2 = 3;
1ca2fd11
IR
2519 unsigned long keepalive = 0;
2520 unsigned long holdtime = 0;
718e3744 2521
1ca2fd11
IR
2522 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
2523 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
718e3744 2524
1ca2fd11
IR
2525 /* Holdtime value check. */
2526 if (holdtime < 3 && holdtime != 0) {
2527 vty_out(vty,
2528 "%% hold time value must be either 0 or greater than 3\n");
2529 return CMD_WARNING_CONFIG_FAILED;
2530 }
718e3744 2531
1ca2fd11
IR
2532 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY,
2533 BGP_DEFAULT_DELAYOPEN);
718e3744 2534
1ca2fd11 2535 return CMD_SUCCESS;
718e3744 2536}
2537
1ca2fd11
IR
2538DEFUN (no_bgp_timers,
2539 no_bgp_timers_cmd,
2540 "no timers bgp [(0-65535) (0-65535)]",
2541 NO_STR
2542 "Adjust routing timers\n"
2543 "BGP timers\n"
2544 "Keepalive interval\n"
2545 "Holdtime\n")
718e3744 2546{
1ca2fd11
IR
2547 VTY_DECLVAR_CONTEXT(bgp, bgp);
2548 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
2549 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
ff8a8a7a 2550
1ca2fd11 2551 return CMD_SUCCESS;
718e3744 2552}
2553
b042667a
TI
2554/* BGP minimum holdtime. */
2555
2556DEFUN(bgp_minimum_holdtime, bgp_minimum_holdtime_cmd,
2557 "bgp minimum-holdtime (1-65535)",
2558 "BGP specific commands\n"
2559 "BGP minimum holdtime\n"
2560 "Seconds\n")
2561{
2562 VTY_DECLVAR_CONTEXT(bgp, bgp);
2563 int idx_number = 2;
2564 unsigned long min_holdtime;
2565
2566 min_holdtime = strtoul(argv[idx_number]->arg, NULL, 10);
2567
2568 bgp->default_min_holdtime = min_holdtime;
2569
2570 return CMD_SUCCESS;
2571}
2572
2573DEFUN(no_bgp_minimum_holdtime, no_bgp_minimum_holdtime_cmd,
2574 "no bgp minimum-holdtime [(1-65535)]",
2575 NO_STR
2576 "BGP specific commands\n"
2577 "BGP minimum holdtime\n"
2578 "Seconds\n")
2579{
2580 VTY_DECLVAR_CONTEXT(bgp, bgp);
2581
2582 bgp->default_min_holdtime = 0;
2583
2584 return CMD_SUCCESS;
2585}
ff8a8a7a 2586
d1adb448
PG
2587DEFPY(bgp_tcp_keepalive, bgp_tcp_keepalive_cmd,
2588 "bgp tcp-keepalive (1-65535)$idle (1-65535)$intvl (1-30)$probes",
2589 BGP_STR
2590 "TCP keepalive parameters\n"
2591 "TCP keepalive idle time (seconds)\n"
2592 "TCP keepalive interval (seconds)\n"
2593 "TCP keepalive maximum probes\n")
2594{
2595 VTY_DECLVAR_CONTEXT(bgp, bgp);
2596
2597 bgp_tcp_keepalive_set(bgp, (uint16_t)idle, (uint16_t)intvl,
2598 (uint16_t)probes);
2599
2600 return CMD_SUCCESS;
2601}
2602
2603DEFPY(no_bgp_tcp_keepalive, no_bgp_tcp_keepalive_cmd,
2604 "no bgp tcp-keepalive [(1-65535) (1-65535) (1-30)]",
2605 NO_STR
2606 BGP_STR
2607 "TCP keepalive parameters\n"
2608 "TCP keepalive idle time (seconds)\n"
2609 "TCP keepalive interval (seconds)\n"
2610 "TCP keepalive maximum probes\n")
2611{
2612 VTY_DECLVAR_CONTEXT(bgp, bgp);
2613
2614 bgp_tcp_keepalive_unset(bgp);
2615
2616 return CMD_SUCCESS;
2617}
2618
1ca2fd11
IR
2619DEFUN (bgp_client_to_client_reflection,
2620 bgp_client_to_client_reflection_cmd,
2621 "bgp client-to-client reflection",
e9273987 2622 BGP_STR
1ca2fd11
IR
2623 "Configure client to client route reflection\n"
2624 "reflection of routes allowed\n")
718e3744 2625{
1ca2fd11
IR
2626 VTY_DECLVAR_CONTEXT(bgp, bgp);
2627 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2628 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 2629
1ca2fd11 2630 return CMD_SUCCESS;
718e3744 2631}
2632
1ca2fd11
IR
2633DEFUN (no_bgp_client_to_client_reflection,
2634 no_bgp_client_to_client_reflection_cmd,
2635 "no bgp client-to-client reflection",
2636 NO_STR
e9273987 2637 BGP_STR
1ca2fd11
IR
2638 "Configure client to client route reflection\n"
2639 "reflection of routes allowed\n")
718e3744 2640{
1ca2fd11
IR
2641 VTY_DECLVAR_CONTEXT(bgp, bgp);
2642 SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2643 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 2644
1ca2fd11 2645 return CMD_SUCCESS;
718e3744 2646}
2647
2648/* "bgp always-compare-med" configuration. */
1ca2fd11
IR
2649DEFUN (bgp_always_compare_med,
2650 bgp_always_compare_med_cmd,
2651 "bgp always-compare-med",
e9273987 2652 BGP_STR
1ca2fd11 2653 "Allow comparing MED from different neighbors\n")
718e3744 2654{
1ca2fd11
IR
2655 VTY_DECLVAR_CONTEXT(bgp, bgp);
2656 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2657 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2658
1ca2fd11 2659 return CMD_SUCCESS;
718e3744 2660}
2661
1ca2fd11
IR
2662DEFUN (no_bgp_always_compare_med,
2663 no_bgp_always_compare_med_cmd,
2664 "no bgp always-compare-med",
2665 NO_STR
e9273987 2666 BGP_STR
1ca2fd11 2667 "Allow comparing MED from different neighbors\n")
718e3744 2668{
1ca2fd11
IR
2669 VTY_DECLVAR_CONTEXT(bgp, bgp);
2670 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2671 bgp_recalculate_all_bestpaths(bgp);
6b0655a2 2672
1ca2fd11 2673 return CMD_SUCCESS;
2adac256
DA
2674}
2675
2adac256 2676
1ca2fd11
IR
2677DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2678 "bgp ebgp-requires-policy",
e9273987 2679 BGP_STR
1ca2fd11 2680 "Require in and out policy for eBGP peers (RFC8212)\n")
2adac256 2681{
1ca2fd11
IR
2682 VTY_DECLVAR_CONTEXT(bgp, bgp);
2683 SET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2684 return CMD_SUCCESS;
2adac256
DA
2685}
2686
1ca2fd11
IR
2687DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2688 "no bgp ebgp-requires-policy",
2689 NO_STR
e9273987 2690 BGP_STR
1ca2fd11 2691 "Require in and out policy for eBGP peers (RFC8212)\n")
ff8a8a7a 2692{
1ca2fd11
IR
2693 VTY_DECLVAR_CONTEXT(bgp, bgp);
2694 UNSET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2695 return CMD_SUCCESS;
ff8a8a7a 2696}
9dac9fc8 2697
1ca2fd11
IR
2698DEFUN(bgp_suppress_duplicates, bgp_suppress_duplicates_cmd,
2699 "bgp suppress-duplicates",
e9273987 2700 BGP_STR
1ca2fd11 2701 "Suppress duplicate updates if the route actually not changed\n")
9dac9fc8 2702{
1ca2fd11
IR
2703 VTY_DECLVAR_CONTEXT(bgp, bgp);
2704 SET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2705 return CMD_SUCCESS;
9dac9fc8
DA
2706}
2707
1ca2fd11
IR
2708DEFUN(no_bgp_suppress_duplicates, no_bgp_suppress_duplicates_cmd,
2709 "no bgp suppress-duplicates",
2710 NO_STR
e9273987 2711 BGP_STR
1ca2fd11 2712 "Suppress duplicate updates if the route actually not changed\n")
9dac9fc8 2713{
1ca2fd11
IR
2714 VTY_DECLVAR_CONTEXT(bgp, bgp);
2715 UNSET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2716 return CMD_SUCCESS;
9dac9fc8
DA
2717}
2718
fb29348a
DA
2719DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2720 "bgp reject-as-sets",
e9273987 2721 BGP_STR
fb29348a
DA
2722 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2723{
2724 VTY_DECLVAR_CONTEXT(bgp, bgp);
2725 struct listnode *node, *nnode;
2726 struct peer *peer;
2727
7f972cd8 2728 bgp->reject_as_sets = true;
fb29348a
DA
2729
2730 /* Reset existing BGP sessions to reject routes
2731 * with aspath containing AS_SET or AS_CONFED_SET.
2732 */
2733 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2734 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2735 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2736 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2737 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2738 }
2739 }
2740
2741 return CMD_SUCCESS;
2742}
2743
2744DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2745 "no bgp reject-as-sets",
2746 NO_STR
e9273987 2747 BGP_STR
fb29348a
DA
2748 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2749{
2750 VTY_DECLVAR_CONTEXT(bgp, bgp);
2751 struct listnode *node, *nnode;
2752 struct peer *peer;
2753
7f972cd8 2754 bgp->reject_as_sets = false;
fb29348a
DA
2755
2756 /* Reset existing BGP sessions to reject routes
2757 * with aspath containing AS_SET or AS_CONFED_SET.
2758 */
2759 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2760 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2761 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2762 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2763 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2764 }
2765 }
2766
2767 return CMD_SUCCESS;
2768}
9dac9fc8 2769
718e3744 2770/* "bgp deterministic-med" configuration. */
1ca2fd11 2771DEFUN (bgp_deterministic_med,
718e3744 2772 bgp_deterministic_med_cmd,
2773 "bgp deterministic-med",
e9273987 2774 BGP_STR
718e3744 2775 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2776{
1ca2fd11
IR
2777 VTY_DECLVAR_CONTEXT(bgp, bgp);
2778
2779 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2780 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2781 bgp_recalculate_all_bestpaths(bgp);
2782 }
7aafcaca 2783
1ca2fd11 2784 return CMD_SUCCESS;
718e3744 2785}
2786
1ca2fd11 2787DEFUN (no_bgp_deterministic_med,
718e3744 2788 no_bgp_deterministic_med_cmd,
2789 "no bgp deterministic-med",
2790 NO_STR
e9273987 2791 BGP_STR
718e3744 2792 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2793{
1ca2fd11
IR
2794 VTY_DECLVAR_CONTEXT(bgp, bgp);
2795 int bestpath_per_as_used;
2796 afi_t afi;
2797 safi_t safi;
2798 struct peer *peer;
2799 struct listnode *node, *nnode;
2800
2801 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2802 bestpath_per_as_used = 0;
2803
2804 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2805 FOREACH_AFI_SAFI (afi, safi)
2806 if (bgp_addpath_dmed_required(
2807 peer->addpath_type[afi][safi])) {
2808 bestpath_per_as_used = 1;
2809 break;
2810 }
2811
2812 if (bestpath_per_as_used)
2813 break;
2814 }
2815
2816 if (bestpath_per_as_used) {
2817 vty_out(vty,
2818 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2819 return CMD_WARNING_CONFIG_FAILED;
2820 } else {
2821 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2822 bgp_recalculate_all_bestpaths(bgp);
2823 }
2824 }
d62a17ae 2825
1ca2fd11 2826 return CMD_SUCCESS;
718e3744 2827}
538621f2 2828
055679e9 2829/* "bgp graceful-restart mode" configuration. */
538621f2 2830DEFUN (bgp_graceful_restart,
2ba1fe69 2831 bgp_graceful_restart_cmd,
2832 "bgp graceful-restart",
e9273987 2833 BGP_STR
2ba1fe69 2834 GR_CMD
055679e9 2835 )
538621f2 2836{
055679e9 2837 int ret = BGP_GR_FAILURE;
2838
2839 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2840 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
dc95985f 2841
d62a17ae 2842 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2843
2844 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2845
36235319
QY
2846 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2847 ret);
5cce3f05 2848
055679e9 2849 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2850 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
dc95985f 2851 vty_out(vty,
2852 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2853 return bgp_vty_return(vty, ret);
538621f2 2854}
2855
2856DEFUN (no_bgp_graceful_restart,
2ba1fe69 2857 no_bgp_graceful_restart_cmd,
2858 "no bgp graceful-restart",
2859 NO_STR
e9273987 2860 BGP_STR
2ba1fe69 2861 NO_GR_CMD
055679e9 2862 )
538621f2 2863{
d62a17ae 2864 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2865
2866 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2867 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
055679e9 2868
2869 int ret = BGP_GR_FAILURE;
2870
2871 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2872
36235319
QY
2873 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2874 ret);
5cce3f05 2875
055679e9 2876 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2877 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
dc95985f 2878 vty_out(vty,
2879 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2880
2881 return bgp_vty_return(vty, ret);
538621f2 2882}
2883
93406d87 2884DEFUN (bgp_graceful_restart_stalepath_time,
2ba1fe69 2885 bgp_graceful_restart_stalepath_time_cmd,
2886 "bgp graceful-restart stalepath-time (1-4095)",
e9273987 2887 BGP_STR
2ba1fe69 2888 "Graceful restart capability parameters\n"
2889 "Set the max time to hold onto restarting peer's stale paths\n"
2890 "Delay value (seconds)\n")
93406d87 2891{
d62a17ae 2892 VTY_DECLVAR_CONTEXT(bgp, bgp);
2893 int idx_number = 3;
d7c0a89a 2894 uint32_t stalepath;
93406d87 2895
d62a17ae 2896 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2897 bgp->stalepath_time = stalepath;
2898 return CMD_SUCCESS;
93406d87 2899}
2900
eb6f1b41 2901DEFUN (bgp_graceful_restart_restart_time,
2ba1fe69 2902 bgp_graceful_restart_restart_time_cmd,
dcbebfd3 2903 "bgp graceful-restart restart-time (0-4095)",
e9273987 2904 BGP_STR
2ba1fe69 2905 "Graceful restart capability parameters\n"
2906 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2907 "Delay value (seconds)\n")
eb6f1b41 2908{
d62a17ae 2909 VTY_DECLVAR_CONTEXT(bgp, bgp);
2910 int idx_number = 3;
d7c0a89a 2911 uint32_t restart;
eb6f1b41 2912
d62a17ae 2913 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2914 bgp->restart_time = restart;
2915 return CMD_SUCCESS;
eb6f1b41
PG
2916}
2917
cfd47646 2918DEFUN (bgp_graceful_restart_select_defer_time,
2919 bgp_graceful_restart_select_defer_time_cmd,
2920 "bgp graceful-restart select-defer-time (0-3600)",
e9273987 2921 BGP_STR
cfd47646 2922 "Graceful restart capability parameters\n"
2923 "Set the time to defer the BGP route selection after restart\n"
2924 "Delay value (seconds, 0 - disable)\n")
2925{
2926 VTY_DECLVAR_CONTEXT(bgp, bgp);
2927 int idx_number = 3;
2928 uint32_t defer_time;
2929
2930 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2931 bgp->select_defer_time = defer_time;
2932 if (defer_time == 0)
892fedb6 2933 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2934 else
892fedb6 2935 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2936
2937 return CMD_SUCCESS;
2938}
2939
93406d87 2940DEFUN (no_bgp_graceful_restart_stalepath_time,
2ba1fe69 2941 no_bgp_graceful_restart_stalepath_time_cmd,
2942 "no bgp graceful-restart stalepath-time [(1-4095)]",
2943 NO_STR
e9273987 2944 BGP_STR
2ba1fe69 2945 "Graceful restart capability parameters\n"
2946 "Set the max time to hold onto restarting peer's stale paths\n"
2947 "Delay value (seconds)\n")
93406d87 2948{
d62a17ae 2949 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 2950
d62a17ae 2951 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2952 return CMD_SUCCESS;
93406d87 2953}
2954
eb6f1b41 2955DEFUN (no_bgp_graceful_restart_restart_time,
2ba1fe69 2956 no_bgp_graceful_restart_restart_time_cmd,
dcbebfd3 2957 "no bgp graceful-restart restart-time [(0-4095)]",
2ba1fe69 2958 NO_STR
e9273987 2959 BGP_STR
2ba1fe69 2960 "Graceful restart capability parameters\n"
2961 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2962 "Delay value (seconds)\n")
eb6f1b41 2963{
d62a17ae 2964 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 2965
d62a17ae 2966 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2967 return CMD_SUCCESS;
eb6f1b41
PG
2968}
2969
cfd47646 2970DEFUN (no_bgp_graceful_restart_select_defer_time,
2971 no_bgp_graceful_restart_select_defer_time_cmd,
2972 "no bgp graceful-restart select-defer-time [(0-3600)]",
2973 NO_STR
e9273987 2974 BGP_STR
cfd47646 2975 "Graceful restart capability parameters\n"
2976 "Set the time to defer the BGP route selection after restart\n"
2977 "Delay value (seconds)\n")
2978{
2979 VTY_DECLVAR_CONTEXT(bgp, bgp);
2980
2981 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
892fedb6 2982 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2983
2984 return CMD_SUCCESS;
2985}
2986
43fc21b3 2987DEFUN (bgp_graceful_restart_preserve_fw,
2ba1fe69 2988 bgp_graceful_restart_preserve_fw_cmd,
2989 "bgp graceful-restart preserve-fw-state",
e9273987 2990 BGP_STR
2ba1fe69 2991 "Graceful restart capability parameters\n"
2992 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2993{
d62a17ae 2994 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2995 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2996 return CMD_SUCCESS;
43fc21b3
JC
2997}
2998
2999DEFUN (no_bgp_graceful_restart_preserve_fw,
2ba1fe69 3000 no_bgp_graceful_restart_preserve_fw_cmd,
3001 "no bgp graceful-restart preserve-fw-state",
3002 NO_STR
e9273987 3003 BGP_STR
2ba1fe69 3004 "Graceful restart capability parameters\n"
3005 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 3006{
d62a17ae 3007 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3008 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 3009 return CMD_SUCCESS;
43fc21b3
JC
3010}
3011
f2ca5c5b
DA
3012DEFPY (bgp_graceful_restart_notification,
3013 bgp_graceful_restart_notification_cmd,
3014 "[no$no] bgp graceful-restart notification",
3015 NO_STR
3016 BGP_STR
3017 "Graceful restart capability parameters\n"
3018 "Indicate Graceful Restart support for BGP NOTIFICATION messages\n")
3019{
3020 VTY_DECLVAR_CONTEXT(bgp, bgp);
3021
3022 if (no)
3023 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
3024 else
3025 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
3026
3027 return CMD_SUCCESS;
3028}
3029
1ae314be
DA
3030DEFPY (bgp_administrative_reset,
3031 bgp_administrative_reset_cmd,
3032 "[no$no] bgp hard-administrative-reset",
3033 NO_STR
3034 BGP_STR
3035 "Send Hard Reset CEASE Notification for 'Administrative Reset'\n")
3036{
3037 VTY_DECLVAR_CONTEXT(bgp, bgp);
3038
3039 if (no)
3040 UNSET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3041 else
3042 SET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3043
3044 return CMD_SUCCESS;
3045}
3046
055679e9 3047DEFUN (bgp_graceful_restart_disable,
2ba1fe69 3048 bgp_graceful_restart_disable_cmd,
3049 "bgp graceful-restart-disable",
e9273987 3050 BGP_STR
2ba1fe69 3051 GR_DISABLE)
055679e9 3052{
3053 int ret = BGP_GR_FAILURE;
3054
3055 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3056 zlog_debug(
2ba1fe69 3057 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
dc95985f 3058
055679e9 3059 VTY_DECLVAR_CONTEXT(bgp, bgp);
3060
3061 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
3062
dc95985f 3063 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
3064 bgp->peer, ret);
5cce3f05 3065
055679e9 3066 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3067 zlog_debug(
2ba1fe69 3068 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
dc95985f 3069 vty_out(vty,
3070 "Graceful restart configuration changed, reset all peers to take effect\n");
3071
055679e9 3072 return bgp_vty_return(vty, ret);
3073}
3074
3075DEFUN (no_bgp_graceful_restart_disable,
2ba1fe69 3076 no_bgp_graceful_restart_disable_cmd,
3077 "no bgp graceful-restart-disable",
3078 NO_STR
e9273987 3079 BGP_STR
2ba1fe69 3080 NO_GR_DISABLE
055679e9 3081 )
3082{
3083 VTY_DECLVAR_CONTEXT(bgp, bgp);
3084
3085 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3086 zlog_debug(
2ba1fe69 3087 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
055679e9 3088
3089 int ret = BGP_GR_FAILURE;
3090
3091 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
3092
36235319
QY
3093 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
3094 ret);
5cce3f05 3095
055679e9 3096 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3097 zlog_debug(
2ba1fe69 3098 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
dc95985f 3099 vty_out(vty,
3100 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 3101
3102 return bgp_vty_return(vty, ret);
3103}
3104
3105DEFUN (bgp_neighbor_graceful_restart_set,
2ba1fe69 3106 bgp_neighbor_graceful_restart_set_cmd,
3107 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3108 NEIGHBOR_STR
3109 NEIGHBOR_ADDR_STR2
3110 GR_NEIGHBOR_CMD
055679e9 3111 )
3112{
3113 int idx_peer = 1;
3114 struct peer *peer;
3115 int ret = BGP_GR_FAILURE;
3116
dc95985f 3117 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3118
055679e9 3119 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3120 zlog_debug(
2ba1fe69 3121 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
dc95985f 3122
055679e9 3123 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3124 if (!peer)
3125 return CMD_WARNING_CONFIG_FAILED;
3126
3127 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
3128
dc95985f 3129 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3130 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3131
3132 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3133 zlog_debug(
2ba1fe69 3134 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 3135 vty_out(vty,
3136 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3137
3138 return bgp_vty_return(vty, ret);
3139}
3140
3141DEFUN (no_bgp_neighbor_graceful_restart,
2ba1fe69 3142 no_bgp_neighbor_graceful_restart_set_cmd,
3143 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3144 NO_STR
3145 NEIGHBOR_STR
3146 NEIGHBOR_ADDR_STR2
3147 NO_GR_NEIGHBOR_CMD
055679e9 3148 )
3149{
3150 int idx_peer = 2;
3151 int ret = BGP_GR_FAILURE;
3152 struct peer *peer;
3153
dc95985f 3154 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3155
055679e9 3156 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3157 if (!peer)
3158 return CMD_WARNING_CONFIG_FAILED;
3159
3160 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3161 zlog_debug(
2ba1fe69 3162 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
055679e9 3163
3164 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
3165
dc95985f 3166 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3167 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3168
3169 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3170 zlog_debug(
2ba1fe69 3171 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 3172 vty_out(vty,
3173 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3174
3175 return bgp_vty_return(vty, ret);
3176}
3177
3178DEFUN (bgp_neighbor_graceful_restart_helper_set,
2ba1fe69 3179 bgp_neighbor_graceful_restart_helper_set_cmd,
3180 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3181 NEIGHBOR_STR
3182 NEIGHBOR_ADDR_STR2
3183 GR_NEIGHBOR_HELPER_CMD
055679e9 3184 )
3185{
3186 int idx_peer = 1;
3187 struct peer *peer;
3188 int ret = BGP_GR_FAILURE;
3189
dc95985f 3190 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3191
055679e9 3192 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3193 zlog_debug(
2ba1fe69 3194 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
dc95985f 3195
055679e9 3196 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3197
055679e9 3198 if (!peer)
3199 return CMD_WARNING_CONFIG_FAILED;
3200
3201
3202 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
5cce3f05 3203
dc95985f 3204 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3205 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
5cce3f05 3206
055679e9 3207 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3208 zlog_debug(
2ba1fe69 3209 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 3210 vty_out(vty,
3211 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3212
3213 return bgp_vty_return(vty, ret);
3214}
3215
3216DEFUN (no_bgp_neighbor_graceful_restart_helper,
2ba1fe69 3217 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3218 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3219 NO_STR
3220 NEIGHBOR_STR
3221 NEIGHBOR_ADDR_STR2
3222 NO_GR_NEIGHBOR_HELPER_CMD
055679e9 3223 )
3224{
3225 int idx_peer = 2;
3226 int ret = BGP_GR_FAILURE;
3227 struct peer *peer;
3228
dc95985f 3229 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3230
055679e9 3231 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3232 if (!peer)
3233 return CMD_WARNING_CONFIG_FAILED;
3234
3235 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3236 zlog_debug(
2ba1fe69 3237 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
055679e9 3238
36235319 3239 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
055679e9 3240
dc95985f 3241 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3242 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3243
3244 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3245 zlog_debug(
2ba1fe69 3246 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 3247 vty_out(vty,
3248 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3249
3250 return bgp_vty_return(vty, ret);
3251}
3252
3253DEFUN (bgp_neighbor_graceful_restart_disable_set,
2ba1fe69 3254 bgp_neighbor_graceful_restart_disable_set_cmd,
3255 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3256 NEIGHBOR_STR
3257 NEIGHBOR_ADDR_STR2
3258 GR_NEIGHBOR_DISABLE_CMD
055679e9 3259 )
3260{
3261 int idx_peer = 1;
3262 struct peer *peer;
3263 int ret = BGP_GR_FAILURE;
3264
dc95985f 3265 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3266
055679e9 3267 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3268 zlog_debug(
2ba1fe69 3269 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 3270
3271 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3272 if (!peer)
3273 return CMD_WARNING_CONFIG_FAILED;
3274
36235319 3275 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
055679e9 3276
3277 if (peer->bgp->t_startup)
3278 bgp_peer_gr_flags_update(peer);
3279
dc95985f 3280 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3281 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3282
055679e9 3283 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3284 zlog_debug(
2ba1fe69 3285 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3286 vty_out(vty,
3287 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3288
3289 return bgp_vty_return(vty, ret);
3290}
3291
3292DEFUN (no_bgp_neighbor_graceful_restart_disable,
2ba1fe69 3293 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3294 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3295 NO_STR
3296 NEIGHBOR_STR
3297 NEIGHBOR_ADDR_STR2
3298 NO_GR_NEIGHBOR_DISABLE_CMD
055679e9 3299 )
3300{
3301 int idx_peer = 2;
3302 int ret = BGP_GR_FAILURE;
3303 struct peer *peer;
3304
dc95985f 3305 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3306
055679e9 3307 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3308 if (!peer)
3309 return CMD_WARNING_CONFIG_FAILED;
3310
3311 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3312 zlog_debug(
2ba1fe69 3313 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 3314
3315 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3316
dc95985f 3317 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3318 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3319
3320 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3321 zlog_debug(
2ba1fe69 3322 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3323 vty_out(vty,
3324 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3325
3326 return bgp_vty_return(vty, ret);
3327}
3328
d6e3c15b 3329DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3330 bgp_graceful_restart_disable_eor_cmd,
3331 "bgp graceful-restart disable-eor",
e9273987 3332 BGP_STR
d6e3c15b 3333 "Graceful restart configuration parameters\n"
3334 "Disable EOR Check\n")
3335{
3336 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3337 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3338
d6e3c15b 3339 return CMD_SUCCESS;
3340}
3341
3342DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3343 no_bgp_graceful_restart_disable_eor_cmd,
3344 "no bgp graceful-restart disable-eor",
3345 NO_STR
e9273987 3346 BGP_STR
d6e3c15b 3347 "Graceful restart configuration parameters\n"
3348 "Disable EOR Check\n")
3349{
3350 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3351 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3352
3353 return CMD_SUCCESS;
3354}
3355
3356DEFUN (bgp_graceful_restart_rib_stale_time,
3357 bgp_graceful_restart_rib_stale_time_cmd,
3358 "bgp graceful-restart rib-stale-time (1-3600)",
e9273987 3359 BGP_STR
dc95985f 3360 "Graceful restart configuration parameters\n"
3361 "Specify the stale route removal timer in rib\n"
3362 "Delay value (seconds)\n")
3363{
3364 VTY_DECLVAR_CONTEXT(bgp, bgp);
3365 int idx_number = 3;
3366 uint32_t stale_time;
3367
3368 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3369 bgp->rib_stale_time = stale_time;
3370 /* Send the stale timer update message to RIB */
3371 if (bgp_zebra_stale_timer_update(bgp))
3372 return CMD_WARNING;
3373
3374 return CMD_SUCCESS;
3375}
3376
3377DEFUN (no_bgp_graceful_restart_rib_stale_time,
3378 no_bgp_graceful_restart_rib_stale_time_cmd,
3379 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3380 NO_STR
e9273987 3381 BGP_STR
dc95985f 3382 "Graceful restart configuration parameters\n"
3383 "Specify the stale route removal timer in rib\n"
3384 "Delay value (seconds)\n")
3385{
3386 VTY_DECLVAR_CONTEXT(bgp, bgp);
3387
3388 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3389 /* Send the stale timer update message to RIB */
3390 if (bgp_zebra_stale_timer_update(bgp))
3391 return CMD_WARNING;
3392
d6e3c15b 3393 return CMD_SUCCESS;
3394}
3395
8606be87 3396DEFUN(bgp_llgr_stalepath_time, bgp_llgr_stalepath_time_cmd,
5970204c 3397 "bgp long-lived-graceful-restart stale-time (1-16777215)",
7f8a9a24 3398 BGP_STR
8606be87
DA
3399 "Enable Long-lived Graceful Restart\n"
3400 "Specifies maximum time to wait before purging long-lived stale routes\n"
3401 "Stale time value (seconds)\n")
3402{
3403 VTY_DECLVAR_CONTEXT(bgp, bgp);
3404
3405 uint32_t llgr_stale_time;
3406
3407 llgr_stale_time = strtoul(argv[3]->arg, NULL, 10);
3408 bgp->llgr_stale_time = llgr_stale_time;
3409
3410 return CMD_SUCCESS;
3411}
3412
3413DEFUN(no_bgp_llgr_stalepath_time, no_bgp_llgr_stalepath_time_cmd,
5970204c 3414 "no bgp long-lived-graceful-restart stale-time [(1-16777215)]",
8606be87
DA
3415 NO_STR BGP_STR
3416 "Enable Long-lived Graceful Restart\n"
3417 "Specifies maximum time to wait before purging long-lived stale routes\n"
3418 "Stale time value (seconds)\n")
3419{
3420 VTY_DECLVAR_CONTEXT(bgp, bgp);
3421
3422 bgp->llgr_stale_time = BGP_DEFAULT_LLGR_STALE_TIME;
3423
3424 return CMD_SUCCESS;
3425}
3426
1ca2fd11
IR
3427static inline void bgp_initiate_graceful_shut_unshut(struct vty *vty,
3428 struct bgp *bgp)
05bd726c 3429{
3430 bgp_static_redo_import_check(bgp);
3431 bgp_redistribute_redo(bgp);
1ca2fd11
IR
3432 bgp_clear_star_soft_out(vty, bgp->name);
3433 bgp_clear_star_soft_in(vty, bgp->name);
05bd726c 3434}
3435
3436static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3437{
3438 struct listnode *node, *nnode;
3439 struct bgp *bgp;
3440 bool vrf_cfg = false;
3441
3442 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3443 return CMD_SUCCESS;
3444
3445 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3446 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3447 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3448 vty_out(vty,
3449 "%% graceful-shutdown configuration found in vrf %s\n",
3450 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3451 VRF_DEFAULT_NAME : bgp->name);
3452 vrf_cfg = true;
3453 }
3454 }
3455
3456 if (vrf_cfg) {
3457 vty_out(vty,
3458 "%%Failed: global graceful-shutdown not permitted\n");
3459 return CMD_WARNING;
3460 }
3461
3462 /* Set flag globally */
3463 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3464
3465 /* Initiate processing for all BGP instances. */
1ca2fd11
IR
3466 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3467 bgp_initiate_graceful_shut_unshut(vty, bgp);
05bd726c 3468
3469 return CMD_SUCCESS;
3470}
3471
3472static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3473{
3474 struct listnode *node, *nnode;
3475 struct bgp *bgp;
3476
3477 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3478 return CMD_SUCCESS;
3479
3480 /* Unset flag globally */
3481 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3482
3483 /* Initiate processing for all BGP instances. */
1ca2fd11
IR
3484 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3485 bgp_initiate_graceful_shut_unshut(vty, bgp);
05bd726c 3486
3487 return CMD_SUCCESS;
3488}
3489
7f323236
DW
3490/* "bgp graceful-shutdown" configuration */
3491DEFUN (bgp_graceful_shutdown,
3492 bgp_graceful_shutdown_cmd,
3493 "bgp graceful-shutdown",
3494 BGP_STR
3495 "Graceful shutdown parameters\n")
3496{
05bd726c 3497 if (vty->node == CONFIG_NODE)
3498 return bgp_global_graceful_shutdown_config_vty(vty);
3499
1ca2fd11 3500 VTY_DECLVAR_CONTEXT(bgp, bgp);
7f323236 3501
1ca2fd11
IR
3502 /* if configured globally, per-instance config is not allowed */
3503 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3504 vty_out(vty,
3505 "%%Failed: per-vrf graceful-shutdown config not permitted with global graceful-shutdown\n");
3506 return CMD_WARNING_CONFIG_FAILED;
3507 }
3508
3509 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3510 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3511 bgp_initiate_graceful_shut_unshut(vty, bgp);
3512 }
3513
3514 return CMD_SUCCESS;
7f323236
DW
3515}
3516
1ca2fd11 3517DEFUN (no_bgp_graceful_shutdown,
7f323236
DW
3518 no_bgp_graceful_shutdown_cmd,
3519 "no bgp graceful-shutdown",
3520 NO_STR
3521 BGP_STR
3522 "Graceful shutdown parameters\n")
3523{
05bd726c 3524 if (vty->node == CONFIG_NODE)
3525 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3526
1ca2fd11 3527 VTY_DECLVAR_CONTEXT(bgp, bgp);
05bd726c 3528
1ca2fd11
IR
3529 /* If configured globally, cannot remove from one bgp instance */
3530 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3531 vty_out(vty,
3532 "%%Failed: bgp graceful-shutdown configured globally. Delete per-vrf not permitted\n");
3533 return CMD_WARNING_CONFIG_FAILED;
3534 }
7f323236 3535
1ca2fd11
IR
3536 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3537 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3538 bgp_initiate_graceful_shut_unshut(vty, bgp);
3539 }
3540
3541 return CMD_SUCCESS;
7f323236
DW
3542}
3543
718e3744 3544/* "bgp fast-external-failover" configuration. */
1ca2fd11 3545DEFUN (bgp_fast_external_failover,
718e3744 3546 bgp_fast_external_failover_cmd,
3547 "bgp fast-external-failover",
3548 BGP_STR
3549 "Immediately reset session if a link to a directly connected external peer goes down\n")
3550{
1ca2fd11
IR
3551 VTY_DECLVAR_CONTEXT(bgp, bgp);
3552 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3553 return CMD_SUCCESS;
718e3744 3554}
3555
1ca2fd11 3556DEFUN (no_bgp_fast_external_failover,
718e3744 3557 no_bgp_fast_external_failover_cmd,
3558 "no bgp fast-external-failover",
3559 NO_STR
3560 BGP_STR
3561 "Immediately reset session if a link to a directly connected external peer goes down\n")
3562{
1ca2fd11
IR
3563 VTY_DECLVAR_CONTEXT(bgp, bgp);
3564 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3565 return CMD_SUCCESS;
718e3744 3566}
6b0655a2 3567
97a52c82
DA
3568DEFPY (bgp_bestpath_aigp,
3569 bgp_bestpath_aigp_cmd,
3570 "[no$no] bgp bestpath aigp",
3571 NO_STR
3572 BGP_STR
3573 "Change the default bestpath selection\n"
3574 "Evaluate the AIGP attribute during the best path selection process\n")
3575{
3576 VTY_DECLVAR_CONTEXT(bgp, bgp);
3577
3578 if (no)
3579 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_AIGP);
3580 else
3581 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_AIGP);
3582
3583 bgp_recalculate_all_bestpaths(bgp);
3584
3585 return CMD_SUCCESS;
3586}
3587
718e3744 3588/* "bgp bestpath compare-routerid" configuration. */
1ca2fd11
IR
3589DEFUN (bgp_bestpath_compare_router_id,
3590 bgp_bestpath_compare_router_id_cmd,
3591 "bgp bestpath compare-routerid",
e9273987 3592 BGP_STR
1ca2fd11
IR
3593 "Change the default bestpath selection\n"
3594 "Compare router-id for identical EBGP paths\n")
718e3744 3595{
1ca2fd11
IR
3596 VTY_DECLVAR_CONTEXT(bgp, bgp);
3597 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3598 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3599
1ca2fd11 3600 return CMD_SUCCESS;
718e3744 3601}
3602
1ca2fd11
IR
3603DEFUN (no_bgp_bestpath_compare_router_id,
3604 no_bgp_bestpath_compare_router_id_cmd,
3605 "no bgp bestpath compare-routerid",
3606 NO_STR
e9273987 3607 BGP_STR
1ca2fd11
IR
3608 "Change the default bestpath selection\n"
3609 "Compare router-id for identical EBGP paths\n")
718e3744 3610{
1ca2fd11
IR
3611 VTY_DECLVAR_CONTEXT(bgp, bgp);
3612 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3613 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3614
1ca2fd11 3615 return CMD_SUCCESS;
718e3744 3616}
6b0655a2 3617
718e3744 3618/* "bgp bestpath as-path ignore" configuration. */
1ca2fd11
IR
3619DEFUN (bgp_bestpath_aspath_ignore,
3620 bgp_bestpath_aspath_ignore_cmd,
3621 "bgp bestpath as-path ignore",
e9273987 3622 BGP_STR
1ca2fd11
IR
3623 "Change the default bestpath selection\n"
3624 "AS-path attribute\n"
3625 "Ignore as-path length in selecting a route\n")
718e3744 3626{
1ca2fd11
IR
3627 VTY_DECLVAR_CONTEXT(bgp, bgp);
3628 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3629 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3630
1ca2fd11 3631 return CMD_SUCCESS;
718e3744 3632}
3633
1ca2fd11
IR
3634DEFUN (no_bgp_bestpath_aspath_ignore,
3635 no_bgp_bestpath_aspath_ignore_cmd,
3636 "no bgp bestpath as-path ignore",
3637 NO_STR
e9273987 3638 BGP_STR
1ca2fd11
IR
3639 "Change the default bestpath selection\n"
3640 "AS-path attribute\n"
3641 "Ignore as-path length in selecting a route\n")
718e3744 3642{
1ca2fd11
IR
3643 VTY_DECLVAR_CONTEXT(bgp, bgp);
3644 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3645 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3646
1ca2fd11 3647 return CMD_SUCCESS;
718e3744 3648}
6b0655a2 3649
6811845b 3650/* "bgp bestpath as-path confed" configuration. */
1ca2fd11 3651DEFUN (bgp_bestpath_aspath_confed,
6811845b 3652 bgp_bestpath_aspath_confed_cmd,
3653 "bgp bestpath as-path confed",
e9273987 3654 BGP_STR
6811845b 3655 "Change the default bestpath selection\n"
3656 "AS-path attribute\n"
3657 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3658{
1ca2fd11
IR
3659 VTY_DECLVAR_CONTEXT(bgp, bgp);
3660 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3661 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3662
1ca2fd11 3663 return CMD_SUCCESS;
6811845b 3664}
3665
1ca2fd11 3666DEFUN (no_bgp_bestpath_aspath_confed,
6811845b 3667 no_bgp_bestpath_aspath_confed_cmd,
3668 "no bgp bestpath as-path confed",
3669 NO_STR
e9273987 3670 BGP_STR
6811845b 3671 "Change the default bestpath selection\n"
3672 "AS-path attribute\n"
3673 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3674{
1ca2fd11
IR
3675 VTY_DECLVAR_CONTEXT(bgp, bgp);
3676 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3677 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3678
1ca2fd11 3679 return CMD_SUCCESS;
6811845b 3680}
6b0655a2 3681
2fdd455c 3682/* "bgp bestpath as-path multipath-relax" configuration. */
1ca2fd11 3683DEFUN (bgp_bestpath_aspath_multipath_relax,
2fdd455c 3684 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3685 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
e9273987 3686 BGP_STR
16fc1eec
DS
3687 "Change the default bestpath selection\n"
3688 "AS-path attribute\n"
3689 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3690 "Generate an AS_SET\n"
16fc1eec
DS
3691 "Do not generate an AS_SET\n")
3692{
1ca2fd11 3693 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 3694 int idx = 0;
1ca2fd11 3695 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6 3696
1ca2fd11
IR
3697 /* no-as-set is now the default behavior so we can silently
3698 * ignore it */
d62a17ae 3699 if (argv_find(argv, argc, "as-set", &idx))
1ca2fd11 3700 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
d62a17ae 3701 else
1ca2fd11 3702 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
7aafcaca 3703
1ca2fd11
IR
3704 bgp_recalculate_all_bestpaths(bgp);
3705
3706 return CMD_SUCCESS;
16fc1eec
DS
3707}
3708
1ca2fd11 3709DEFUN (no_bgp_bestpath_aspath_multipath_relax,
219178b6 3710 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3711 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec 3712 NO_STR
e9273987 3713 BGP_STR
16fc1eec
DS
3714 "Change the default bestpath selection\n"
3715 "AS-path attribute\n"
3716 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3717 "Generate an AS_SET\n"
16fc1eec
DS
3718 "Do not generate an AS_SET\n")
3719{
1ca2fd11
IR
3720 VTY_DECLVAR_CONTEXT(bgp, bgp);
3721 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3722 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3723 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3724
1ca2fd11 3725 return CMD_SUCCESS;
2fdd455c 3726}
6b0655a2 3727
ee88563a
JM
3728/* "bgp bestpath peer-type multipath-relax" configuration. */
3729DEFUN(bgp_bestpath_peer_type_multipath_relax,
3730 bgp_bestpath_peer_type_multipath_relax_cmd,
3731 "bgp bestpath peer-type multipath-relax",
3732 BGP_STR
3733 "Change the default bestpath selection\n"
3734 "Peer type\n"
3735 "Allow load sharing across routes learned from different peer types\n")
3736{
3737 VTY_DECLVAR_CONTEXT(bgp, bgp);
3738 SET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3739 bgp_recalculate_all_bestpaths(bgp);
3740
3741 return CMD_SUCCESS;
3742}
3743
3744DEFUN(no_bgp_bestpath_peer_type_multipath_relax,
3745 no_bgp_bestpath_peer_type_multipath_relax_cmd,
3746 "no bgp bestpath peer-type multipath-relax",
3747 NO_STR BGP_STR
3748 "Change the default bestpath selection\n"
3749 "Peer type\n"
3750 "Allow load sharing across routes learned from different peer types\n")
3751{
3752 VTY_DECLVAR_CONTEXT(bgp, bgp);
3753 UNSET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3754 bgp_recalculate_all_bestpaths(bgp);
3755
3756 return CMD_SUCCESS;
3757}
3758
848973c7 3759/* "bgp log-neighbor-changes" configuration. */
1ca2fd11
IR
3760DEFUN (bgp_log_neighbor_changes,
3761 bgp_log_neighbor_changes_cmd,
3762 "bgp log-neighbor-changes",
e9273987 3763 BGP_STR
1ca2fd11 3764 "Log neighbor up/down and reset reason\n")
848973c7 3765{
1ca2fd11
IR
3766 VTY_DECLVAR_CONTEXT(bgp, bgp);
3767 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3768 return CMD_SUCCESS;
848973c7 3769}
3770
1ca2fd11
IR
3771DEFUN (no_bgp_log_neighbor_changes,
3772 no_bgp_log_neighbor_changes_cmd,
3773 "no bgp log-neighbor-changes",
3774 NO_STR
e9273987 3775 BGP_STR
1ca2fd11 3776 "Log neighbor up/down and reset reason\n")
848973c7 3777{
1ca2fd11
IR
3778 VTY_DECLVAR_CONTEXT(bgp, bgp);
3779 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3780 return CMD_SUCCESS;
848973c7 3781}
6b0655a2 3782
718e3744 3783/* "bgp bestpath med" configuration. */
1ca2fd11 3784DEFUN (bgp_bestpath_med,
718e3744 3785 bgp_bestpath_med_cmd,
2d8c1a4d 3786 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
e9273987 3787 BGP_STR
718e3744 3788 "Change the default bestpath selection\n"
3789 "MED attribute\n"
3790 "Compare MED among confederation paths\n"
838758ac
DW
3791 "Treat missing MED as the least preferred one\n"
3792 "Treat missing MED as the least preferred one\n"
3793 "Compare MED among confederation paths\n")
718e3744 3794{
1ca2fd11 3795 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 3796
1ca2fd11 3797 int idx = 0;
d62a17ae 3798 if (argv_find(argv, argc, "confed", &idx))
1ca2fd11 3799 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
d62a17ae 3800 idx = 0;
3801 if (argv_find(argv, argc, "missing-as-worst", &idx))
1ca2fd11 3802 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
e52702f2 3803
1ca2fd11 3804 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3805
1ca2fd11 3806 return CMD_SUCCESS;
718e3744 3807}
3808
1ca2fd11 3809DEFUN (no_bgp_bestpath_med,
718e3744 3810 no_bgp_bestpath_med_cmd,
2d8c1a4d 3811 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 3812 NO_STR
e9273987 3813 BGP_STR
718e3744 3814 "Change the default bestpath selection\n"
3815 "MED attribute\n"
3816 "Compare MED among confederation paths\n"
3a2d747c
QY
3817 "Treat missing MED as the least preferred one\n"
3818 "Treat missing MED as the least preferred one\n"
3819 "Compare MED among confederation paths\n")
718e3744 3820{
1ca2fd11 3821 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 3822
1ca2fd11 3823 int idx = 0;
d62a17ae 3824 if (argv_find(argv, argc, "confed", &idx))
1ca2fd11 3825 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
d62a17ae 3826 idx = 0;
3827 if (argv_find(argv, argc, "missing-as-worst", &idx))
1ca2fd11
IR
3828 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3829
3830 bgp_recalculate_all_bestpaths(bgp);
718e3744 3831
1ca2fd11 3832 return CMD_SUCCESS;
718e3744 3833}
3834
f7e1c681 3835/* "bgp bestpath bandwidth" configuration. */
3836DEFPY (bgp_bestpath_bw,
3837 bgp_bestpath_bw_cmd,
ad36d216 3838 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
e9273987 3839 BGP_STR
f7e1c681 3840 "Change the default bestpath selection\n"
3841 "Link Bandwidth attribute\n"
3842 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3843 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3844 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3845{
3846 VTY_DECLVAR_CONTEXT(bgp, bgp);
3847 afi_t afi;
3848 safi_t safi;
3849
ad36d216
DS
3850 if (!bw_cfg) {
3851 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3852 return CMD_ERR_INCOMPLETE;
f7e1c681 3853 }
ad36d216
DS
3854 if (!strcmp(bw_cfg, "ignore"))
3855 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3856 else if (!strcmp(bw_cfg, "skip-missing"))
3857 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3858 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3859 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3860 else
3861 return CMD_ERR_NO_MATCH;
f7e1c681 3862
3863 /* This config is used in route install, so redo that. */
3864 FOREACH_AFI_SAFI (afi, safi) {
3865 if (!bgp_fibupd_safi(safi))
3866 continue;
3867 bgp_zebra_announce_table(bgp, afi, safi);
3868 }
3869
3870 return CMD_SUCCESS;
3871}
3872
ad36d216
DS
3873DEFPY (no_bgp_bestpath_bw,
3874 no_bgp_bestpath_bw_cmd,
3875 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3876 NO_STR
e9273987 3877 BGP_STR
ad36d216
DS
3878 "Change the default bestpath selection\n"
3879 "Link Bandwidth attribute\n"
3880 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3881 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3882 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3883{
3884 VTY_DECLVAR_CONTEXT(bgp, bgp);
3885 afi_t afi;
3886 safi_t safi;
3887
3888 bgp->lb_handling = BGP_LINK_BW_ECMP;
3889
3890 /* This config is used in route install, so redo that. */
3891 FOREACH_AFI_SAFI (afi, safi) {
3892 if (!bgp_fibupd_safi(safi))
3893 continue;
3894 bgp_zebra_announce_table(bgp, afi, safi);
3895 }
3896 return CMD_SUCCESS;
3897}
3898
b16bcbba 3899DEFPY(bgp_default_afi_safi, bgp_default_afi_safi_cmd,
38d11af5
TA
3900 "[no] bgp default <ipv4-unicast|"
3901 "ipv4-multicast|"
3902 "ipv4-vpn|"
3903 "ipv4-labeled-unicast|"
3904 "ipv4-flowspec|"
3905 "ipv6-unicast|"
3906 "ipv6-multicast|"
3907 "ipv6-vpn|"
3908 "ipv6-labeled-unicast|"
3909 "ipv6-flowspec|"
3910 "l2vpn-evpn>$afi_safi",
b16bcbba 3911 NO_STR
e9273987 3912 BGP_STR
e84c59af 3913 "Configure BGP defaults\n"
b16bcbba 3914 "Activate ipv4-unicast for a peer by default\n"
38d11af5
TA
3915 "Activate ipv4-multicast for a peer by default\n"
3916 "Activate ipv4-vpn for a peer by default\n"
3917 "Activate ipv4-labeled-unicast for a peer by default\n"
3918 "Activate ipv4-flowspec for a peer by default\n"
3919 "Activate ipv6-unicast for a peer by default\n"
3920 "Activate ipv6-multicast for a peer by default\n"
3921 "Activate ipv6-vpn for a peer by default\n"
3922 "Activate ipv6-labeled-unicast for a peer by default\n"
3923 "Activate ipv6-flowspec for a peer by default\n"
3924 "Activate l2vpn-evpn for a peer by default\n")
e84c59af
DA
3925{
3926 VTY_DECLVAR_CONTEXT(bgp, bgp);
b16bcbba
TA
3927 char afi_safi_str[strlen(afi_safi) + 1];
3928 char *afi_safi_str_tok;
e84c59af 3929
b16bcbba
TA
3930 strlcpy(afi_safi_str, afi_safi, sizeof(afi_safi_str));
3931 char *afi_str = strtok_r(afi_safi_str, "-", &afi_safi_str_tok);
3932 char *safi_str = strtok_r(NULL, "-", &afi_safi_str_tok);
3933 afi_t afi = bgp_vty_afi_from_str(afi_str);
38d11af5 3934 safi_t safi;
e84c59af 3935
d880a643
DS
3936 /*
3937 * Impossible situation but making coverity happy
3938 */
3939 assert(afi != AFI_MAX);
3940
38d11af5
TA
3941 if (strmatch(safi_str, "labeled"))
3942 safi = bgp_vty_safi_from_str("labeled-unicast");
3943 else
3944 safi = bgp_vty_safi_from_str(safi_str);
b16bcbba 3945
f609bcd6 3946 assert(safi != SAFI_MAX);
b16bcbba
TA
3947 if (no)
3948 bgp->default_af[afi][safi] = false;
38d11af5
TA
3949 else {
3950 if ((safi == SAFI_LABELED_UNICAST
3951 && bgp->default_af[afi][SAFI_UNICAST])
3952 || (safi == SAFI_UNICAST
3953 && bgp->default_af[afi][SAFI_LABELED_UNICAST]))
3954 bgp_vty_return(vty, BGP_ERR_PEER_SAFI_CONFLICT);
3955 else
3956 bgp->default_af[afi][safi] = true;
3957 }
718e3744 3958
d62a17ae 3959 return CMD_SUCCESS;
718e3744 3960}
6b0655a2 3961
04b6bdc0 3962/* Display hostname in certain command outputs */
1ca2fd11 3963DEFUN (bgp_default_show_hostname,
04b6bdc0
DW
3964 bgp_default_show_hostname_cmd,
3965 "bgp default show-hostname",
e9273987 3966 BGP_STR
04b6bdc0 3967 "Configure BGP defaults\n"
0437e105 3968 "Show hostname in certain command outputs\n")
04b6bdc0 3969{
1ca2fd11
IR
3970 VTY_DECLVAR_CONTEXT(bgp, bgp);
3971 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3972 return CMD_SUCCESS;
ff8a8a7a
CS
3973}
3974
1ca2fd11
IR
3975DEFUN (no_bgp_default_show_hostname,
3976 no_bgp_default_show_hostname_cmd,
3977 "no bgp default show-hostname",
3978 NO_STR
e9273987 3979 BGP_STR
1ca2fd11
IR
3980 "Configure BGP defaults\n"
3981 "Show hostname in certain command outputs\n")
ff8a8a7a 3982{
1ca2fd11
IR
3983 VTY_DECLVAR_CONTEXT(bgp, bgp);
3984 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3985 return CMD_SUCCESS;
04b6bdc0
DW
3986}
3987
aef999a2 3988/* Display hostname in certain command outputs */
1d80f243
IR
3989DEFUN (bgp_default_show_nexthop_hostname,
3990 bgp_default_show_nexthop_hostname_cmd,
3991 "bgp default show-nexthop-hostname",
e9273987 3992 BGP_STR
1d80f243
IR
3993 "Configure BGP defaults\n"
3994 "Show hostname for nexthop in certain command outputs\n")
aef999a2 3995{
1ca2fd11
IR
3996 VTY_DECLVAR_CONTEXT(bgp, bgp);
3997 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3998 return CMD_SUCCESS;
aef999a2
DA
3999}
4000
4001DEFUN (no_bgp_default_show_nexthop_hostname,
4002 no_bgp_default_show_nexthop_hostname_cmd,
4003 "no bgp default show-nexthop-hostname",
4004 NO_STR
e9273987 4005 BGP_STR
aef999a2
DA
4006 "Configure BGP defaults\n"
4007 "Show hostname for nexthop in certain command outputs\n")
4008{
1ca2fd11
IR
4009 VTY_DECLVAR_CONTEXT(bgp, bgp);
4010 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
4011 return CMD_SUCCESS;
aef999a2
DA
4012}
4013
8233ef81 4014/* "bgp network import-check" configuration. */
1ca2fd11
IR
4015DEFUN (bgp_network_import_check,
4016 bgp_network_import_check_cmd,
4017 "bgp network import-check",
e9273987 4018 BGP_STR
1ca2fd11
IR
4019 "BGP network command\n"
4020 "Check BGP network route exists in IGP\n")
718e3744 4021{
1ca2fd11
IR
4022 VTY_DECLVAR_CONTEXT(bgp, bgp);
4023 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
4024 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
4025 bgp_static_redo_import_check(bgp);
4026 }
078430f6 4027
1ca2fd11 4028 return CMD_SUCCESS;
718e3744 4029}
4030
d62a17ae 4031ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
4032 "bgp network import-check exact",
e9273987 4033 BGP_STR
d62a17ae 4034 "BGP network command\n"
4035 "Check BGP network route exists in IGP\n"
4036 "Match route precisely\n")
8233ef81 4037
1ca2fd11
IR
4038DEFUN (no_bgp_network_import_check,
4039 no_bgp_network_import_check_cmd,
4040 "no bgp network import-check",
4041 NO_STR
e9273987 4042 BGP_STR
1ca2fd11
IR
4043 "BGP network command\n"
4044 "Check BGP network route exists in IGP\n")
718e3744 4045{
1ca2fd11
IR
4046 VTY_DECLVAR_CONTEXT(bgp, bgp);
4047 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
4048 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
4049 bgp_static_redo_import_check(bgp);
4050 }
6b0655a2 4051
1ca2fd11 4052 return CMD_SUCCESS;
ff8a8a7a 4053}
718e3744 4054
1ca2fd11
IR
4055DEFUN (bgp_default_local_preference,
4056 bgp_default_local_preference_cmd,
4057 "bgp default local-preference (0-4294967295)",
e9273987 4058 BGP_STR
1ca2fd11
IR
4059 "Configure BGP defaults\n"
4060 "local preference (higher=more preferred)\n"
4061 "Configure default local preference value\n")
ff8a8a7a 4062{
1ca2fd11 4063 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 4064 int idx_number = 3;
1ca2fd11 4065 uint32_t local_pref;
718e3744 4066
1ca2fd11 4067 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 4068
1ca2fd11
IR
4069 bgp_default_local_preference_set(bgp, local_pref);
4070 bgp_clear_star_soft_in(vty, bgp->name);
718e3744 4071
1ca2fd11 4072 return CMD_SUCCESS;
718e3744 4073}
4074
1ca2fd11
IR
4075DEFUN (no_bgp_default_local_preference,
4076 no_bgp_default_local_preference_cmd,
4077 "no bgp default local-preference [(0-4294967295)]",
4078 NO_STR
e9273987 4079 BGP_STR
1ca2fd11
IR
4080 "Configure BGP defaults\n"
4081 "local preference (higher=more preferred)\n"
4082 "Configure default local preference value\n")
ff8a8a7a 4083{
1ca2fd11
IR
4084 VTY_DECLVAR_CONTEXT(bgp, bgp);
4085 bgp_default_local_preference_unset(bgp);
4086 bgp_clear_star_soft_in(vty, bgp->name);
4087
4088 return CMD_SUCCESS;
ff8a8a7a 4089}
6b0655a2 4090
ff8a8a7a 4091
1ca2fd11
IR
4092DEFUN (bgp_default_subgroup_pkt_queue_max,
4093 bgp_default_subgroup_pkt_queue_max_cmd,
4094 "bgp default subgroup-pkt-queue-max (20-100)",
e9273987 4095 BGP_STR
1ca2fd11
IR
4096 "Configure BGP defaults\n"
4097 "subgroup-pkt-queue-max\n"
4098 "Configure subgroup packet queue max\n")
8bd9d948 4099{
1ca2fd11 4100 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4101 int idx_number = 3;
1ca2fd11 4102 uint32_t max_size;
3f9c7369 4103
1ca2fd11 4104 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3f9c7369 4105
1ca2fd11 4106 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
ff8a8a7a 4107
1ca2fd11 4108 return CMD_SUCCESS;
8bd9d948
DS
4109}
4110
1ca2fd11
IR
4111DEFUN (no_bgp_default_subgroup_pkt_queue_max,
4112 no_bgp_default_subgroup_pkt_queue_max_cmd,
4113 "no bgp default subgroup-pkt-queue-max [(20-100)]",
4114 NO_STR
e9273987 4115 BGP_STR
1ca2fd11
IR
4116 "Configure BGP defaults\n"
4117 "subgroup-pkt-queue-max\n"
4118 "Configure subgroup packet queue max\n")
ff8a8a7a 4119{
1ca2fd11
IR
4120 VTY_DECLVAR_CONTEXT(bgp, bgp);
4121 bgp_default_subgroup_pkt_queue_max_unset(bgp);
4122 return CMD_SUCCESS;
ff8a8a7a 4123}
813d4307 4124
8bd9d948 4125
1ca2fd11
IR
4126DEFUN (bgp_rr_allow_outbound_policy,
4127 bgp_rr_allow_outbound_policy_cmd,
4128 "bgp route-reflector allow-outbound-policy",
e9273987 4129 BGP_STR
1ca2fd11
IR
4130 "Allow modifications made by out route-map\n"
4131 "on ibgp neighbors\n")
ff8a8a7a 4132{
1ca2fd11 4133 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 4134
1ca2fd11
IR
4135 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4136 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4137 update_group_announce_rrclients(bgp);
4138 bgp_clear_star_soft_out(vty, bgp->name);
4139 }
8bd9d948 4140
1ca2fd11
IR
4141 return CMD_SUCCESS;
4142}
ff8a8a7a 4143
1ca2fd11
IR
4144DEFUN (no_bgp_rr_allow_outbound_policy,
4145 no_bgp_rr_allow_outbound_policy_cmd,
4146 "no bgp route-reflector allow-outbound-policy",
4147 NO_STR
e9273987 4148 BGP_STR
1ca2fd11
IR
4149 "Allow modifications made by out route-map\n"
4150 "on ibgp neighbors\n")
8bd9d948 4151{
1ca2fd11 4152 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 4153
1ca2fd11
IR
4154 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4155 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4156 update_group_announce_rrclients(bgp);
4157 bgp_clear_star_soft_out(vty, bgp->name);
d62a17ae 4158 }
8bd9d948 4159
1ca2fd11 4160 return CMD_SUCCESS;
8bd9d948
DS
4161}
4162
1ca2fd11
IR
4163DEFUN (bgp_listen_limit,
4164 bgp_listen_limit_cmd,
4165 "bgp listen limit (1-65535)",
e9273987 4166 BGP_STR
1ca2fd11
IR
4167 "BGP Dynamic Neighbors listen commands\n"
4168 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4169 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 4170{
1ca2fd11 4171 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4172 int idx_number = 3;
1ca2fd11
IR
4173 int listen_limit;
4174
4175 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
f14e6fdb 4176
1ca2fd11 4177 bgp_listen_limit_set(bgp, listen_limit);
f14e6fdb 4178
1ca2fd11 4179 return CMD_SUCCESS;
f14e6fdb
DS
4180}
4181
1ca2fd11
IR
4182DEFUN (no_bgp_listen_limit,
4183 no_bgp_listen_limit_cmd,
4184 "no bgp listen limit [(1-65535)]",
4185 NO_STR
e9273987 4186 BGP_STR
1ca2fd11
IR
4187 "BGP Dynamic Neighbors listen commands\n"
4188 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4189 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 4190{
1ca2fd11
IR
4191 VTY_DECLVAR_CONTEXT(bgp, bgp);
4192 bgp_listen_limit_unset(bgp);
4193 return CMD_SUCCESS;
f14e6fdb
DS
4194}
4195
4196
20eb8864 4197/*
4198 * Check if this listen range is already configured. Check for exact
4199 * match or overlap based on input.
4200 */
d62a17ae 4201static struct peer_group *listen_range_exists(struct bgp *bgp,
4202 struct prefix *range, int exact)
4203{
4204 struct listnode *node, *nnode;
4205 struct listnode *node1, *nnode1;
4206 struct peer_group *group;
4207 struct prefix *lr;
4208 afi_t afi;
4209 int match;
4210
4211 afi = family2afi(range->family);
4212 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4213 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
4214 lr)) {
4215 if (exact)
4216 match = prefix_same(range, lr);
4217 else
4218 match = (prefix_match(range, lr)
4219 || prefix_match(lr, range));
4220 if (match)
4221 return group;
4222 }
4223 }
4224
4225 return NULL;
20eb8864 4226}
4227
f14e6fdb
DS
4228DEFUN (bgp_listen_range,
4229 bgp_listen_range_cmd,
d7b9898c 4230 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
e9273987 4231 BGP_STR
d7fa34c1
QY
4232 "Configure BGP dynamic neighbors listen range\n"
4233 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
4234 NEIGHBOR_ADDR_STR
4235 "Member of the peer-group\n"
4236 "Peer-group name\n")
f14e6fdb 4237{
d62a17ae 4238 VTY_DECLVAR_CONTEXT(bgp, bgp);
4239 struct prefix range;
4240 struct peer_group *group, *existing_group;
4241 afi_t afi;
4242 int ret;
4243 int idx = 0;
4244
4245 argv_find(argv, argc, "A.B.C.D/M", &idx);
4246 argv_find(argv, argc, "X:X::X:X/M", &idx);
4247 char *prefix = argv[idx]->arg;
d7b9898c 4248 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 4249 char *peergroup = argv[idx]->arg;
4250
4251 /* Convert IP prefix string to struct prefix. */
4252 ret = str2prefix(prefix, &range);
4253 if (!ret) {
4254 vty_out(vty, "%% Malformed listen range\n");
4255 return CMD_WARNING_CONFIG_FAILED;
4256 }
4257
4258 afi = family2afi(range.family);
4259
4260 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4261 vty_out(vty,
4262 "%% Malformed listen range (link-local address)\n");
4263 return CMD_WARNING_CONFIG_FAILED;
4264 }
4265
4266 apply_mask(&range);
4267
4268 /* Check if same listen range is already configured. */
4269 existing_group = listen_range_exists(bgp, &range, 1);
4270 if (existing_group) {
4271 if (strcmp(existing_group->name, peergroup) == 0)
4272 return CMD_SUCCESS;
4273 else {
4274 vty_out(vty,
4275 "%% Same listen range is attached to peer-group %s\n",
4276 existing_group->name);
4277 return CMD_WARNING_CONFIG_FAILED;
4278 }
4279 }
4280
4281 /* Check if an overlapping listen range exists. */
4282 if (listen_range_exists(bgp, &range, 0)) {
4283 vty_out(vty,
4284 "%% Listen range overlaps with existing listen range\n");
4285 return CMD_WARNING_CONFIG_FAILED;
4286 }
4287
4288 group = peer_group_lookup(bgp, peergroup);
4289 if (!group) {
4290 vty_out(vty, "%% Configure the peer-group first\n");
4291 return CMD_WARNING_CONFIG_FAILED;
4292 }
4293
4294 ret = peer_group_listen_range_add(group, &range);
4295 return bgp_vty_return(vty, ret);
f14e6fdb
DS
4296}
4297
4298DEFUN (no_bgp_listen_range,
4299 no_bgp_listen_range_cmd,
d7b9898c 4300 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
d7fa34c1 4301 NO_STR
e9273987 4302 BGP_STR
d7fa34c1
QY
4303 "Unconfigure BGP dynamic neighbors listen range\n"
4304 "Unconfigure BGP dynamic neighbors listen range\n"
4305 NEIGHBOR_ADDR_STR
4306 "Member of the peer-group\n"
4307 "Peer-group name\n")
f14e6fdb 4308{
d62a17ae 4309 VTY_DECLVAR_CONTEXT(bgp, bgp);
4310 struct prefix range;
4311 struct peer_group *group;
4312 afi_t afi;
4313 int ret;
4314 int idx = 0;
4315
4316 argv_find(argv, argc, "A.B.C.D/M", &idx);
4317 argv_find(argv, argc, "X:X::X:X/M", &idx);
4318 char *prefix = argv[idx]->arg;
21d88a71 4319 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 4320 char *peergroup = argv[idx]->arg;
4321
4322 /* Convert IP prefix string to struct prefix. */
4323 ret = str2prefix(prefix, &range);
4324 if (!ret) {
4325 vty_out(vty, "%% Malformed listen range\n");
4326 return CMD_WARNING_CONFIG_FAILED;
4327 }
4328
4329 afi = family2afi(range.family);
4330
4331 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4332 vty_out(vty,
4333 "%% Malformed listen range (link-local address)\n");
4334 return CMD_WARNING_CONFIG_FAILED;
4335 }
4336
4337 apply_mask(&range);
4338
4339 group = peer_group_lookup(bgp, peergroup);
4340 if (!group) {
4341 vty_out(vty, "%% Peer-group does not exist\n");
4342 return CMD_WARNING_CONFIG_FAILED;
4343 }
4344
4345 ret = peer_group_listen_range_del(group, &range);
4346 return bgp_vty_return(vty, ret);
4347}
4348
2b791107 4349void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 4350{
4351 struct peer_group *group;
4352 struct listnode *node, *nnode, *rnode, *nrnode;
4353 struct prefix *range;
4354 afi_t afi;
d62a17ae 4355
4356 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4357 vty_out(vty, " bgp listen limit %d\n",
4358 bgp->dynamic_neighbors_limit);
4359
4360 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4361 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4362 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4363 nrnode, range)) {
d62a17ae 4364 vty_out(vty,
2dbe669b
DA
4365 " bgp listen range %pFX peer-group %s\n",
4366 range, group->name);
d62a17ae 4367 }
4368 }
4369 }
f14e6fdb
DS
4370}
4371
4372
1ca2fd11
IR
4373DEFUN (bgp_disable_connected_route_check,
4374 bgp_disable_connected_route_check_cmd,
4375 "bgp disable-ebgp-connected-route-check",
e9273987 4376 BGP_STR
1ca2fd11 4377 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4378{
1ca2fd11
IR
4379 VTY_DECLVAR_CONTEXT(bgp, bgp);
4380 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4381 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 4382
1ca2fd11 4383 return CMD_SUCCESS;
907f92c8
DS
4384}
4385
1ca2fd11
IR
4386DEFUN (no_bgp_disable_connected_route_check,
4387 no_bgp_disable_connected_route_check_cmd,
4388 "no bgp disable-ebgp-connected-route-check",
4389 NO_STR
e9273987 4390 BGP_STR
1ca2fd11 4391 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4392{
1ca2fd11
IR
4393 VTY_DECLVAR_CONTEXT(bgp, bgp);
4394 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4395 bgp_clear_star_soft_in(vty, bgp->name);
d62a17ae 4396
1ca2fd11 4397 return CMD_SUCCESS;
d62a17ae 4398}
4399
4400
28c6e247
IR
4401static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
4402 const char *as_str)
4403{
4404 VTY_DECLVAR_CONTEXT(bgp, bgp);
4405 int ret;
4406 as_t as;
4407 int as_type = AS_SPECIFIED;
4408 union sockunion su;
4409
4410 if (as_str[0] == 'i') {
4411 as = 0;
4412 as_type = AS_INTERNAL;
4413 } else if (as_str[0] == 'e') {
4414 as = 0;
4415 as_type = AS_EXTERNAL;
4416 } else {
4417 /* Get AS number. */
4418 as = strtoul(as_str, NULL, 10);
4419 }
4420
4421 /* If peer is peer group or interface peer, call proper function. */
4422 ret = str2sockunion(peer_str, &su);
4423 if (ret < 0) {
4424 struct peer *peer;
4425
4426 /* Check if existing interface peer */
4427 peer = peer_lookup_by_conf_if(bgp, peer_str);
4428
4429 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type);
4430
4431 /* if not interface peer, check peer-group settings */
4432 if (ret < 0 && !peer) {
4433 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
4434 if (ret < 0) {
4435 vty_out(vty,
4436 "%% Create the peer-group or interface first\n");
4437 return CMD_WARNING_CONFIG_FAILED;
4438 }
4439 return CMD_SUCCESS;
4440 }
4441 } else {
4442 if (peer_address_self_check(bgp, &su)) {
4443 vty_out(vty,
4444 "%% Can not configure the local system as neighbor\n");
4445 return CMD_WARNING_CONFIG_FAILED;
4446 }
4447 ret = peer_remote_as(bgp, &su, NULL, &as, as_type);
4448 }
4449
28c6e247
IR
4450 return bgp_vty_return(vty, ret);
4451}
4452
1ca2fd11
IR
4453DEFUN (bgp_default_shutdown,
4454 bgp_default_shutdown_cmd,
4455 "[no] bgp default shutdown",
4456 NO_STR
4457 BGP_STR
4458 "Configure BGP defaults\n"
4459 "Apply administrative shutdown to newly configured peers\n")
ff8a8a7a 4460{
1ca2fd11
IR
4461 VTY_DECLVAR_CONTEXT(bgp, bgp);
4462 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
4463 return CMD_SUCCESS;
f26845f9
QY
4464}
4465
736b68f3
DS
4466DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4467 BGP_STR
9ddf4b81 4468 "Administrative shutdown of the BGP instance\n"
736b68f3
DS
4469 "Add a shutdown message (RFC 8203)\n"
4470 "Shutdown message\n")
9cf59432 4471{
736b68f3 4472 char *msgstr = NULL;
8389c83a 4473
9cf59432
DS
4474 VTY_DECLVAR_CONTEXT(bgp, bgp);
4475
8389c83a 4476 if (argc > 3)
f80e35b6 4477 msgstr = argv_concat(argv, argc, 3);
8389c83a 4478
b776f48c
DA
4479 if (msgstr && strlen(msgstr) > BGP_ADMIN_SHUTDOWN_MSG_LEN) {
4480 vty_out(vty, "%% Shutdown message size exceeded %d\n",
4481 BGP_ADMIN_SHUTDOWN_MSG_LEN);
4482 return CMD_WARNING_CONFIG_FAILED;
4483 }
4484
8389c83a
DS
4485 bgp_shutdown_enable(bgp, msgstr);
4486 XFREE(MTYPE_TMP, msgstr);
9cf59432
DS
4487
4488 return CMD_SUCCESS;
4489}
4490
736b68f3 4491DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
9ddf4b81 4492 BGP_STR "Administrative shutdown of the BGP instance\n")
1e12ebbc
DS
4493{
4494 VTY_DECLVAR_CONTEXT(bgp, bgp);
4495
4496 bgp_shutdown_enable(bgp, NULL);
4497
4498 return CMD_SUCCESS;
4499}
8389c83a 4500
736b68f3 4501DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
9ddf4b81 4502 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
9cf59432
DS
4503{
4504 VTY_DECLVAR_CONTEXT(bgp, bgp);
4505
4506 bgp_shutdown_disable(bgp);
4507
4508 return CMD_SUCCESS;
4509}
4510
9ddf4b81 4511ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
1b6e7a88 4512 "no bgp shutdown message MSG...", NO_STR BGP_STR
9ddf4b81 4513 "Administrative shutdown of the BGP instance\n"
1b6e7a88 4514 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
1b6e7a88 4515
28c6e247
IR
4516DEFUN (neighbor_remote_as,
4517 neighbor_remote_as_cmd,
4518 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4519 NEIGHBOR_STR
4520 NEIGHBOR_ADDR_STR2
4521 "Specify a BGP neighbor\n"
4522 AS_STR
4523 "Internal BGP peer\n"
4524 "External BGP peer\n")
718e3744 4525{
d62a17ae 4526 int idx_peer = 1;
4527 int idx_remote_as = 3;
28c6e247
IR
4528 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
4529 argv[idx_remote_as]->arg);
d62a17ae 4530}
8666265e
DS
4531
4532DEFPY (bgp_allow_martian,
4533 bgp_allow_martian_cmd,
4534 "[no]$no bgp allow-martian-nexthop",
4535 NO_STR
4536 BGP_STR
4537 "Allow Martian nexthops to be received in the NLRI from a peer\n")
4538{
4539 VTY_DECLVAR_CONTEXT(bgp, bgp);
4540
4541 if (no)
4542 bgp->allow_martian = false;
4543 else
4544 bgp->allow_martian = true;
4545
4546 return CMD_SUCCESS;
4547}
4548
f852eb98
PG
4549/* Enable fast convergence of bgp sessions. If this is enabled, bgp
4550 * sessions do not wait for hold timer expiry to bring down the sessions
4551 * when nexthop becomes unreachable
4552 */
4553DEFUN(bgp_fast_convergence, bgp_fast_convergence_cmd, "bgp fast-convergence",
4554 BGP_STR "Fast convergence for bgp sessions\n")
4555{
4556 VTY_DECLVAR_CONTEXT(bgp, bgp);
4557 bgp->fast_convergence = true;
4558
4559 return CMD_SUCCESS;
4560}
4561
4562DEFUN(no_bgp_fast_convergence, no_bgp_fast_convergence_cmd,
4563 "no bgp fast-convergence",
4564 NO_STR BGP_STR "Fast convergence for bgp sessions\n")
4565{
4566 VTY_DECLVAR_CONTEXT(bgp, bgp);
4567 bgp->fast_convergence = false;
4568
4569 return CMD_SUCCESS;
4570}
d62a17ae 4571
28c6e247
IR
4572static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
4573 int v6only,
4574 const char *peer_group_name,
4575 const char *as_str)
d62a17ae 4576{
28c6e247
IR
4577 VTY_DECLVAR_CONTEXT(bgp, bgp);
4578 as_t as = 0;
4579 int as_type = AS_UNSPECIFIED;
d62a17ae 4580 struct peer *peer;
4581 struct peer_group *group;
4582 int ret = 0;
d62a17ae 4583
4584 group = peer_group_lookup(bgp, conf_if);
4585
4586 if (group) {
28c6e247
IR
4587 vty_out(vty, "%% Name conflict with peer-group \n");
4588 return CMD_WARNING_CONFIG_FAILED;
4589 }
4590
4591 if (as_str) {
4592 if (as_str[0] == 'i') {
4593 as_type = AS_INTERNAL;
4594 } else if (as_str[0] == 'e') {
4595 as_type = AS_EXTERNAL;
4596 } else {
4597 /* Get AS number. */
4598 as = strtoul(as_str, NULL, 10);
4599 as_type = AS_SPECIFIED;
4600 }
d62a17ae 4601 }
4602
4603 peer = peer_lookup_by_conf_if(bgp, conf_if);
4604 if (peer) {
28c6e247 4605 if (as_str)
e84c59af 4606 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type);
d62a17ae 4607 } else {
e84c59af
DA
4608 peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
4609 NULL);
d62a17ae 4610
4611 if (!peer) {
28c6e247
IR
4612 vty_out(vty, "%% BGP failed to create peer\n");
4613 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4614 }
4615
4616 if (v6only)
527de3dc 4617 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4618
4619 /* Request zebra to initiate IPv6 RAs on this interface. We do
4620 * this
4621 * any unnumbered peer in order to not worry about run-time
4622 * transitions
4623 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4624 * address
4625 * gets deleted later etc.)
4626 */
4627 if (peer->ifp)
4628 bgp_zebra_initiate_radv(bgp, peer);
4629 }
4630
4631 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4632 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4633 if (v6only)
527de3dc 4634 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4635 else
527de3dc 4636 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4637
4638 /* v6only flag changed. Reset bgp seesion */
4639 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4640 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4641 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4642 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4643 } else
4644 bgp_session_reset(peer);
4645 }
4646
9fb964de
PM
4647 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4648 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4649 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
dc2f50f3 4650 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
9fb964de 4651 }
d62a17ae 4652
4653 if (peer_group_name) {
4654 group = peer_group_lookup(bgp, peer_group_name);
4655 if (!group) {
28c6e247
IR
4656 vty_out(vty, "%% Configure the peer-group first\n");
4657 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4658 }
4659
8395c1f8 4660 ret = peer_group_bind(bgp, NULL, peer, group, &as);
d62a17ae 4661 }
4662
28c6e247 4663 return bgp_vty_return(vty, ret);
a80beece
DS
4664}
4665
28c6e247
IR
4666DEFUN (neighbor_interface_config,
4667 neighbor_interface_config_cmd,
4668 "neighbor WORD interface [peer-group PGNAME]",
4669 NEIGHBOR_STR
4670 "Interface name or neighbor tag\n"
4671 "Enable BGP on interface\n"
4672 "Member of the peer-group\n"
4673 "Peer-group name\n")
4c48cf63 4674{
d62a17ae 4675 int idx_word = 1;
4676 int idx_peer_group_word = 4;
f4b8ec07 4677
d62a17ae 4678 if (argc > idx_peer_group_word)
28c6e247
IR
4679 return peer_conf_interface_get(
4680 vty, argv[idx_word]->arg, 0,
4681 argv[idx_peer_group_word]->arg, NULL);
4682 else
4683 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0,
4684 NULL, NULL);
4c48cf63
DW
4685}
4686
28c6e247
IR
4687DEFUN (neighbor_interface_config_v6only,
4688 neighbor_interface_config_v6only_cmd,
4689 "neighbor WORD interface v6only [peer-group PGNAME]",
4690 NEIGHBOR_STR
4691 "Interface name or neighbor tag\n"
4692 "Enable BGP on interface\n"
4693 "Enable BGP with v6 link-local only\n"
4694 "Member of the peer-group\n"
4695 "Peer-group name\n")
4c48cf63 4696{
d62a17ae 4697 int idx_word = 1;
4698 int idx_peer_group_word = 5;
31500417 4699
d62a17ae 4700 if (argc > idx_peer_group_word)
28c6e247
IR
4701 return peer_conf_interface_get(
4702 vty, argv[idx_word]->arg, 1,
4703 argv[idx_peer_group_word]->arg, NULL);
31500417 4704
28c6e247 4705 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL, NULL);
4c48cf63
DW
4706}
4707
a80beece 4708
28c6e247
IR
4709DEFUN (neighbor_interface_config_remote_as,
4710 neighbor_interface_config_remote_as_cmd,
4711 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4712 NEIGHBOR_STR
4713 "Interface name or neighbor tag\n"
4714 "Enable BGP on interface\n"
4715 "Specify a BGP neighbor\n"
4716 AS_STR
4717 "Internal BGP peer\n"
4718 "External BGP peer\n")
b3a39dc5 4719{
d62a17ae 4720 int idx_word = 1;
4721 int idx_remote_as = 4;
28c6e247
IR
4722 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0, NULL,
4723 argv[idx_remote_as]->arg);
b3a39dc5
DD
4724}
4725
28c6e247
IR
4726DEFUN (neighbor_interface_v6only_config_remote_as,
4727 neighbor_interface_v6only_config_remote_as_cmd,
4728 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4729 NEIGHBOR_STR
4730 "Interface name or neighbor tag\n"
4731 "Enable BGP with v6 link-local only\n"
4732 "Enable BGP on interface\n"
4733 "Specify a BGP neighbor\n"
4734 AS_STR
4735 "Internal BGP peer\n"
4736 "External BGP peer\n")
b3a39dc5 4737{
d62a17ae 4738 int idx_word = 1;
4739 int idx_remote_as = 5;
28c6e247
IR
4740 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL,
4741 argv[idx_remote_as]->arg);
b3a39dc5
DD
4742}
4743
28c6e247
IR
4744DEFUN (neighbor_peer_group,
4745 neighbor_peer_group_cmd,
4746 "neighbor WORD peer-group",
4747 NEIGHBOR_STR
4748 "Interface name or neighbor tag\n"
4749 "Configure peer-group\n")
718e3744 4750{
28c6e247 4751 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4752 int idx_word = 1;
28c6e247
IR
4753 struct peer *peer;
4754 struct peer_group *group;
718e3744 4755
28c6e247
IR
4756 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4757 if (peer) {
4758 vty_out(vty, "%% Name conflict with interface: \n");
4759 return CMD_WARNING_CONFIG_FAILED;
4760 }
718e3744 4761
28c6e247
IR
4762 group = peer_group_get(bgp, argv[idx_word]->arg);
4763 if (!group) {
4764 vty_out(vty, "%% BGP failed to find or create peer-group\n");
4765 return CMD_WARNING_CONFIG_FAILED;
4766 }
718e3744 4767
28c6e247 4768 return CMD_SUCCESS;
718e3744 4769}
4770
1d80f243
IR
4771DEFUN (no_neighbor,
4772 no_neighbor_cmd,
4773 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4774 NO_STR
4775 NEIGHBOR_STR
4776 NEIGHBOR_ADDR_STR2
4777 "Specify a BGP neighbor\n"
4778 AS_STR
4779 "Internal BGP peer\n"
4780 "External BGP peer\n")
718e3744 4781{
28c6e247 4782 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4783 int idx_peer = 2;
28c6e247 4784 int ret;
d62a17ae 4785 union sockunion su;
28c6e247
IR
4786 struct peer_group *group;
4787 struct peer *peer;
4788 struct peer *other;
d62a17ae 4789
28c6e247
IR
4790 ret = str2sockunion(argv[idx_peer]->arg, &su);
4791 if (ret < 0) {
4792 /* look up for neighbor by interface name config. */
4793 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4794 if (peer) {
4795 /* Request zebra to terminate IPv6 RAs on this
4796 * interface. */
4797 if (peer->ifp)
4798 bgp_zebra_terminate_radv(peer->bgp, peer);
4799 peer_notify_unconfig(peer);
4800 peer_delete(peer);
4801 return CMD_SUCCESS;
d62a17ae 4802 }
28c6e247
IR
4803
4804 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4805 if (group) {
4806 peer_group_notify_unconfig(group);
4807 peer_group_delete(group);
4e2786df 4808 } else {
28c6e247 4809 vty_out(vty, "%% Create the peer-group first\n");
d62a17ae 4810 return CMD_WARNING_CONFIG_FAILED;
4811 }
28c6e247
IR
4812 } else {
4813 peer = peer_lookup(bgp, &su);
4814 if (peer) {
4815 if (peer_dynamic_neighbor(peer)) {
4816 vty_out(vty,
4817 "%% Operation not allowed on a dynamic neighbor\n");
4818 return CMD_WARNING_CONFIG_FAILED;
4819 }
d62a17ae 4820
28c6e247 4821 other = peer->doppelganger;
f4b8ec07 4822
28c6e247
IR
4823 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4824 bgp_zebra_terminate_radv(peer->bgp, peer);
f4b8ec07 4825
28c6e247
IR
4826 peer_notify_unconfig(peer);
4827 peer_delete(peer);
4828 if (other && other->status != Deleted) {
4829 peer_notify_unconfig(other);
4830 peer_delete(other);
4831 }
4832 }
4833 }
4834
4835 return CMD_SUCCESS;
a80beece
DS
4836}
4837
28c6e247
IR
4838DEFUN (no_neighbor_interface_config,
4839 no_neighbor_interface_config_cmd,
4840 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4841 NO_STR
4842 NEIGHBOR_STR
4843 "Interface name\n"
4844 "Configure BGP on interface\n"
4845 "Enable BGP with v6 link-local only\n"
4846 "Member of the peer-group\n"
4847 "Peer-group name\n"
4848 "Specify a BGP neighbor\n"
4849 AS_STR
4850 "Internal BGP peer\n"
4851 "External BGP peer\n")
718e3744 4852{
28c6e247 4853 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4854 int idx_word = 2;
28c6e247 4855 struct peer *peer;
718e3744 4856
28c6e247
IR
4857 /* look up for neighbor by interface name config. */
4858 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4859 if (peer) {
4860 /* Request zebra to terminate IPv6 RAs on this interface. */
4861 if (peer->ifp)
4862 bgp_zebra_terminate_radv(peer->bgp, peer);
4863 peer_notify_unconfig(peer);
4864 peer_delete(peer);
4865 } else {
4866 vty_out(vty, "%% Create the bgp interface first\n");
4867 return CMD_WARNING_CONFIG_FAILED;
4868 }
4869 return CMD_SUCCESS;
718e3744 4870}
4871
28c6e247
IR
4872DEFUN (no_neighbor_peer_group,
4873 no_neighbor_peer_group_cmd,
4874 "no neighbor WORD peer-group",
4875 NO_STR
4876 NEIGHBOR_STR
4877 "Neighbor tag\n"
4878 "Configure peer-group\n")
718e3744 4879{
28c6e247
IR
4880 VTY_DECLVAR_CONTEXT(bgp, bgp);
4881 int idx_word = 2;
4882 struct peer_group *group;
f4b8ec07 4883
28c6e247
IR
4884 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4885 if (group) {
4886 peer_group_notify_unconfig(group);
4887 peer_group_delete(group);
f4b8ec07 4888 } else {
28c6e247 4889 vty_out(vty, "%% Create the peer-group first\n");
d62a17ae 4890 return CMD_WARNING_CONFIG_FAILED;
4891 }
28c6e247
IR
4892 return CMD_SUCCESS;
4893}
f4b8ec07 4894
28c6e247
IR
4895DEFUN (no_neighbor_interface_peer_group_remote_as,
4896 no_neighbor_interface_peer_group_remote_as_cmd,
4897 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4898 NO_STR
4899 NEIGHBOR_STR
4900 "Interface name or neighbor tag\n"
4901 "Specify a BGP neighbor\n"
4902 AS_STR
4903 "Internal BGP peer\n"
4904 "External BGP peer\n")
4905{
4906 VTY_DECLVAR_CONTEXT(bgp, bgp);
4907 int idx_word = 2;
4908 struct peer_group *group;
4909 struct peer *peer;
f4b8ec07 4910
28c6e247
IR
4911 /* look up for neighbor by interface name config. */
4912 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4913 if (peer) {
4914 peer_as_change(peer, 0, AS_UNSPECIFIED);
4915 return CMD_SUCCESS;
4916 }
f4b8ec07 4917
28c6e247
IR
4918 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4919 if (group)
4920 peer_group_remote_as_delete(group);
4921 else {
4922 vty_out(vty, "%% Create the peer-group or interface first\n");
4923 return CMD_WARNING_CONFIG_FAILED;
4924 }
4925 return CMD_SUCCESS;
718e3744 4926}
6b0655a2 4927
28c6e247
IR
4928DEFUN (neighbor_local_as,
4929 neighbor_local_as_cmd,
4930 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4931 NEIGHBOR_STR
4932 NEIGHBOR_ADDR_STR2
4933 "Specify a local-as number\n"
4934 "AS number used as local AS\n")
718e3744 4935{
d62a17ae 4936 int idx_peer = 1;
4937 int idx_number = 3;
28c6e247
IR
4938 struct peer *peer;
4939 int ret;
4940 as_t as;
718e3744 4941
28c6e247
IR
4942 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4943 if (!peer)
d62a17ae 4944 return CMD_WARNING_CONFIG_FAILED;
718e3744 4945
28c6e247
IR
4946 as = strtoul(argv[idx_number]->arg, NULL, 10);
4947 ret = peer_local_as_set(peer, as, 0, 0);
4948 return bgp_vty_return(vty, ret);
718e3744 4949}
4950
28c6e247
IR
4951DEFUN (neighbor_local_as_no_prepend,
4952 neighbor_local_as_no_prepend_cmd,
4953 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
4954 NEIGHBOR_STR
4955 NEIGHBOR_ADDR_STR2
4956 "Specify a local-as number\n"
4957 "AS number used as local AS\n"
4958 "Do not prepend local-as to updates from ebgp peers\n")
718e3744 4959{
d62a17ae 4960 int idx_peer = 1;
4961 int idx_number = 3;
28c6e247
IR
4962 struct peer *peer;
4963 int ret;
4964 as_t as;
718e3744 4965
28c6e247
IR
4966 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4967 if (!peer)
d62a17ae 4968 return CMD_WARNING_CONFIG_FAILED;
718e3744 4969
28c6e247
IR
4970 as = strtoul(argv[idx_number]->arg, NULL, 10);
4971 ret = peer_local_as_set(peer, as, 1, 0);
4972 return bgp_vty_return(vty, ret);
718e3744 4973}
4974
28c6e247
IR
4975DEFUN (neighbor_local_as_no_prepend_replace_as,
4976 neighbor_local_as_no_prepend_replace_as_cmd,
4977 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4978 NEIGHBOR_STR
4979 NEIGHBOR_ADDR_STR2
4980 "Specify a local-as number\n"
4981 "AS number used as local AS\n"
4982 "Do not prepend local-as to updates from ebgp peers\n"
4983 "Do not prepend local-as to updates from ibgp peers\n")
9d3f9705 4984{
d62a17ae 4985 int idx_peer = 1;
4986 int idx_number = 3;
28c6e247
IR
4987 struct peer *peer;
4988 int ret;
4989 as_t as;
9d3f9705 4990
28c6e247
IR
4991 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4992 if (!peer)
d62a17ae 4993 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 4994
28c6e247
IR
4995 as = strtoul(argv[idx_number]->arg, NULL, 10);
4996 ret = peer_local_as_set(peer, as, 1, 1);
4997 return bgp_vty_return(vty, ret);
9d3f9705
AC
4998}
4999
28c6e247
IR
5000DEFUN (no_neighbor_local_as,
5001 no_neighbor_local_as_cmd,
5002 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
5003 NO_STR
5004 NEIGHBOR_STR
5005 NEIGHBOR_ADDR_STR2
5006 "Specify a local-as number\n"
5007 "AS number used as local AS\n"
5008 "Do not prepend local-as to updates from ebgp peers\n"
5009 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 5010{
d62a17ae 5011 int idx_peer = 2;
28c6e247
IR
5012 struct peer *peer;
5013 int ret;
718e3744 5014
28c6e247
IR
5015 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5016 if (!peer)
d62a17ae 5017 return CMD_WARNING_CONFIG_FAILED;
718e3744 5018
28c6e247
IR
5019 ret = peer_local_as_unset(peer);
5020 return bgp_vty_return(vty, ret);
718e3744 5021}
5022
718e3744 5023
3f9c7369
DS
5024DEFUN (neighbor_solo,
5025 neighbor_solo_cmd,
9ccf14f7 5026 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
5027 NEIGHBOR_STR
5028 NEIGHBOR_ADDR_STR2
5029 "Solo peer - part of its own update group\n")
5030{
d62a17ae 5031 int idx_peer = 1;
5032 struct peer *peer;
5033 int ret;
3f9c7369 5034
d62a17ae 5035 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5036 if (!peer)
5037 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 5038
d62a17ae 5039 ret = update_group_adjust_soloness(peer, 1);
5040 return bgp_vty_return(vty, ret);
3f9c7369
DS
5041}
5042
5043DEFUN (no_neighbor_solo,
5044 no_neighbor_solo_cmd,
9ccf14f7 5045 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
5046 NO_STR
5047 NEIGHBOR_STR
5048 NEIGHBOR_ADDR_STR2
5049 "Solo peer - part of its own update group\n")
5050{
d62a17ae 5051 int idx_peer = 2;
5052 struct peer *peer;
5053 int ret;
3f9c7369 5054
d62a17ae 5055 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5056 if (!peer)
5057 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 5058
d62a17ae 5059 ret = update_group_adjust_soloness(peer, 0);
5060 return bgp_vty_return(vty, ret);
3f9c7369
DS
5061}
5062
28c6e247
IR
5063DEFUN (neighbor_password,
5064 neighbor_password_cmd,
5065 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
5066 NEIGHBOR_STR
5067 NEIGHBOR_ADDR_STR2
5068 "Set a password\n"
5069 "The password\n")
0df7c91f 5070{
d62a17ae 5071 int idx_peer = 1;
5072 int idx_line = 3;
28c6e247
IR
5073 struct peer *peer;
5074 int ret;
0df7c91f 5075
28c6e247
IR
5076 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5077 if (!peer)
d62a17ae 5078 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 5079
28c6e247
IR
5080 ret = peer_password_set(peer, argv[idx_line]->arg);
5081 return bgp_vty_return(vty, ret);
0df7c91f
PJ
5082}
5083
28c6e247
IR
5084DEFUN (no_neighbor_password,
5085 no_neighbor_password_cmd,
5086 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
5087 NO_STR
5088 NEIGHBOR_STR
5089 NEIGHBOR_ADDR_STR2
5090 "Set a password\n"
5091 "The password\n")
0df7c91f 5092{
d62a17ae 5093 int idx_peer = 2;
28c6e247
IR
5094 struct peer *peer;
5095 int ret;
0df7c91f 5096
28c6e247
IR
5097 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5098 if (!peer)
d62a17ae 5099 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 5100
28c6e247
IR
5101 ret = peer_password_unset(peer);
5102 return bgp_vty_return(vty, ret);
0df7c91f 5103}
6b0655a2 5104
28c6e247
IR
5105DEFUN (neighbor_activate,
5106 neighbor_activate_cmd,
5107 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5108 NEIGHBOR_STR
5109 NEIGHBOR_ADDR_STR2
5110 "Enable the Address Family for this Neighbor\n")
718e3744 5111{
d62a17ae 5112 int idx_peer = 1;
28c6e247
IR
5113 int ret;
5114 struct peer *peer;
56ceae84 5115
28c6e247
IR
5116 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5117 if (!peer)
d62a17ae 5118 return CMD_WARNING_CONFIG_FAILED;
718e3744 5119
28c6e247
IR
5120 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5121 return bgp_vty_return(vty, ret);
718e3744 5122}
5123
d62a17ae 5124ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
5125 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5126 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5127 "Enable the Address Family for this Neighbor\n")
596c17ba 5128
28c6e247
IR
5129DEFUN (no_neighbor_activate,
5130 no_neighbor_activate_cmd,
5131 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5132 NO_STR
5133 NEIGHBOR_STR
5134 NEIGHBOR_ADDR_STR2
5135 "Enable the Address Family for this Neighbor\n")
718e3744 5136{
d62a17ae 5137 int idx_peer = 2;
28c6e247
IR
5138 int ret;
5139 struct peer *peer;
f4b8ec07 5140
28c6e247
IR
5141 /* Lookup peer. */
5142 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5143 if (!peer)
d62a17ae 5144 return CMD_WARNING_CONFIG_FAILED;
718e3744 5145
28c6e247
IR
5146 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5147 return bgp_vty_return(vty, ret);
718e3744 5148}
6b0655a2 5149
d62a17ae 5150ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
5151 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5152 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5153 "Enable the Address Family for this Neighbor\n")
596c17ba 5154
28c6e247
IR
5155DEFUN (neighbor_set_peer_group,
5156 neighbor_set_peer_group_cmd,
5157 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5158 NEIGHBOR_STR
5159 NEIGHBOR_ADDR_STR2
5160 "Member of the peer-group\n"
5161 "Peer-group name\n")
718e3744 5162{
28c6e247 5163 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 5164 int idx_peer = 1;
5165 int idx_word = 3;
28c6e247
IR
5166 int ret;
5167 as_t as;
5168 union sockunion su;
5169 struct peer *peer;
5170 struct peer_group *group;
5171
5172 ret = str2sockunion(argv[idx_peer]->arg, &su);
5173 if (ret < 0) {
5174 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
5175 if (!peer) {
5176 vty_out(vty, "%% Malformed address or name: %s\n",
5177 argv[idx_peer]->arg);
5178 return CMD_WARNING_CONFIG_FAILED;
5179 }
5180 } else {
5181 if (peer_address_self_check(bgp, &su)) {
5182 vty_out(vty,
5183 "%% Can not configure the local system as neighbor\n");
5184 return CMD_WARNING_CONFIG_FAILED;
5185 }
2a059a54 5186
28c6e247
IR
5187 /* Disallow for dynamic neighbor. */
5188 peer = peer_lookup(bgp, &su);
5189 if (peer && peer_dynamic_neighbor(peer)) {
5190 vty_out(vty,
5191 "%% Operation not allowed on a dynamic neighbor\n");
5192 return CMD_WARNING_CONFIG_FAILED;
5193 }
5194 }
5195
5196 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5197 if (!group) {
5198 vty_out(vty, "%% Configure the peer-group first\n");
d62a17ae 5199 return CMD_WARNING_CONFIG_FAILED;
28c6e247 5200 }
d62a17ae 5201
28c6e247 5202 ret = peer_group_bind(bgp, &su, peer, group, &as);
2a059a54 5203
28c6e247 5204 return bgp_vty_return(vty, ret);
d62a17ae 5205}
5206
5207ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
d7b9898c 5208 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 5209 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5210 "Member of the peer-group\n"
5211 "Peer-group name\n")
596c17ba 5212
28c6e247
IR
5213DEFUN (no_neighbor_set_peer_group,
5214 no_neighbor_set_peer_group_cmd,
5215 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5216 NO_STR
5217 NEIGHBOR_STR
5218 NEIGHBOR_ADDR_STR2
5219 "Member of the peer-group\n"
5220 "Peer-group name\n")
718e3744 5221{
28c6e247 5222 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 5223 int idx_peer = 2;
28c6e247
IR
5224 int idx_word = 4;
5225 int ret;
5226 struct peer *peer;
5227 struct peer_group *group;
d62a17ae 5228
28c6e247
IR
5229 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
5230 if (!peer)
d62a17ae 5231 return CMD_WARNING_CONFIG_FAILED;
b3a3290e 5232
28c6e247
IR
5233 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5234 if (!group) {
5235 vty_out(vty, "%% Configure the peer-group first\n");
5236 return CMD_WARNING_CONFIG_FAILED;
5237 }
718e3744 5238
28c6e247
IR
5239 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
5240 bgp_zebra_terminate_radv(peer->bgp, peer);
5241
5242 peer_notify_unconfig(peer);
5243 ret = peer_delete(peer);
5244
5245 return bgp_vty_return(vty, ret);
718e3744 5246}
6b0655a2 5247
d62a17ae 5248ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
71cc0c88 5249 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 5250 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5251 "Member of the peer-group\n"
5252 "Peer-group name\n")
596c17ba 5253
d62a17ae 5254static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
83194f39 5255 uint64_t flag, int set)
718e3744 5256{
d62a17ae 5257 int ret;
5258 struct peer *peer;
718e3744 5259
d62a17ae 5260 peer = peer_and_group_lookup_vty(vty, ip_str);
5261 if (!peer)
5262 return CMD_WARNING_CONFIG_FAILED;
718e3744 5263
7ebe625c
QY
5264 /*
5265 * If 'neighbor <interface>', then this is for directly connected peers,
5266 * we should not accept disable-connected-check.
5267 */
5268 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5269 vty_out(vty,
3efd0893 5270 "%s is directly connected peer, cannot accept disable-connected-check\n",
7ebe625c
QY
5271 ip_str);
5272 return CMD_WARNING_CONFIG_FAILED;
5273 }
5274
5597214c 5275 if (!set && flag == PEER_FLAG_SHUTDOWN) {
d62a17ae 5276 peer_tx_shutdown_message_unset(peer);
5597214c
DA
5277 UNSET_FLAG(peer->sflags, PEER_STATUS_RTT_SHUTDOWN);
5278 }
ae9b0e11 5279
d62a17ae 5280 if (set)
5281 ret = peer_flag_set(peer, flag);
5282 else
5283 ret = peer_flag_unset(peer, flag);
718e3744 5284
d62a17ae 5285 return bgp_vty_return(vty, ret);
718e3744 5286}
5287
83194f39 5288static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint64_t flag)
718e3744 5289{
d62a17ae 5290 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 5291}
5292
d62a17ae 5293static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
83194f39 5294 uint64_t flag)
718e3744 5295{
d62a17ae 5296 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 5297}
5298
5299/* neighbor passive. */
28c6e247
IR
5300DEFUN (neighbor_passive,
5301 neighbor_passive_cmd,
5302 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5303 NEIGHBOR_STR
5304 NEIGHBOR_ADDR_STR2
5305 "Don't send open messages to this neighbor\n")
718e3744 5306{
d62a17ae 5307 int idx_peer = 1;
28c6e247 5308 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 5309}
5310
28c6e247
IR
5311DEFUN (no_neighbor_passive,
5312 no_neighbor_passive_cmd,
5313 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5314 NO_STR
5315 NEIGHBOR_STR
5316 NEIGHBOR_ADDR_STR2
5317 "Don't send open messages to this neighbor\n")
718e3744 5318{
d62a17ae 5319 int idx_peer = 2;
28c6e247 5320 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 5321}
6b0655a2 5322
718e3744 5323/* neighbor shutdown. */
28c6e247
IR
5324DEFUN (neighbor_shutdown_msg,
5325 neighbor_shutdown_msg_cmd,
5326 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5327 NEIGHBOR_STR
5328 NEIGHBOR_ADDR_STR2
5329 "Administratively shut down this neighbor\n"
5330 "Add a shutdown message (RFC 8203)\n"
5331 "Shutdown message\n")
718e3744 5332{
d62a17ae 5333 int idx_peer = 1;
73d70fa6 5334
d62a17ae 5335 if (argc >= 5) {
28c6e247
IR
5336 struct peer *peer =
5337 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
d62a17ae 5338 char *message;
73d70fa6 5339
28c6e247
IR
5340 if (!peer)
5341 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5342 message = argv_concat(argv, argc, 4);
28c6e247
IR
5343 peer_tx_shutdown_message_set(peer, message);
5344 XFREE(MTYPE_TMP, message);
d62a17ae 5345 }
73d70fa6 5346
28c6e247 5347 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 5348}
5349
1d80f243 5350ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
d62a17ae 5351 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5352 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5353 "Administratively shut down this neighbor\n")
73d70fa6 5354
28c6e247
IR
5355DEFUN (no_neighbor_shutdown_msg,
5356 no_neighbor_shutdown_msg_cmd,
5357 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5358 NO_STR
5359 NEIGHBOR_STR
5360 NEIGHBOR_ADDR_STR2
5361 "Administratively shut down this neighbor\n"
5362 "Remove a shutdown message (RFC 8203)\n"
5363 "Shutdown message\n")
718e3744 5364{
d62a17ae 5365 int idx_peer = 2;
73d70fa6 5366
28c6e247
IR
5367 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5368 PEER_FLAG_SHUTDOWN);
718e3744 5369}
6b0655a2 5370
1d80f243 5371ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
d62a17ae 5372 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5373 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5374 "Administratively shut down this neighbor\n")
73d70fa6 5375
8336c896
DA
5376DEFUN(neighbor_shutdown_rtt,
5377 neighbor_shutdown_rtt_cmd,
5378 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5379 NEIGHBOR_STR
5380 NEIGHBOR_ADDR_STR2
5381 "Administratively shut down this neighbor\n"
5382 "Shutdown if round-trip-time is higher than expected\n"
5383 "Round-trip-time in milliseconds\n"
5384 "Specify the number of keepalives before shutdown\n"
5385 "The number of keepalives with higher RTT to shutdown\n")
5386{
5387 int idx_peer = 1;
5388 int idx_rtt = 4;
5389 int idx_count = 0;
5390 struct peer *peer;
5391
5392 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5393
5394 if (!peer)
5395 return CMD_WARNING_CONFIG_FAILED;
5396
5397 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5398
5399 if (argv_find(argv, argc, "count", &idx_count))
5400 peer->rtt_keepalive_conf =
5401 strtol(argv[idx_count + 1]->arg, NULL, 10);
5402
5403 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5404 PEER_FLAG_RTT_SHUTDOWN);
5405}
5406
5407DEFUN(no_neighbor_shutdown_rtt,
5408 no_neighbor_shutdown_rtt_cmd,
5409 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5410 NO_STR
5411 NEIGHBOR_STR
5412 NEIGHBOR_ADDR_STR2
5413 "Administratively shut down this neighbor\n"
5414 "Shutdown if round-trip-time is higher than expected\n"
5415 "Round-trip-time in milliseconds\n"
5416 "Specify the number of keepalives before shutdown\n"
5417 "The number of keepalives with higher RTT to shutdown\n")
5418{
5419 int idx_peer = 2;
5420 struct peer *peer;
5421
5422 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5423
5424 if (!peer)
5425 return CMD_WARNING_CONFIG_FAILED;
5426
5427 peer->rtt_expected = 0;
5428 peer->rtt_keepalive_conf = 1;
5429
5430 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5431 PEER_FLAG_RTT_SHUTDOWN);
5432}
5433
718e3744 5434/* neighbor capability dynamic. */
28c6e247
IR
5435DEFUN (neighbor_capability_dynamic,
5436 neighbor_capability_dynamic_cmd,
5437 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5438 NEIGHBOR_STR
5439 NEIGHBOR_ADDR_STR2
5440 "Advertise capability to the peer\n"
5441 "Advertise dynamic capability to this neighbor\n")
718e3744 5442{
d62a17ae 5443 int idx_peer = 1;
28c6e247
IR
5444 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5445 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 5446}
5447
28c6e247
IR
5448DEFUN (no_neighbor_capability_dynamic,
5449 no_neighbor_capability_dynamic_cmd,
5450 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5451 NO_STR
5452 NEIGHBOR_STR
5453 NEIGHBOR_ADDR_STR2
5454 "Advertise capability to the peer\n"
5455 "Advertise dynamic capability to this neighbor\n")
718e3744 5456{
d62a17ae 5457 int idx_peer = 2;
28c6e247
IR
5458 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5459 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 5460}
6b0655a2 5461
718e3744 5462/* neighbor dont-capability-negotiate */
5463DEFUN (neighbor_dont_capability_negotiate,
5464 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5465 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5466 NEIGHBOR_STR
5467 NEIGHBOR_ADDR_STR2
5468 "Do not perform capability negotiation\n")
5469{
d62a17ae 5470 int idx_peer = 1;
5471 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5472 PEER_FLAG_DONT_CAPABILITY);
718e3744 5473}
5474
5475DEFUN (no_neighbor_dont_capability_negotiate,
5476 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5477 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5478 NO_STR
5479 NEIGHBOR_STR
5480 NEIGHBOR_ADDR_STR2
5481 "Do not perform capability negotiation\n")
5482{
28c6e247
IR
5483 int idx_peer = 2;
5484 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5485 PEER_FLAG_DONT_CAPABILITY);
f4b8ec07
CS
5486}
5487
28c6e247
IR
5488/* neighbor capability extended next hop encoding */
5489DEFUN (neighbor_capability_enhe,
5490 neighbor_capability_enhe_cmd,
5491 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5492 NEIGHBOR_STR
5493 NEIGHBOR_ADDR_STR2
5494 "Advertise capability to the peer\n"
5495 "Advertise extended next-hop capability to the peer\n")
f4b8ec07 5496{
28c6e247 5497 int idx_peer = 1;
c4786405
DS
5498 struct peer *peer;
5499
5500 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5501 if (peer && peer->conf_if)
5502 return CMD_SUCCESS;
5503
28c6e247
IR
5504 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5505 PEER_FLAG_CAPABILITY_ENHE);
5506}
f4b8ec07 5507
28c6e247
IR
5508DEFUN (no_neighbor_capability_enhe,
5509 no_neighbor_capability_enhe_cmd,
5510 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5511 NO_STR
5512 NEIGHBOR_STR
5513 NEIGHBOR_ADDR_STR2
5514 "Advertise capability to the peer\n"
5515 "Advertise extended next-hop capability to the peer\n")
5516{
5517 int idx_peer = 2;
c4786405
DS
5518 struct peer *peer;
5519
5520 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5521 if (peer && peer->conf_if) {
5522 vty_out(vty,
5523 "Peer %s cannot have capability extended-nexthop turned off\n",
5524 argv[idx_peer]->arg);
5525 return CMD_WARNING_CONFIG_FAILED;
5526 }
5527
28c6e247
IR
5528 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5529 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
5530}
5531
d62a17ae 5532static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5533 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 5534 int set)
718e3744 5535{
d62a17ae 5536 int ret;
5537 struct peer *peer;
718e3744 5538
d62a17ae 5539 peer = peer_and_group_lookup_vty(vty, peer_str);
5540 if (!peer)
5541 return CMD_WARNING_CONFIG_FAILED;
718e3744 5542
d62a17ae 5543 if (set)
5544 ret = peer_af_flag_set(peer, afi, safi, flag);
5545 else
5546 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 5547
d62a17ae 5548 return bgp_vty_return(vty, ret);
718e3744 5549}
5550
d62a17ae 5551static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5552 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5553{
d62a17ae 5554 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 5555}
5556
d62a17ae 5557static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5558 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5559{
d62a17ae 5560 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 5561}
6b0655a2 5562
718e3744 5563/* neighbor capability orf prefix-list. */
5564DEFUN (neighbor_capability_orf_prefix,
5565 neighbor_capability_orf_prefix_cmd,
9ccf14f7 5566 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5567 NEIGHBOR_STR
5568 NEIGHBOR_ADDR_STR2
5569 "Advertise capability to the peer\n"
5570 "Advertise ORF capability to the peer\n"
5571 "Advertise prefixlist ORF capability to this neighbor\n"
5572 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5573 "Capability to RECEIVE the ORF from this neighbor\n"
5574 "Capability to SEND the ORF to this neighbor\n")
5575{
d62a17ae 5576 int idx_send_recv = 5;
db45f64d
DS
5577 char *peer_str = argv[1]->arg;
5578 struct peer *peer;
5579 afi_t afi = bgp_node_afi(vty);
5580 safi_t safi = bgp_node_safi(vty);
d62a17ae 5581
db45f64d
DS
5582 peer = peer_and_group_lookup_vty(vty, peer_str);
5583 if (!peer)
d62a17ae 5584 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5585
db45f64d
DS
5586 if (strmatch(argv[idx_send_recv]->text, "send"))
5587 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5588 PEER_FLAG_ORF_PREFIX_SM);
5589
5590 if (strmatch(argv[idx_send_recv]->text, "receive"))
5591 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5592 PEER_FLAG_ORF_PREFIX_RM);
5593
5594 if (strmatch(argv[idx_send_recv]->text, "both"))
5595 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5596 PEER_FLAG_ORF_PREFIX_SM)
5597 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5598 PEER_FLAG_ORF_PREFIX_RM);
5599
5600 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5601}
5602
5603ALIAS_HIDDEN(
5604 neighbor_capability_orf_prefix,
5605 neighbor_capability_orf_prefix_hidden_cmd,
5606 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5607 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5608 "Advertise capability to the peer\n"
5609 "Advertise ORF capability to the peer\n"
5610 "Advertise prefixlist ORF capability to this neighbor\n"
5611 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5612 "Capability to RECEIVE the ORF from this neighbor\n"
5613 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5614
718e3744 5615DEFUN (no_neighbor_capability_orf_prefix,
5616 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 5617 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5618 NO_STR
5619 NEIGHBOR_STR
5620 NEIGHBOR_ADDR_STR2
5621 "Advertise capability to the peer\n"
5622 "Advertise ORF capability to the peer\n"
5623 "Advertise prefixlist ORF capability to this neighbor\n"
5624 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5625 "Capability to RECEIVE the ORF from this neighbor\n"
5626 "Capability to SEND the ORF to this neighbor\n")
5627{
d62a17ae 5628 int idx_send_recv = 6;
db45f64d
DS
5629 char *peer_str = argv[2]->arg;
5630 struct peer *peer;
5631 afi_t afi = bgp_node_afi(vty);
5632 safi_t safi = bgp_node_safi(vty);
d62a17ae 5633
db45f64d
DS
5634 peer = peer_and_group_lookup_vty(vty, peer_str);
5635 if (!peer)
d62a17ae 5636 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5637
db45f64d
DS
5638 if (strmatch(argv[idx_send_recv]->text, "send"))
5639 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5640 PEER_FLAG_ORF_PREFIX_SM);
5641
5642 if (strmatch(argv[idx_send_recv]->text, "receive"))
5643 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5644 PEER_FLAG_ORF_PREFIX_RM);
5645
5646 if (strmatch(argv[idx_send_recv]->text, "both"))
5647 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5648 PEER_FLAG_ORF_PREFIX_SM)
5649 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5650 PEER_FLAG_ORF_PREFIX_RM);
5651
5652 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5653}
5654
5655ALIAS_HIDDEN(
5656 no_neighbor_capability_orf_prefix,
5657 no_neighbor_capability_orf_prefix_hidden_cmd,
5658 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5659 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5660 "Advertise capability to the peer\n"
5661 "Advertise ORF capability to the peer\n"
5662 "Advertise prefixlist ORF capability to this neighbor\n"
5663 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5664 "Capability to RECEIVE the ORF from this neighbor\n"
5665 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5666
718e3744 5667/* neighbor next-hop-self. */
28c6e247
IR
5668DEFUN (neighbor_nexthop_self,
5669 neighbor_nexthop_self_cmd,
5670 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5671 NEIGHBOR_STR
5672 NEIGHBOR_ADDR_STR2
5673 "Disable the next hop calculation for this neighbor\n")
718e3744 5674{
d62a17ae 5675 int idx_peer = 1;
28c6e247
IR
5676 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5677 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 5678}
9e7a53c1 5679
d62a17ae 5680ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5681 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5682 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5683 "Disable the next hop calculation for this neighbor\n")
596c17ba 5684
f4b8ec07 5685/* neighbor next-hop-self. */
28c6e247
IR
5686DEFUN (neighbor_nexthop_self_force,
5687 neighbor_nexthop_self_force_cmd,
5688 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5689 NEIGHBOR_STR
5690 NEIGHBOR_ADDR_STR2
5691 "Disable the next hop calculation for this neighbor\n"
5692 "Set the next hop to self for reflected routes\n")
f4b8ec07
CS
5693{
5694 int idx_peer = 1;
28c6e247
IR
5695 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5696 bgp_node_safi(vty),
5697 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 5698}
5699
d62a17ae 5700ALIAS_HIDDEN(neighbor_nexthop_self_force,
5701 neighbor_nexthop_self_force_hidden_cmd,
5702 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5703 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5704 "Disable the next hop calculation for this neighbor\n"
5705 "Set the next hop to self for reflected routes\n")
596c17ba 5706
1bc4e531
DA
5707ALIAS_HIDDEN(neighbor_nexthop_self_force,
5708 neighbor_nexthop_self_all_hidden_cmd,
5709 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5710 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5711 "Disable the next hop calculation for this neighbor\n"
5712 "Set the next hop to self for reflected routes\n")
5713
28c6e247
IR
5714DEFUN (no_neighbor_nexthop_self,
5715 no_neighbor_nexthop_self_cmd,
5716 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5717 NO_STR
5718 NEIGHBOR_STR
5719 NEIGHBOR_ADDR_STR2
5720 "Disable the next hop calculation for this neighbor\n")
718e3744 5721{
d62a17ae 5722 int idx_peer = 2;
28c6e247
IR
5723 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5724 bgp_node_afi(vty), bgp_node_safi(vty),
5725 PEER_FLAG_NEXTHOP_SELF);
718e3744 5726}
6b0655a2 5727
d62a17ae 5728ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5729 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5730 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5731 "Disable the next hop calculation for this neighbor\n")
596c17ba 5732
28c6e247
IR
5733DEFUN (no_neighbor_nexthop_self_force,
5734 no_neighbor_nexthop_self_force_cmd,
5735 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5736 NO_STR
5737 NEIGHBOR_STR
5738 NEIGHBOR_ADDR_STR2
5739 "Disable the next hop calculation for this neighbor\n"
5740 "Set the next hop to self for reflected routes\n")
88b8ed8d 5741{
d62a17ae 5742 int idx_peer = 2;
28c6e247
IR
5743 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5744 bgp_node_afi(vty), bgp_node_safi(vty),
5745 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 5746}
a538debe 5747
d62a17ae 5748ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5749 no_neighbor_nexthop_self_force_hidden_cmd,
5750 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5751 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5752 "Disable the next hop calculation for this neighbor\n"
5753 "Set the next hop to self for reflected routes\n")
596c17ba 5754
1bc4e531
DA
5755ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5756 no_neighbor_nexthop_self_all_hidden_cmd,
5757 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5758 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5759 "Disable the next hop calculation for this neighbor\n"
5760 "Set the next hop to self for reflected routes\n")
5761
c7122e14 5762/* neighbor as-override */
28c6e247
IR
5763DEFUN (neighbor_as_override,
5764 neighbor_as_override_cmd,
5765 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5766 NEIGHBOR_STR
5767 NEIGHBOR_ADDR_STR2
5768 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5769{
d62a17ae 5770 int idx_peer = 1;
28c6e247
IR
5771 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5772 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
5773}
5774
d62a17ae 5775ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5776 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5777 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5778 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5779
28c6e247
IR
5780DEFUN (no_neighbor_as_override,
5781 no_neighbor_as_override_cmd,
5782 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5783 NO_STR
5784 NEIGHBOR_STR
5785 NEIGHBOR_ADDR_STR2
5786 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5787{
d62a17ae 5788 int idx_peer = 2;
28c6e247
IR
5789 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5790 bgp_node_afi(vty), bgp_node_safi(vty),
5791 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
5792}
5793
d62a17ae 5794ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5795 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5796 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5797 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5798
718e3744 5799/* neighbor remove-private-AS. */
28c6e247
IR
5800DEFUN (neighbor_remove_private_as,
5801 neighbor_remove_private_as_cmd,
5802 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5803 NEIGHBOR_STR
5804 NEIGHBOR_ADDR_STR2
5805 "Remove private ASNs in outbound updates\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),
5810 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 5811}
5812
d62a17ae 5813ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5814 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5815 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5816 "Remove private ASNs in outbound updates\n")
596c17ba 5817
28c6e247
IR
5818DEFUN (neighbor_remove_private_as_all,
5819 neighbor_remove_private_as_all_cmd,
5820 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5821 NEIGHBOR_STR
5822 NEIGHBOR_ADDR_STR2
5823 "Remove private ASNs in outbound updates\n"
5824 "Apply to all AS numbers\n")
5000f21c 5825{
d62a17ae 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_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
5830}
5831
d62a17ae 5832ALIAS_HIDDEN(neighbor_remove_private_as_all,
5833 neighbor_remove_private_as_all_hidden_cmd,
5834 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5835 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5836 "Remove private ASNs in outbound updates\n"
a0dfca37 5837 "Apply to all AS numbers\n")
596c17ba 5838
28c6e247
IR
5839DEFUN (neighbor_remove_private_as_replace_as,
5840 neighbor_remove_private_as_replace_as_cmd,
5841 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5842 NEIGHBOR_STR
5843 NEIGHBOR_ADDR_STR2
5844 "Remove private ASNs in outbound updates\n"
5845 "Replace private ASNs with our ASN in outbound updates\n")
5000f21c 5846{
d62a17ae 5847 int idx_peer = 1;
28c6e247
IR
5848 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5849 bgp_node_safi(vty),
5850 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
5851}
5852
d62a17ae 5853ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5854 neighbor_remove_private_as_replace_as_hidden_cmd,
5855 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5856 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5857 "Remove private ASNs in outbound updates\n"
5858 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5859
28c6e247
IR
5860DEFUN (neighbor_remove_private_as_all_replace_as,
5861 neighbor_remove_private_as_all_replace_as_cmd,
5862 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5863 NEIGHBOR_STR
5864 NEIGHBOR_ADDR_STR2
5865 "Remove private ASNs in outbound updates\n"
5866 "Apply to all AS numbers\n"
5867 "Replace private ASNs with our ASN in outbound updates\n")
5000f21c 5868{
d62a17ae 5869 int idx_peer = 1;
28c6e247
IR
5870 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5871 bgp_node_safi(vty),
5872 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
5873}
5874
d62a17ae 5875ALIAS_HIDDEN(
5876 neighbor_remove_private_as_all_replace_as,
5877 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5878 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5879 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5880 "Remove private ASNs in outbound updates\n"
5881 "Apply to all AS numbers\n"
5882 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5883
28c6e247
IR
5884DEFUN (no_neighbor_remove_private_as,
5885 no_neighbor_remove_private_as_cmd,
5886 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5887 NO_STR
5888 NEIGHBOR_STR
5889 NEIGHBOR_ADDR_STR2
5890 "Remove private ASNs in outbound updates\n")
718e3744 5891{
d62a17ae 5892 int idx_peer = 2;
28c6e247
IR
5893 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5894 bgp_node_afi(vty), bgp_node_safi(vty),
5895 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 5896}
6b0655a2 5897
d62a17ae 5898ALIAS_HIDDEN(no_neighbor_remove_private_as,
5899 no_neighbor_remove_private_as_hidden_cmd,
5900 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5901 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5902 "Remove private ASNs in outbound updates\n")
596c17ba 5903
28c6e247
IR
5904DEFUN (no_neighbor_remove_private_as_all,
5905 no_neighbor_remove_private_as_all_cmd,
5906 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5907 NO_STR
5908 NEIGHBOR_STR
5909 NEIGHBOR_ADDR_STR2
5910 "Remove private ASNs in outbound updates\n"
5911 "Apply to all AS numbers\n")
88b8ed8d 5912{
d62a17ae 5913 int idx_peer = 2;
28c6e247
IR
5914 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5915 bgp_node_afi(vty), bgp_node_safi(vty),
5916 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 5917}
5000f21c 5918
d62a17ae 5919ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
5920 no_neighbor_remove_private_as_all_hidden_cmd,
5921 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5922 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5923 "Remove private ASNs in outbound updates\n"
5924 "Apply to all AS numbers\n")
596c17ba 5925
28c6e247
IR
5926DEFUN (no_neighbor_remove_private_as_replace_as,
5927 no_neighbor_remove_private_as_replace_as_cmd,
5928 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5929 NO_STR
5930 NEIGHBOR_STR
5931 NEIGHBOR_ADDR_STR2
5932 "Remove private ASNs in outbound updates\n"
5933 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 5934{
d62a17ae 5935 int idx_peer = 2;
28c6e247
IR
5936 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5937 bgp_node_afi(vty), bgp_node_safi(vty),
5938 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 5939}
5000f21c 5940
d62a17ae 5941ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
5942 no_neighbor_remove_private_as_replace_as_hidden_cmd,
5943 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5944 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5945 "Remove private ASNs in outbound updates\n"
5946 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5947
28c6e247
IR
5948DEFUN (no_neighbor_remove_private_as_all_replace_as,
5949 no_neighbor_remove_private_as_all_replace_as_cmd,
5950 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5951 NO_STR
5952 NEIGHBOR_STR
5953 NEIGHBOR_ADDR_STR2
5954 "Remove private ASNs in outbound updates\n"
5955 "Apply to all AS numbers\n"
5956 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 5957{
d62a17ae 5958 int idx_peer = 2;
28c6e247
IR
5959 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5960 bgp_node_afi(vty), bgp_node_safi(vty),
5961 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 5962}
5000f21c 5963
d62a17ae 5964ALIAS_HIDDEN(
5965 no_neighbor_remove_private_as_all_replace_as,
5966 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
5967 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5968 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5969 "Remove private ASNs in outbound updates\n"
5970 "Apply to all AS numbers\n"
5971 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5972
5000f21c 5973
718e3744 5974/* neighbor send-community. */
28c6e247
IR
5975DEFUN (neighbor_send_community,
5976 neighbor_send_community_cmd,
5977 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5978 NEIGHBOR_STR
5979 NEIGHBOR_ADDR_STR2
5980 "Send Community attribute to this neighbor\n")
718e3744 5981{
d62a17ae 5982 int idx_peer = 1;
27c05d4d 5983
f63d4054
IR
5984 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5985 bgp_node_safi(vty),
5986 PEER_FLAG_SEND_COMMUNITY);
718e3744 5987}
5988
d62a17ae 5989ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
5990 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5991 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5992 "Send Community attribute to this neighbor\n")
596c17ba 5993
28c6e247
IR
5994DEFUN (no_neighbor_send_community,
5995 no_neighbor_send_community_cmd,
5996 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5997 NO_STR
5998 NEIGHBOR_STR
5999 NEIGHBOR_ADDR_STR2
6000 "Send Community attribute to this neighbor\n")
718e3744 6001{
d62a17ae 6002 int idx_peer = 2;
27c05d4d 6003
f63d4054
IR
6004 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6005 bgp_node_afi(vty), bgp_node_safi(vty),
6006 PEER_FLAG_SEND_COMMUNITY);
718e3744 6007}
6b0655a2 6008
d62a17ae 6009ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
6010 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6011 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6012 "Send Community attribute to this neighbor\n")
596c17ba 6013
718e3744 6014/* neighbor send-community extended. */
28c6e247
IR
6015DEFUN (neighbor_send_community_type,
6016 neighbor_send_community_type_cmd,
6017 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6018 NEIGHBOR_STR
6019 NEIGHBOR_ADDR_STR2
6020 "Send Community attribute to this neighbor\n"
6021 "Send Standard and Extended Community attributes\n"
6022 "Send Standard, Large and Extended Community attributes\n"
6023 "Send Extended Community attributes\n"
6024 "Send Standard Community attributes\n"
6025 "Send Large Community attributes\n")
718e3744 6026{
27c05d4d 6027 const char *type = argv[argc - 1]->text;
db45f64d 6028 char *peer_str = argv[1]->arg;
28c6e247 6029 struct peer *peer;
db45f64d 6030 afi_t afi = bgp_node_afi(vty);
28c6e247 6031 safi_t safi = bgp_node_safi(vty);
f4b8ec07 6032
28c6e247
IR
6033 peer = peer_and_group_lookup_vty(vty, peer_str);
6034 if (!peer)
6035 return CMD_WARNING_CONFIG_FAILED;
f4b8ec07 6036
28c6e247
IR
6037 if (strmatch(type, "standard"))
6038 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6039 PEER_FLAG_SEND_COMMUNITY);
f4b8ec07 6040
28c6e247
IR
6041 if (strmatch(type, "extended"))
6042 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6043 PEER_FLAG_SEND_EXT_COMMUNITY);
f4b8ec07 6044
28c6e247
IR
6045 if (strmatch(type, "large"))
6046 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6047 PEER_FLAG_SEND_LARGE_COMMUNITY);
f4b8ec07 6048
28c6e247
IR
6049 if (strmatch(type, "both")) {
6050 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6051 PEER_FLAG_SEND_COMMUNITY)
6052 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6053 PEER_FLAG_SEND_EXT_COMMUNITY);
f4b8ec07 6054 }
28c6e247
IR
6055 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6056 PEER_FLAG_SEND_COMMUNITY)
6057 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6058 PEER_FLAG_SEND_EXT_COMMUNITY)
6059 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6060 PEER_FLAG_SEND_LARGE_COMMUNITY);
d62a17ae 6061}
6062
6063ALIAS_HIDDEN(
6064 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
6065 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6066 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6067 "Send Community attribute to this neighbor\n"
6068 "Send Standard and Extended Community attributes\n"
6069 "Send Standard, Large and Extended Community attributes\n"
6070 "Send Extended Community attributes\n"
6071 "Send Standard Community attributes\n"
6072 "Send Large Community attributes\n")
596c17ba 6073
28c6e247
IR
6074DEFUN (no_neighbor_send_community_type,
6075 no_neighbor_send_community_type_cmd,
6076 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6077 NO_STR
6078 NEIGHBOR_STR
6079 NEIGHBOR_ADDR_STR2
6080 "Send Community attribute to this neighbor\n"
6081 "Send Standard and Extended Community attributes\n"
6082 "Send Standard, Large and Extended Community attributes\n"
6083 "Send Extended Community attributes\n"
6084 "Send Standard Community attributes\n"
6085 "Send Large Community attributes\n")
718e3744 6086{
d62a17ae 6087 const char *type = argv[argc - 1]->text;
db45f64d 6088 char *peer_str = argv[2]->arg;
28c6e247 6089 struct peer *peer;
db45f64d
DS
6090 afi_t afi = bgp_node_afi(vty);
6091 safi_t safi = bgp_node_safi(vty);
6092
28c6e247
IR
6093 peer = peer_and_group_lookup_vty(vty, peer_str);
6094 if (!peer)
f4b8ec07
CS
6095 return CMD_WARNING_CONFIG_FAILED;
6096
28c6e247
IR
6097 if (strmatch(type, "standard"))
6098 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6099 PEER_FLAG_SEND_COMMUNITY);
f4b8ec07 6100
28c6e247
IR
6101 if (strmatch(type, "extended"))
6102 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6103 PEER_FLAG_SEND_EXT_COMMUNITY);
f4b8ec07 6104
28c6e247
IR
6105 if (strmatch(type, "large"))
6106 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6107 PEER_FLAG_SEND_LARGE_COMMUNITY);
f4b8ec07
CS
6108
6109 if (strmatch(type, "both")) {
db45f64d 6110
28c6e247
IR
6111 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6112 PEER_FLAG_SEND_COMMUNITY)
6113 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6114 PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d
PM
6115 }
6116
28c6e247
IR
6117 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6118 PEER_FLAG_SEND_COMMUNITY)
6119 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6120 PEER_FLAG_SEND_EXT_COMMUNITY)
6121 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6122 PEER_FLAG_SEND_LARGE_COMMUNITY);
d62a17ae 6123}
6124
6125ALIAS_HIDDEN(
6126 no_neighbor_send_community_type,
6127 no_neighbor_send_community_type_hidden_cmd,
6128 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6129 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6130 "Send Community attribute to this neighbor\n"
6131 "Send Standard and Extended Community attributes\n"
6132 "Send Standard, Large and Extended Community attributes\n"
6133 "Send Extended Community attributes\n"
6134 "Send Standard Community attributes\n"
6135 "Send Large Community attributes\n")
596c17ba 6136
718e3744 6137/* neighbor soft-reconfig. */
28c6e247
IR
6138DEFUN (neighbor_soft_reconfiguration,
6139 neighbor_soft_reconfiguration_cmd,
6140 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6141 NEIGHBOR_STR
6142 NEIGHBOR_ADDR_STR2
6143 "Per neighbor soft reconfiguration\n"
6144 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 6145{
d62a17ae 6146 int idx_peer = 1;
28c6e247
IR
6147 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6148 bgp_node_safi(vty),
6149 PEER_FLAG_SOFT_RECONFIG);
718e3744 6150}
6151
d62a17ae 6152ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6153 neighbor_soft_reconfiguration_hidden_cmd,
6154 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6155 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6156 "Per neighbor soft reconfiguration\n"
6157 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 6158
28c6e247
IR
6159DEFUN (no_neighbor_soft_reconfiguration,
6160 no_neighbor_soft_reconfiguration_cmd,
6161 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6162 NO_STR
6163 NEIGHBOR_STR
6164 NEIGHBOR_ADDR_STR2
6165 "Per neighbor soft reconfiguration\n"
6166 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 6167{
d62a17ae 6168 int idx_peer = 2;
28c6e247
IR
6169 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6170 bgp_node_afi(vty), bgp_node_safi(vty),
6171 PEER_FLAG_SOFT_RECONFIG);
718e3744 6172}
6b0655a2 6173
d62a17ae 6174ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6175 no_neighbor_soft_reconfiguration_hidden_cmd,
6176 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6177 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6178 "Per neighbor soft reconfiguration\n"
6179 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 6180
28c6e247
IR
6181DEFUN (neighbor_route_reflector_client,
6182 neighbor_route_reflector_client_cmd,
6183 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6184 NEIGHBOR_STR
6185 NEIGHBOR_ADDR_STR2
6186 "Configure a neighbor as Route Reflector client\n")
718e3744 6187{
d62a17ae 6188 int idx_peer = 1;
28c6e247 6189 struct peer *peer;
718e3744 6190
6191
28c6e247
IR
6192 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6193 if (!peer)
d62a17ae 6194 return CMD_WARNING_CONFIG_FAILED;
718e3744 6195
28c6e247
IR
6196 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6197 bgp_node_safi(vty),
6198 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 6199}
6200
d62a17ae 6201ALIAS_HIDDEN(neighbor_route_reflector_client,
6202 neighbor_route_reflector_client_hidden_cmd,
6203 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6204 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6205 "Configure a neighbor as Route Reflector client\n")
596c17ba 6206
28c6e247
IR
6207DEFUN (no_neighbor_route_reflector_client,
6208 no_neighbor_route_reflector_client_cmd,
6209 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6210 NO_STR
6211 NEIGHBOR_STR
6212 NEIGHBOR_ADDR_STR2
6213 "Configure a neighbor as Route Reflector client\n")
718e3744 6214{
d62a17ae 6215 int idx_peer = 2;
28c6e247
IR
6216 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6217 bgp_node_afi(vty), bgp_node_safi(vty),
6218 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 6219}
6b0655a2 6220
d62a17ae 6221ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6222 no_neighbor_route_reflector_client_hidden_cmd,
6223 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6224 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6225 "Configure a neighbor as Route Reflector client\n")
596c17ba 6226
70cd87ca
MK
6227/* optimal-route-reflection Root Routers configuration */
6228DEFPY (optimal_route_reflection,
6229 optimal_route_reflection_cmd,
6230 "[no$no] optimal-route-reflection WORD$orr_group [<A.B.C.D|X:X::X:X>$primary [<A.B.C.D|X:X::X:X>$secondary [<A.B.C.D|X:X::X:X>$tertiary]]]",
6231 NO_STR
6232 "Create ORR group and assign root router(s)\n"
6233 "ORR Group name\n"
6234 "Primary Root address\n"
6235 "Primary Root IPv6 address\n"
6236 "Secondary Root address\n"
6237 "Secondary Root IPv6 address\n"
6238 "Tertiary Root address\n"
6239 "Tertiary Root IPv6 address\n")
6240{
6241 if (!no && !primary) {
6242 vty_out(vty, "%% Specify Primary Root address\n");
6243 return CMD_WARNING_CONFIG_FAILED;
6244 }
6245 return bgp_afi_safi_orr_group_set_vty(
6246 vty, bgp_node_afi(vty), bgp_node_safi(vty), orr_group,
80f6ea8b 6247 primary_str, secondary_str, tertiary_str, !!no);
70cd87ca
MK
6248}
6249
6250/* neighbor optimal-route-reflection group*/
6251DEFPY (neighbor_optimal_route_reflection,
6252 neighbor_optimal_route_reflection_cmd,
6253 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor optimal-route-reflection WORD$orr_group",
6254 NO_STR
6255 NEIGHBOR_STR
6256 NEIGHBOR_ADDR_STR2
6257 "Apply ORR group configuration to the neighbor\n"
6258 "ORR group name\n")
6259{
6260 return peer_orr_group_set_vty(vty, neighbor, bgp_node_afi(vty),
80f6ea8b 6261 bgp_node_safi(vty), orr_group, !!no);
70cd87ca
MK
6262}
6263
718e3744 6264/* neighbor route-server-client. */
28c6e247
IR
6265DEFUN (neighbor_route_server_client,
6266 neighbor_route_server_client_cmd,
6267 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6268 NEIGHBOR_STR
6269 NEIGHBOR_ADDR_STR2
6270 "Configure a neighbor as Route Server client\n")
718e3744 6271{
d62a17ae 6272 int idx_peer = 1;
28c6e247 6273 struct peer *peer;
f4b8ec07 6274
28c6e247
IR
6275 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6276 if (!peer)
d62a17ae 6277 return CMD_WARNING_CONFIG_FAILED;
28c6e247
IR
6278 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6279 bgp_node_safi(vty),
6280 PEER_FLAG_RSERVER_CLIENT);
718e3744 6281}
6282
d62a17ae 6283ALIAS_HIDDEN(neighbor_route_server_client,
6284 neighbor_route_server_client_hidden_cmd,
6285 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6286 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6287 "Configure a neighbor as Route Server client\n")
596c17ba 6288
28c6e247
IR
6289DEFUN (no_neighbor_route_server_client,
6290 no_neighbor_route_server_client_cmd,
6291 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6292 NO_STR
6293 NEIGHBOR_STR
6294 NEIGHBOR_ADDR_STR2
6295 "Configure a neighbor as Route Server client\n")
fee0f4c6 6296{
d62a17ae 6297 int idx_peer = 2;
28c6e247
IR
6298 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6299 bgp_node_afi(vty), bgp_node_safi(vty),
6300 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 6301}
6b0655a2 6302
d62a17ae 6303ALIAS_HIDDEN(no_neighbor_route_server_client,
6304 no_neighbor_route_server_client_hidden_cmd,
6305 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6306 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6307 "Configure a neighbor as Route Server client\n")
596c17ba 6308
fee0f4c6 6309DEFUN (neighbor_nexthop_local_unchanged,
6310 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 6311 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 6312 NEIGHBOR_STR
6313 NEIGHBOR_ADDR_STR2
6314 "Configure treatment of outgoing link-local nexthop attribute\n"
6315 "Leave link-local nexthop unchanged for this peer\n")
6316{
d62a17ae 6317 int idx_peer = 1;
6318 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6319 bgp_node_safi(vty),
6320 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 6321}
6b0655a2 6322
fee0f4c6 6323DEFUN (no_neighbor_nexthop_local_unchanged,
6324 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 6325 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 6326 NO_STR
6327 NEIGHBOR_STR
6328 NEIGHBOR_ADDR_STR2
6329 "Configure treatment of outgoing link-local-nexthop attribute\n"
6330 "Leave link-local nexthop unchanged for this peer\n")
718e3744 6331{
d62a17ae 6332 int idx_peer = 2;
6333 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6334 bgp_node_afi(vty), bgp_node_safi(vty),
6335 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 6336}
6b0655a2 6337
28c6e247
IR
6338DEFUN (neighbor_attr_unchanged,
6339 neighbor_attr_unchanged_cmd,
6340 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6341 NEIGHBOR_STR
6342 NEIGHBOR_ADDR_STR2
6343 "BGP attribute is propagated unchanged to this neighbor\n"
6344 "As-path attribute\n"
6345 "Nexthop attribute\n"
6346 "Med attribute\n")
718e3744 6347{
d62a17ae 6348 int idx = 0;
8eeb0335 6349 char *peer_str = argv[1]->arg;
28c6e247 6350 struct peer *peer;
db45f64d
DS
6351 bool aspath = false;
6352 bool nexthop = false;
6353 bool med = false;
8eeb0335
DW
6354 afi_t afi = bgp_node_afi(vty);
6355 safi_t safi = bgp_node_safi(vty);
28c6e247 6356 int ret = 0;
f4b8ec07 6357
28c6e247
IR
6358 peer = peer_and_group_lookup_vty(vty, peer_str);
6359 if (!peer)
8eeb0335 6360 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6361
6362 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
6363 aspath = true;
6364
d62a17ae 6365 idx = 0;
6366 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6367 nexthop = true;
6368
d62a17ae 6369 idx = 0;
6370 if (argv_find(argv, argc, "med", &idx))
db45f64d 6371 med = true;
d62a17ae 6372
8eeb0335 6373 /* no flags means all of them! */
db45f64d 6374 if (!aspath && !nexthop && !med) {
28c6e247
IR
6375 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
6376 PEER_FLAG_AS_PATH_UNCHANGED);
6377 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6378 PEER_FLAG_NEXTHOP_UNCHANGED);
6379 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6380 PEER_FLAG_MED_UNCHANGED);
8eeb0335 6381 } else {
28c6e247
IR
6382 if (!aspath) {
6383 if (peer_af_flag_check(peer, afi, safi,
6384 PEER_FLAG_AS_PATH_UNCHANGED)) {
6385 ret |= peer_af_flag_unset_vty(
6386 vty, peer_str, afi, safi,
6387 PEER_FLAG_AS_PATH_UNCHANGED);
6388 }
6389 } else
6390 ret |= peer_af_flag_set_vty(
6391 vty, peer_str, afi, safi,
6392 PEER_FLAG_AS_PATH_UNCHANGED);
6393
6394 if (!nexthop) {
6395 if (peer_af_flag_check(peer, afi, safi,
6396 PEER_FLAG_NEXTHOP_UNCHANGED)) {
6397 ret |= peer_af_flag_unset_vty(
6398 vty, peer_str, afi, safi,
6399 PEER_FLAG_NEXTHOP_UNCHANGED);
6400 }
6401 } else
6402 ret |= peer_af_flag_set_vty(
6403 vty, peer_str, afi, safi,
6404 PEER_FLAG_NEXTHOP_UNCHANGED);
6405
6406 if (!med) {
6407 if (peer_af_flag_check(peer, afi, safi,
6408 PEER_FLAG_MED_UNCHANGED)) {
6409 ret |= peer_af_flag_unset_vty(
6410 vty, peer_str, afi, safi,
6411 PEER_FLAG_MED_UNCHANGED);
6412 }
6413 } else
6414 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6415 PEER_FLAG_MED_UNCHANGED);
d62a17ae 6416 }
6417
28c6e247 6418 return ret;
d62a17ae 6419}
6420
6421ALIAS_HIDDEN(
6422 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6423 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6424 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6425 "BGP attribute is propagated unchanged to this neighbor\n"
6426 "As-path attribute\n"
6427 "Nexthop attribute\n"
6428 "Med attribute\n")
596c17ba 6429
28c6e247
IR
6430DEFUN (no_neighbor_attr_unchanged,
6431 no_neighbor_attr_unchanged_cmd,
6432 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6433 NO_STR
6434 NEIGHBOR_STR
6435 NEIGHBOR_ADDR_STR2
6436 "BGP attribute is propagated unchanged to this neighbor\n"
6437 "As-path attribute\n"
6438 "Nexthop attribute\n"
6439 "Med attribute\n")
718e3744 6440{
d62a17ae 6441 int idx = 0;
db45f64d 6442 char *peer_str = argv[2]->arg;
28c6e247 6443 struct peer *peer;
db45f64d
DS
6444 bool aspath = false;
6445 bool nexthop = false;
6446 bool med = false;
6447 afi_t afi = bgp_node_afi(vty);
6448 safi_t safi = bgp_node_safi(vty);
28c6e247 6449 int ret = 0;
f4b8ec07 6450
28c6e247
IR
6451 peer = peer_and_group_lookup_vty(vty, peer_str);
6452 if (!peer)
db45f64d 6453 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6454
6455 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
6456 aspath = true;
6457
d62a17ae 6458 idx = 0;
6459 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6460 nexthop = true;
6461
d62a17ae 6462 idx = 0;
6463 if (argv_find(argv, argc, "med", &idx))
db45f64d 6464 med = true;
d62a17ae 6465
28c6e247
IR
6466 if (!aspath && !nexthop && !med) // no flags means all of them!
6467 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6468 PEER_FLAG_AS_PATH_UNCHANGED)
6469 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6470 PEER_FLAG_NEXTHOP_UNCHANGED)
6471 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6472 PEER_FLAG_MED_UNCHANGED);
db45f64d
DS
6473
6474 if (aspath)
28c6e247
IR
6475 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6476 PEER_FLAG_AS_PATH_UNCHANGED);
db45f64d
DS
6477
6478 if (nexthop)
28c6e247
IR
6479 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6480 PEER_FLAG_NEXTHOP_UNCHANGED);
d62a17ae 6481
db45f64d 6482 if (med)
28c6e247
IR
6483 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6484 PEER_FLAG_MED_UNCHANGED);
db45f64d 6485
28c6e247 6486 return ret;
d62a17ae 6487}
6488
6489ALIAS_HIDDEN(
6490 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6491 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6492 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6493 "BGP attribute is propagated unchanged to this neighbor\n"
6494 "As-path attribute\n"
6495 "Nexthop attribute\n"
6496 "Med attribute\n")
718e3744 6497
28c6e247
IR
6498/* EBGP multihop configuration. */
6499static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
6500 const char *ttl_str)
718e3744 6501{
28c6e247
IR
6502 struct peer *peer;
6503 unsigned int ttl;
718e3744 6504
28c6e247
IR
6505 peer = peer_and_group_lookup_vty(vty, ip_str);
6506 if (!peer)
d62a17ae 6507 return CMD_WARNING_CONFIG_FAILED;
718e3744 6508
28c6e247
IR
6509 if (peer->conf_if)
6510 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
6511
6512 if (!ttl_str)
6513 ttl = MAXTTL;
6514 else
6515 ttl = strtoul(ttl_str, NULL, 10);
718e3744 6516
28c6e247 6517 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 6518}
6519
28c6e247 6520static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 6521{
28c6e247 6522 struct peer *peer;
718e3744 6523
28c6e247
IR
6524 peer = peer_and_group_lookup_vty(vty, ip_str);
6525 if (!peer)
d62a17ae 6526 return CMD_WARNING_CONFIG_FAILED;
718e3744 6527
28c6e247 6528 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 6529}
6530
28c6e247
IR
6531/* neighbor ebgp-multihop. */
6532DEFUN (neighbor_ebgp_multihop,
6533 neighbor_ebgp_multihop_cmd,
6534 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6535 NEIGHBOR_STR
6536 NEIGHBOR_ADDR_STR2
6537 "Allow EBGP neighbors not on directly connected networks\n")
718e3744 6538{
28c6e247
IR
6539 int idx_peer = 1;
6540 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
6541}
f4b8ec07 6542
28c6e247
IR
6543DEFUN (neighbor_ebgp_multihop_ttl,
6544 neighbor_ebgp_multihop_ttl_cmd,
6545 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6546 NEIGHBOR_STR
6547 NEIGHBOR_ADDR_STR2
6548 "Allow EBGP neighbors not on directly connected networks\n"
6549 "maximum hop count\n")
6550{
6551 int idx_peer = 1;
6552 int idx_number = 3;
6553 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
6554 argv[idx_number]->arg);
6555}
f4b8ec07 6556
28c6e247
IR
6557DEFUN (no_neighbor_ebgp_multihop,
6558 no_neighbor_ebgp_multihop_cmd,
6559 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6560 NO_STR
6561 NEIGHBOR_STR
6562 NEIGHBOR_ADDR_STR2
6563 "Allow EBGP neighbors not on directly connected networks\n"
6564 "maximum hop count\n")
6565{
6566 int idx_peer = 2;
6567 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 6568}
6569
97a52c82
DA
6570DEFPY (neighbor_aigp,
6571 neighbor_aigp_cmd,
6572 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor aigp",
6573 NO_STR
6574 NEIGHBOR_STR
6575 NEIGHBOR_ADDR_STR2
6576 "Enable send and receive of the AIGP attribute per neighbor\n")
6577{
6578 struct peer *peer;
6579
6580 peer = peer_and_group_lookup_vty(vty, neighbor);
6581 if (!peer)
6582 return CMD_WARNING_CONFIG_FAILED;
6583
6584 if (no)
6585 return peer_flag_unset_vty(vty, neighbor, PEER_FLAG_AIGP);
6586 else
6587 return peer_flag_set_vty(vty, neighbor, PEER_FLAG_AIGP);
6588}
6589
d864dd9e
EB
6590static uint8_t get_role_by_name(const char *role_str)
6591{
6592 if (strncmp(role_str, "peer", 2) == 0)
6593 return ROLE_PEER;
6594 if (strncmp(role_str, "provider", 2) == 0)
6595 return ROLE_PROVIDER;
6596 if (strncmp(role_str, "customer", 2) == 0)
6597 return ROLE_CUSTOMER;
6598 if (strncmp(role_str, "rs-server", 4) == 0)
6599 return ROLE_RS_SERVER;
6600 if (strncmp(role_str, "rs-client", 4) == 0)
6601 return ROLE_RS_CLIENT;
8f2d6021 6602 return ROLE_UNDEFINED;
d864dd9e
EB
6603}
6604
6605static int peer_role_set_vty(struct vty *vty, const char *ip_str,
8f2d6021 6606 const char *role_str, bool strict_mode)
d864dd9e
EB
6607{
6608 struct peer *peer;
6609
7dddd1f7 6610 peer = peer_and_group_lookup_vty(vty, ip_str);
d864dd9e
EB
6611 if (!peer)
6612 return CMD_WARNING_CONFIG_FAILED;
6613 uint8_t role = get_role_by_name(role_str);
6614
8f2d6021 6615 if (role == ROLE_UNDEFINED)
d864dd9e
EB
6616 return bgp_vty_return(vty, BGP_ERR_INVALID_ROLE_NAME);
6617 return bgp_vty_return(vty, peer_role_set(peer, role, strict_mode));
6618}
6619
6620static int peer_role_unset_vty(struct vty *vty, const char *ip_str)
6621{
6622 struct peer *peer;
6623
7dddd1f7 6624 peer = peer_and_group_lookup_vty(vty, ip_str);
d864dd9e
EB
6625 if (!peer)
6626 return CMD_WARNING_CONFIG_FAILED;
6627 return bgp_vty_return(vty, peer_role_unset(peer));
6628}
6629
8f2d6021 6630DEFPY(neighbor_role,
d864dd9e
EB
6631 neighbor_role_cmd,
6632 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer>",
6633 NEIGHBOR_STR
6634 NEIGHBOR_ADDR_STR2
6635 "Set session role\n"
6636 ROLE_STR)
6637{
6638 int idx_peer = 1;
6639 int idx_role = 3;
6640
6641 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
8f2d6021 6642 false);
d864dd9e
EB
6643}
6644
8f2d6021 6645DEFPY(neighbor_role_strict,
d864dd9e
EB
6646 neighbor_role_strict_cmd,
6647 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> strict-mode",
6648 NEIGHBOR_STR
6649 NEIGHBOR_ADDR_STR2
6650 "Set session role\n"
6651 ROLE_STR
6652 "Use additional restriction on peer\n")
6653{
6654 int idx_peer = 1;
6655 int idx_role = 3;
6656
6657 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
8f2d6021 6658 true);
d864dd9e
EB
6659}
6660
8f2d6021 6661DEFPY(no_neighbor_role,
d864dd9e
EB
6662 no_neighbor_role_cmd,
6663 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> [strict-mode]",
6664 NO_STR
6665 NEIGHBOR_STR
6666 NEIGHBOR_ADDR_STR2
8f2d6021 6667 "Set session role\n"
d864dd9e 6668 ROLE_STR
8f2d6021 6669 "Use additional restriction on peer\n")
d864dd9e
EB
6670{
6671 int idx_peer = 2;
6672
6673 return peer_role_unset_vty(vty, argv[idx_peer]->arg);
6674}
6b0655a2 6675
6ffd2079 6676/* disable-connected-check */
28c6e247
IR
6677DEFUN (neighbor_disable_connected_check,
6678 neighbor_disable_connected_check_cmd,
6679 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6680 NEIGHBOR_STR
6681 NEIGHBOR_ADDR_STR2
6682 "one-hop away EBGP peer using loopback address\n"
6683 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6684{
d62a17ae 6685 int idx_peer = 1;
28c6e247
IR
6686 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6687 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 6688}
6689
28c6e247
IR
6690DEFUN (no_neighbor_disable_connected_check,
6691 no_neighbor_disable_connected_check_cmd,
6692 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6693 NO_STR
6694 NEIGHBOR_STR
6695 NEIGHBOR_ADDR_STR2
6696 "one-hop away EBGP peer using loopback address\n"
6697 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6698{
d62a17ae 6699 int idx_peer = 2;
28c6e247
IR
6700 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6701 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 6702}
6703
7ab294ea
DA
6704/* disable-link-bw-encoding-ieee */
6705DEFUN(neighbor_disable_link_bw_encoding_ieee,
6706 neighbor_disable_link_bw_encoding_ieee_cmd,
27aa23a4
DA
6707 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6708 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7ab294ea 6709 "Disable IEEE floating-point encoding for extended community bandwidth\n")
27aa23a4
DA
6710{
6711 int idx_peer = 1;
6712
6713 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6714 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6715}
6716
7ab294ea
DA
6717DEFUN(no_neighbor_disable_link_bw_encoding_ieee,
6718 no_neighbor_disable_link_bw_encoding_ieee_cmd,
27aa23a4
DA
6719 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6720 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7ab294ea 6721 "Disable IEEE floating-point encoding for extended community bandwidth\n")
27aa23a4
DA
6722{
6723 int idx_peer = 2;
6724
6725 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6726 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6727}
6728
d08c0c80
DA
6729/* extended-optional-parameters */
6730DEFUN(neighbor_extended_optional_parameters,
6731 neighbor_extended_optional_parameters_cmd,
6732 "neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6733 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6734 "Force the extended optional parameters format for OPEN messages\n")
6735{
6736 int idx_peer = 1;
6737
6738 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6739 PEER_FLAG_EXTENDED_OPT_PARAMS);
6740}
6741
6742DEFUN(no_neighbor_extended_optional_parameters,
6743 no_neighbor_extended_optional_parameters_cmd,
6744 "no neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6745 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6746 "Force the extended optional parameters format for OPEN messages\n")
6747{
6748 int idx_peer = 2;
6749
6750 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6751 PEER_FLAG_EXTENDED_OPT_PARAMS);
6752}
47cbc09b
PM
6753
6754/* enforce-first-as */
28c6e247
IR
6755DEFUN (neighbor_enforce_first_as,
6756 neighbor_enforce_first_as_cmd,
6757 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6758 NEIGHBOR_STR
6759 NEIGHBOR_ADDR_STR2
6760 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
6761{
6762 int idx_peer = 1;
f4b8ec07 6763
28c6e247
IR
6764 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6765 PEER_FLAG_ENFORCE_FIRST_AS);
47cbc09b
PM
6766}
6767
28c6e247
IR
6768DEFUN (no_neighbor_enforce_first_as,
6769 no_neighbor_enforce_first_as_cmd,
6770 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6771 NO_STR
6772 NEIGHBOR_STR
6773 NEIGHBOR_ADDR_STR2
6774 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
6775{
6776 int idx_peer = 2;
f4b8ec07 6777
28c6e247
IR
6778 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6779 PEER_FLAG_ENFORCE_FIRST_AS);
47cbc09b
PM
6780}
6781
6782
28c6e247
IR
6783DEFUN (neighbor_description,
6784 neighbor_description_cmd,
6785 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6786 NEIGHBOR_STR
6787 NEIGHBOR_ADDR_STR2
6788 "Neighbor specific description\n"
6789 "Up to 80 characters describing this neighbor\n")
718e3744 6790{
d62a17ae 6791 int idx_peer = 1;
6792 int idx_line = 3;
28c6e247 6793 struct peer *peer;
d62a17ae 6794 char *str;
718e3744 6795
28c6e247
IR
6796 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6797 if (!peer)
d62a17ae 6798 return CMD_WARNING_CONFIG_FAILED;
718e3744 6799
d62a17ae 6800 str = argv_concat(argv, argc, idx_line);
718e3744 6801
28c6e247 6802 peer_description_set(peer, str);
718e3744 6803
d62a17ae 6804 XFREE(MTYPE_TMP, str);
718e3744 6805
28c6e247 6806 return CMD_SUCCESS;
718e3744 6807}
6808
28c6e247
IR
6809DEFUN (no_neighbor_description,
6810 no_neighbor_description_cmd,
6811 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6812 NO_STR
6813 NEIGHBOR_STR
6814 NEIGHBOR_ADDR_STR2
6815 "Neighbor specific description\n")
718e3744 6816{
d62a17ae 6817 int idx_peer = 2;
28c6e247 6818 struct peer *peer;
f4b8ec07 6819
28c6e247
IR
6820 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6821 if (!peer)
d62a17ae 6822 return CMD_WARNING_CONFIG_FAILED;
718e3744 6823
28c6e247 6824 peer_description_unset(peer);
718e3744 6825
28c6e247 6826 return CMD_SUCCESS;
718e3744 6827}
6828
1d80f243 6829ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
a14810f4
PM
6830 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6831 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6832 "Neighbor specific description\n"
6833 "Up to 80 characters describing this neighbor\n")
6b0655a2 6834
28c6e247
IR
6835/* Neighbor update-source. */
6836static int peer_update_source_vty(struct vty *vty, const char *peer_str,
6837 const char *source_str)
6838{
6839 struct peer *peer;
6840 struct prefix p;
6841 union sockunion su;
6842
6843 peer = peer_and_group_lookup_vty(vty, peer_str);
6844 if (!peer)
6845 return CMD_WARNING_CONFIG_FAILED;
6846
6847 if (peer->conf_if)
6848 return CMD_WARNING;
6849
6850 if (source_str) {
6851 if (str2sockunion(source_str, &su) == 0)
6852 peer_update_source_addr_set(peer, &su);
6853 else {
6854 if (str2prefix(source_str, &p)) {
6855 vty_out(vty,
6856 "%% Invalid update-source, remove prefix length \n");
6857 return CMD_WARNING_CONFIG_FAILED;
6858 } else
6859 peer_update_source_if_set(peer, source_str);
6860 }
6861 } else
6862 peer_update_source_unset(peer);
6863
6864 return CMD_SUCCESS;
6865}
6866
d62a17ae 6867#define BGP_UPDATE_SOURCE_HELP_STR \
6868 "IPv4 address\n" \
6869 "IPv6 address\n" \
6870 "Interface name (requires zebra to be running)\n"
369688c0 6871
28c6e247
IR
6872DEFUN (neighbor_update_source,
6873 neighbor_update_source_cmd,
6874 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
6875 NEIGHBOR_STR
6876 NEIGHBOR_ADDR_STR2
6877 "Source of routing updates\n"
6878 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 6879{
d62a17ae 6880 int idx_peer = 1;
6881 int idx_peer_2 = 3;
28c6e247 6882 return peer_update_source_vty(vty, argv[idx_peer]->arg,
d62a17ae 6883 argv[idx_peer_2]->arg);
718e3744 6884}
6885
28c6e247
IR
6886DEFUN (no_neighbor_update_source,
6887 no_neighbor_update_source_cmd,
6888 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
6889 NO_STR
6890 NEIGHBOR_STR
6891 NEIGHBOR_ADDR_STR2
6892 "Source of routing updates\n"
6893 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 6894{
d62a17ae 6895 int idx_peer = 2;
28c6e247 6896 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 6897}
6b0655a2 6898
d62a17ae 6899static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
6900 afi_t afi, safi_t safi,
6901 const char *rmap, int set)
718e3744 6902{
d62a17ae 6903 int ret;
6904 struct peer *peer;
80912664 6905 struct route_map *route_map = NULL;
718e3744 6906
d62a17ae 6907 peer = peer_and_group_lookup_vty(vty, peer_str);
6908 if (!peer)
6909 return CMD_WARNING_CONFIG_FAILED;
718e3744 6910
1de27621 6911 if (set) {
80912664
DS
6912 if (rmap)
6913 route_map = route_map_lookup_warn_noexist(vty, rmap);
1de27621
DA
6914 ret = peer_default_originate_set(peer, afi, safi,
6915 rmap, route_map);
6916 } else
d62a17ae 6917 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 6918
d62a17ae 6919 return bgp_vty_return(vty, ret);
718e3744 6920}
6921
6922/* neighbor default-originate. */
6923DEFUN (neighbor_default_originate,
6924 neighbor_default_originate_cmd,
9ccf14f7 6925 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 6926 NEIGHBOR_STR
6927 NEIGHBOR_ADDR_STR2
6928 "Originate default route to this neighbor\n")
6929{
d62a17ae 6930 int idx_peer = 1;
6931 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6932 bgp_node_afi(vty),
6933 bgp_node_safi(vty), NULL, 1);
718e3744 6934}
6935
d62a17ae 6936ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
6937 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6938 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6939 "Originate default route to this neighbor\n")
596c17ba 6940
718e3744 6941DEFUN (neighbor_default_originate_rmap,
6942 neighbor_default_originate_rmap_cmd,
70dd370f 6943 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
718e3744 6944 NEIGHBOR_STR
6945 NEIGHBOR_ADDR_STR2
6946 "Originate default route to this neighbor\n"
6947 "Route-map to specify criteria to originate default\n"
6948 "route-map name\n")
6949{
d62a17ae 6950 int idx_peer = 1;
6951 int idx_word = 4;
6952 return peer_default_originate_set_vty(
6953 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6954 argv[idx_word]->arg, 1);
718e3744 6955}
6956
d62a17ae 6957ALIAS_HIDDEN(
6958 neighbor_default_originate_rmap,
6959 neighbor_default_originate_rmap_hidden_cmd,
70dd370f 6960 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
d62a17ae 6961 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6962 "Originate default route to this neighbor\n"
6963 "Route-map to specify criteria to originate default\n"
6964 "route-map name\n")
596c17ba 6965
718e3744 6966DEFUN (no_neighbor_default_originate,
6967 no_neighbor_default_originate_cmd,
70dd370f 6968 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
718e3744 6969 NO_STR
6970 NEIGHBOR_STR
6971 NEIGHBOR_ADDR_STR2
a636c635
DW
6972 "Originate default route to this neighbor\n"
6973 "Route-map to specify criteria to originate default\n"
6974 "route-map name\n")
718e3744 6975{
d62a17ae 6976 int idx_peer = 2;
6977 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6978 bgp_node_afi(vty),
6979 bgp_node_safi(vty), NULL, 0);
718e3744 6980}
6981
d62a17ae 6982ALIAS_HIDDEN(
6983 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
70dd370f 6984 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
d62a17ae 6985 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6986 "Originate default route to this neighbor\n"
6987 "Route-map to specify criteria to originate default\n"
6988 "route-map name\n")
596c17ba 6989
6b0655a2 6990
28c6e247
IR
6991/* Set neighbor's BGP port. */
6992static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
6993 const char *port_str)
718e3744 6994{
28c6e247
IR
6995 struct peer *peer;
6996 uint16_t port;
6997 struct servent *sp;
6998
a3aecc99 6999 peer = peer_and_group_lookup_vty(vty, ip_str);
28c6e247
IR
7000 if (!peer)
7001 return CMD_WARNING_CONFIG_FAILED;
7002
7003 if (!port_str) {
7004 sp = getservbyname("bgp", "tcp");
7005 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
7006 } else {
7007 port = strtoul(port_str, NULL, 10);
7008 }
718e3744 7009
28c6e247 7010 peer_port_set(peer, port);
718e3744 7011
28c6e247
IR
7012 return CMD_SUCCESS;
7013}
f4b8ec07 7014
28c6e247
IR
7015/* Set specified peer's BGP port. */
7016DEFUN (neighbor_port,
7017 neighbor_port_cmd,
a3aecc99 7018 "neighbor <A.B.C.D|X:X::X:X|WORD> port (0-65535)",
28c6e247 7019 NEIGHBOR_STR
a3aecc99 7020 NEIGHBOR_ADDR_STR2
28c6e247
IR
7021 "Neighbor's BGP port\n"
7022 "TCP port number\n")
7023{
7024 int idx_ip = 1;
7025 int idx_number = 3;
7026 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
7027 argv[idx_number]->arg);
f4b8ec07 7028}
6b0655a2 7029
28c6e247
IR
7030DEFUN (no_neighbor_port,
7031 no_neighbor_port_cmd,
a3aecc99 7032 "no neighbor <A.B.C.D|X:X::X:X|WORD> port [(0-65535)]",
28c6e247
IR
7033 NO_STR
7034 NEIGHBOR_STR
a3aecc99 7035 NEIGHBOR_ADDR_STR2
28c6e247
IR
7036 "Neighbor's BGP port\n"
7037 "TCP port number\n")
718e3744 7038{
f4b8ec07 7039 int idx_ip = 2;
28c6e247
IR
7040 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
7041}
7042
7043
7044/* neighbor weight. */
7045static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7046 safi_t safi, const char *weight_str)
7047{
7048 int ret;
7049 struct peer *peer;
7050 unsigned long weight;
718e3744 7051
28c6e247
IR
7052 peer = peer_and_group_lookup_vty(vty, ip_str);
7053 if (!peer)
7054 return CMD_WARNING_CONFIG_FAILED;
718e3744 7055
28c6e247 7056 weight = strtoul(weight_str, NULL, 10);
718e3744 7057
28c6e247
IR
7058 ret = peer_weight_set(peer, afi, safi, weight);
7059 return bgp_vty_return(vty, ret);
718e3744 7060}
7061
28c6e247
IR
7062static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7063 safi_t safi)
718e3744 7064{
28c6e247
IR
7065 int ret;
7066 struct peer *peer;
f4b8ec07 7067
28c6e247
IR
7068 peer = peer_and_group_lookup_vty(vty, ip_str);
7069 if (!peer)
d62a17ae 7070 return CMD_WARNING_CONFIG_FAILED;
718e3744 7071
28c6e247
IR
7072 ret = peer_weight_unset(peer, afi, safi);
7073 return bgp_vty_return(vty, ret);
7074}
f4b8ec07 7075
28c6e247
IR
7076DEFUN (neighbor_weight,
7077 neighbor_weight_cmd,
7078 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7079 NEIGHBOR_STR
7080 NEIGHBOR_ADDR_STR2
7081 "Set default weight for routes from this neighbor\n"
7082 "default weight\n")
7083{
7084 int idx_peer = 1;
7085 int idx_number = 3;
7086 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7087 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 7088}
7089
d62a17ae 7090ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
7091 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7092 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7093 "Set default weight for routes from this neighbor\n"
7094 "default weight\n")
596c17ba 7095
28c6e247
IR
7096DEFUN (no_neighbor_weight,
7097 no_neighbor_weight_cmd,
7098 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7099 NO_STR
7100 NEIGHBOR_STR
7101 NEIGHBOR_ADDR_STR2
7102 "Set default weight for routes from this neighbor\n"
7103 "default weight\n")
718e3744 7104{
d62a17ae 7105 int idx_peer = 2;
28c6e247
IR
7106 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
7107 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 7108}
7109
d62a17ae 7110ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
7111 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7112 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7113 "Set default weight for routes from this neighbor\n"
7114 "default weight\n")
596c17ba 7115
6b0655a2 7116
718e3744 7117/* Override capability negotiation. */
c36bc05f
IR
7118DEFUN (neighbor_override_capability,
7119 neighbor_override_capability_cmd,
7120 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7121 NEIGHBOR_STR
7122 NEIGHBOR_ADDR_STR2
7123 "Override capability negotiation result\n")
718e3744 7124{
d62a17ae 7125 int idx_peer = 1;
c36bc05f
IR
7126 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7127 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 7128}
7129
c36bc05f
IR
7130DEFUN (no_neighbor_override_capability,
7131 no_neighbor_override_capability_cmd,
7132 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7133 NO_STR
7134 NEIGHBOR_STR
7135 NEIGHBOR_ADDR_STR2
7136 "Override capability negotiation result\n")
718e3744 7137{
d62a17ae 7138 int idx_peer = 2;
c36bc05f
IR
7139 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7140 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 7141}
6b0655a2 7142
c36bc05f
IR
7143DEFUN (neighbor_strict_capability,
7144 neighbor_strict_capability_cmd,
7145 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7146 NEIGHBOR_STR
7147 NEIGHBOR_ADDR_STR2
7148 "Strict capability negotiation match\n")
718e3744 7149{
9fb964de
PM
7150 int idx_peer = 1;
7151
c36bc05f
IR
7152 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7153 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 7154}
7155
c36bc05f
IR
7156DEFUN (no_neighbor_strict_capability,
7157 no_neighbor_strict_capability_cmd,
7158 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7159 NO_STR
7160 NEIGHBOR_STR
7161 NEIGHBOR_ADDR_STR2
7162 "Strict capability negotiation match\n")
718e3744 7163{
9fb964de 7164 int idx_peer = 2;
8611c7f3 7165
c36bc05f
IR
7166 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7167 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 7168}
6b0655a2 7169
28c6e247
IR
7170static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
7171 const char *keep_str, const char *hold_str)
718e3744 7172{
28c6e247
IR
7173 int ret;
7174 struct peer *peer;
7175 uint32_t keepalive;
7176 uint32_t holdtime;
718e3744 7177
28c6e247
IR
7178 peer = peer_and_group_lookup_vty(vty, ip_str);
7179 if (!peer)
d62a17ae 7180 return CMD_WARNING_CONFIG_FAILED;
718e3744 7181
28c6e247
IR
7182 keepalive = strtoul(keep_str, NULL, 10);
7183 holdtime = strtoul(hold_str, NULL, 10);
718e3744 7184
28c6e247 7185 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 7186
28c6e247 7187 return bgp_vty_return(vty, ret);
718e3744 7188}
6b0655a2 7189
28c6e247 7190static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 7191{
28c6e247
IR
7192 int ret;
7193 struct peer *peer;
718e3744 7194
28c6e247
IR
7195 peer = peer_and_group_lookup_vty(vty, ip_str);
7196 if (!peer)
d62a17ae 7197 return CMD_WARNING_CONFIG_FAILED;
718e3744 7198
28c6e247 7199 ret = peer_timers_unset(peer);
718e3744 7200
28c6e247 7201 return bgp_vty_return(vty, ret);
718e3744 7202}
6b0655a2 7203
28c6e247
IR
7204DEFUN (neighbor_timers,
7205 neighbor_timers_cmd,
7206 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
7207 NEIGHBOR_STR
7208 NEIGHBOR_ADDR_STR2
7209 "BGP per neighbor timers\n"
7210 "Keepalive interval\n"
7211 "Holdtime\n")
718e3744 7212{
f4b8ec07 7213 int idx_peer = 1;
28c6e247
IR
7214 int idx_number = 3;
7215 int idx_number_2 = 4;
7216 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
7217 argv[idx_number]->arg,
7218 argv[idx_number_2]->arg);
7219}
7220
7221DEFUN (no_neighbor_timers,
7222 no_neighbor_timers_cmd,
7223 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
7224 NO_STR
7225 NEIGHBOR_STR
7226 NEIGHBOR_ADDR_STR2
7227 "BGP per neighbor timers\n"
7228 "Keepalive interval\n"
7229 "Holdtime\n")
7230{
7231 int idx_peer = 2;
7232 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
7233}
7234
7235
7236static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
7237 const char *time_str)
7238{
7239 int ret;
7240 struct peer *peer;
7241 uint32_t connect;
718e3744 7242
28c6e247
IR
7243 peer = peer_and_group_lookup_vty(vty, ip_str);
7244 if (!peer)
d62a17ae 7245 return CMD_WARNING_CONFIG_FAILED;
718e3744 7246
28c6e247
IR
7247 connect = strtoul(time_str, NULL, 10);
7248
7249 ret = peer_timers_connect_set(peer, connect);
718e3744 7250
28c6e247 7251 return bgp_vty_return(vty, ret);
718e3744 7252}
7253
28c6e247 7254static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 7255{
28c6e247
IR
7256 int ret;
7257 struct peer *peer;
718e3744 7258
28c6e247
IR
7259 peer = peer_and_group_lookup_vty(vty, ip_str);
7260 if (!peer)
d62a17ae 7261 return CMD_WARNING_CONFIG_FAILED;
718e3744 7262
28c6e247
IR
7263 ret = peer_timers_connect_unset(peer);
7264
7265 return bgp_vty_return(vty, ret);
7266}
7267
7268DEFUN (neighbor_timers_connect,
7269 neighbor_timers_connect_cmd,
7270 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7271 NEIGHBOR_STR
7272 NEIGHBOR_ADDR_STR2
7273 "BGP per neighbor timers\n"
7274 "BGP connect timer\n"
7275 "Connect timer\n")
7276{
7277 int idx_peer = 1;
7278 int idx_number = 4;
7279 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
7280 argv[idx_number]->arg);
7281}
718e3744 7282
28c6e247
IR
7283DEFUN (no_neighbor_timers_connect,
7284 no_neighbor_timers_connect_cmd,
7285 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7286 NO_STR
7287 NEIGHBOR_STR
7288 NEIGHBOR_ADDR_STR2
7289 "BGP per neighbor timers\n"
7290 "BGP connect timer\n"
7291 "Connect timer\n")
7292{
7293 int idx_peer = 2;
7294 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 7295}
7296
d43114f3
DS
7297DEFPY (neighbor_timers_delayopen,
7298 neighbor_timers_delayopen_cmd,
7299 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
7300 NEIGHBOR_STR
7301 NEIGHBOR_ADDR_STR2
7302 "BGP per neighbor timers\n"
7303 "RFC 4271 DelayOpenTimer\n"
7304 "DelayOpenTime timer interval\n")
7305{
7306 struct peer *peer;
7307
7308 peer = peer_and_group_lookup_vty(vty, neighbor);
7309 if (!peer)
7310 return CMD_WARNING_CONFIG_FAILED;
7311
7312 if (!interval) {
7313 if (peer_timers_delayopen_unset(peer))
7314 return CMD_WARNING_CONFIG_FAILED;
7315 } else {
7316 if (peer_timers_delayopen_set(peer, interval))
7317 return CMD_WARNING_CONFIG_FAILED;
7318 }
7319
7320 return CMD_SUCCESS;
7321}
7322
7323DEFPY (no_neighbor_timers_delayopen,
7324 no_neighbor_timers_delayopen_cmd,
7325 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7326 NO_STR
7327 NEIGHBOR_STR
7328 NEIGHBOR_ADDR_STR2
7329 "BGP per neighbor timers\n"
7330 "RFC 4271 DelayOpenTimer\n"
7331 "DelayOpenTime timer interval\n")
7332{
7333 struct peer *peer;
7334
7335 peer = peer_and_group_lookup_vty(vty, neighbor);
7336 if (!peer)
7337 return CMD_WARNING_CONFIG_FAILED;
7338
7339 if (peer_timers_delayopen_unset(peer))
7340 return CMD_WARNING_CONFIG_FAILED;
7341
7342 return CMD_SUCCESS;
7343}
7344
28c6e247
IR
7345static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
7346 const char *time_str, int set)
718e3744 7347{
28c6e247
IR
7348 int ret;
7349 struct peer *peer;
7350 uint32_t routeadv = 0;
718e3744 7351
28c6e247
IR
7352 peer = peer_and_group_lookup_vty(vty, ip_str);
7353 if (!peer)
d62a17ae 7354 return CMD_WARNING_CONFIG_FAILED;
718e3744 7355
28c6e247
IR
7356 if (time_str)
7357 routeadv = strtoul(time_str, NULL, 10);
7358
7359 if (set)
7360 ret = peer_advertise_interval_set(peer, routeadv);
7361 else
7362 ret = peer_advertise_interval_unset(peer);
718e3744 7363
28c6e247 7364 return bgp_vty_return(vty, ret);
718e3744 7365}
7366
28c6e247
IR
7367DEFUN (neighbor_advertise_interval,
7368 neighbor_advertise_interval_cmd,
7369 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7370 NEIGHBOR_STR
7371 NEIGHBOR_ADDR_STR2
7372 "Minimum interval between sending BGP routing updates\n"
7373 "time in seconds\n")
718e3744 7374{
28c6e247
IR
7375 int idx_peer = 1;
7376 int idx_number = 3;
7377 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
7378 argv[idx_number]->arg, 1);
7379}
f4b8ec07 7380
28c6e247
IR
7381DEFUN (no_neighbor_advertise_interval,
7382 no_neighbor_advertise_interval_cmd,
7383 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7384 NO_STR
7385 NEIGHBOR_STR
7386 NEIGHBOR_ADDR_STR2
7387 "Minimum interval between sending BGP routing updates\n"
7388 "time in seconds\n")
7389{
7390 int idx_peer = 2;
7391 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 7392}
7393
6b0655a2 7394
518f0eb1
DS
7395/* Time to wait before processing route-map updates */
7396DEFUN (bgp_set_route_map_delay_timer,
7397 bgp_set_route_map_delay_timer_cmd,
6147e2c6 7398 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
7399 SET_STR
7400 "BGP route-map delay timer\n"
7401 "Time in secs to wait before processing route-map changes\n"
f414725f 7402 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 7403{
d62a17ae 7404 int idx_number = 3;
d7c0a89a 7405 uint32_t rmap_delay_timer;
d62a17ae 7406
7407 if (argv[idx_number]->arg) {
7408 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7409 bm->rmap_update_timer = rmap_delay_timer;
7410
7411 /* if the dynamic update handling is being disabled, and a timer
7412 * is
7413 * running, stop the timer and act as if the timer has already
7414 * fired.
7415 */
7416 if (!rmap_delay_timer && bm->t_rmap_update) {
fa5806c3 7417 THREAD_OFF(bm->t_rmap_update);
d62a17ae 7418 thread_execute(bm->master, bgp_route_map_update_timer,
7419 NULL, 0);
7420 }
7421 return CMD_SUCCESS;
7422 } else {
7423 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7424 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 7425 }
518f0eb1
DS
7426}
7427
7428DEFUN (no_bgp_set_route_map_delay_timer,
7429 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 7430 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 7431 NO_STR
3a2d747c 7432 BGP_STR
518f0eb1 7433 "Default BGP route-map delay timer\n"
8334fd5a
DW
7434 "Reset to default time to wait for processing route-map changes\n"
7435 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 7436{
518f0eb1 7437
d62a17ae 7438 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 7439
d62a17ae 7440 return CMD_SUCCESS;
518f0eb1
DS
7441}
7442
28c6e247
IR
7443/* neighbor interface */
7444static int peer_interface_vty(struct vty *vty, const char *ip_str,
7445 const char *str)
718e3744 7446{
28c6e247 7447 struct peer *peer;
718e3744 7448
28c6e247
IR
7449 peer = peer_lookup_vty(vty, ip_str);
7450 if (!peer || peer->conf_if) {
7451 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
7452 return CMD_WARNING_CONFIG_FAILED;
7453 }
718e3744 7454
28c6e247
IR
7455 if (str)
7456 peer_interface_set(peer, str);
7457 else
7458 peer_interface_unset(peer);
718e3744 7459
28c6e247 7460 return CMD_SUCCESS;
718e3744 7461}
7462
28c6e247
IR
7463DEFUN (neighbor_interface,
7464 neighbor_interface_cmd,
7465 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7466 NEIGHBOR_STR
7467 NEIGHBOR_ADDR_STR
7468 "Interface\n"
7469 "Interface name\n")
718e3744 7470{
28c6e247
IR
7471 int idx_ip = 1;
7472 int idx_word = 3;
294d8425 7473
28c6e247
IR
7474 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
7475}
f4b8ec07 7476
28c6e247
IR
7477DEFUN (no_neighbor_interface,
7478 no_neighbor_interface_cmd,
294d8425 7479 "no neighbor <A.B.C.D|X:X::X:X> interface WORD",
28c6e247
IR
7480 NO_STR
7481 NEIGHBOR_STR
294d8425 7482 NEIGHBOR_ADDR_STR
28c6e247
IR
7483 "Interface\n"
7484 "Interface name\n")
7485{
7486 int idx_peer = 2;
294d8425 7487
28c6e247 7488 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 7489}
6b0655a2 7490
718e3744 7491DEFUN (neighbor_distribute_list,
7492 neighbor_distribute_list_cmd,
c60dec36 7493 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
718e3744 7494 NEIGHBOR_STR
7495 NEIGHBOR_ADDR_STR2
7496 "Filter updates to/from this neighbor\n"
718e3744 7497 "IP Access-list name\n"
7498 "Filter incoming updates\n"
7499 "Filter outgoing updates\n")
7500{
d62a17ae 7501 int idx_peer = 1;
7502 int idx_acl = 3;
7503 int direct, ret;
7504 struct peer *peer;
a8206004 7505
d62a17ae 7506 const char *pstr = argv[idx_peer]->arg;
7507 const char *acl = argv[idx_acl]->arg;
7508 const char *inout = argv[argc - 1]->text;
a8206004 7509
d62a17ae 7510 peer = peer_and_group_lookup_vty(vty, pstr);
7511 if (!peer)
7512 return CMD_WARNING_CONFIG_FAILED;
a8206004 7513
d62a17ae 7514 /* Check filter direction. */
7515 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7516 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7517 direct, acl);
a8206004 7518
d62a17ae 7519 return bgp_vty_return(vty, ret);
718e3744 7520}
7521
d62a17ae 7522ALIAS_HIDDEN(
7523 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
c60dec36 7524 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
d62a17ae 7525 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7526 "Filter updates to/from this neighbor\n"
d62a17ae 7527 "IP Access-list name\n"
7528 "Filter incoming updates\n"
7529 "Filter outgoing updates\n")
596c17ba 7530
718e3744 7531DEFUN (no_neighbor_distribute_list,
7532 no_neighbor_distribute_list_cmd,
c60dec36 7533 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
718e3744 7534 NO_STR
7535 NEIGHBOR_STR
7536 NEIGHBOR_ADDR_STR2
7537 "Filter updates to/from this neighbor\n"
718e3744 7538 "IP Access-list name\n"
7539 "Filter incoming updates\n"
7540 "Filter outgoing updates\n")
7541{
d62a17ae 7542 int idx_peer = 2;
7543 int direct, ret;
7544 struct peer *peer;
a8206004 7545
d62a17ae 7546 const char *pstr = argv[idx_peer]->arg;
7547 const char *inout = argv[argc - 1]->text;
a8206004 7548
d62a17ae 7549 peer = peer_and_group_lookup_vty(vty, pstr);
7550 if (!peer)
7551 return CMD_WARNING_CONFIG_FAILED;
a8206004 7552
d62a17ae 7553 /* Check filter direction. */
7554 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7555 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7556 direct);
a8206004 7557
d62a17ae 7558 return bgp_vty_return(vty, ret);
718e3744 7559}
6b0655a2 7560
d62a17ae 7561ALIAS_HIDDEN(
7562 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
c60dec36 7563 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
d62a17ae 7564 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7565 "Filter updates to/from this neighbor\n"
d62a17ae 7566 "IP Access-list name\n"
7567 "Filter incoming updates\n"
7568 "Filter outgoing updates\n")
596c17ba 7569
718e3744 7570/* Set prefix list to the peer. */
642ef664
IR
7571static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
7572 afi_t afi, safi_t safi,
7573 const char *name_str,
7574 const char *direct_str)
718e3744 7575{
642ef664
IR
7576 int ret;
7577 int direct = FILTER_IN;
7578 struct peer *peer;
718e3744 7579
642ef664
IR
7580 peer = peer_and_group_lookup_vty(vty, ip_str);
7581 if (!peer)
d62a17ae 7582 return CMD_WARNING_CONFIG_FAILED;
e52702f2 7583
642ef664
IR
7584 /* Check filter direction. */
7585 if (strncmp(direct_str, "i", 1) == 0)
7586 direct = FILTER_IN;
7587 else if (strncmp(direct_str, "o", 1) == 0)
7588 direct = FILTER_OUT;
718e3744 7589
642ef664 7590 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 7591
642ef664
IR
7592 return bgp_vty_return(vty, ret);
7593}
7594
7595static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
7596 afi_t afi, safi_t safi,
7597 const char *direct_str)
7598{
7599 int ret;
7600 struct peer *peer;
7601 int direct = FILTER_IN;
7602
7603 peer = peer_and_group_lookup_vty(vty, ip_str);
7604 if (!peer)
7605 return CMD_WARNING_CONFIG_FAILED;
7606
7607 /* Check filter direction. */
7608 if (strncmp(direct_str, "i", 1) == 0)
7609 direct = FILTER_IN;
7610 else if (strncmp(direct_str, "o", 1) == 0)
7611 direct = FILTER_OUT;
7612
7613 ret = peer_prefix_list_unset(peer, afi, safi, direct);
7614
7615 return bgp_vty_return(vty, ret);
7616}
7617
7618DEFUN (neighbor_prefix_list,
7619 neighbor_prefix_list_cmd,
7620 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7621 NEIGHBOR_STR
7622 NEIGHBOR_ADDR_STR2
7623 "Filter updates to/from this neighbor\n"
7624 "Name of a prefix list\n"
7625 "Filter incoming updates\n"
7626 "Filter outgoing updates\n")
7627{
7628 int idx_peer = 1;
7629 int idx_word = 3;
7630 int idx_in_out = 4;
7631 return peer_prefix_list_set_vty(
7632 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7633 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 7634}
7635
d62a17ae 7636ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7637 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7638 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7639 "Filter updates to/from this neighbor\n"
7640 "Name of a prefix list\n"
7641 "Filter incoming updates\n"
7642 "Filter outgoing updates\n")
596c17ba 7643
642ef664
IR
7644DEFUN (no_neighbor_prefix_list,
7645 no_neighbor_prefix_list_cmd,
7646 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7647 NO_STR
7648 NEIGHBOR_STR
7649 NEIGHBOR_ADDR_STR2
7650 "Filter updates to/from this neighbor\n"
7651 "Name of a prefix list\n"
7652 "Filter incoming updates\n"
7653 "Filter outgoing updates\n")
7654{
7655 int idx_peer = 2;
7656 int idx_in_out = 5;
7657 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7658 bgp_node_afi(vty), bgp_node_safi(vty),
7659 argv[idx_in_out]->arg);
7660}
7661
7662ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7663 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7664 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7665 "Filter updates to/from this neighbor\n"
7666 "Name of a prefix list\n"
7667 "Filter incoming updates\n"
7668 "Filter outgoing updates\n")
7669
d62a17ae 7670static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7671 safi_t safi, const char *name_str,
7672 const char *direct_str)
718e3744 7673{
d62a17ae 7674 int ret;
7675 struct peer *peer;
7676 int direct = FILTER_IN;
718e3744 7677
d62a17ae 7678 peer = peer_and_group_lookup_vty(vty, ip_str);
7679 if (!peer)
7680 return CMD_WARNING_CONFIG_FAILED;
718e3744 7681
d62a17ae 7682 /* Check filter direction. */
7683 if (strncmp(direct_str, "i", 1) == 0)
7684 direct = FILTER_IN;
7685 else if (strncmp(direct_str, "o", 1) == 0)
7686 direct = FILTER_OUT;
718e3744 7687
d62a17ae 7688 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 7689
d62a17ae 7690 return bgp_vty_return(vty, ret);
718e3744 7691}
7692
d62a17ae 7693static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7694 safi_t safi, const char *direct_str)
718e3744 7695{
d62a17ae 7696 int ret;
7697 struct peer *peer;
7698 int direct = FILTER_IN;
718e3744 7699
d62a17ae 7700 peer = peer_and_group_lookup_vty(vty, ip_str);
7701 if (!peer)
7702 return CMD_WARNING_CONFIG_FAILED;
718e3744 7703
d62a17ae 7704 /* Check filter direction. */
7705 if (strncmp(direct_str, "i", 1) == 0)
7706 direct = FILTER_IN;
7707 else if (strncmp(direct_str, "o", 1) == 0)
7708 direct = FILTER_OUT;
718e3744 7709
d62a17ae 7710 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 7711
d62a17ae 7712 return bgp_vty_return(vty, ret);
718e3744 7713}
7714
7715DEFUN (neighbor_filter_list,
7716 neighbor_filter_list_cmd,
de71d43e 7717 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
718e3744 7718 NEIGHBOR_STR
7719 NEIGHBOR_ADDR_STR2
7720 "Establish BGP filters\n"
7721 "AS path access-list name\n"
7722 "Filter incoming routes\n"
7723 "Filter outgoing routes\n")
7724{
d62a17ae 7725 int idx_peer = 1;
7726 int idx_word = 3;
7727 int idx_in_out = 4;
7728 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7729 bgp_node_safi(vty), argv[idx_word]->arg,
7730 argv[idx_in_out]->arg);
718e3744 7731}
7732
d62a17ae 7733ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
de71d43e 7734 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
d62a17ae 7735 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7736 "Establish BGP filters\n"
7737 "AS path access-list name\n"
7738 "Filter incoming routes\n"
7739 "Filter outgoing routes\n")
596c17ba 7740
718e3744 7741DEFUN (no_neighbor_filter_list,
7742 no_neighbor_filter_list_cmd,
de71d43e 7743 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
718e3744 7744 NO_STR
7745 NEIGHBOR_STR
7746 NEIGHBOR_ADDR_STR2
7747 "Establish BGP filters\n"
7748 "AS path access-list name\n"
7749 "Filter incoming routes\n"
7750 "Filter outgoing routes\n")
7751{
d62a17ae 7752 int idx_peer = 2;
7753 int idx_in_out = 5;
7754 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7755 bgp_node_afi(vty), bgp_node_safi(vty),
7756 argv[idx_in_out]->arg);
718e3744 7757}
6b0655a2 7758
d62a17ae 7759ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
de71d43e 7760 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
d62a17ae 7761 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7762 "Establish BGP filters\n"
7763 "AS path access-list name\n"
7764 "Filter incoming routes\n"
7765 "Filter outgoing routes\n")
596c17ba 7766
7f7940e6
MK
7767/* Set advertise-map to the peer. */
7768static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7769 afi_t afi, safi_t safi,
cf2ad4d8
MK
7770 const char *advertise_str,
7771 const char *condition_str, bool condition,
7772 bool set)
7f7940e6
MK
7773{
7774 int ret = CMD_WARNING_CONFIG_FAILED;
7775 struct peer *peer;
7776 struct route_map *advertise_map;
7777 struct route_map *condition_map;
7778
7779 peer = peer_and_group_lookup_vty(vty, ip_str);
7780 if (!peer)
7781 return ret;
7782
7783 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7784 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7785
cf2ad4d8
MK
7786 if (set)
7787 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7788 advertise_map, condition_str,
7789 condition_map, condition);
7790 else
7791 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7792 advertise_map, condition_str,
7793 condition_map, condition);
7f7940e6
MK
7794
7795 return bgp_vty_return(vty, ret);
7796}
7797
389e4f92
QY
7798DEFPY (bgp_condadv_period,
7799 bgp_condadv_period_cmd,
7800 "[no$no] bgp conditional-advertisement timer (5-240)$period",
7801 NO_STR
7802 BGP_STR
7803 "Conditional advertisement settings\n"
7804 "Set period to rescan BGP table to check if condition is met\n"
7805 "Period between BGP table scans, in seconds; default 60\n")
7806{
7807 VTY_DECLVAR_CONTEXT(bgp, bgp);
7808
7809 bgp->condition_check_period =
7810 no ? DEFAULT_CONDITIONAL_ROUTES_POLL_TIME : period;
7811
7812 return CMD_SUCCESS;
7813}
7814
cf2ad4d8 7815DEFPY (neighbor_advertise_map,
7f7940e6 7816 neighbor_advertise_map_cmd,
3ccddc25 7817 "[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 7818 NO_STR
7f7940e6
MK
7819 NEIGHBOR_STR
7820 NEIGHBOR_ADDR_STR2
7821 "Route-map to conditionally advertise routes\n"
7822 "Name of advertise map\n"
7823 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 7824 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 7825 "Name of the exist or non exist map\n")
7f7940e6 7826{
7f7940e6
MK
7827 bool condition = CONDITION_EXIST;
7828
52b84062 7829 if (!strcmp(exist, "non-exist-map"))
7f7940e6
MK
7830 condition = CONDITION_NON_EXIST;
7831
52b84062
MK
7832 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7833 bgp_node_safi(vty), advertise_str,
7834 condition_str, condition, !no);
7f7940e6
MK
7835}
7836
7837ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
3ccddc25 7838 "[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
7839 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7840 "Route-map to conditionally advertise routes\n"
7841 "Name of advertise map\n"
7842 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 7843 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 7844 "Name of the exist or non exist map\n")
7f7940e6 7845
718e3744 7846/* Set route-map to the peer. */
0ea8d871
IR
7847static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7848 afi_t afi, safi_t safi, const char *name_str,
7849 const char *direct_str)
718e3744 7850{
0ea8d871
IR
7851 int ret;
7852 struct peer *peer;
7853 int direct = RMAP_IN;
7854 struct route_map *route_map;
718e3744 7855
0ea8d871
IR
7856 peer = peer_and_group_lookup_vty(vty, ip_str);
7857 if (!peer)
d62a17ae 7858 return CMD_WARNING_CONFIG_FAILED;
718e3744 7859
0ea8d871
IR
7860 /* Check filter direction. */
7861 if (strncmp(direct_str, "in", 2) == 0)
7862 direct = RMAP_IN;
7863 else if (strncmp(direct_str, "o", 1) == 0)
7864 direct = RMAP_OUT;
718e3744 7865
0ea8d871
IR
7866 route_map = route_map_lookup_warn_noexist(vty, name_str);
7867 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
718e3744 7868
0ea8d871
IR
7869 return bgp_vty_return(vty, ret);
7870}
7871
7872static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7873 afi_t afi, safi_t safi,
7874 const char *direct_str)
7875{
7876 int ret;
7877 struct peer *peer;
7878 int direct = RMAP_IN;
7879
7880 peer = peer_and_group_lookup_vty(vty, ip_str);
7881 if (!peer)
7882 return CMD_WARNING_CONFIG_FAILED;
7883
7884 /* Check filter direction. */
7885 if (strncmp(direct_str, "in", 2) == 0)
7886 direct = RMAP_IN;
7887 else if (strncmp(direct_str, "o", 1) == 0)
7888 direct = RMAP_OUT;
7889
7890 ret = peer_route_map_unset(peer, afi, safi, direct);
7891
7892 return bgp_vty_return(vty, ret);
7893}
7894
7895DEFUN (neighbor_route_map,
7896 neighbor_route_map_cmd,
70dd370f 7897 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
0ea8d871
IR
7898 NEIGHBOR_STR
7899 NEIGHBOR_ADDR_STR2
7900 "Apply route map to neighbor\n"
7901 "Name of route map\n"
7902 "Apply map to incoming routes\n"
7903 "Apply map to outbound routes\n")
7904{
7905 int idx_peer = 1;
7906 int idx_word = 3;
7907 int idx_in_out = 4;
7908 return peer_route_map_set_vty(
7909 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7910 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 7911}
7912
d6d7ed37 7913ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
70dd370f 7914 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
d6d7ed37
IR
7915 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7916 "Apply route map to neighbor\n"
7917 "Name of route map\n"
7918 "Apply map to incoming routes\n"
7919 "Apply map to outbound routes\n")
7920
0ea8d871
IR
7921DEFUN (no_neighbor_route_map,
7922 no_neighbor_route_map_cmd,
70dd370f 7923 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
0ea8d871
IR
7924 NO_STR
7925 NEIGHBOR_STR
7926 NEIGHBOR_ADDR_STR2
7927 "Apply route map to neighbor\n"
7928 "Name of route map\n"
7929 "Apply map to incoming routes\n"
7930 "Apply map to outbound routes\n")
7931{
7932 int idx_peer = 2;
7933 int idx_in_out = 5;
7934 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
7935 bgp_node_afi(vty), bgp_node_safi(vty),
7936 argv[idx_in_out]->arg);
7937}
7938
7939ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
70dd370f 7940 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
d6d7ed37
IR
7941 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7942 "Apply route map to neighbor\n"
7943 "Name of route map\n"
7944 "Apply map to incoming routes\n"
7945 "Apply map to outbound routes\n")
7946
718e3744 7947/* Set unsuppress-map to the peer. */
d62a17ae 7948static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
7949 afi_t afi, safi_t safi,
7950 const char *name_str)
718e3744 7951{
d62a17ae 7952 int ret;
7953 struct peer *peer;
1de27621 7954 struct route_map *route_map;
718e3744 7955
d62a17ae 7956 peer = peer_and_group_lookup_vty(vty, ip_str);
7957 if (!peer)
7958 return CMD_WARNING_CONFIG_FAILED;
718e3744 7959
1de27621
DA
7960 route_map = route_map_lookup_warn_noexist(vty, name_str);
7961 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
718e3744 7962
d62a17ae 7963 return bgp_vty_return(vty, ret);
718e3744 7964}
7965
7966/* Unset route-map from the peer. */
d62a17ae 7967static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
7968 afi_t afi, safi_t safi)
718e3744 7969{
d62a17ae 7970 int ret;
7971 struct peer *peer;
718e3744 7972
d62a17ae 7973 peer = peer_and_group_lookup_vty(vty, ip_str);
7974 if (!peer)
7975 return CMD_WARNING_CONFIG_FAILED;
718e3744 7976
d62a17ae 7977 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 7978
d62a17ae 7979 return bgp_vty_return(vty, ret);
718e3744 7980}
7981
7982DEFUN (neighbor_unsuppress_map,
7983 neighbor_unsuppress_map_cmd,
9ccf14f7 7984 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 7985 NEIGHBOR_STR
7986 NEIGHBOR_ADDR_STR2
7987 "Route-map to selectively unsuppress suppressed routes\n"
7988 "Name of route map\n")
7989{
d62a17ae 7990 int idx_peer = 1;
7991 int idx_word = 3;
7992 return peer_unsuppress_map_set_vty(
7993 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7994 argv[idx_word]->arg);
718e3744 7995}
7996
d62a17ae 7997ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
7998 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7999 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8000 "Route-map to selectively unsuppress suppressed routes\n"
8001 "Name of route map\n")
596c17ba 8002
718e3744 8003DEFUN (no_neighbor_unsuppress_map,
8004 no_neighbor_unsuppress_map_cmd,
9ccf14f7 8005 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 8006 NO_STR
8007 NEIGHBOR_STR
8008 NEIGHBOR_ADDR_STR2
8009 "Route-map to selectively unsuppress suppressed routes\n"
8010 "Name of route map\n")
8011{
d62a17ae 8012 int idx_peer = 2;
8013 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
8014 bgp_node_afi(vty),
8015 bgp_node_safi(vty));
718e3744 8016}
6b0655a2 8017
d62a17ae 8018ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
8019 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8020 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8021 "Route-map to selectively unsuppress suppressed routes\n"
8022 "Name of route map\n")
596c17ba 8023
7e62b792
IR
8024static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
8025 afi_t afi, safi_t safi,
8026 const char *num_str,
8027 const char *threshold_str, int warning,
8028 const char *restart_str,
8029 const char *force_str)
8030{
8031 int ret;
8032 struct peer *peer;
8033 uint32_t max;
8034 uint8_t threshold;
8035 uint16_t restart;
8036
8037 peer = peer_and_group_lookup_vty(vty, ip_str);
8038 if (!peer)
8039 return CMD_WARNING_CONFIG_FAILED;
8040
8041 max = strtoul(num_str, NULL, 10);
8042 if (threshold_str)
8043 threshold = atoi(threshold_str);
8044 else
8045 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
8046
8047 if (restart_str)
8048 restart = atoi(restart_str);
8049 else
8050 restart = 0;
8051
8052 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
8053 restart, force_str ? true : false);
8054
8055 return bgp_vty_return(vty, ret);
8056}
8057
8058static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
8059 afi_t afi, safi_t safi)
8060{
8061 int ret;
8062 struct peer *peer;
8063
8064 peer = peer_and_group_lookup_vty(vty, ip_str);
8065 if (!peer)
8066 return CMD_WARNING_CONFIG_FAILED;
8067
8068 ret = peer_maximum_prefix_unset(peer, afi, safi);
8069
8070 return bgp_vty_return(vty, ret);
8071}
8072
fde246e8 8073/* Maximum number of prefix to be sent to the neighbor. */
1d80f243
IR
8074DEFUN(neighbor_maximum_prefix_out,
8075 neighbor_maximum_prefix_out_cmd,
8076 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
8077 NEIGHBOR_STR
8078 NEIGHBOR_ADDR_STR2
8079 "Maximum number of prefixes to be sent to this peer\n"
8080 "Maximum no. of prefix limit\n")
fde246e8 8081{
80444d30 8082 int ret;
fde246e8
DA
8083 int idx_peer = 1;
8084 int idx_number = 3;
7e62b792
IR
8085 struct peer *peer;
8086 uint32_t max;
fde246e8
DA
8087 afi_t afi = bgp_node_afi(vty);
8088 safi_t safi = bgp_node_safi(vty);
8089
7e62b792
IR
8090 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8091 if (!peer)
fde246e8
DA
8092 return CMD_WARNING_CONFIG_FAILED;
8093
7e62b792 8094 max = strtoul(argv[idx_number]->arg, NULL, 10);
fde246e8 8095
80444d30 8096 ret = peer_maximum_prefix_out_set(peer, afi, safi, max);
fde246e8 8097
80444d30 8098 return bgp_vty_return(vty, ret);
fde246e8
DA
8099}
8100
1d80f243
IR
8101DEFUN(no_neighbor_maximum_prefix_out,
8102 no_neighbor_maximum_prefix_out_cmd,
bc03c622 8103 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out [(1-4294967295)]",
1d80f243
IR
8104 NO_STR
8105 NEIGHBOR_STR
8106 NEIGHBOR_ADDR_STR2
bc03c622
LS
8107 "Maximum number of prefixes to be sent to this peer\n"
8108 "Maximum no. of prefix limit\n")
fde246e8 8109{
80444d30 8110 int ret;
fde246e8 8111 int idx_peer = 2;
7e62b792 8112 struct peer *peer;
fde246e8
DA
8113 afi_t afi = bgp_node_afi(vty);
8114 safi_t safi = bgp_node_safi(vty);
8115
7e62b792
IR
8116 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8117 if (!peer)
fde246e8
DA
8118 return CMD_WARNING_CONFIG_FAILED;
8119
80444d30 8120 ret = peer_maximum_prefix_out_unset(peer, afi, safi);
fde246e8 8121
80444d30 8122 return bgp_vty_return(vty, ret);
fde246e8
DA
8123}
8124
9cbd06e0
DA
8125/* Maximum number of prefix configuration. Prefix count is different
8126 for each peer configuration. So this configuration can be set for
718e3744 8127 each peer configuration. */
1d80f243
IR
8128DEFUN (neighbor_maximum_prefix,
8129 neighbor_maximum_prefix_cmd,
8130 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8131 NEIGHBOR_STR
8132 NEIGHBOR_ADDR_STR2
8133 "Maximum number of prefix accept from this peer\n"
8134 "maximum no. of prefix limit\n"
8135 "Force checking all received routes not only accepted\n")
718e3744 8136{
d62a17ae 8137 int idx_peer = 1;
8138 int idx_number = 3;
9cbd06e0 8139 int idx_force = 0;
7e62b792 8140 char *force = NULL;
9cbd06e0
DA
8141
8142 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 8143 force = argv[idx_force]->arg;
9cbd06e0 8144
7e62b792
IR
8145 return peer_maximum_prefix_set_vty(
8146 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8147 argv[idx_number]->arg, NULL, 0, NULL, force);
718e3744 8148}
8149
d62a17ae 8150ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 8151 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
d62a17ae 8152 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8153 "Maximum number of prefix accept from this peer\n"
9cbd06e0
DA
8154 "maximum no. of prefix limit\n"
8155 "Force checking all received routes not only accepted\n")
596c17ba 8156
1d80f243
IR
8157DEFUN (neighbor_maximum_prefix_threshold,
8158 neighbor_maximum_prefix_threshold_cmd,
8159 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8160 NEIGHBOR_STR
8161 NEIGHBOR_ADDR_STR2
8162 "Maximum number of prefix accept from this peer\n"
8163 "maximum no. of prefix limit\n"
8164 "Threshold value (%) at which to generate a warning msg\n"
8165 "Force checking all received routes not only accepted\n")
e0701b79 8166{
d62a17ae 8167 int idx_peer = 1;
8168 int idx_number = 3;
8169 int idx_number_2 = 4;
9cbd06e0 8170 int idx_force = 0;
7e62b792 8171 char *force = NULL;
9cbd06e0
DA
8172
8173 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 8174 force = argv[idx_force]->arg;
9cbd06e0 8175
7e62b792
IR
8176 return peer_maximum_prefix_set_vty(
8177 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8178 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
0a486e5f 8179}
e0701b79 8180
d62a17ae 8181ALIAS_HIDDEN(
8182 neighbor_maximum_prefix_threshold,
8183 neighbor_maximum_prefix_threshold_hidden_cmd,
9cbd06e0 8184 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
d62a17ae 8185 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8186 "Maximum number of prefix accept from this peer\n"
8187 "maximum no. of prefix limit\n"
9cbd06e0
DA
8188 "Threshold value (%) at which to generate a warning msg\n"
8189 "Force checking all received routes not only accepted\n")
596c17ba 8190
1d80f243
IR
8191DEFUN (neighbor_maximum_prefix_warning,
8192 neighbor_maximum_prefix_warning_cmd,
8193 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8194 NEIGHBOR_STR
8195 NEIGHBOR_ADDR_STR2
8196 "Maximum number of prefix accept from this peer\n"
8197 "maximum no. of prefix limit\n"
8198 "Only give warning message when limit is exceeded\n"
8199 "Force checking all received routes not only accepted\n")
718e3744 8200{
d62a17ae 8201 int idx_peer = 1;
8202 int idx_number = 3;
9cbd06e0 8203 int idx_force = 0;
7e62b792 8204 char *force = NULL;
9cbd06e0
DA
8205
8206 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 8207 force = argv[idx_force]->arg;
9cbd06e0 8208
7e62b792
IR
8209 return peer_maximum_prefix_set_vty(
8210 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8211 argv[idx_number]->arg, NULL, 1, NULL, force);
718e3744 8212}
8213
d62a17ae 8214ALIAS_HIDDEN(
8215 neighbor_maximum_prefix_warning,
8216 neighbor_maximum_prefix_warning_hidden_cmd,
9cbd06e0 8217 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
d62a17ae 8218 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8219 "Maximum number of prefix accept from this peer\n"
8220 "maximum no. of prefix limit\n"
9cbd06e0
DA
8221 "Only give warning message when limit is exceeded\n"
8222 "Force checking all received routes not only accepted\n")
596c17ba 8223
1d80f243
IR
8224DEFUN (neighbor_maximum_prefix_threshold_warning,
8225 neighbor_maximum_prefix_threshold_warning_cmd,
8226 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8227 NEIGHBOR_STR
8228 NEIGHBOR_ADDR_STR2
8229 "Maximum number of prefix accept from this peer\n"
8230 "maximum no. of prefix limit\n"
8231 "Threshold value (%) at which to generate a warning msg\n"
8232 "Only give warning message when limit is exceeded\n"
8233 "Force checking all received routes not only accepted\n")
e0701b79 8234{
d62a17ae 8235 int idx_peer = 1;
8236 int idx_number = 3;
8237 int idx_number_2 = 4;
9cbd06e0 8238 int idx_force = 0;
7e62b792 8239 char *force = NULL;
9cbd06e0
DA
8240
8241 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 8242 force = argv[idx_force]->arg;
9cbd06e0 8243
7e62b792
IR
8244 return peer_maximum_prefix_set_vty(
8245 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8246 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
0a486e5f 8247}
8248
d62a17ae 8249ALIAS_HIDDEN(
8250 neighbor_maximum_prefix_threshold_warning,
8251 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
9cbd06e0 8252 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
d62a17ae 8253 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8254 "Maximum number of prefix accept from this peer\n"
8255 "maximum no. of prefix limit\n"
8256 "Threshold value (%) at which to generate a warning msg\n"
9cbd06e0
DA
8257 "Only give warning message when limit is exceeded\n"
8258 "Force checking all received routes not only accepted\n")
596c17ba 8259
1d80f243
IR
8260DEFUN (neighbor_maximum_prefix_restart,
8261 neighbor_maximum_prefix_restart_cmd,
8262 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8263 NEIGHBOR_STR
8264 NEIGHBOR_ADDR_STR2
8265 "Maximum number of prefix accept from this peer\n"
8266 "maximum no. of prefix limit\n"
8267 "Restart bgp connection after limit is exceeded\n"
8268 "Restart interval in minutes\n"
8269 "Force checking all received routes not only accepted\n")
0a486e5f 8270{
d62a17ae 8271 int idx_peer = 1;
8272 int idx_number = 3;
8273 int idx_number_2 = 5;
9cbd06e0 8274 int idx_force = 0;
7e62b792 8275 char *force = NULL;
9cbd06e0
DA
8276
8277 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 8278 force = argv[idx_force]->arg;
9cbd06e0 8279
7e62b792
IR
8280 return peer_maximum_prefix_set_vty(
8281 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8282 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
0a486e5f 8283}
8284
d62a17ae 8285ALIAS_HIDDEN(
8286 neighbor_maximum_prefix_restart,
8287 neighbor_maximum_prefix_restart_hidden_cmd,
9cbd06e0 8288 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
d62a17ae 8289 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8290 "Maximum number of prefix accept from this peer\n"
8291 "maximum no. of prefix limit\n"
8292 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
8293 "Restart interval in minutes\n"
8294 "Force checking all received routes not only accepted\n")
596c17ba 8295
1d80f243
IR
8296DEFUN (neighbor_maximum_prefix_threshold_restart,
8297 neighbor_maximum_prefix_threshold_restart_cmd,
8298 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8299 NEIGHBOR_STR
8300 NEIGHBOR_ADDR_STR2
8301 "Maximum number of prefixes to accept from this peer\n"
8302 "maximum no. of prefix limit\n"
8303 "Threshold value (%) at which to generate a warning msg\n"
8304 "Restart bgp connection after limit is exceeded\n"
8305 "Restart interval in minutes\n"
8306 "Force checking all received routes not only accepted\n")
0a486e5f 8307{
d62a17ae 8308 int idx_peer = 1;
8309 int idx_number = 3;
8310 int idx_number_2 = 4;
8311 int idx_number_3 = 6;
9cbd06e0 8312 int idx_force = 0;
7e62b792 8313 char *force = NULL;
9cbd06e0
DA
8314
8315 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 8316 force = argv[idx_force]->arg;
9cbd06e0 8317
7e62b792
IR
8318 return peer_maximum_prefix_set_vty(
8319 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8320 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
8321 argv[idx_number_3]->arg, force);
d62a17ae 8322}
8323
8324ALIAS_HIDDEN(
8325 neighbor_maximum_prefix_threshold_restart,
8326 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
9cbd06e0 8327 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
d62a17ae 8328 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8329 "Maximum number of prefixes to accept from this peer\n"
8330 "maximum no. of prefix limit\n"
8331 "Threshold value (%) at which to generate a warning msg\n"
8332 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
8333 "Restart interval in minutes\n"
8334 "Force checking all received routes not only accepted\n")
596c17ba 8335
1d80f243
IR
8336DEFUN (no_neighbor_maximum_prefix,
8337 no_neighbor_maximum_prefix_cmd,
8338 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8339 NO_STR
8340 NEIGHBOR_STR
8341 NEIGHBOR_ADDR_STR2
8342 "Maximum number of prefixes to accept from this peer\n"
8343 "maximum no. of prefix limit\n"
8344 "Threshold value (%) at which to generate a warning msg\n"
8345 "Restart bgp connection after limit is exceeded\n"
8346 "Restart interval in minutes\n"
8347 "Only give warning message when limit is exceeded\n"
8348 "Force checking all received routes not only accepted\n")
718e3744 8349{
d62a17ae 8350 int idx_peer = 2;
7e62b792
IR
8351 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
8352 bgp_node_afi(vty),
8353 bgp_node_safi(vty));
718e3744 8354}
e52702f2 8355
d62a17ae 8356ALIAS_HIDDEN(
8357 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 8358 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
d62a17ae 8359 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8360 "Maximum number of prefixes to accept from this peer\n"
8361 "maximum no. of prefix limit\n"
8362 "Threshold value (%) at which to generate a warning msg\n"
8363 "Restart bgp connection after limit is exceeded\n"
8364 "Restart interval in minutes\n"
9cbd06e0
DA
8365 "Only give warning message when limit is exceeded\n"
8366 "Force checking all received routes not only accepted\n")
596c17ba 8367
46dbf9d0
DA
8368/* "neighbor accept-own" */
8369DEFPY (neighbor_accept_own,
8370 neighbor_accept_own_cmd,
8371 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor accept-own",
8372 NO_STR
8373 NEIGHBOR_STR
8374 NEIGHBOR_ADDR_STR2
8375 "Enable handling of self-originated VPN routes containing ACCEPT_OWN community\n")
8376{
8377 struct peer *peer;
8378 afi_t afi = bgp_node_afi(vty);
8379 safi_t safi = bgp_node_safi(vty);
8380 int ret;
8381
8382 peer = peer_and_group_lookup_vty(vty, neighbor);
8383 if (!peer)
8384 return CMD_WARNING_CONFIG_FAILED;
8385
8386 if (no)
8387 ret = peer_af_flag_unset(peer, afi, safi, PEER_FLAG_ACCEPT_OWN);
8388 else
8389 ret = peer_af_flag_set(peer, afi, safi, PEER_FLAG_ACCEPT_OWN);
8390
8391 return bgp_vty_return(vty, ret);
8392}
8393
01da2d26
DA
8394/* "neighbor soo" */
8395DEFPY (neighbor_soo,
8396 neighbor_soo_cmd,
8397 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo ASN:NN_OR_IP-ADDRESS:NN$soo",
8398 NEIGHBOR_STR
8399 NEIGHBOR_ADDR_STR2
8400 "Set the Site-of-Origin (SoO) extended community\n"
8401 "VPN extended community\n")
8402{
8403 struct peer *peer;
8404 afi_t afi = bgp_node_afi(vty);
8405 safi_t safi = bgp_node_safi(vty);
8406 struct ecommunity *ecomm_soo;
8407
8408 peer = peer_and_group_lookup_vty(vty, neighbor);
8409 if (!peer)
8410 return CMD_WARNING_CONFIG_FAILED;
8411
8412 ecomm_soo = ecommunity_str2com(soo, ECOMMUNITY_SITE_ORIGIN, 0);
8413 if (!ecomm_soo) {
8414 vty_out(vty, "%% Malformed SoO extended community\n");
8415 return CMD_WARNING;
8416 }
8417 ecommunity_str(ecomm_soo);
8418
8419 if (!ecommunity_match(peer->soo[afi][safi], ecomm_soo)) {
8420 ecommunity_free(&peer->soo[afi][safi]);
8421 peer->soo[afi][safi] = ecomm_soo;
8422 peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO);
8423 }
8424
8425 return bgp_vty_return(vty,
8426 peer_af_flag_set(peer, afi, safi, PEER_FLAG_SOO));
8427}
8428
8429DEFPY (no_neighbor_soo,
8430 no_neighbor_soo_cmd,
8431 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo [ASN:NN_OR_IP-ADDRESS:NN$soo]",
8432 NO_STR
8433 NEIGHBOR_STR
8434 NEIGHBOR_ADDR_STR2
8435 "Set the Site-of-Origin (SoO) extended community\n"
8436 "VPN extended community\n")
8437{
8438 struct peer *peer;
8439 afi_t afi = bgp_node_afi(vty);
8440 safi_t safi = bgp_node_safi(vty);
8441
8442 peer = peer_and_group_lookup_vty(vty, neighbor);
8443 if (!peer)
8444 return CMD_WARNING_CONFIG_FAILED;
8445
8446 ecommunity_free(&peer->soo[afi][safi]);
8447
8448 return bgp_vty_return(
8449 vty, peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO));
8450}
718e3744 8451
718e3744 8452/* "neighbor allowas-in" */
8453DEFUN (neighbor_allowas_in,
8454 neighbor_allowas_in_cmd,
fd8503f5 8455 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 8456 NEIGHBOR_STR
8457 NEIGHBOR_ADDR_STR2
31500417 8458 "Accept as-path with my AS present in it\n"
f79f7a7b 8459 "Number of occurrences of AS number\n"
fd8503f5 8460 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 8461{
d62a17ae 8462 int idx_peer = 1;
8463 int idx_number_origin = 3;
8464 int ret;
8465 int origin = 0;
8466 struct peer *peer;
8467 int allow_num = 0;
8468
8469 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8470 if (!peer)
8471 return CMD_WARNING_CONFIG_FAILED;
8472
8473 if (argc <= idx_number_origin)
8474 allow_num = 3;
8475 else {
8476 if (argv[idx_number_origin]->type == WORD_TKN)
8477 origin = 1;
8478 else
8479 allow_num = atoi(argv[idx_number_origin]->arg);
8480 }
8481
8482 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8483 allow_num, origin);
8484
8485 return bgp_vty_return(vty, ret);
8486}
8487
8488ALIAS_HIDDEN(
8489 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8490 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8491 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8492 "Accept as-path with my AS present in it\n"
f79f7a7b 8493 "Number of occurrences of AS number\n"
d62a17ae 8494 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 8495
718e3744 8496DEFUN (no_neighbor_allowas_in,
8497 no_neighbor_allowas_in_cmd,
fd8503f5 8498 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 8499 NO_STR
8500 NEIGHBOR_STR
8501 NEIGHBOR_ADDR_STR2
8334fd5a 8502 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8503 "Number of occurrences of AS number\n"
fd8503f5 8504 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 8505{
d62a17ae 8506 int idx_peer = 2;
8507 int ret;
8508 struct peer *peer;
718e3744 8509
d62a17ae 8510 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8511 if (!peer)
8512 return CMD_WARNING_CONFIG_FAILED;
718e3744 8513
d62a17ae 8514 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8515 bgp_node_safi(vty));
718e3744 8516
d62a17ae 8517 return bgp_vty_return(vty, ret);
718e3744 8518}
6b0655a2 8519
d62a17ae 8520ALIAS_HIDDEN(
8521 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8522 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8523 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8524 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8525 "Number of occurrences of AS number\n"
d62a17ae 8526 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 8527
28c6e247
IR
8528DEFUN (neighbor_ttl_security,
8529 neighbor_ttl_security_cmd,
8530 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8531 NEIGHBOR_STR
8532 NEIGHBOR_ADDR_STR2
8533 "BGP ttl-security parameters\n"
8534 "Specify the maximum number of hops to the BGP peer\n"
8535 "Number of hops to BGP peer\n")
fa411a21 8536{
d62a17ae 8537 int idx_peer = 1;
8538 int idx_number = 4;
28c6e247
IR
8539 struct peer *peer;
8540 int gtsm_hops;
d62a17ae 8541
28c6e247
IR
8542 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8543 if (!peer)
d62a17ae 8544 return CMD_WARNING_CONFIG_FAILED;
8545
28c6e247
IR
8546 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
8547
8548 /*
8549 * If 'neighbor swpX', then this is for directly connected peers,
8550 * we should not accept a ttl-security hops value greater than 1.
8551 */
8552 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
8553 vty_out(vty,
8554 "%s is directly connected peer, hops cannot exceed 1\n",
8555 argv[idx_peer]->arg);
8556 return CMD_WARNING_CONFIG_FAILED;
8557 }
7ebe625c 8558
28c6e247 8559 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
8560}
8561
1d80f243
IR
8562DEFUN (no_neighbor_ttl_security,
8563 no_neighbor_ttl_security_cmd,
8564 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8565 NO_STR
8566 NEIGHBOR_STR
8567 NEIGHBOR_ADDR_STR2
8568 "BGP ttl-security parameters\n"
8569 "Specify the maximum number of hops to the BGP peer\n"
8570 "Number of hops to BGP peer\n")
fa411a21 8571{
d62a17ae 8572 int idx_peer = 2;
28c6e247 8573 struct peer *peer;
fa411a21 8574
28c6e247
IR
8575 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8576 if (!peer)
d62a17ae 8577 return CMD_WARNING_CONFIG_FAILED;
fa411a21 8578
28c6e247 8579 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 8580}
6b0655a2 8581
7c0e4312
DA
8582/* disable-addpath-rx */
8583DEFUN(neighbor_disable_addpath_rx,
8584 neighbor_disable_addpath_rx_cmd,
8585 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8586 NEIGHBOR_STR
8587 NEIGHBOR_ADDR_STR2
8588 "Do not accept additional paths\n")
8589{
8590 char *peer_str = argv[1]->arg;
8591 struct peer *peer;
8592 afi_t afi = bgp_node_afi(vty);
8593 safi_t safi = bgp_node_safi(vty);
8594
8595 peer = peer_and_group_lookup_vty(vty, peer_str);
8596 if (!peer)
8597 return CMD_WARNING_CONFIG_FAILED;
8598
8599 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
8600 PEER_FLAG_DISABLE_ADDPATH_RX);
8601}
8602
8603DEFUN(no_neighbor_disable_addpath_rx,
8604 no_neighbor_disable_addpath_rx_cmd,
8605 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8606 NO_STR
8607 NEIGHBOR_STR
8608 NEIGHBOR_ADDR_STR2
8609 "Do not accept additional paths\n")
8610{
8611 char *peer_str = argv[2]->arg;
8612 struct peer *peer;
8613 afi_t afi = bgp_node_afi(vty);
8614 safi_t safi = bgp_node_safi(vty);
8615
8616 peer = peer_and_group_lookup_vty(vty, peer_str);
8617 if (!peer)
8618 return CMD_WARNING_CONFIG_FAILED;
8619
8620 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
8621 PEER_FLAG_DISABLE_ADDPATH_RX);
8622}
8623
adbac85e
DW
8624DEFUN (neighbor_addpath_tx_all_paths,
8625 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8626 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8627 NEIGHBOR_STR
8628 NEIGHBOR_ADDR_STR2
8629 "Use addpath to advertise all paths to a neighbor\n")
8630{
d62a17ae 8631 int idx_peer = 1;
8632 struct peer *peer;
adbac85e 8633
d62a17ae 8634 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8635 if (!peer)
8636 return CMD_WARNING_CONFIG_FAILED;
adbac85e 8637
dcc68b5e
MS
8638 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8639 BGP_ADDPATH_ALL);
8640 return CMD_SUCCESS;
adbac85e
DW
8641}
8642
d62a17ae 8643ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8644 neighbor_addpath_tx_all_paths_hidden_cmd,
8645 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8646 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8647 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8648
adbac85e
DW
8649DEFUN (no_neighbor_addpath_tx_all_paths,
8650 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8651 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8652 NO_STR
8653 NEIGHBOR_STR
8654 NEIGHBOR_ADDR_STR2
8655 "Use addpath to advertise all paths to a neighbor\n")
8656{
d62a17ae 8657 int idx_peer = 2;
dcc68b5e
MS
8658 struct peer *peer;
8659
8660 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8661 if (!peer)
8662 return CMD_WARNING_CONFIG_FAILED;
8663
8664 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8665 != BGP_ADDPATH_ALL) {
8666 vty_out(vty,
8667 "%% Peer not currently configured to transmit all paths.");
8668 return CMD_WARNING_CONFIG_FAILED;
8669 }
8670
8671 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8672 BGP_ADDPATH_NONE);
8673
8674 return CMD_SUCCESS;
adbac85e
DW
8675}
8676
d62a17ae 8677ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8678 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8679 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8680 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8681 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8682
06370dac
DW
8683DEFUN (neighbor_addpath_tx_bestpath_per_as,
8684 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8685 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8686 NEIGHBOR_STR
8687 NEIGHBOR_ADDR_STR2
8688 "Use addpath to advertise the bestpath per each neighboring AS\n")
8689{
d62a17ae 8690 int idx_peer = 1;
8691 struct peer *peer;
06370dac 8692
d62a17ae 8693 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8694 if (!peer)
8695 return CMD_WARNING_CONFIG_FAILED;
06370dac 8696
dcc68b5e
MS
8697 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8698 BGP_ADDPATH_BEST_PER_AS);
8699
8700 return CMD_SUCCESS;
06370dac
DW
8701}
8702
d62a17ae 8703ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8704 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8705 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8706 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8707 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8708
06370dac
DW
8709DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8710 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8711 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8712 NO_STR
8713 NEIGHBOR_STR
8714 NEIGHBOR_ADDR_STR2
8715 "Use addpath to advertise the bestpath per each neighboring AS\n")
8716{
d62a17ae 8717 int idx_peer = 2;
dcc68b5e
MS
8718 struct peer *peer;
8719
8720 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8721 if (!peer)
8722 return CMD_WARNING_CONFIG_FAILED;
8723
8724 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8725 != BGP_ADDPATH_BEST_PER_AS) {
8726 vty_out(vty,
8727 "%% Peer not currently configured to transmit all best path per as.");
8728 return CMD_WARNING_CONFIG_FAILED;
8729 }
8730
8731 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8732 BGP_ADDPATH_NONE);
8733
8734 return CMD_SUCCESS;
06370dac
DW
8735}
8736
d62a17ae 8737ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8738 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8739 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8740 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8741 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8742
2b31007c
RZ
8743DEFPY(
8744 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8745 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8746 NEIGHBOR_STR
8747 NEIGHBOR_ADDR_STR2
8748 "Detect AS loops before sending to neighbor\n")
8749{
8750 struct peer *peer;
8751
8752 peer = peer_and_group_lookup_vty(vty, neighbor);
8753 if (!peer)
8754 return CMD_WARNING_CONFIG_FAILED;
8755
8756 peer->as_path_loop_detection = true;
8757
8758 return CMD_SUCCESS;
8759}
8760
8761DEFPY(
8762 no_neighbor_aspath_loop_detection,
8763 no_neighbor_aspath_loop_detection_cmd,
8764 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8765 NO_STR
8766 NEIGHBOR_STR
8767 NEIGHBOR_ADDR_STR2
8768 "Detect AS loops before sending to neighbor\n")
8769{
8770 struct peer *peer;
8771
8772 peer = peer_and_group_lookup_vty(vty, neighbor);
8773 if (!peer)
8774 return CMD_WARNING_CONFIG_FAILED;
8775
8776 peer->as_path_loop_detection = false;
8777
8778 return CMD_SUCCESS;
8779}
8780
b9c7bc5a 8781static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
c6423c31 8782 struct ecommunity **list, bool is_rt6)
ddb5b488 8783{
b9c7bc5a
PZ
8784 struct ecommunity *ecom = NULL;
8785 struct ecommunity *ecomadd;
ddb5b488 8786
b9c7bc5a 8787 for (; argc; --argc, ++argv) {
9a659715
PG
8788 if (is_rt6)
8789 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8790 ECOMMUNITY_ROUTE_TARGET,
8791 0);
8792 else
8793 ecomadd = ecommunity_str2com(argv[0]->arg,
8794 ECOMMUNITY_ROUTE_TARGET,
8795 0);
b9c7bc5a
PZ
8796 if (!ecomadd) {
8797 vty_out(vty, "Malformed community-list value\n");
8798 if (ecom)
8799 ecommunity_free(&ecom);
8800 return CMD_WARNING_CONFIG_FAILED;
8801 }
ddb5b488 8802
b9c7bc5a
PZ
8803 if (ecom) {
8804 ecommunity_merge(ecom, ecomadd);
8805 ecommunity_free(&ecomadd);
8806 } else {
8807 ecom = ecomadd;
8808 }
8809 }
8810
8811 if (*list) {
8812 ecommunity_free(&*list);
ddb5b488 8813 }
b9c7bc5a
PZ
8814 *list = ecom;
8815
8816 return CMD_SUCCESS;
ddb5b488
PZ
8817}
8818
0ca70ba5
DS
8819/*
8820 * v2vimport is true if we are handling a `import vrf ...` command
8821 */
8822static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 8823{
0ca70ba5
DS
8824 afi_t afi;
8825
ddb5b488 8826 switch (vty->node) {
b9c7bc5a 8827 case BGP_IPV4_NODE:
0ca70ba5
DS
8828 afi = AFI_IP;
8829 break;
b9c7bc5a 8830 case BGP_IPV6_NODE:
0ca70ba5
DS
8831 afi = AFI_IP6;
8832 break;
ddb5b488
PZ
8833 default:
8834 vty_out(vty,
b9c7bc5a 8835 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 8836 return AFI_MAX;
ddb5b488 8837 }
69b07479 8838
0ca70ba5
DS
8839 if (!v2vimport) {
8840 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8841 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8842 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8843 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8844 vty_out(vty,
8845 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8846 return AFI_MAX;
8847 }
8848 } else {
8849 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8850 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8851 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8852 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8853 vty_out(vty,
8854 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
8855 return AFI_MAX;
8856 }
8857 }
8858 return afi;
ddb5b488
PZ
8859}
8860
585f1adc
IR
8861DEFPY (af_rd_vpn_export,
8862 af_rd_vpn_export_cmd,
8863 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
8864 NO_STR
8865 "Specify route distinguisher\n"
8866 "Between current address-family and vpn\n"
8867 "For routes leaked from current address-family to vpn\n"
8868 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
ddb5b488 8869{
585f1adc
IR
8870 VTY_DECLVAR_CONTEXT(bgp, bgp);
8871 struct prefix_rd prd;
8872 int ret;
ddb5b488 8873 afi_t afi;
b9c7bc5a 8874 int idx = 0;
585f1adc 8875 bool yes = true;
b9c7bc5a 8876
585f1adc
IR
8877 if (argv_find(argv, argc, "no", &idx))
8878 yes = false;
ddb5b488 8879
585f1adc
IR
8880 if (yes) {
8881 ret = str2prefix_rd(rd_str, &prd);
8882 if (!ret) {
8883 vty_out(vty, "%% Malformed rd\n");
8884 return CMD_WARNING_CONFIG_FAILED;
8885 }
8886 }
ddb5b488 8887
585f1adc
IR
8888 afi = vpn_policy_getafi(vty, bgp, false);
8889 if (afi == AFI_MAX)
8890 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8891
585f1adc
IR
8892 /*
8893 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8894 */
8895 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8896 bgp_get_default(), bgp);
ddb5b488 8897
585f1adc
IR
8898 if (yes) {
8899 bgp->vpn_policy[afi].tovpn_rd = prd;
8900 SET_FLAG(bgp->vpn_policy[afi].flags,
8901 BGP_VPN_POLICY_TOVPN_RD_SET);
8902 } else {
8903 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8904 BGP_VPN_POLICY_TOVPN_RD_SET);
8905 }
69b07479 8906
585f1adc
IR
8907 /* post-change: re-export vpn routes */
8908 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8909 bgp_get_default(), bgp);
8910
8911 return CMD_SUCCESS;
ddb5b488
PZ
8912}
8913
b9c7bc5a
PZ
8914ALIAS (af_rd_vpn_export,
8915 af_no_rd_vpn_export_cmd,
8916 "no rd vpn export",
ddb5b488 8917 NO_STR
b9c7bc5a
PZ
8918 "Specify route distinguisher\n"
8919 "Between current address-family and vpn\n"
8920 "For routes leaked from current address-family to vpn\n")
ddb5b488 8921
b9c7bc5a
PZ
8922DEFPY (af_label_vpn_export,
8923 af_label_vpn_export_cmd,
e70e9f8e 8924 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 8925 NO_STR
ddb5b488 8926 "label value for VRF\n"
b9c7bc5a
PZ
8927 "Between current address-family and vpn\n"
8928 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
8929 "Label Value <0-1048575>\n"
8930 "Automatically assign a label\n")
ddb5b488
PZ
8931{
8932 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 8933 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 8934 afi_t afi;
b9c7bc5a 8935 int idx = 0;
c6423c31 8936 bool yes = true;
b9c7bc5a
PZ
8937
8938 if (argv_find(argv, argc, "no", &idx))
c6423c31 8939 yes = false;
ddb5b488 8940
21a16cc2
PZ
8941 /* If "no ...", squash trailing parameter */
8942 if (!yes)
8943 label_auto = NULL;
8944
e70e9f8e
PZ
8945 if (yes) {
8946 if (!label_auto)
8947 label = label_val; /* parser should force unsigned */
8948 }
ddb5b488 8949
0ca70ba5 8950 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
8951 if (afi == AFI_MAX)
8952 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 8953
e70e9f8e 8954
69b07479
DS
8955 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8956 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
8957 /* no change */
8958 return CMD_SUCCESS;
e70e9f8e 8959
69b07479
DS
8960 /*
8961 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8962 */
8963 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8964 bgp_get_default(), bgp);
8965
8966 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8967 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
8968
8969 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
8970
8971 /*
8972 * label has previously been automatically
8973 * assigned by labelpool: release it
8974 *
8975 * NB if tovpn_label == MPLS_LABEL_NONE it
8976 * means the automatic assignment is in flight
8977 * and therefore the labelpool callback must
8978 * detect that the auto label is not needed.
8979 */
8980
8981 bgp_lp_release(LP_TYPE_VRF,
8982 &bgp->vpn_policy[afi],
8983 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 8984 }
69b07479
DS
8985 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8986 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8987 }
ddb5b488 8988
69b07479
DS
8989 bgp->vpn_policy[afi].tovpn_label = label;
8990 if (label_auto) {
8991 SET_FLAG(bgp->vpn_policy[afi].flags,
8992 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8993 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
8994 vpn_leak_label_callback);
ddb5b488
PZ
8995 }
8996
69b07479
DS
8997 /* post-change: re-export vpn routes */
8998 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8999 bgp_get_default(), bgp);
9000
0d020cd6 9001 hook_call(bgp_snmp_update_last_changed, bgp);
ddb5b488
PZ
9002 return CMD_SUCCESS;
9003}
9004
b72c9e14
HS
9005DEFPY (af_sid_vpn_export,
9006 af_sid_vpn_export_cmd,
46279a11 9007 "[no] sid vpn export <(1-1048575)$sid_idx|auto$sid_auto>",
b72c9e14
HS
9008 NO_STR
9009 "sid value for VRF\n"
9010 "Between current address-family and vpn\n"
9011 "For routes leaked from current address-family to vpn\n"
9012 "Sid allocation index\n"
9013 "Automatically assign a label\n")
9014{
9015 VTY_DECLVAR_CONTEXT(bgp, bgp);
9016 afi_t afi;
9017 int debug = 0;
9018 int idx = 0;
9019 bool yes = true;
9020
9021 if (argv_find(argv, argc, "no", &idx))
9022 yes = false;
9023 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
9024 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
9025
9026 afi = vpn_policy_getafi(vty, bgp, false);
9027 if (afi == AFI_MAX)
9028 return CMD_WARNING_CONFIG_FAILED;
9029
9030 if (!yes) {
9031 /* implement me */
4d4c404b 9032 vty_out(vty, "It's not implemented\n");
b72c9e14
HS
9033 return CMD_WARNING_CONFIG_FAILED;
9034 }
9035
527588aa
CS
9036 if (bgp->tovpn_sid_index != 0 ||
9037 CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)) {
9038 vty_out(vty,
9039 "per-vrf sid and per-af sid are mutually exclusive\n"
9040 "Failed: per-vrf sid is configured. Remove per-vrf sid before configuring per-af sid\n");
9041 return CMD_WARNING_CONFIG_FAILED;
9042 }
9043
b72c9e14
HS
9044 /* skip when it's already configured */
9045 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9046 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9047 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
9048 return CMD_SUCCESS;
9049
7de4c885
HS
9050 /*
9051 * mode change between sid_idx and sid_auto isn't supported.
9052 * user must negate sid vpn export when they want to change the mode
9053 */
b72c9e14
HS
9054 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9055 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9056 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
9057 vty_out(vty, "it's already configured as %s.\n",
9058 sid_auto ? "auto-mode" : "idx-mode");
9059 return CMD_WARNING_CONFIG_FAILED;
9060 }
9061
9062 /* pre-change */
9063 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9064 bgp_get_default(), bgp);
9065
9066 if (sid_auto) {
9067 /* SID allocation auto-mode */
9068 if (debug)
9069 zlog_debug("%s: auto sid alloc.", __func__);
9070 SET_FLAG(bgp->vpn_policy[afi].flags,
9071 BGP_VPN_POLICY_TOVPN_SID_AUTO);
9072 } else {
9073 /* SID allocation index-mode */
9074 if (debug)
9075 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
9076 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
9077 }
9078
9079 /* post-change */
9080 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9081 bgp_get_default(), bgp);
9082 return CMD_SUCCESS;
9083}
9084
527588aa
CS
9085DEFPY (bgp_sid_vpn_export,
9086 bgp_sid_vpn_export_cmd,
346bbb39 9087 "[no] sid vpn per-vrf export <(1-1048575)$sid_idx|auto$sid_auto>",
527588aa
CS
9088 NO_STR
9089 "sid value for VRF\n"
9090 "Between current vrf and vpn\n"
9091 "sid per-VRF (both IPv4 and IPv6 address families)\n"
9092 "For routes leaked from current vrf to vpn\n"
9093 "Sid allocation index\n"
9094 "Automatically assign a label\n")
9095{
9096 VTY_DECLVAR_CONTEXT(bgp, bgp);
9097 int debug;
9098
9099 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
9100 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
9101
9102 if (no) {
e606d8ec
CS
9103 /* when per-VRF SID is not set, do nothing */
9104 if (bgp->tovpn_sid_index == 0 &&
9105 !CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO))
9106 return CMD_SUCCESS;
9107
9108 sid_idx = 0;
9109 sid_auto = false;
9110 bgp->tovpn_sid_index = 0;
9111 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO);
527588aa
CS
9112 }
9113
9114 if (bgp->vpn_policy[AFI_IP].tovpn_sid_index != 0 ||
9115 CHECK_FLAG(bgp->vpn_policy[AFI_IP].flags,
9116 BGP_VPN_POLICY_TOVPN_SID_AUTO) ||
9117 bgp->vpn_policy[AFI_IP6].tovpn_sid_index != 0 ||
9118 CHECK_FLAG(bgp->vpn_policy[AFI_IP6].flags,
9119 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
9120 vty_out(vty,
9121 "per-vrf sid and per-af sid are mutually exclusive\n"
9122 "Failed: per-af sid is configured. Remove per-af sid before configuring per-vrf sid\n");
9123 return CMD_WARNING_CONFIG_FAILED;
9124 }
9125
9126 /* skip when it's already configured */
9127 if ((sid_idx != 0 && bgp->tovpn_sid_index != 0) ||
9128 (sid_auto && CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)))
9129 return CMD_SUCCESS;
9130
9131 /*
9132 * mode change between sid_idx and sid_auto isn't supported.
9133 * user must negate sid vpn export when they want to change the mode
9134 */
9135 if ((sid_auto && bgp->tovpn_sid_index != 0) ||
9136 (sid_idx != 0 &&
9137 CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO))) {
9138 vty_out(vty, "it's already configured as %s.\n",
9139 sid_auto ? "auto-mode" : "idx-mode");
9140 return CMD_WARNING_CONFIG_FAILED;
9141 }
9142
9143 /* pre-change */
9144 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP, bgp_get_default(),
9145 bgp);
9146 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP6, bgp_get_default(),
9147 bgp);
9148
9149 if (sid_auto) {
9150 /* SID allocation auto-mode */
9151 if (debug)
9152 zlog_debug("%s: auto per-vrf sid alloc.", __func__);
9153 SET_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO);
e606d8ec 9154 } else if (sid_idx != 0) {
527588aa
CS
9155 /* SID allocation index-mode */
9156 if (debug)
9157 zlog_debug("%s: idx %ld per-vrf sid alloc.", __func__,
9158 sid_idx);
9159 bgp->tovpn_sid_index = sid_idx;
9160 }
9161
9162 /* post-change */
9163 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP, bgp_get_default(),
9164 bgp);
9165 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP6,
9166 bgp_get_default(), bgp);
9167
9168 return CMD_SUCCESS;
9169}
9170
b9c7bc5a
PZ
9171ALIAS (af_label_vpn_export,
9172 af_no_label_vpn_export_cmd,
9173 "no label vpn export",
9174 NO_STR
9175 "label value for VRF\n"
9176 "Between current address-family and vpn\n"
9177 "For routes leaked from current address-family to vpn\n")
ddb5b488 9178
e606d8ec
CS
9179ALIAS (bgp_sid_vpn_export,
9180 no_bgp_sid_vpn_export_cmd,
9181 "no$no sid vpn per-vrf export",
9182 NO_STR
9183 "sid value for VRF\n"
9184 "Between current vrf and vpn\n"
9185 "sid per-VRF (both IPv4 and IPv6 address families)\n"
9186 "For routes leaked from current vrf to vpn\n")
9187
585f1adc 9188DEFPY (af_nexthop_vpn_export,
b9c7bc5a 9189 af_nexthop_vpn_export_cmd,
8c85ca28 9190 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
b9c7bc5a 9191 NO_STR
ddb5b488 9192 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
9193 "Between current address-family and vpn\n"
9194 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
9195 "IPv4 prefix\n"
9196 "IPv6 prefix\n")
9197{
585f1adc 9198 VTY_DECLVAR_CONTEXT(bgp, bgp);
ddb5b488 9199 afi_t afi;
ddb5b488
PZ
9200 struct prefix p;
9201
8c85ca28
QY
9202 if (!no) {
9203 if (!nexthop_su) {
9204 vty_out(vty, "%% Nexthop required\n");
9205 return CMD_WARNING_CONFIG_FAILED;
9206 }
8c85ca28 9207 if (!sockunion2hostprefix(nexthop_su, &p))
b9c7bc5a
PZ
9208 return CMD_WARNING_CONFIG_FAILED;
9209 }
ddb5b488 9210
585f1adc
IR
9211 afi = vpn_policy_getafi(vty, bgp, false);
9212 if (afi == AFI_MAX)
9213 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9214
585f1adc
IR
9215 /*
9216 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9217 */
9218 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9219 bgp_get_default(), bgp);
ddb5b488 9220
585f1adc
IR
9221 if (!no) {
9222 bgp->vpn_policy[afi].tovpn_nexthop = p;
9223 SET_FLAG(bgp->vpn_policy[afi].flags,
9224 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9225 } else {
9226 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9227 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9228 }
69b07479 9229
585f1adc
IR
9230 /* post-change: re-export vpn routes */
9231 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9232 bgp_get_default(), bgp);
37a87b8f 9233
585f1adc 9234 return CMD_SUCCESS;
ddb5b488
PZ
9235}
9236
b9c7bc5a 9237static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 9238{
b9c7bc5a
PZ
9239 if (!strcmp(dstr, "import")) {
9240 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9241 } else if (!strcmp(dstr, "export")) {
9242 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9243 } else if (!strcmp(dstr, "both")) {
9244 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9245 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9246 } else {
9247 vty_out(vty, "%% direction parse error\n");
9248 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9249 }
ddb5b488
PZ
9250 return CMD_SUCCESS;
9251}
9252
b9c7bc5a
PZ
9253DEFPY (af_rt_vpn_imexport,
9254 af_rt_vpn_imexport_cmd,
9255 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9256 NO_STR
9257 "Specify route target list\n"
ddb5b488 9258 "Specify route target list\n"
b9c7bc5a
PZ
9259 "Between current address-family and vpn\n"
9260 "For routes leaked from vpn to current address-family: match any\n"
9261 "For routes leaked from current address-family to vpn: set\n"
9262 "both import: match any and export: set\n"
ddb5b488
PZ
9263 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9264{
9265 VTY_DECLVAR_CONTEXT(bgp, bgp);
9266 int ret;
9267 struct ecommunity *ecom = NULL;
9268 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9c2fd3fe 9269 enum vpn_policy_direction dir;
ddb5b488
PZ
9270 afi_t afi;
9271 int idx = 0;
c6423c31 9272 bool yes = true;
ddb5b488 9273
b9c7bc5a 9274 if (argv_find(argv, argc, "no", &idx))
c6423c31 9275 yes = false;
b9c7bc5a 9276
0ca70ba5 9277 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9278 if (afi == AFI_MAX)
9279 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9280
b9c7bc5a 9281 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
9282 if (ret != CMD_SUCCESS)
9283 return ret;
9284
b9c7bc5a
PZ
9285 if (yes) {
9286 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9287 vty_out(vty, "%% Missing RTLIST\n");
9288 return CMD_WARNING_CONFIG_FAILED;
9289 }
c6423c31 9290 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
b9c7bc5a
PZ
9291 if (ret != CMD_SUCCESS) {
9292 return ret;
9293 }
ddb5b488
PZ
9294 }
9295
69b07479
DS
9296 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9297 if (!dodir[dir])
ddb5b488 9298 continue;
ddb5b488 9299
69b07479 9300 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 9301
69b07479
DS
9302 if (yes) {
9303 if (bgp->vpn_policy[afi].rtlist[dir])
9304 ecommunity_free(
9305 &bgp->vpn_policy[afi].rtlist[dir]);
9306 bgp->vpn_policy[afi].rtlist[dir] =
9307 ecommunity_dup(ecom);
9308 } else {
9309 if (bgp->vpn_policy[afi].rtlist[dir])
9310 ecommunity_free(
9311 &bgp->vpn_policy[afi].rtlist[dir]);
9312 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 9313 }
69b07479
DS
9314
9315 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 9316 }
69b07479 9317
d555f3e9
PZ
9318 if (ecom)
9319 ecommunity_free(&ecom);
ddb5b488
PZ
9320
9321 return CMD_SUCCESS;
9322}
9323
b9c7bc5a
PZ
9324ALIAS (af_rt_vpn_imexport,
9325 af_no_rt_vpn_imexport_cmd,
9326 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
9327 NO_STR
9328 "Specify route target list\n"
b9c7bc5a
PZ
9329 "Specify route target list\n"
9330 "Between current address-family and vpn\n"
9331 "For routes leaked from vpn to current address-family\n"
9332 "For routes leaked from current address-family to vpn\n"
9333 "both import and export\n")
9334
585f1adc 9335DEFPY (af_route_map_vpn_imexport,
b9c7bc5a
PZ
9336 af_route_map_vpn_imexport_cmd,
9337/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9338 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9339 NO_STR
ddb5b488 9340 "Specify route map\n"
b9c7bc5a
PZ
9341 "Between current address-family and vpn\n"
9342 "For routes leaked from vpn to current address-family\n"
9343 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
9344 "name of route-map\n")
9345{
585f1adc
IR
9346 VTY_DECLVAR_CONTEXT(bgp, bgp);
9347 int ret;
9348 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9c2fd3fe 9349 enum vpn_policy_direction dir;
ddb5b488 9350 afi_t afi;
ddb5b488 9351 int idx = 0;
585f1adc 9352 bool yes = true;
ddb5b488 9353
585f1adc
IR
9354 if (argv_find(argv, argc, "no", &idx))
9355 yes = false;
ddb5b488 9356
585f1adc
IR
9357 afi = vpn_policy_getafi(vty, bgp, false);
9358 if (afi == AFI_MAX)
9359 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9360
585f1adc
IR
9361 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9362 if (ret != CMD_SUCCESS)
9363 return ret;
ddb5b488 9364
585f1adc
IR
9365 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9366 if (!dodir[dir])
9367 continue;
69b07479 9368
585f1adc
IR
9369 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9370
9371 if (yes) {
9372 if (bgp->vpn_policy[afi].rmap_name[dir])
9373 XFREE(MTYPE_ROUTE_MAP_NAME,
9374 bgp->vpn_policy[afi].rmap_name[dir]);
9375 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
9376 MTYPE_ROUTE_MAP_NAME, rmap_str);
9377 bgp->vpn_policy[afi].rmap[dir] =
9378 route_map_lookup_warn_noexist(vty, rmap_str);
9379 if (!bgp->vpn_policy[afi].rmap[dir])
9380 return CMD_SUCCESS;
9381 } else {
9382 if (bgp->vpn_policy[afi].rmap_name[dir])
9383 XFREE(MTYPE_ROUTE_MAP_NAME,
9384 bgp->vpn_policy[afi].rmap_name[dir]);
9385 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9386 bgp->vpn_policy[afi].rmap[dir] = NULL;
9387 }
9388
9389 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9390 }
ddb5b488 9391
585f1adc 9392 return CMD_SUCCESS;
ddb5b488
PZ
9393}
9394
b9c7bc5a
PZ
9395ALIAS (af_route_map_vpn_imexport,
9396 af_no_route_map_vpn_imexport_cmd,
9397 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
9398 NO_STR
9399 "Specify route map\n"
b9c7bc5a
PZ
9400 "Between current address-family and vpn\n"
9401 "For routes leaked from vpn to current address-family\n"
9402 "For routes leaked from current address-family to vpn\n")
9403
bb4f6190 9404DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
ae6a6fb4 9405 "import vrf route-map RMAP$rmap_str",
bb4f6190
DS
9406 "Import routes from another VRF\n"
9407 "Vrf routes being filtered\n"
9408 "Specify route map\n"
9409 "name of route-map\n")
9410{
9411 VTY_DECLVAR_CONTEXT(bgp, bgp);
9c2fd3fe 9412 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
bb4f6190 9413 afi_t afi;
bb4f6190
DS
9414 struct bgp *bgp_default;
9415
0ca70ba5 9416 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
9417 if (afi == AFI_MAX)
9418 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
9419
9420 bgp_default = bgp_get_default();
9421 if (!bgp_default) {
9422 int32_t ret;
9423 as_t as = bgp->as;
9424
9425 /* Auto-create assuming the same AS */
5d5393b9
DL
9426 ret = bgp_get_vty(&bgp_default, &as, NULL,
9427 BGP_INSTANCE_TYPE_DEFAULT);
bb4f6190
DS
9428
9429 if (ret) {
9430 vty_out(vty,
9431 "VRF default is not configured as a bgp instance\n");
9432 return CMD_WARNING;
9433 }
9434 }
9435
69b07479 9436 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 9437
ae6a6fb4
DS
9438 if (bgp->vpn_policy[afi].rmap_name[dir])
9439 XFREE(MTYPE_ROUTE_MAP_NAME,
9440 bgp->vpn_policy[afi].rmap_name[dir]);
9441 bgp->vpn_policy[afi].rmap_name[dir] =
9442 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9443 bgp->vpn_policy[afi].rmap[dir] =
9444 route_map_lookup_warn_noexist(vty, rmap_str);
9445 if (!bgp->vpn_policy[afi].rmap[dir])
9446 return CMD_SUCCESS;
9447
9448 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9449 BGP_CONFIG_VRF_TO_VRF_IMPORT);
bb4f6190 9450
69b07479
DS
9451 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9452
bb4f6190
DS
9453 return CMD_SUCCESS;
9454}
9455
ae6a6fb4
DS
9456DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9457 "no import vrf route-map [RMAP$rmap_str]",
bb4f6190
DS
9458 NO_STR
9459 "Import routes from another VRF\n"
9460 "Vrf routes being filtered\n"
ae6a6fb4
DS
9461 "Specify route map\n"
9462 "name of route-map\n")
9463{
9464 VTY_DECLVAR_CONTEXT(bgp, bgp);
9c2fd3fe 9465 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
ae6a6fb4
DS
9466 afi_t afi;
9467
9468 afi = vpn_policy_getafi(vty, bgp, true);
9469 if (afi == AFI_MAX)
9470 return CMD_WARNING_CONFIG_FAILED;
9471
9472 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9473
9474 if (bgp->vpn_policy[afi].rmap_name[dir])
9475 XFREE(MTYPE_ROUTE_MAP_NAME,
9476 bgp->vpn_policy[afi].rmap_name[dir]);
9477 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9478 bgp->vpn_policy[afi].rmap[dir] = NULL;
9479
9480 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9481 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9482 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9483
9484 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9485
9486 return CMD_SUCCESS;
9487}
bb4f6190 9488
585f1adc
IR
9489DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
9490 "[no] import vrf VIEWVRFNAME$import_name",
9491 NO_STR
9492 "Import routes from another VRF\n"
9493 "VRF to import from\n"
9494 "The name of the VRF\n")
12a844a5 9495{
585f1adc
IR
9496 VTY_DECLVAR_CONTEXT(bgp, bgp);
9497 struct listnode *node;
9498 struct bgp *vrf_bgp, *bgp_default;
9499 int32_t ret = 0;
9500 as_t as = bgp->as;
9501 bool remove = false;
9502 int32_t idx = 0;
9503 char *vname;
9504 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
12a844a5
DS
9505 safi_t safi;
9506 afi_t afi;
9507
867f0cca 9508 if (import_name == NULL) {
9509 vty_out(vty, "%% Missing import name\n");
9510 return CMD_WARNING;
9511 }
9512
ae6a6fb4
DS
9513 if (strcmp(import_name, "route-map") == 0) {
9514 vty_out(vty, "%% Must include route-map name\n");
9515 return CMD_WARNING;
9516 }
9517
585f1adc
IR
9518 if (argv_find(argv, argc, "no", &idx))
9519 remove = true;
9520
9521 afi = vpn_policy_getafi(vty, bgp, true);
9522 if (afi == AFI_MAX)
9523 return CMD_WARNING_CONFIG_FAILED;
9524
12a844a5
DS
9525 safi = bgp_node_safi(vty);
9526
585f1adc
IR
9527 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
9528 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
9529 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
9530 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
9531 remove ? "unimport" : "import", import_name);
9532 return CMD_WARNING;
9533 }
25679caa 9534
585f1adc
IR
9535 bgp_default = bgp_get_default();
9536 if (!bgp_default) {
9537 /* Auto-create assuming the same AS */
9538 ret = bgp_get_vty(&bgp_default, &as, NULL,
9539 BGP_INSTANCE_TYPE_DEFAULT);
12a844a5 9540
585f1adc
IR
9541 if (ret) {
9542 vty_out(vty,
9543 "VRF default is not configured as a bgp instance\n");
9544 return CMD_WARNING;
9545 }
9546 }
12a844a5 9547
585f1adc
IR
9548 vrf_bgp = bgp_lookup_by_name(import_name);
9549 if (!vrf_bgp) {
9550 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
9551 vrf_bgp = bgp_default;
9552 else
9553 /* Auto-create assuming the same AS */
9554 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
9555
9556 if (ret) {
9557 vty_out(vty,
9558 "VRF %s is not configured as a bgp instance\n",
9559 import_name);
9560 return CMD_WARNING;
9561 }
9562 }
9563
9564 if (remove) {
9565 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
9566 } else {
9567 /* Already importing from "import_vrf"? */
9568 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
9569 vname)) {
9570 if (strcmp(vname, import_name) == 0)
9571 return CMD_WARNING;
9572 }
9573
9574 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
9575 }
9576
9577 return CMD_SUCCESS;
12a844a5
DS
9578}
9579
b9c7bc5a 9580/* This command is valid only in a bgp vrf instance or the default instance */
585f1adc 9581DEFPY (bgp_imexport_vpn,
b9c7bc5a
PZ
9582 bgp_imexport_vpn_cmd,
9583 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
9584 NO_STR
9585 "Import routes to this address-family\n"
9586 "Export routes from this address-family\n"
9587 "to/from default instance VPN RIB\n")
ddb5b488 9588{
585f1adc
IR
9589 VTY_DECLVAR_CONTEXT(bgp, bgp);
9590 int previous_state;
37a87b8f 9591 afi_t afi;
585f1adc
IR
9592 safi_t safi;
9593 int idx = 0;
9594 bool yes = true;
9595 int flag;
9c2fd3fe 9596 enum vpn_policy_direction dir;
585f1adc
IR
9597
9598 if (argv_find(argv, argc, "no", &idx))
9599 yes = false;
9600
9601 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
9602 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
9603
9604 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
9605 return CMD_WARNING_CONFIG_FAILED;
9606 }
ddb5b488 9607
b9c7bc5a
PZ
9608 afi = bgp_node_afi(vty);
9609 safi = bgp_node_safi(vty);
585f1adc
IR
9610 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
9611 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
9612 return CMD_WARNING_CONFIG_FAILED;
9613 }
ddb5b488 9614
b9c7bc5a 9615 if (!strcmp(direction_str, "import")) {
585f1adc
IR
9616 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
9617 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b9c7bc5a 9618 } else if (!strcmp(direction_str, "export")) {
585f1adc
IR
9619 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
9620 dir = BGP_VPN_POLICY_DIR_TOVPN;
b9c7bc5a
PZ
9621 } else {
9622 vty_out(vty, "%% unknown direction %s\n", direction_str);
9623 return CMD_WARNING_CONFIG_FAILED;
9624 }
9625
585f1adc 9626 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488 9627
585f1adc
IR
9628 if (yes) {
9629 SET_FLAG(bgp->af_flags[afi][safi], flag);
9630 if (!previous_state) {
9631 /* trigger export current vrf */
9632 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9633 }
9634 } else {
9635 if (previous_state) {
9636 /* trigger un-export current vrf */
9637 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9638 }
9639 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
9640 }
37a87b8f 9641
1ca2fd11
IR
9642 hook_call(bgp_snmp_init_stats, bgp);
9643
585f1adc 9644 return CMD_SUCCESS;
ddb5b488
PZ
9645}
9646
301ad80a
PG
9647DEFPY (af_routetarget_import,
9648 af_routetarget_import_cmd,
9a659715 9649 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
301ad80a
PG
9650 NO_STR
9651 "Specify route target list\n"
9652 "Specify route target list\n"
9a659715
PG
9653 "Specify route target list\n"
9654 "Specify route target list\n"
301ad80a
PG
9655 "Flow-spec redirect type route target\n"
9656 "Import routes to this address-family\n"
9a659715 9657 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
301ad80a
PG
9658{
9659 VTY_DECLVAR_CONTEXT(bgp, bgp);
9660 int ret;
9661 struct ecommunity *ecom = NULL;
301ad80a 9662 afi_t afi;
9a659715 9663 int idx = 0, idx_unused = 0;
c6423c31
PG
9664 bool yes = true;
9665 bool rt6 = false;
301ad80a
PG
9666
9667 if (argv_find(argv, argc, "no", &idx))
c6423c31 9668 yes = false;
301ad80a 9669
9a659715
PG
9670 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9671 argv_find(argv, argc, "route-target6", &idx_unused))
c6423c31 9672 rt6 = true;
301ad80a 9673
0ca70ba5 9674 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9675 if (afi == AFI_MAX)
9676 return CMD_WARNING_CONFIG_FAILED;
9677
9a659715
PG
9678 if (rt6 && afi != AFI_IP6)
9679 return CMD_WARNING_CONFIG_FAILED;
9680
301ad80a
PG
9681 if (yes) {
9682 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9683 vty_out(vty, "%% Missing RTLIST\n");
9684 return CMD_WARNING_CONFIG_FAILED;
9685 }
9a659715 9686 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
301ad80a
PG
9687 if (ret != CMD_SUCCESS)
9688 return ret;
9689 }
69b07479
DS
9690
9691 if (yes) {
9692 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9693 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9694 .import_redirect_rtlist);
69b07479
DS
9695 bgp->vpn_policy[afi].import_redirect_rtlist =
9696 ecommunity_dup(ecom);
9697 } else {
9698 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9699 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9700 .import_redirect_rtlist);
69b07479 9701 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 9702 }
69b07479 9703
301ad80a
PG
9704 if (ecom)
9705 ecommunity_free(&ecom);
9706
9707 return CMD_SUCCESS;
9708}
9709
505e5056 9710DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 9711 address_family_ipv4_safi_cmd,
9712 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9713 "Enter Address Family command mode\n"
00e6edb9 9714 BGP_AF_STR
7c40bf39 9715 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 9716{
f51bae9c 9717
d62a17ae 9718 if (argc == 3) {
585f1adc
IR
9719 VTY_DECLVAR_CONTEXT(bgp, bgp);
9720 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9721 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
a4d82a8a 9722 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9723 && safi != SAFI_EVPN) {
31947174
MK
9724 vty_out(vty,
9725 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9726 return CMD_WARNING_CONFIG_FAILED;
9727 }
585f1adc
IR
9728 vty->node = bgp_node_type(AFI_IP, safi);
9729 } else
9730 vty->node = BGP_IPV4_NODE;
718e3744 9731
d62a17ae 9732 return CMD_SUCCESS;
718e3744 9733}
9734
505e5056 9735DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 9736 address_family_ipv6_safi_cmd,
9737 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9738 "Enter Address Family command mode\n"
00e6edb9 9739 BGP_AF_STR
7c40bf39 9740 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 9741{
d62a17ae 9742 if (argc == 3) {
585f1adc
IR
9743 VTY_DECLVAR_CONTEXT(bgp, bgp);
9744 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9745 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
a4d82a8a 9746 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9747 && safi != SAFI_EVPN) {
31947174
MK
9748 vty_out(vty,
9749 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9750 return CMD_WARNING_CONFIG_FAILED;
9751 }
585f1adc
IR
9752 vty->node = bgp_node_type(AFI_IP6, safi);
9753 } else
9754 vty->node = BGP_IPV6_NODE;
25ffbdc1 9755
d62a17ae 9756 return CMD_SUCCESS;
25ffbdc1 9757}
718e3744 9758
d6902373 9759#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 9760DEFUN_NOSH (address_family_vpnv4,
718e3744 9761 address_family_vpnv4_cmd,
8334fd5a 9762 "address-family vpnv4 [unicast]",
718e3744 9763 "Enter Address Family command mode\n"
00e6edb9
DA
9764 BGP_AF_STR
9765 BGP_AF_MODIFIER_STR)
718e3744 9766{
d62a17ae 9767 vty->node = BGP_VPNV4_NODE;
9768 return CMD_SUCCESS;
718e3744 9769}
9770
505e5056 9771DEFUN_NOSH (address_family_vpnv6,
8ecd3266 9772 address_family_vpnv6_cmd,
8334fd5a 9773 "address-family vpnv6 [unicast]",
8ecd3266 9774 "Enter Address Family command mode\n"
00e6edb9
DA
9775 BGP_AF_STR
9776 BGP_AF_MODIFIER_STR)
8ecd3266 9777{
d62a17ae 9778 vty->node = BGP_VPNV6_NODE;
9779 return CMD_SUCCESS;
8ecd3266 9780}
64e4a6c5 9781#endif /* KEEP_OLD_VPN_COMMANDS */
d6902373 9782
505e5056 9783DEFUN_NOSH (address_family_evpn,
4e0b7b6d 9784 address_family_evpn_cmd,
7111c1a0 9785 "address-family l2vpn evpn",
4e0b7b6d 9786 "Enter Address Family command mode\n"
00e6edb9
DA
9787 BGP_AF_STR
9788 BGP_AF_MODIFIER_STR)
4e0b7b6d 9789{
2131d5cf 9790 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 9791 vty->node = BGP_EVPN_NODE;
9792 return CMD_SUCCESS;
4e0b7b6d
PG
9793}
9794
bfaab44d
HS
9795DEFUN_NOSH (bgp_segment_routing_srv6,
9796 bgp_segment_routing_srv6_cmd,
9797 "segment-routing srv6",
9798 "Segment-Routing configuration\n"
9799 "Segment-Routing SRv6 configuration\n")
9800{
9801 VTY_DECLVAR_CONTEXT(bgp, bgp);
92a9e6f2 9802 bgp->srv6_enabled = true;
bfaab44d
HS
9803 vty->node = BGP_SRV6_NODE;
9804 return CMD_SUCCESS;
9805}
9806
0249b8b6
HS
9807DEFUN (no_bgp_segment_routing_srv6,
9808 no_bgp_segment_routing_srv6_cmd,
9809 "no segment-routing srv6",
9810 NO_STR
9811 "Segment-Routing configuration\n"
9812 "Segment-Routing SRv6 configuration\n")
9813{
9814 VTY_DECLVAR_CONTEXT(bgp, bgp);
9815
9816 if (strlen(bgp->srv6_locator_name) > 0)
9817 if (bgp_srv6_locator_unset(bgp) < 0)
9818 return CMD_WARNING_CONFIG_FAILED;
9819
9820 bgp->srv6_enabled = false;
9821 return CMD_SUCCESS;
9822}
9823
a0281b2e
HS
9824DEFPY (bgp_srv6_locator,
9825 bgp_srv6_locator_cmd,
9826 "locator NAME$name",
9827 "Specify SRv6 locator\n"
9828 "Specify SRv6 locator\n")
9829{
9830 VTY_DECLVAR_CONTEXT(bgp, bgp);
7de4c885 9831 int ret;
a0281b2e
HS
9832
9833 if (strlen(bgp->srv6_locator_name) > 0
9834 && strcmp(name, bgp->srv6_locator_name) != 0) {
9835 vty_out(vty, "srv6 locator is already configured\n");
9836 return CMD_WARNING_CONFIG_FAILED;
7de4c885
HS
9837 }
9838
9839 snprintf(bgp->srv6_locator_name,
9840 sizeof(bgp->srv6_locator_name), "%s", name);
a0281b2e 9841
7de4c885 9842 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
a0281b2e
HS
9843 if (ret < 0)
9844 return CMD_WARNING_CONFIG_FAILED;
9845
9846 return CMD_SUCCESS;
9847}
9848
0249b8b6
HS
9849DEFPY (no_bgp_srv6_locator,
9850 no_bgp_srv6_locator_cmd,
9851 "no locator NAME$name",
9852 NO_STR
9853 "Specify SRv6 locator\n"
9854 "Specify SRv6 locator\n")
9855{
9856 VTY_DECLVAR_CONTEXT(bgp, bgp);
9857
9858 /* when locator isn't configured, do nothing */
9859 if (strlen(bgp->srv6_locator_name) < 1)
9860 return CMD_SUCCESS;
9861
9862 /* name validation */
9863 if (strcmp(name, bgp->srv6_locator_name) != 0) {
9864 vty_out(vty, "%% No srv6 locator is configured\n");
9865 return CMD_WARNING_CONFIG_FAILED;
9866 }
9867
9868 /* unset locator */
9869 if (bgp_srv6_locator_unset(bgp) < 0)
9870 return CMD_WARNING_CONFIG_FAILED;
9871
9872 return CMD_SUCCESS;
9873}
9874
ea372e81
HS
9875DEFPY (show_bgp_srv6,
9876 show_bgp_srv6_cmd,
9877 "show bgp segment-routing srv6",
9878 SHOW_STR
9879 BGP_STR
9880 "BGP Segment Routing\n"
9881 "BGP Segment Routing SRv6\n")
9882{
9883 struct bgp *bgp;
9884 struct listnode *node;
1c21a234 9885 struct srv6_locator_chunk *chunk;
ea372e81 9886 struct bgp_srv6_function *func;
ea372e81 9887 char buf[256];
ea372e81
HS
9888
9889 bgp = bgp_get_default();
96db4340 9890 if (!bgp)
ea372e81
HS
9891 return CMD_SUCCESS;
9892
9893 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
9894 vty_out(vty, "locator_chunks:\n");
dccef127 9895 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk)) {
511211bf 9896 vty_out(vty, "- %pFX\n", &chunk->prefix);
dccef127
CS
9897 vty_out(vty, " block-length: %d\n", chunk->block_bits_length);
9898 vty_out(vty, " node-length: %d\n", chunk->node_bits_length);
9899 vty_out(vty, " func-length: %d\n",
9900 chunk->function_bits_length);
9901 vty_out(vty, " arg-length: %d\n", chunk->argument_bits_length);
9902 }
ea372e81
HS
9903
9904 vty_out(vty, "functions:\n");
9905 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
9906 inet_ntop(AF_INET6, &func->sid, buf, sizeof(buf));
9907 vty_out(vty, "- sid: %s\n", buf);
9908 vty_out(vty, " locator: %s\n", func->locator_name);
9909 }
9910
9911 vty_out(vty, "bgps:\n");
9912 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
9913 vty_out(vty, "- name: %s\n",
9914 bgp->name ? bgp->name : "default");
9915
1830895a
CS
9916 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %pI6\n",
9917 bgp->vpn_policy[AFI_IP].tovpn_sid);
9918 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %pI6\n",
9919 bgp->vpn_policy[AFI_IP6].tovpn_sid);
9f5d4430 9920 vty_out(vty, " per-vrf tovpn_sid: %pI6\n", bgp->tovpn_sid);
ea372e81
HS
9921 }
9922
9923 return CMD_SUCCESS;
9924}
9925
505e5056 9926DEFUN_NOSH (exit_address_family,
718e3744 9927 exit_address_family_cmd,
9928 "exit-address-family",
9929 "Exit from Address Family configuration mode\n")
9930{
d62a17ae 9931 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9932 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9933 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9934 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
9935 || vty->node == BGP_EVPN_NODE
9936 || vty->node == BGP_FLOWSPECV4_NODE
9937 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 9938 vty->node = BGP_NODE;
9939 return CMD_SUCCESS;
718e3744 9940}
6b0655a2 9941
8ad7271d 9942/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 9943static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9944 const char *ip_str, afi_t afi, safi_t safi,
9945 struct prefix_rd *prd)
9946{
9947 int ret;
9948 struct prefix match;
9bcb3eef
DS
9949 struct bgp_dest *dest;
9950 struct bgp_dest *rm;
d62a17ae 9951 struct bgp *bgp;
9952 struct bgp_table *table;
9953 struct bgp_table *rib;
9954
9955 /* BGP structure lookup. */
9956 if (view_name) {
9957 bgp = bgp_lookup_by_name(view_name);
9958 if (bgp == NULL) {
9959 vty_out(vty, "%% Can't find BGP instance %s\n",
9960 view_name);
9961 return CMD_WARNING;
9962 }
9963 } else {
9964 bgp = bgp_get_default();
9965 if (bgp == NULL) {
9966 vty_out(vty, "%% No BGP process is configured\n");
9967 return CMD_WARNING;
9968 }
9969 }
9970
9971 /* Check IP address argument. */
9972 ret = str2prefix(ip_str, &match);
9973 if (!ret) {
9974 vty_out(vty, "%% address is malformed\n");
9975 return CMD_WARNING;
9976 }
9977
9978 match.family = afi2family(afi);
9979 rib = bgp->rib[afi][safi];
9980
9981 if (safi == SAFI_MPLS_VPN) {
9bcb3eef
DS
9982 for (dest = bgp_table_top(rib); dest;
9983 dest = bgp_route_next(dest)) {
9984 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 9985
9bcb3eef 9986 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
d62a17ae 9987 continue;
9988
9bcb3eef 9989 table = bgp_dest_get_bgp_table_info(dest);
b54892e0
DS
9990 if (table == NULL)
9991 continue;
9992
4953391b
DA
9993 rm = bgp_node_match(table, &match);
9994 if (rm != NULL) {
b54892e0 9995 const struct prefix *rm_p =
9bcb3eef 9996 bgp_dest_get_prefix(rm);
b54892e0
DS
9997
9998 if (rm_p->prefixlen == match.prefixlen) {
9999 SET_FLAG(rm->flags,
10000 BGP_NODE_USER_CLEAR);
10001 bgp_process(bgp, rm, afi, safi);
d62a17ae 10002 }
9bcb3eef 10003 bgp_dest_unlock_node(rm);
d62a17ae 10004 }
10005 }
10006 } else {
4953391b
DA
10007 dest = bgp_node_match(rib, &match);
10008 if (dest != NULL) {
9bcb3eef 10009 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 10010
9bcb3eef
DS
10011 if (dest_p->prefixlen == match.prefixlen) {
10012 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
10013 bgp_process(bgp, dest, afi, safi);
d62a17ae 10014 }
9bcb3eef 10015 bgp_dest_unlock_node(dest);
d62a17ae 10016 }
10017 }
10018
10019 return CMD_SUCCESS;
8ad7271d
DS
10020}
10021
b09b5ae0 10022/* one clear bgp command to rule them all */
718e3744 10023DEFUN (clear_ip_bgp_all,
10024 clear_ip_bgp_all_cmd,
3cb14f26 10025 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6|l2vpn> [<unicast|multicast|vpn|labeled-unicast|flowspec|evpn>]] <*|A.B.C.D$neighbor|X:X::X:X$neighbor|WORD$neighbor|(1-4294967295)|external|peer-group PGNAME> [<soft [<in|out>]|in [prefix-filter]|out|message-stats>]",
718e3744 10026 CLEAR_STR
10027 IP_STR
10028 BGP_STR
838758ac 10029 BGP_INSTANCE_HELP_STR
510afcd6 10030 BGP_AFI_HELP_STR
00e6edb9 10031 BGP_AF_STR
510afcd6 10032 BGP_SAFI_WITH_LABEL_HELP_STR
00e6edb9 10033 BGP_AF_MODIFIER_STR
b09b5ae0 10034 "Clear all peers\n"
453c92f6 10035 "BGP IPv4 neighbor to clear\n"
a80beece 10036 "BGP IPv6 neighbor to clear\n"
838758ac 10037 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
10038 "Clear peers with the AS number\n"
10039 "Clear all external peers\n"
718e3744 10040 "Clear all members of peer-group\n"
b09b5ae0 10041 "BGP peer-group name\n"
b09b5ae0
DW
10042 BGP_SOFT_STR
10043 BGP_SOFT_IN_STR
b09b5ae0
DW
10044 BGP_SOFT_OUT_STR
10045 BGP_SOFT_IN_STR
10046 "Push out prefix-list ORF and do inbound soft reconfig\n"
3cb14f26
DS
10047 BGP_SOFT_OUT_STR
10048 "Reset message statistics\n")
718e3744 10049{
d62a17ae 10050 char *vrf = NULL;
10051
dc912615
DS
10052 afi_t afi = AFI_UNSPEC;
10053 safi_t safi = SAFI_UNSPEC;
d62a17ae 10054 enum clear_sort clr_sort = clear_peer;
10055 enum bgp_clear_type clr_type;
10056 char *clr_arg = NULL;
10057
10058 int idx = 0;
10059
10060 /* clear [ip] bgp */
10061 if (argv_find(argv, argc, "ip", &idx))
10062 afi = AFI_IP;
10063
9a8bdf1c
PG
10064 /* [<vrf> VIEWVRFNAME] */
10065 if (argv_find(argv, argc, "vrf", &idx)) {
10066 vrf = argv[idx + 1]->arg;
10067 idx += 2;
10068 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10069 vrf = NULL;
10070 } else if (argv_find(argv, argc, "view", &idx)) {
10071 /* [<view> VIEWVRFNAME] */
d62a17ae 10072 vrf = argv[idx + 1]->arg;
10073 idx += 2;
10074 }
d62a17ae 10075 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
10076 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
10077 argv_find_and_parse_safi(argv, argc, &idx, &safi);
10078
d7b9898c 10079 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
d62a17ae 10080 if (argv_find(argv, argc, "*", &idx)) {
10081 clr_sort = clear_all;
10082 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
10083 clr_sort = clear_peer;
10084 clr_arg = argv[idx]->arg;
10085 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
10086 clr_sort = clear_peer;
10087 clr_arg = argv[idx]->arg;
10088 } else if (argv_find(argv, argc, "peer-group", &idx)) {
10089 clr_sort = clear_group;
10090 idx++;
10091 clr_arg = argv[idx]->arg;
d7b9898c 10092 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
d62a17ae 10093 clr_sort = clear_peer;
10094 clr_arg = argv[idx]->arg;
8fa7d444
DS
10095 } else if (argv_find(argv, argc, "WORD", &idx)) {
10096 clr_sort = clear_peer;
10097 clr_arg = argv[idx]->arg;
d62a17ae 10098 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
10099 clr_sort = clear_as;
10100 clr_arg = argv[idx]->arg;
10101 } else if (argv_find(argv, argc, "external", &idx)) {
10102 clr_sort = clear_external;
10103 }
10104
3cb14f26 10105 /* [<soft [<in|out>]|in [prefix-filter]|out|message-stats>] */
d62a17ae 10106 if (argv_find(argv, argc, "soft", &idx)) {
10107 if (argv_find(argv, argc, "in", &idx)
10108 || argv_find(argv, argc, "out", &idx))
10109 clr_type = strmatch(argv[idx]->text, "in")
10110 ? BGP_CLEAR_SOFT_IN
10111 : BGP_CLEAR_SOFT_OUT;
10112 else
10113 clr_type = BGP_CLEAR_SOFT_BOTH;
10114 } else if (argv_find(argv, argc, "in", &idx)) {
10115 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
10116 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
10117 : BGP_CLEAR_SOFT_IN;
10118 } else if (argv_find(argv, argc, "out", &idx)) {
10119 clr_type = BGP_CLEAR_SOFT_OUT;
3cb14f26
DS
10120 } else if (argv_find(argv, argc, "message-stats", &idx)) {
10121 clr_type = BGP_CLEAR_MESSAGE_STATS;
d62a17ae 10122 } else
10123 clr_type = BGP_CLEAR_SOFT_NONE;
10124
1ca2fd11 10125 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 10126}
01080f7c 10127
8ad7271d
DS
10128DEFUN (clear_ip_bgp_prefix,
10129 clear_ip_bgp_prefix_cmd,
18c57037 10130 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
10131 CLEAR_STR
10132 IP_STR
10133 BGP_STR
838758ac 10134 BGP_INSTANCE_HELP_STR
8ad7271d 10135 "Clear bestpath and re-advertise\n"
0c7b1b01 10136 "IPv4 prefix\n")
8ad7271d 10137{
d62a17ae 10138 char *vrf = NULL;
10139 char *prefix = NULL;
8ad7271d 10140
d62a17ae 10141 int idx = 0;
01080f7c 10142
d62a17ae 10143 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
10144 if (argv_find(argv, argc, "vrf", &idx)) {
10145 vrf = argv[idx + 1]->arg;
10146 idx += 2;
10147 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10148 vrf = NULL;
10149 } else if (argv_find(argv, argc, "view", &idx)) {
10150 /* [<view> VIEWVRFNAME] */
10151 vrf = argv[idx + 1]->arg;
10152 idx += 2;
10153 }
0c7b1b01 10154
d62a17ae 10155 prefix = argv[argc - 1]->arg;
8ad7271d 10156
d62a17ae 10157 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 10158}
8ad7271d 10159
b09b5ae0
DW
10160DEFUN (clear_bgp_ipv6_safi_prefix,
10161 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 10162 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 10163 CLEAR_STR
3a2d747c 10164 IP_STR
718e3744 10165 BGP_STR
00e6edb9 10166 BGP_AF_STR
46f296b4 10167 BGP_SAFI_HELP_STR
b09b5ae0 10168 "Clear bestpath and re-advertise\n"
0c7b1b01 10169 "IPv6 prefix\n")
718e3744 10170{
9b475e76
PG
10171 int idx_safi = 0;
10172 int idx_ipv6_prefix = 0;
10173 safi_t safi = SAFI_UNICAST;
10174 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10175 argv[idx_ipv6_prefix]->arg : NULL;
10176
10177 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 10178 return bgp_clear_prefix(
9b475e76
PG
10179 vty, NULL, prefix, AFI_IP6,
10180 safi, NULL);
838758ac 10181}
01080f7c 10182
b09b5ae0
DW
10183DEFUN (clear_bgp_instance_ipv6_safi_prefix,
10184 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 10185 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 10186 CLEAR_STR
3a2d747c 10187 IP_STR
718e3744 10188 BGP_STR
838758ac 10189 BGP_INSTANCE_HELP_STR
00e6edb9 10190 BGP_AF_STR
46f296b4 10191 BGP_SAFI_HELP_STR
b09b5ae0 10192 "Clear bestpath and re-advertise\n"
0c7b1b01 10193 "IPv6 prefix\n")
718e3744 10194{
9b475e76 10195 int idx_safi = 0;
9a8bdf1c 10196 int idx_vrfview = 0;
9b475e76
PG
10197 int idx_ipv6_prefix = 0;
10198 safi_t safi = SAFI_UNICAST;
10199 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10200 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 10201 char *vrfview = NULL;
9b475e76 10202
9a8bdf1c
PG
10203 /* [<view|vrf> VIEWVRFNAME] */
10204 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
10205 vrfview = argv[idx_vrfview + 1]->arg;
10206 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
10207 vrfview = NULL;
10208 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
10209 /* [<view> VIEWVRFNAME] */
10210 vrfview = argv[idx_vrfview + 1]->arg;
10211 }
9b475e76
PG
10212 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10213
d62a17ae 10214 return bgp_clear_prefix(
9b475e76
PG
10215 vty, vrfview, prefix,
10216 AFI_IP6, safi, NULL);
718e3744 10217}
10218
b09b5ae0
DW
10219DEFUN (show_bgp_views,
10220 show_bgp_views_cmd,
d6e3c605 10221 "show [ip] bgp views",
b09b5ae0 10222 SHOW_STR
d6e3c605 10223 IP_STR
01080f7c 10224 BGP_STR
b09b5ae0 10225 "Show the defined BGP views\n")
01080f7c 10226{
d62a17ae 10227 struct list *inst = bm->bgp;
10228 struct listnode *node;
10229 struct bgp *bgp;
01080f7c 10230
d62a17ae 10231 vty_out(vty, "Defined BGP views:\n");
10232 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10233 /* Skip VRFs. */
10234 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
10235 continue;
10236 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
10237 bgp->as);
10238 }
e52702f2 10239
d62a17ae 10240 return CMD_SUCCESS;
e0081f70
ML
10241}
10242
8386ac43 10243DEFUN (show_bgp_vrfs,
10244 show_bgp_vrfs_cmd,
d6e3c605 10245 "show [ip] bgp vrfs [json]",
8386ac43 10246 SHOW_STR
d6e3c605 10247 IP_STR
8386ac43 10248 BGP_STR
10249 "Show BGP VRFs\n"
9973d184 10250 JSON_STR)
8386ac43 10251{
fe1dc5a3 10252 char buf[ETHER_ADDR_STRLEN];
d62a17ae 10253 struct list *inst = bm->bgp;
10254 struct listnode *node;
10255 struct bgp *bgp;
9f049418 10256 bool uj = use_json(argc, argv);
d62a17ae 10257 json_object *json = NULL;
10258 json_object *json_vrfs = NULL;
10259 int count = 0;
d62a17ae 10260
d62a17ae 10261 if (uj) {
10262 json = json_object_new_object();
10263 json_vrfs = json_object_new_object();
10264 }
10265
10266 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10267 const char *name, *type;
10268 struct peer *peer;
7fe96307 10269 struct listnode *node2, *nnode2;
d62a17ae 10270 int peers_cfg, peers_estb;
10271 json_object *json_vrf = NULL;
d62a17ae 10272
10273 /* Skip Views. */
10274 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
10275 continue;
10276
10277 count++;
efb4077a 10278 if (!uj && count == 1) {
fe1dc5a3 10279 vty_out(vty,
efb4077a 10280 "%4s %-5s %-16s %9s %10s %-37s\n",
3c0e7aa4 10281 "Type", "Id", "routerId", "#PeersCfg",
efb4077a
CS
10282 "#PeersEstb", "Name");
10283 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
10284 "L3-VNI", "RouterMAC", "Interface");
10285 }
d62a17ae 10286
10287 peers_cfg = peers_estb = 0;
10288 if (uj)
10289 json_vrf = json_object_new_object();
10290
10291
7fe96307 10292 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
d62a17ae 10293 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10294 continue;
10295 peers_cfg++;
feb17238 10296 if (peer_established(peer))
d62a17ae 10297 peers_estb++;
10298 }
10299
10300 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
5742e42b 10301 name = VRF_DEFAULT_NAME;
d62a17ae 10302 type = "DFLT";
10303 } else {
10304 name = bgp->name;
10305 type = "VRF";
10306 }
10307
a8bf7d9c 10308
d62a17ae 10309 if (uj) {
a4d82a8a
PZ
10310 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10311 ? -1
10312 : (int64_t)bgp->vrf_id;
23d0a753
DA
10313 char buf[BUFSIZ] = {0};
10314
d62a17ae 10315 json_object_string_add(json_vrf, "type", type);
10316 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
c949c771
DA
10317 json_object_string_addf(json_vrf, "routerId", "%pI4",
10318 &bgp->router_id);
d62a17ae 10319 json_object_int_add(json_vrf, "numConfiguredPeers",
10320 peers_cfg);
10321 json_object_int_add(json_vrf, "numEstablishedPeers",
10322 peers_estb);
10323
fe1dc5a3 10324 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
10325 json_object_string_add(
10326 json_vrf, "rmac",
10327 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
efb4077a
CS
10328 json_object_string_add(json_vrf, "interface",
10329 ifindex2ifname(bgp->l3vni_svi_ifindex,
10330 bgp->vrf_id));
d62a17ae 10331 json_object_object_add(json_vrfs, name, json_vrf);
efb4077a 10332 } else {
23d0a753 10333 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
a4d82a8a
PZ
10334 type,
10335 bgp->vrf_id == VRF_UNKNOWN ? -1
10336 : (int)bgp->vrf_id,
23d0a753 10337 &bgp->router_id, peers_cfg, peers_estb, name);
efb4077a
CS
10338 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
10339 bgp->l3vni,
10340 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
10341 ifindex2ifname(bgp->l3vni_svi_ifindex,
10342 bgp->vrf_id));
10343 }
d62a17ae 10344 }
10345
10346 if (uj) {
10347 json_object_object_add(json, "vrfs", json_vrfs);
10348
10349 json_object_int_add(json, "totalVrfs", count);
10350
75eeda93 10351 vty_json(vty, json);
d62a17ae 10352 } else {
10353 if (count)
10354 vty_out(vty,
10355 "\nTotal number of VRFs (including default): %d\n",
10356 count);
10357 }
10358
10359 return CMD_SUCCESS;
8386ac43 10360}
10361
48ecf8f5
DS
10362DEFUN (show_bgp_mac_hash,
10363 show_bgp_mac_hash_cmd,
10364 "show bgp mac hash",
10365 SHOW_STR
10366 BGP_STR
10367 "Mac Address\n"
10368 "Mac Address database\n")
10369{
10370 bgp_mac_dump_table(vty);
10371
10372 return CMD_SUCCESS;
10373}
acf71666 10374
e3b78da8 10375static void show_tip_entry(struct hash_bucket *bucket, void *args)
acf71666 10376{
0291c246 10377 struct vty *vty = (struct vty *)args;
e3b78da8 10378 struct tip_addr *tip = (struct tip_addr *)bucket->data;
acf71666 10379
23d0a753 10380 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
acf71666
MK
10381}
10382
10383static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10384{
10385 vty_out(vty, "self nexthop database:\n");
af97a18b 10386 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
10387
10388 vty_out(vty, "Tunnel-ip database:\n");
10389 hash_iterate(bgp->tip_hash,
e3b78da8 10390 (void (*)(struct hash_bucket *, void *))show_tip_entry,
acf71666
MK
10391 vty);
10392}
10393
15c81ca4
DS
10394DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10395 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10396 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
10397 "martian next-hops\n"
10398 "martian next-hop database\n")
acf71666 10399{
0291c246 10400 struct bgp *bgp = NULL;
15c81ca4 10401 int idx = 0;
9a8bdf1c
PG
10402 char *name = NULL;
10403
10404 /* [<vrf> VIEWVRFNAME] */
10405 if (argv_find(argv, argc, "vrf", &idx)) {
10406 name = argv[idx + 1]->arg;
10407 if (name && strmatch(name, VRF_DEFAULT_NAME))
10408 name = NULL;
10409 } else if (argv_find(argv, argc, "view", &idx))
10410 /* [<view> VIEWVRFNAME] */
10411 name = argv[idx + 1]->arg;
10412 if (name)
10413 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
10414 else
10415 bgp = bgp_get_default();
acf71666 10416
acf71666
MK
10417 if (!bgp) {
10418 vty_out(vty, "%% No BGP process is configured\n");
10419 return CMD_WARNING;
10420 }
10421 bgp_show_martian_nexthops(vty, bgp);
10422
10423 return CMD_SUCCESS;
10424}
10425
f412b39a 10426DEFUN (show_bgp_memory,
4bf6a362 10427 show_bgp_memory_cmd,
7fa12b13 10428 "show [ip] bgp memory",
4bf6a362 10429 SHOW_STR
3a2d747c 10430 IP_STR
4bf6a362
PJ
10431 BGP_STR
10432 "Global BGP memory statistics\n")
10433{
d62a17ae 10434 char memstrbuf[MTYPE_MEMSTR_LEN];
10435 unsigned long count;
10436
10437 /* RIB related usage stats */
10438 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10439 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10440 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9bcb3eef 10441 count * sizeof(struct bgp_dest)));
d62a17ae 10442
10443 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10444 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10445 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 10446 count * sizeof(struct bgp_path_info)));
d62a17ae 10447 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10448 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10449 count,
4b7e6066
DS
10450 mtype_memstr(
10451 memstrbuf, sizeof(memstrbuf),
10452 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 10453
10454 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10455 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10456 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10457 count * sizeof(struct bgp_static)));
10458
10459 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10460 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10461 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10462 count * sizeof(struct bpacket)));
10463
10464 /* Adj-In/Out */
10465 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10466 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10467 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10468 count * sizeof(struct bgp_adj_in)));
10469 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10470 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10471 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10472 count * sizeof(struct bgp_adj_out)));
10473
10474 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10475 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10476 count,
10477 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10478 count * sizeof(struct bgp_nexthop_cache)));
10479
10480 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10481 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10482 count,
10483 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10484 count * sizeof(struct bgp_damp_info)));
10485
10486 /* Attributes */
10487 count = attr_count();
10488 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10489 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10490 count * sizeof(struct attr)));
10491
10492 if ((count = attr_unknown_count()))
10493 vty_out(vty, "%ld unknown attributes\n", count);
10494
10495 /* AS_PATH attributes */
10496 count = aspath_count();
10497 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10498 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10499 count * sizeof(struct aspath)));
10500
10501 count = mtype_stats_alloc(MTYPE_AS_SEG);
10502 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10503 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10504 count * sizeof(struct assegment)));
10505
10506 /* Other attributes */
10507 if ((count = community_count()))
10508 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
10509 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10510 count * sizeof(struct community)));
d62a17ae 10511 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
145f7619
DA
10512 vty_out(vty,
10513 "%ld BGP ext-community entries, using %s of memory\n",
10514 count,
10515 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10516 count * sizeof(struct ecommunity)));
d62a17ae 10517 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10518 vty_out(vty,
10519 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
10520 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10521 count * sizeof(struct lcommunity)));
d62a17ae 10522
10523 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10524 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10525 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10526 count * sizeof(struct cluster_list)));
10527
10528 /* Peer related usage */
10529 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10530 vty_out(vty, "%ld peers, using %s of memory\n", count,
10531 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10532 count * sizeof(struct peer)));
10533
10534 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10535 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10536 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10537 count * sizeof(struct peer_group)));
10538
10539 /* Other */
d62a17ae 10540 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10541 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
10542 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10543 count * sizeof(regex_t)));
d62a17ae 10544 return CMD_SUCCESS;
4bf6a362 10545}
fee0f4c6 10546
57a9c8a8
DS
10547static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10548{
10549 json_object *bestpath = json_object_new_object();
10550
892fedb6 10551 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
57a9c8a8
DS
10552 json_object_string_add(bestpath, "asPath", "ignore");
10553
892fedb6 10554 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
57a9c8a8
DS
10555 json_object_string_add(bestpath, "asPath", "confed");
10556
892fedb6
DA
10557 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10558 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
a4d82a8a 10559 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
10560 "as-set");
10561 else
a4d82a8a 10562 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
10563 "true");
10564 } else
a4d82a8a 10565 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8 10566
ee88563a
JM
10567 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
10568 json_object_boolean_true_add(bestpath, "peerTypeRelax");
10569
892fedb6 10570 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
57a9c8a8 10571 json_object_string_add(bestpath, "compareRouterId", "true");
892fedb6
DA
10572 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10573 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10574 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
a4d82a8a 10575 json_object_string_add(bestpath, "med", "confed");
892fedb6 10576 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
57a9c8a8
DS
10577 json_object_string_add(bestpath, "med",
10578 "missing-as-worst");
10579 else
10580 json_object_string_add(bestpath, "med", "true");
10581 }
10582
10583 json_object_object_add(json, "bestPath", bestpath);
10584}
10585
3577f1c5
DD
10586/* Print the error code/subcode for why the peer is down */
10587static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10588 json_object *json_peer, bool use_json)
10589{
10590 const char *code_str;
10591 const char *subcode_str;
10592
10593 if (use_json) {
10594 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10595 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10596 char errorcodesubcode_hexstr[5];
10597 char errorcodesubcode_str[256];
10598
10599 code_str = bgp_notify_code_str(peer->notify.code);
10600 subcode_str = bgp_notify_subcode_str(
10601 peer->notify.code,
10602 peer->notify.subcode);
10603
772270f3
QY
10604 snprintf(errorcodesubcode_hexstr,
10605 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10606 peer->notify.code, peer->notify.subcode);
3577f1c5
DD
10607 json_object_string_add(json_peer,
10608 "lastErrorCodeSubcode",
10609 errorcodesubcode_hexstr);
10610 snprintf(errorcodesubcode_str, 255, "%s%s",
10611 code_str, subcode_str);
10612 json_object_string_add(json_peer,
10613 "lastNotificationReason",
10614 errorcodesubcode_str);
eea685b6
DA
10615 json_object_boolean_add(json_peer,
10616 "lastNotificationHardReset",
10617 peer->notify.hard_reset);
3577f1c5
DD
10618 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10619 && peer->notify.code == BGP_NOTIFY_CEASE
10620 && (peer->notify.subcode
10621 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10622 || peer->notify.subcode
10623 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10624 && peer->notify.length) {
10625 char msgbuf[1024];
10626 const char *msg_str;
10627
10628 msg_str = bgp_notify_admin_message(
10629 msgbuf, sizeof(msgbuf),
10630 (uint8_t *)peer->notify.data,
10631 peer->notify.length);
10632 if (msg_str)
10633 json_object_string_add(
10634 json_peer,
10635 "lastShutdownDescription",
10636 msg_str);
10637 }
10638
c258527b 10639 }
3577f1c5
DD
10640 json_object_string_add(json_peer, "lastResetDueTo",
10641 peer_down_str[(int)peer->last_reset]);
05912a17
DD
10642 json_object_int_add(json_peer, "lastResetCode",
10643 peer->last_reset);
3577f1c5
DD
10644 } else {
10645 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10646 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10647 code_str = bgp_notify_code_str(peer->notify.code);
10648 subcode_str =
10649 bgp_notify_subcode_str(peer->notify.code,
10650 peer->notify.subcode);
eea685b6 10651 vty_out(vty, " Notification %s (%s%s%s)\n",
3577f1c5 10652 peer->last_reset == PEER_DOWN_NOTIFY_SEND
eea685b6
DA
10653 ? "sent"
10654 : "received",
10655 code_str, subcode_str,
10656 peer->notify.hard_reset
10657 ? bgp_notify_subcode_str(
10658 BGP_NOTIFY_CEASE,
10659 BGP_NOTIFY_CEASE_HARD_RESET)
10660 : "");
3577f1c5 10661 } else {
e91c24c8 10662 vty_out(vty, " %s\n",
3577f1c5
DD
10663 peer_down_str[(int)peer->last_reset]);
10664 }
10665 }
10666}
10667
10668static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10669 safi_t safi)
10670{
feb17238 10671 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
3577f1c5
DD
10672}
10673
10674static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10675 struct peer *peer, json_object *json_peer,
10676 int max_neighbor_width, bool use_json)
10677{
10678 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10679 int len;
10680
10681 if (use_json) {
10682 if (peer_dynamic_neighbor(peer))
10683 json_object_boolean_true_add(json_peer,
10684 "dynamicPeer");
10685 if (peer->hostname)
10686 json_object_string_add(json_peer, "hostname",
10687 peer->hostname);
10688
10689 if (peer->domainname)
10690 json_object_string_add(json_peer, "domainname",
10691 peer->domainname);
10692 json_object_int_add(json_peer, "connectionsEstablished",
10693 peer->established);
10694 json_object_int_add(json_peer, "connectionsDropped",
10695 peer->dropped);
10696 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10697 use_json, json_peer);
feb17238 10698 if (peer_established(peer))
3577f1c5
DD
10699 json_object_string_add(json_peer, "lastResetDueTo",
10700 "AFI/SAFI Not Negotiated");
10701 else
10702 bgp_show_peer_reset(NULL, peer, json_peer, true);
10703 } else {
10704 dn_flag[1] = '\0';
10705 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10706 if (peer->hostname
892fedb6 10707 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
3577f1c5
DD
10708 len = vty_out(vty, "%s%s(%s)", dn_flag,
10709 peer->hostname, peer->host);
10710 else
10711 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10712
10713 /* pad the neighbor column with spaces */
10714 if (len < max_neighbor_width)
10715 vty_out(vty, "%*s", max_neighbor_width - len,
10716 " ");
e91c24c8 10717 vty_out(vty, "%7d %7d %9s", peer->established,
3577f1c5
DD
10718 peer->dropped,
10719 peer_uptime(peer->uptime, timebuf,
10720 BGP_UPTIME_LEN, 0, NULL));
feb17238 10721 if (peer_established(peer))
3577f1c5
DD
10722 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10723 else
10724 bgp_show_peer_reset(vty, peer, NULL,
10725 false);
10726 }
10727}
c258527b 10728
565e9ddd 10729/* Strip peer's description to the given size. */
cb75bb31
DA
10730static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10731{
10732 static char stripped[BUFSIZ];
64541ffa
FD
10733 uint32_t i = 0;
10734 uint32_t last_space = 0;
cb75bb31 10735
64541ffa
FD
10736 while (i < size) {
10737 if (*(desc + i) == 0) {
10738 stripped[i] = '\0';
10739 return stripped;
10740 }
10741 if (i != 0 && *(desc + i) == ' ' && last_space != i - 1)
10742 last_space = i;
10743 stripped[i] = *(desc + i);
10744 i++;
10745 }
10746
10747 if (last_space > size)
10748 stripped[size + 1] = '\0';
10749 else
10750 stripped[last_space] = '\0';
cb75bb31
DA
10751
10752 return stripped;
10753}
3577f1c5 10754
8c1d4cd5
LS
10755/* Determine whether var peer should be filtered out of the summary. */
10756static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
10757 struct peer *fpeer, int as_type,
10758 as_t as)
10759{
10760
10761 /* filter neighbor XXXX */
10762 if (fpeer && fpeer != peer)
10763 return true;
10764
10765 /* filter remote-as (internal|external) */
10766 if (as_type != AS_UNSPECIFIED) {
10767 if (peer->as_type == AS_SPECIFIED) {
10768 if (as_type == AS_INTERNAL) {
10769 if (peer->as != peer->local_as)
10770 return true;
10771 } else if (peer->as == peer->local_as)
10772 return true;
10773 } else if (as_type != peer->as_type)
10774 return true;
10775 } else if (as && as != peer->as) /* filter remote-as XXX */
10776 return true;
10777
10778 return false;
10779}
10780
565e9ddd
DA
10781/* Show BGP peer's summary information.
10782 *
10783 * Peer's description is stripped according to if `wide` option is given
10784 * or not.
10785 *
10786 * When adding new columns to `show bgp summary` output, please make
10787 * sure `Desc` is the lastest column to show because it can contain
10788 * whitespaces and the whole output will be tricky.
10789 */
d62a17ae 10790static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
8c1d4cd5 10791 struct peer *fpeer, int as_type, as_t as,
96c81f66 10792 uint16_t show_flags)
d62a17ae 10793{
10794 struct peer *peer;
10795 struct listnode *node, *nnode;
10796 unsigned int count = 0, dn_count = 0;
10797 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10798 char neighbor_buf[VTY_BUFSIZ];
10799 int neighbor_col_default_width = 16;
3577f1c5 10800 int len, failed_count = 0;
ce1944f0 10801 unsigned int filtered_count = 0;
d62a17ae 10802 int max_neighbor_width = 0;
10803 int pfx_rcd_safi;
3c13337d 10804 json_object *json = NULL;
d62a17ae 10805 json_object *json_peer = NULL;
10806 json_object *json_peers = NULL;
50e05855 10807 struct peer_af *paf;
d3ada366 10808 struct bgp_filter *filter;
85eeb029
DA
10809 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10810 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10811 bool show_established =
10812 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10813 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
96c81f66 10814 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
d62a17ae 10815
10816 /* labeled-unicast routes are installed in the unicast table so in order
10817 * to
10818 * display the correct PfxRcd value we must look at SAFI_UNICAST
10819 */
3577f1c5 10820
d62a17ae 10821 if (safi == SAFI_LABELED_UNICAST)
10822 pfx_rcd_safi = SAFI_UNICAST;
10823 else
10824 pfx_rcd_safi = safi;
10825
10826 if (use_json) {
3c13337d 10827 json = json_object_new_object();
d62a17ae 10828 json_peers = json_object_new_object();
3577f1c5 10829 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8c1d4cd5
LS
10830 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10831 as_type, as)) {
ce1944f0 10832 filtered_count++;
8c1d4cd5
LS
10833 count++;
10834 continue;
10835 }
10836
3577f1c5
DD
10837 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10838 continue;
10839
10840 if (peer->afc[afi][safi]) {
10841 /* See if we have at least a single failed peer */
10842 if (bgp_has_peer_failed(peer, afi, safi))
10843 failed_count++;
10844 count++;
10845 }
10846 if (peer_dynamic_neighbor(peer))
10847 dn_count++;
10848 }
c258527b 10849
d62a17ae 10850 } else {
10851 /* Loop over all neighbors that will be displayed to determine
10852 * how many
10853 * characters are needed for the Neighbor column
10854 */
10855 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8c1d4cd5
LS
10856 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10857 as_type, as)) {
ce1944f0 10858 filtered_count++;
8c1d4cd5
LS
10859 count++;
10860 continue;
10861 }
10862
d62a17ae 10863 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10864 continue;
10865
10866 if (peer->afc[afi][safi]) {
10867 memset(dn_flag, '\0', sizeof(dn_flag));
10868 if (peer_dynamic_neighbor(peer))
10869 dn_flag[0] = '*';
10870
10871 if (peer->hostname
892fedb6
DA
10872 && CHECK_FLAG(bgp->flags,
10873 BGP_FLAG_SHOW_HOSTNAME))
772270f3
QY
10874 snprintf(neighbor_buf,
10875 sizeof(neighbor_buf),
10876 "%s%s(%s) ", dn_flag,
10877 peer->hostname, peer->host);
d62a17ae 10878 else
772270f3
QY
10879 snprintf(neighbor_buf,
10880 sizeof(neighbor_buf), "%s%s ",
10881 dn_flag, peer->host);
d62a17ae 10882
10883 len = strlen(neighbor_buf);
10884
10885 if (len > max_neighbor_width)
10886 max_neighbor_width = len;
c258527b 10887
3577f1c5
DD
10888 /* See if we have at least a single failed peer */
10889 if (bgp_has_peer_failed(peer, afi, safi))
10890 failed_count++;
10891 count++;
d62a17ae 10892 }
10893 }
f933309e 10894
d62a17ae 10895 /* Originally we displayed the Neighbor column as 16
10896 * characters wide so make that the default
10897 */
10898 if (max_neighbor_width < neighbor_col_default_width)
10899 max_neighbor_width = neighbor_col_default_width;
10900 }
f933309e 10901
3577f1c5
DD
10902 if (show_failed && !failed_count) {
10903 if (use_json) {
10904 json_object_int_add(json, "failedPeersCount", 0);
10905 json_object_int_add(json, "dynamicPeers", dn_count);
c258527b 10906 json_object_int_add(json, "totalPeers", count);
3577f1c5 10907
75eeda93 10908 vty_json(vty, json);
3577f1c5
DD
10909 } else {
10910 vty_out(vty, "%% No failed BGP neighbors found\n");
3577f1c5
DD
10911 }
10912 return CMD_SUCCESS;
10913 }
c258527b 10914
3577f1c5 10915 count = 0; /* Reset the value as its used again */
ce1944f0 10916 filtered_count = 0;
800867d8 10917 dn_count = 0;
d62a17ae 10918 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10919 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10920 continue;
10921
ea47320b
DL
10922 if (!peer->afc[afi][safi])
10923 continue;
d62a17ae 10924
ea47320b
DL
10925 if (!count) {
10926 unsigned long ents;
10927 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 10928 int64_t vrf_id_ui;
d62a17ae 10929
a4d82a8a
PZ
10930 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10931 ? -1
10932 : (int64_t)bgp->vrf_id;
ea47320b
DL
10933
10934 /* Usage summary and header */
10935 if (use_json) {
c949c771
DA
10936 json_object_string_addf(json, "routerId",
10937 "%pI4",
10938 &bgp->router_id);
60466a63
QY
10939 json_object_int_add(json, "as", bgp->as);
10940 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
10941 json_object_string_add(
10942 json, "vrfName",
10943 (bgp->inst_type
10944 == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 10945 ? VRF_DEFAULT_NAME
ea47320b
DL
10946 : bgp->name);
10947 } else {
10948 vty_out(vty,
23d0a753
DA
10949 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10950 &bgp->router_id, bgp->as,
a4d82a8a
PZ
10951 bgp->vrf_id == VRF_UNKNOWN
10952 ? -1
10953 : (int)bgp->vrf_id);
ea47320b
DL
10954 vty_out(vty, "\n");
10955 }
d62a17ae 10956
ea47320b 10957 if (bgp_update_delay_configured(bgp)) {
d62a17ae 10958 if (use_json) {
ea47320b 10959 json_object_int_add(
60466a63 10960 json, "updateDelayLimit",
ea47320b 10961 bgp->v_update_delay);
d62a17ae 10962
ea47320b
DL
10963 if (bgp->v_update_delay
10964 != bgp->v_establish_wait)
d62a17ae 10965 json_object_int_add(
10966 json,
ea47320b
DL
10967 "updateDelayEstablishWait",
10968 bgp->v_establish_wait);
d62a17ae 10969
60466a63 10970 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
10971 json_object_string_add(
10972 json,
10973 "updateDelayFirstNeighbor",
10974 bgp->update_delay_begin_time);
10975 json_object_boolean_true_add(
10976 json,
10977 "updateDelayInProgress");
10978 } else {
10979 if (bgp->update_delay_over) {
d62a17ae 10980 json_object_string_add(
10981 json,
10982 "updateDelayFirstNeighbor",
10983 bgp->update_delay_begin_time);
ea47320b 10984 json_object_string_add(
d62a17ae 10985 json,
ea47320b
DL
10986 "updateDelayBestpathResumed",
10987 bgp->update_delay_end_time);
10988 json_object_string_add(
d62a17ae 10989 json,
ea47320b
DL
10990 "updateDelayZebraUpdateResume",
10991 bgp->update_delay_zebra_resume_time);
10992 json_object_string_add(
10993 json,
10994 "updateDelayPeerUpdateResume",
10995 bgp->update_delay_peers_resume_time);
d62a17ae 10996 }
ea47320b
DL
10997 }
10998 } else {
10999 vty_out(vty,
11000 "Read-only mode update-delay limit: %d seconds\n",
11001 bgp->v_update_delay);
11002 if (bgp->v_update_delay
11003 != bgp->v_establish_wait)
d62a17ae 11004 vty_out(vty,
ea47320b
DL
11005 " Establish wait: %d seconds\n",
11006 bgp->v_establish_wait);
d62a17ae 11007
60466a63 11008 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
11009 vty_out(vty,
11010 " First neighbor established: %s\n",
11011 bgp->update_delay_begin_time);
11012 vty_out(vty,
11013 " Delay in progress\n");
11014 } else {
11015 if (bgp->update_delay_over) {
d62a17ae 11016 vty_out(vty,
11017 " First neighbor established: %s\n",
11018 bgp->update_delay_begin_time);
11019 vty_out(vty,
ea47320b
DL
11020 " Best-paths resumed: %s\n",
11021 bgp->update_delay_end_time);
11022 vty_out(vty,
11023 " zebra update resumed: %s\n",
11024 bgp->update_delay_zebra_resume_time);
11025 vty_out(vty,
11026 " peers update resumed: %s\n",
11027 bgp->update_delay_peers_resume_time);
d62a17ae 11028 }
11029 }
11030 }
ea47320b 11031 }
d62a17ae 11032
ea47320b
DL
11033 if (use_json) {
11034 if (bgp_maxmed_onstartup_configured(bgp)
11035 && bgp->maxmed_active)
11036 json_object_boolean_true_add(
60466a63 11037 json, "maxMedOnStartup");
ea47320b
DL
11038 if (bgp->v_maxmed_admin)
11039 json_object_boolean_true_add(
60466a63 11040 json, "maxMedAdministrative");
d62a17ae 11041
ea47320b
DL
11042 json_object_int_add(
11043 json, "tableVersion",
60466a63 11044 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 11045
60466a63
QY
11046 ents = bgp_table_count(bgp->rib[afi][safi]);
11047 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
11048 json_object_int_add(
11049 json, "ribMemory",
9bcb3eef 11050 ents * sizeof(struct bgp_dest));
d62a17ae 11051
210ec2a0 11052 ents = bgp->af_peer_count[afi][safi];
60466a63
QY
11053 json_object_int_add(json, "peerCount", ents);
11054 json_object_int_add(json, "peerMemory",
11055 ents * sizeof(struct peer));
d62a17ae 11056
ea47320b
DL
11057 if ((ents = listcount(bgp->group))) {
11058 json_object_int_add(
60466a63 11059 json, "peerGroupCount", ents);
ea47320b
DL
11060 json_object_int_add(
11061 json, "peerGroupMemory",
996c9314
LB
11062 ents * sizeof(struct
11063 peer_group));
ea47320b 11064 }
d62a17ae 11065
ea47320b
DL
11066 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11067 BGP_CONFIG_DAMPENING))
11068 json_object_boolean_true_add(
60466a63 11069 json, "dampeningEnabled");
ea47320b 11070 } else {
96c81f66
LS
11071 if (!show_terse) {
11072 if (bgp_maxmed_onstartup_configured(bgp)
11073 && bgp->maxmed_active)
11074 vty_out(vty,
11075 "Max-med on-startup active\n");
11076 if (bgp->v_maxmed_admin)
11077 vty_out(vty,
11078 "Max-med administrative active\n");
d62a17ae 11079
96c81f66
LS
11080 vty_out(vty,
11081 "BGP table version %" PRIu64
11082 "\n",
11083 bgp_table_version(
11084 bgp->rib[afi][safi]));
ea47320b 11085
96c81f66
LS
11086 ents = bgp_table_count(
11087 bgp->rib[afi][safi]);
d62a17ae 11088 vty_out(vty,
96c81f66 11089 "RIB entries %ld, using %s of memory\n",
d62a17ae 11090 ents,
11091 mtype_memstr(
11092 memstrbuf,
11093 sizeof(memstrbuf),
96c81f66
LS
11094 ents
11095 * sizeof(
11096 struct
11097 bgp_dest)));
d62a17ae 11098
96c81f66
LS
11099 /* Peer related usage */
11100 ents = bgp->af_peer_count[afi][safi];
11101 vty_out(vty,
11102 "Peers %ld, using %s of memory\n",
11103 ents,
11104 mtype_memstr(
11105 memstrbuf,
11106 sizeof(memstrbuf),
11107 ents
11108 * sizeof(
11109 struct
11110 peer)));
d62a17ae 11111
96c81f66
LS
11112 if ((ents = listcount(bgp->group)))
11113 vty_out(vty,
11114 "Peer groups %ld, using %s of memory\n",
11115 ents,
11116 mtype_memstr(
11117 memstrbuf,
11118 sizeof(memstrbuf),
11119 ents
11120 * sizeof(
11121 struct
11122 peer_group)));
11123
11124 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11125 BGP_CONFIG_DAMPENING))
11126 vty_out(vty,
11127 "Dampening enabled.\n");
11128 }
11129 if (show_failed) {
11130 vty_out(vty, "\n");
11131
11132 /* Subtract 8 here because 'Neighbor' is
11133 * 8 characters */
11134 vty_out(vty, "Neighbor");
11135 vty_out(vty, "%*s",
11136 max_neighbor_width - 8, " ");
85eeb029
DA
11137 vty_out(vty,
11138 BGP_SHOW_SUMMARY_HEADER_FAILED);
96c81f66 11139 }
d62a17ae 11140 }
ea47320b 11141 }
d62a17ae 11142
d55811cc 11143 paf = peer_af_find(peer, afi, safi);
d3ada366 11144 filter = &peer->filter[afi][safi];
db92d226 11145
ea47320b 11146 count++;
3577f1c5
DD
11147 /* Works for both failed & successful cases */
11148 if (peer_dynamic_neighbor(peer))
11149 dn_count++;
d62a17ae 11150
ea47320b 11151 if (use_json) {
3577f1c5 11152 json_peer = NULL;
8c1d4cd5 11153 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
ce1944f0
LS
11154 as_type, as)) {
11155 filtered_count++;
8c1d4cd5 11156 continue;
ce1944f0 11157 }
3577f1c5
DD
11158 if (show_failed &&
11159 bgp_has_peer_failed(peer, afi, safi)) {
11160 json_peer = json_object_new_object();
11161 bgp_show_failed_summary(vty, bgp, peer,
11162 json_peer, 0, use_json);
11163 } else if (!show_failed) {
10b49f14 11164 if (show_established
ce1944f0
LS
11165 && bgp_has_peer_failed(peer, afi, safi)) {
11166 filtered_count++;
10b49f14 11167 continue;
ce1944f0 11168 }
10b49f14 11169
3577f1c5
DD
11170 json_peer = json_object_new_object();
11171 if (peer_dynamic_neighbor(peer)) {
11172 json_object_boolean_true_add(json_peer,
11173 "dynamicPeer");
11174 }
d62a17ae 11175
3577f1c5
DD
11176 if (peer->hostname)
11177 json_object_string_add(json_peer, "hostname",
11178 peer->hostname);
11179
11180 if (peer->domainname)
11181 json_object_string_add(json_peer, "domainname",
11182 peer->domainname);
11183
11184 json_object_int_add(json_peer, "remoteAs", peer->as);
c854765f
DA
11185 json_object_int_add(
11186 json_peer, "localAs",
11187 peer->change_local_as
11188 ? peer->change_local_as
11189 : peer->local_as);
3577f1c5
DD
11190 json_object_int_add(json_peer, "version", 4);
11191 json_object_int_add(json_peer, "msgRcvd",
11192 PEER_TOTAL_RX(peer));
11193 json_object_int_add(json_peer, "msgSent",
11194 PEER_TOTAL_TX(peer));
11195
43aa5965
QY
11196 atomic_size_t outq_count, inq_count;
11197 outq_count = atomic_load_explicit(
11198 &peer->obuf->count,
11199 memory_order_relaxed);
11200 inq_count = atomic_load_explicit(
11201 &peer->ibuf->count,
11202 memory_order_relaxed);
11203
3577f1c5
DD
11204 json_object_int_add(json_peer, "tableVersion",
11205 peer->version[afi][safi]);
11206 json_object_int_add(json_peer, "outq",
43aa5965
QY
11207 outq_count);
11208 json_object_int_add(json_peer, "inq",
11209 inq_count);
3577f1c5
DD
11210 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
11211 use_json, json_peer);
11212
3577f1c5
DD
11213 json_object_int_add(json_peer, "pfxRcd",
11214 peer->pcount[afi][pfx_rcd_safi]);
11215
3577f1c5 11216 if (paf && PAF_SUBGRP(paf))
a616dd1f
DA
11217 json_object_int_add(
11218 json_peer, "pfxSnt",
11219 (PAF_SUBGRP(paf))->scount);
11220 else
11221 json_object_int_add(json_peer, "pfxSnt",
11222 0);
0e1f8ab5
DA
11223
11224 /* BGP FSM state */
cb9196e7 11225 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
736b68f3
DS
11226 || CHECK_FLAG(peer->bgp->flags,
11227 BGP_FLAG_SHUTDOWN))
0e1f8ab5
DA
11228 json_object_string_add(json_peer,
11229 "state",
3577f1c5
DD
11230 "Idle (Admin)");
11231 else if (peer->afc_recv[afi][safi])
11232 json_object_string_add(
0e1f8ab5
DA
11233 json_peer, "state",
11234 lookup_msg(bgp_status_msg,
11235 peer->status, NULL));
11236 else if (CHECK_FLAG(
11237 peer->sflags,
11238 PEER_STATUS_PREFIX_OVERFLOW))
11239 json_object_string_add(json_peer,
11240 "state",
3577f1c5
DD
11241 "Idle (PfxCt)");
11242 else
11243 json_object_string_add(
0e1f8ab5
DA
11244 json_peer, "state",
11245 lookup_msg(bgp_status_msg,
11246 peer->status, NULL));
11247
11248 /* BGP peer state */
11249 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11250 || CHECK_FLAG(peer->bgp->flags,
11251 BGP_FLAG_SHUTDOWN))
11252 json_object_string_add(json_peer,
11253 "peerState",
11254 "Admin");
11255 else if (CHECK_FLAG(
11256 peer->sflags,
11257 PEER_STATUS_PREFIX_OVERFLOW))
11258 json_object_string_add(json_peer,
11259 "peerState",
11260 "PfxCt");
11261 else if (CHECK_FLAG(peer->flags,
11262 PEER_FLAG_PASSIVE))
11263 json_object_string_add(json_peer,
11264 "peerState",
11265 "Passive");
11266 else if (CHECK_FLAG(peer->sflags,
11267 PEER_STATUS_NSF_WAIT))
11268 json_object_string_add(json_peer,
11269 "peerState",
11270 "NSF passive");
11271 else if (CHECK_FLAG(
11272 peer->bgp->flags,
11273 BGP_FLAG_EBGP_REQUIRES_POLICY)
11274 && (!bgp_inbound_policy_exists(peer,
11275 filter)
11276 || !bgp_outbound_policy_exists(
11277 peer, filter)))
11278 json_object_string_add(json_peer,
11279 "peerState",
11280 "Policy");
11281 else
11282 json_object_string_add(
11283 json_peer, "peerState", "OK");
11284
200116db
DD
11285 json_object_int_add(json_peer, "connectionsEstablished",
11286 peer->established);
11287 json_object_int_add(json_peer, "connectionsDropped",
11288 peer->dropped);
aa72bd7e
PG
11289 if (peer->desc)
11290 json_object_string_add(
11291 json_peer, "desc", peer->desc);
b4e9dcba 11292 }
3577f1c5
DD
11293 /* Avoid creating empty peer dicts in JSON */
11294 if (json_peer == NULL)
11295 continue;
ea47320b
DL
11296
11297 if (peer->conf_if)
60466a63 11298 json_object_string_add(json_peer, "idType",
ea47320b
DL
11299 "interface");
11300 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
11301 json_object_string_add(json_peer, "idType",
11302 "ipv4");
ea47320b 11303 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
11304 json_object_string_add(json_peer, "idType",
11305 "ipv6");
ea47320b
DL
11306 json_object_object_add(json_peers, peer->host,
11307 json_peer);
11308 } else {
8c1d4cd5 11309 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
ce1944f0
LS
11310 as_type, as)) {
11311 filtered_count++;
8c1d4cd5 11312 continue;
ce1944f0 11313 }
3577f1c5
DD
11314 if (show_failed &&
11315 bgp_has_peer_failed(peer, afi, safi)) {
11316 bgp_show_failed_summary(vty, bgp, peer, NULL,
11317 max_neighbor_width,
11318 use_json);
11319 } else if (!show_failed) {
10b49f14 11320 if (show_established
ce1944f0
LS
11321 && bgp_has_peer_failed(peer, afi, safi)) {
11322 filtered_count++;
10b49f14 11323 continue;
ce1944f0 11324 }
96c81f66
LS
11325
11326 if ((count - filtered_count) == 1) {
11327 /* display headline before the first
11328 * neighbor line */
11329 vty_out(vty, "\n");
11330
11331 /* Subtract 8 here because 'Neighbor' is
11332 * 8 characters */
11333 vty_out(vty, "Neighbor");
11334 vty_out(vty, "%*s",
11335 max_neighbor_width - 8, " ");
11336 vty_out(vty,
11337 show_wide
11338 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
11339 : BGP_SHOW_SUMMARY_HEADER_ALL);
11340 }
11341
3577f1c5
DD
11342 memset(dn_flag, '\0', sizeof(dn_flag));
11343 if (peer_dynamic_neighbor(peer)) {
11344 dn_flag[0] = '*';
11345 }
d62a17ae 11346
3577f1c5 11347 if (peer->hostname
892fedb6
DA
11348 && CHECK_FLAG(bgp->flags,
11349 BGP_FLAG_SHOW_HOSTNAME))
3577f1c5 11350 len = vty_out(vty, "%s%s(%s)", dn_flag,
892fedb6
DA
11351 peer->hostname,
11352 peer->host);
d62a17ae 11353 else
3577f1c5
DD
11354 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11355
11356 /* pad the neighbor column with spaces */
11357 if (len < max_neighbor_width)
11358 vty_out(vty, "%*s", max_neighbor_width - len,
11359 " ");
11360
43aa5965
QY
11361 atomic_size_t outq_count, inq_count;
11362 outq_count = atomic_load_explicit(
11363 &peer->obuf->count,
11364 memory_order_relaxed);
11365 inq_count = atomic_load_explicit(
11366 &peer->ibuf->count,
11367 memory_order_relaxed);
11368
85eeb029
DA
11369 if (show_wide)
11370 vty_out(vty,
11371 "4 %10u %10u %9u %9u %8" PRIu64
11372 " %4zu %4zu %8s",
11373 peer->as,
11374 peer->change_local_as
11375 ? peer->change_local_as
11376 : peer->local_as,
11377 PEER_TOTAL_RX(peer),
11378 PEER_TOTAL_TX(peer),
11379 peer->version[afi][safi],
11380 inq_count, outq_count,
11381 peer_uptime(peer->uptime,
11382 timebuf,
11383 BGP_UPTIME_LEN, 0,
11384 NULL));
11385 else
11386 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
11387 " %4zu %4zu %8s",
11388 peer->as, PEER_TOTAL_RX(peer),
11389 PEER_TOTAL_TX(peer),
11390 peer->version[afi][safi],
11391 inq_count, outq_count,
11392 peer_uptime(peer->uptime,
11393 timebuf,
11394 BGP_UPTIME_LEN, 0,
11395 NULL));
3577f1c5 11396
feb17238 11397 if (peer_established(peer)) {
d3ada366
DA
11398 if (peer->afc_recv[afi][safi]) {
11399 if (CHECK_FLAG(
11400 bgp->flags,
11401 BGP_FLAG_EBGP_REQUIRES_POLICY)
11402 && !bgp_inbound_policy_exists(
11403 peer, filter))
11404 vty_out(vty, " %12s",
11405 "(Policy)");
11406 else
11407 vty_out(vty,
6cde4b45 11408 " %12u",
d3ada366
DA
11409 peer->pcount
11410 [afi]
11411 [pfx_rcd_safi]);
11412 } else {
749d0f27 11413 vty_out(vty, " NoNeg");
d3ada366 11414 }
db92d226 11415
d3ada366
DA
11416 if (paf && PAF_SUBGRP(paf)) {
11417 if (CHECK_FLAG(
11418 bgp->flags,
11419 BGP_FLAG_EBGP_REQUIRES_POLICY)
11420 && !bgp_outbound_policy_exists(
11421 peer, filter))
11422 vty_out(vty, " %8s",
11423 "(Policy)");
11424 else
11425 vty_out(vty,
6cde4b45 11426 " %8u",
d3ada366
DA
11427 (PAF_SUBGRP(
11428 paf))
11429 ->scount);
749d0f27
DA
11430 } else {
11431 vty_out(vty, " NoNeg");
d3ada366 11432 }
db92d226 11433 } else {
736b68f3
DS
11434 if (CHECK_FLAG(peer->flags,
11435 PEER_FLAG_SHUTDOWN)
11436 || CHECK_FLAG(peer->bgp->flags,
11437 BGP_FLAG_SHUTDOWN))
3577f1c5
DD
11438 vty_out(vty, " Idle (Admin)");
11439 else if (CHECK_FLAG(
11440 peer->sflags,
11441 PEER_STATUS_PREFIX_OVERFLOW))
11442 vty_out(vty, " Idle (PfxCt)");
11443 else
11444 vty_out(vty, " %12s",
11445 lookup_msg(bgp_status_msg,
11446 peer->status, NULL));
db92d226 11447
6cde4b45 11448 vty_out(vty, " %8u", 0);
3577f1c5 11449 }
565e9ddd
DA
11450 /* Make sure `Desc` column is the lastest in
11451 * the output.
11452 */
aa72bd7e 11453 if (peer->desc)
cb75bb31
DA
11454 vty_out(vty, " %s",
11455 bgp_peer_description_stripped(
85eeb029
DA
11456 peer->desc,
11457 show_wide ? 64 : 20));
aa72bd7e
PG
11458 else
11459 vty_out(vty, " N/A");
3577f1c5 11460 vty_out(vty, "\n");
d62a17ae 11461 }
3577f1c5 11462
d62a17ae 11463 }
11464 }
f933309e 11465
d62a17ae 11466 if (use_json) {
11467 json_object_object_add(json, "peers", json_peers);
3577f1c5 11468 json_object_int_add(json, "failedPeers", failed_count);
ce1944f0
LS
11469 json_object_int_add(json, "displayedPeers",
11470 count - filtered_count);
d62a17ae 11471 json_object_int_add(json, "totalPeers", count);
11472 json_object_int_add(json, "dynamicPeers", dn_count);
11473
3577f1c5
DD
11474 if (!show_failed)
11475 bgp_show_bestpath_json(bgp, json);
57a9c8a8 11476
75eeda93 11477 vty_json(vty, json);
d62a17ae 11478 } else {
ce1944f0 11479 if (count) {
96c81f66
LS
11480 if (filtered_count == count)
11481 vty_out(vty, "\n%% No matching neighbor\n");
11482 else {
11483 if (show_failed)
11484 vty_out(vty, "\nDisplayed neighbors %d",
11485 failed_count);
11486 else if (as_type != AS_UNSPECIFIED || as
11487 || fpeer || show_established)
ce1944f0
LS
11488 vty_out(vty, "\nDisplayed neighbors %d",
11489 count - filtered_count);
96c81f66
LS
11490
11491 vty_out(vty, "\nTotal number of neighbors %d\n",
11492 count);
ce1944f0 11493 }
ce1944f0 11494 } else {
d6ceaca3 11495 vty_out(vty, "No %s neighbor is configured\n",
5cb5f4d0 11496 get_afi_safi_str(afi, safi, false));
d62a17ae 11497 }
b05a1c8b 11498
d6ceaca3 11499 if (dn_count) {
d62a17ae 11500 vty_out(vty, "* - dynamic neighbor\n");
11501 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11502 dn_count, bgp->dynamic_neighbors_limit);
11503 }
11504 }
1ff9a340 11505
d62a17ae 11506 return CMD_SUCCESS;
718e3744 11507}
11508
d62a17ae 11509static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8c1d4cd5 11510 int safi, struct peer *fpeer, int as_type,
96c81f66 11511 as_t as, uint16_t show_flags)
d62a17ae 11512{
11513 int is_first = 1;
11514 int afi_wildcard = (afi == AFI_MAX);
11515 int safi_wildcard = (safi == SAFI_MAX);
11516 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 11517 bool nbr_output = false;
85eeb029 11518 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 11519
11520 if (use_json && is_wildcard)
11521 vty_out(vty, "{\n");
11522 if (afi_wildcard)
11523 afi = 1; /* AFI_IP */
11524 while (afi < AFI_MAX) {
11525 if (safi_wildcard)
11526 safi = 1; /* SAFI_UNICAST */
11527 while (safi < SAFI_MAX) {
318cac96 11528 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 11529 nbr_output = true;
f86897b9 11530
d62a17ae 11531 if (is_wildcard) {
11532 /*
11533 * So limit output to those afi/safi
11534 * pairs that
11535 * actualy have something interesting in
11536 * them
11537 */
11538 if (use_json) {
d62a17ae 11539 if (!is_first)
11540 vty_out(vty, ",\n");
11541 else
11542 is_first = 0;
11543
11544 vty_out(vty, "\"%s\":",
5cb5f4d0
DD
11545 get_afi_safi_str(afi,
11546 safi,
11547 true));
d62a17ae 11548 } else {
6cac2fcc
LS
11549 vty_out(vty,
11550 "\n%s Summary (%s):\n",
5cb5f4d0
DD
11551 get_afi_safi_str(afi,
11552 safi,
6cac2fcc
LS
11553 false),
11554 bgp->name_pretty);
d62a17ae 11555 }
11556 }
8c1d4cd5
LS
11557 bgp_show_summary(vty, bgp, afi, safi, fpeer,
11558 as_type, as, show_flags);
d62a17ae 11559 }
11560 safi++;
d62a17ae 11561 if (!safi_wildcard)
11562 safi = SAFI_MAX;
11563 }
11564 afi++;
ee851c8c 11565 if (!afi_wildcard)
d62a17ae 11566 afi = AFI_MAX;
11567 }
11568
11569 if (use_json && is_wildcard)
11570 vty_out(vty, "}\n");
ca61fd25
DS
11571 else if (!nbr_output) {
11572 if (use_json)
11573 vty_out(vty, "{}\n");
11574 else
6cac2fcc
LS
11575 vty_out(vty, "%% No BGP neighbors found in %s\n",
11576 bgp->name_pretty);
ca61fd25 11577 }
d62a17ae 11578}
11579
11580static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8c1d4cd5
LS
11581 safi_t safi,
11582 const char *neighbor,
11583 int as_type, as_t as,
96c81f66 11584 uint16_t show_flags)
d62a17ae 11585{
11586 struct listnode *node, *nnode;
11587 struct bgp *bgp;
8c1d4cd5 11588 struct peer *fpeer = NULL;
d62a17ae 11589 int is_first = 1;
9f049418 11590 bool nbr_output = false;
85eeb029 11591 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 11592
11593 if (use_json)
11594 vty_out(vty, "{\n");
11595
11596 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 11597 nbr_output = true;
d62a17ae 11598 if (use_json) {
d62a17ae 11599 if (!is_first)
11600 vty_out(vty, ",\n");
11601 else
11602 is_first = 0;
11603
11604 vty_out(vty, "\"%s\":",
11605 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11606 ? VRF_DEFAULT_NAME
d62a17ae 11607 : bgp->name);
d62a17ae 11608 }
8c1d4cd5
LS
11609 if (neighbor) {
11610 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11611 use_json);
11612 if (!fpeer)
11613 continue;
11614 }
11615 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11616 as, show_flags);
d62a17ae 11617 }
11618
11619 if (use_json)
11620 vty_out(vty, "}\n");
9f049418
DS
11621 else if (!nbr_output)
11622 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 11623}
11624
11625int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8c1d4cd5 11626 safi_t safi, const char *neighbor, int as_type,
96c81f66 11627 as_t as, uint16_t show_flags)
d62a17ae 11628{
11629 struct bgp *bgp;
85eeb029 11630 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
8c1d4cd5 11631 struct peer *fpeer = NULL;
d62a17ae 11632
11633 if (name) {
11634 if (strmatch(name, "all")) {
85eeb029 11635 bgp_show_all_instances_summary_vty(vty, afi, safi,
8c1d4cd5
LS
11636 neighbor, as_type,
11637 as, show_flags);
d62a17ae 11638 return CMD_SUCCESS;
11639 } else {
11640 bgp = bgp_lookup_by_name(name);
11641
11642 if (!bgp) {
11643 if (use_json)
11644 vty_out(vty, "{}\n");
11645 else
11646 vty_out(vty,
ca61fd25 11647 "%% BGP instance not found\n");
d62a17ae 11648 return CMD_WARNING;
11649 }
11650
8c1d4cd5
LS
11651 if (neighbor) {
11652 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11653 use_json);
11654 if (!fpeer)
11655 return CMD_WARNING;
11656 }
11657 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
11658 as_type, as, show_flags);
d62a17ae 11659 return CMD_SUCCESS;
11660 }
11661 }
11662
11663 bgp = bgp_get_default();
11664
8c1d4cd5
LS
11665 if (bgp) {
11666 if (neighbor) {
11667 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11668 use_json);
11669 if (!fpeer)
11670 return CMD_WARNING;
11671 }
11672 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11673 as, show_flags);
11674 } else {
ca61fd25
DS
11675 if (use_json)
11676 vty_out(vty, "{}\n");
11677 else
11678 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
11679 return CMD_WARNING;
11680 }
d62a17ae 11681
11682 return CMD_SUCCESS;
4fb25c53
DW
11683}
11684
716b2d8a 11685/* `show [ip] bgp summary' commands. */
8c1d4cd5
LS
11686DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
11687 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
11688 " [" BGP_SAFI_WITH_LABEL_CMD_STR
96c81f66 11689 "]] [all$all] summary [established|failed] [<neighbor <A.B.C.D|X:X::X:X|WORD>|remote-as <(1-4294967295)|internal|external>>] [terse] [wide] [json$uj]",
8c1d4cd5
LS
11690 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11691 BGP_SAFI_WITH_LABEL_HELP_STR
11692 "Display the entries for all address families\n"
11693 "Summary of BGP neighbor status\n"
11694 "Show only sessions in Established state\n"
11695 "Show only sessions not in Established state\n"
11696 "Show only the specified neighbor session\n"
11697 "Neighbor to display information about\n"
11698 "Neighbor to display information about\n"
11699 "Neighbor on BGP configured interface\n"
11700 "Show only the specified remote AS sessions\n"
11701 "AS number\n"
11702 "Internal (iBGP) AS sessions\n"
11703 "External (eBGP) AS sessions\n"
96c81f66 11704 "Shorten the information on BGP instances\n"
8c1d4cd5 11705 "Increase table width for longer output\n" JSON_STR)
718e3744 11706{
d62a17ae 11707 char *vrf = NULL;
11708 afi_t afi = AFI_MAX;
11709 safi_t safi = SAFI_MAX;
8c1d4cd5
LS
11710 as_t as = 0; /* 0 means AS filter not set */
11711 int as_type = AS_UNSPECIFIED;
96c81f66 11712 uint16_t show_flags = 0;
d62a17ae 11713
11714 int idx = 0;
11715
11716 /* show [ip] bgp */
96f3485c 11717 if (!all && argv_find(argv, argc, "ip", &idx))
d62a17ae 11718 afi = AFI_IP;
9a8bdf1c
PG
11719 /* [<vrf> VIEWVRFNAME] */
11720 if (argv_find(argv, argc, "vrf", &idx)) {
11721 vrf = argv[idx + 1]->arg;
11722 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11723 vrf = NULL;
11724 } else if (argv_find(argv, argc, "view", &idx))
11725 /* [<view> VIEWVRFNAME] */
11726 vrf = argv[idx + 1]->arg;
d62a17ae 11727 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11728 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11729 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11730 }
11731
3577f1c5 11732 if (argv_find(argv, argc, "failed", &idx))
85eeb029
DA
11733 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11734
10b49f14 11735 if (argv_find(argv, argc, "established", &idx))
85eeb029
DA
11736 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11737
8c1d4cd5
LS
11738 if (argv_find(argv, argc, "remote-as", &idx)) {
11739 if (argv[idx + 1]->arg[0] == 'i')
11740 as_type = AS_INTERNAL;
11741 else if (argv[idx + 1]->arg[0] == 'e')
11742 as_type = AS_EXTERNAL;
11743 else
11744 as = (as_t)atoi(argv[idx + 1]->arg);
11745 }
11746
96c81f66
LS
11747 if (argv_find(argv, argc, "terse", &idx))
11748 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11749
85eeb029
DA
11750 if (argv_find(argv, argc, "wide", &idx))
11751 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11752
11753 if (argv_find(argv, argc, "json", &idx))
11754 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
3577f1c5 11755
8c1d4cd5
LS
11756 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
11757 show_flags);
d62a17ae 11758}
11759
5cb5f4d0 11760const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
d62a17ae 11761{
5cb5f4d0
DD
11762 if (for_json)
11763 return get_afi_safi_json_str(afi, safi);
d62a17ae 11764 else
5cb5f4d0 11765 return get_afi_safi_vty_str(afi, safi);
27162734
LB
11766}
11767
d62a17ae 11768
11769static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11770 afi_t afi, safi_t safi,
d7c0a89a
QY
11771 uint16_t adv_smcap, uint16_t adv_rmcap,
11772 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 11773 bool use_json, json_object *json_pref)
d62a17ae 11774{
11775 /* Send-Mode */
11776 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11777 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11778 if (use_json) {
11779 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11780 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11781 json_object_string_add(json_pref, "sendMode",
11782 "advertisedAndReceived");
11783 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11784 json_object_string_add(json_pref, "sendMode",
11785 "advertised");
11786 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11787 json_object_string_add(json_pref, "sendMode",
11788 "received");
11789 } else {
11790 vty_out(vty, " Send-mode: ");
11791 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11792 vty_out(vty, "advertised");
11793 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11794 vty_out(vty, "%sreceived",
11795 CHECK_FLAG(p->af_cap[afi][safi],
11796 adv_smcap)
11797 ? ", "
11798 : "");
11799 vty_out(vty, "\n");
11800 }
11801 }
11802
11803 /* Receive-Mode */
11804 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11805 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11806 if (use_json) {
11807 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11808 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11809 json_object_string_add(json_pref, "recvMode",
11810 "advertisedAndReceived");
11811 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11812 json_object_string_add(json_pref, "recvMode",
11813 "advertised");
11814 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11815 json_object_string_add(json_pref, "recvMode",
11816 "received");
11817 } else {
11818 vty_out(vty, " Receive-mode: ");
11819 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11820 vty_out(vty, "advertised");
11821 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11822 vty_out(vty, "%sreceived",
11823 CHECK_FLAG(p->af_cap[afi][safi],
11824 adv_rmcap)
11825 ? ", "
11826 : "");
11827 vty_out(vty, "\n");
11828 }
11829 }
11830}
11831
eea685b6
DA
11832static void bgp_show_neighnor_graceful_restart_flags(struct vty *vty,
11833 struct peer *p,
11834 bool use_json,
11835 json_object *json)
2986cac2 11836{
eea685b6
DA
11837 bool rbit = false;
11838 bool nbit = false;
2986cac2 11839
13909c4f
DS
11840 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11841 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
feb17238 11842 && (peer_established(p))) {
eea685b6
DA
11843 rbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_R_BIT_RCV);
11844 nbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_N_BIT_RCV);
2986cac2 11845 }
11846
eea685b6
DA
11847 if (use_json) {
11848 json_object_boolean_add(json, "rBit", rbit);
11849 json_object_boolean_add(json, "nBit", nbit);
2986cac2 11850 } else {
eea685b6
DA
11851 vty_out(vty, "\n R bit: %s", rbit ? "True" : "False");
11852 vty_out(vty, "\n N bit: %s\n", nbit ? "True" : "False");
2986cac2 11853 }
11854}
11855
13909c4f
DS
11856static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11857 struct peer *peer,
11858 bool use_json,
11859 json_object *json)
2986cac2 11860{
2bb5d39b 11861 const char *mode = "NotApplicable";
2986cac2 11862
11863 if (!use_json)
a53ca37b 11864 vty_out(vty, "\n Remote GR Mode: ");
2986cac2 11865
13909c4f 11866 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
feb17238 11867 && (peer_established(peer))) {
2986cac2 11868
13909c4f
DS
11869 if ((peer->nsf_af_count == 0)
11870 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11871
2986cac2 11872 mode = "Disable";
11873
13909c4f
DS
11874 } else if (peer->nsf_af_count == 0
11875 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11876
2986cac2 11877 mode = "Helper";
11878
13909c4f
DS
11879 } else if (peer->nsf_af_count != 0
11880 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11881
2986cac2 11882 mode = "Restart";
2986cac2 11883 }
11884 }
11885
11886 if (use_json) {
13909c4f 11887 json_object_string_add(json, "remoteGrMode", mode);
2986cac2 11888 } else
11889 vty_out(vty, mode, "\n");
11890}
11891
13909c4f
DS
11892static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11893 struct peer *p,
11894 bool use_json,
11895 json_object *json)
2986cac2 11896{
11897 const char *mode = "Invalid";
11898
11899 if (!use_json)
a53ca37b 11900 vty_out(vty, " Local GR Mode: ");
2986cac2 11901
11902 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11903 mode = "Helper";
11904 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11905 mode = "Restart";
11906 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11907 mode = "Disable";
2ba1fe69 11908 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
2986cac2 11909 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11910 mode = "Helper*";
11911 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11912 mode = "Restart*";
11913 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11914 mode = "Disable*";
11915 else
11916 mode = "Invalid*";
2ba1fe69 11917 }
2986cac2 11918
11919 if (use_json) {
13909c4f 11920 json_object_string_add(json, "localGrMode", mode);
2986cac2 11921 } else {
11922 vty_out(vty, mode, "\n");
11923 }
11924}
11925
13909c4f
DS
11926static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11927 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
2986cac2 11928{
2ba1fe69 11929 afi_t afi;
11930 safi_t safi;
2986cac2 11931 json_object *json_afi_safi = NULL;
11932 json_object *json_timer = NULL;
11933 json_object *json_endofrib_status = NULL;
9e3b51a7 11934 bool eor_flag = false;
2986cac2 11935
df8d723c
DA
11936 FOREACH_AFI_SAFI_NSF (afi, safi) {
11937 if (!peer->afc[afi][safi])
11938 continue;
2986cac2 11939
df8d723c
DA
11940 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) ||
11941 !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11942 continue;
9e3b51a7 11943
df8d723c
DA
11944 if (use_json) {
11945 json_afi_safi = json_object_new_object();
11946 json_endofrib_status = json_object_new_object();
11947 json_timer = json_object_new_object();
11948 }
2986cac2 11949
df8d723c
DA
11950 if (peer->eor_stime[afi][safi] >= peer->pkt_stime[afi][safi])
11951 eor_flag = true;
11952 else
11953 eor_flag = false;
2986cac2 11954
df8d723c
DA
11955 if (!use_json) {
11956 vty_out(vty, " %s:\n",
11957 get_afi_safi_str(afi, safi, false));
2986cac2 11958
df8d723c
DA
11959 vty_out(vty, " F bit: ");
11960 }
2986cac2 11961
df8d723c
DA
11962 if (peer->nsf[afi][safi] &&
11963 CHECK_FLAG(peer->af_cap[afi][safi],
11964 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
2986cac2 11965
df8d723c
DA
11966 if (use_json) {
11967 json_object_boolean_true_add(json_afi_safi,
11968 "fBit");
11969 } else
11970 vty_out(vty, "True\n");
11971 } else {
11972 if (use_json)
11973 json_object_boolean_false_add(json_afi_safi,
11974 "fBit");
11975 else
11976 vty_out(vty, "False\n");
11977 }
2986cac2 11978
df8d723c
DA
11979 if (!use_json)
11980 vty_out(vty, " End-of-RIB sent: ");
2986cac2 11981
df8d723c
DA
11982 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11983 PEER_STATUS_EOR_SEND)) {
11984 if (use_json) {
11985 json_object_boolean_true_add(
11986 json_endofrib_status, "endOfRibSend");
9e3b51a7 11987
df8d723c
DA
11988 PRINT_EOR_JSON(eor_flag);
11989 } else {
11990 vty_out(vty, "Yes\n");
11991 vty_out(vty,
11992 " End-of-RIB sent after update: ");
2986cac2 11993
df8d723c
DA
11994 PRINT_EOR(eor_flag);
11995 }
11996 } else {
11997 if (use_json) {
11998 json_object_boolean_false_add(
11999 json_endofrib_status, "endOfRibSend");
12000 json_object_boolean_false_add(
12001 json_endofrib_status,
12002 "endOfRibSentAfterUpdate");
13909c4f 12003 } else {
df8d723c
DA
12004 vty_out(vty, "No\n");
12005 vty_out(vty,
12006 " End-of-RIB sent after update: ");
12007 vty_out(vty, "No\n");
13909c4f 12008 }
df8d723c 12009 }
2986cac2 12010
df8d723c
DA
12011 if (!use_json)
12012 vty_out(vty, " End-of-RIB received: ");
a53ca37b 12013
df8d723c
DA
12014 if (CHECK_FLAG(peer->af_sflags[afi][safi],
12015 PEER_STATUS_EOR_RECEIVED)) {
12016 if (use_json)
12017 json_object_boolean_true_add(
12018 json_endofrib_status, "endOfRibRecv");
12019 else
12020 vty_out(vty, "Yes\n");
12021 } else {
12022 if (use_json)
12023 json_object_boolean_false_add(
12024 json_endofrib_status, "endOfRibRecv");
12025 else
12026 vty_out(vty, "No\n");
12027 }
12028
12029 if (use_json) {
12030 json_object_int_add(json_timer, "stalePathTimer",
12031 peer->bgp->stalepath_time);
12032
12033 if (peer->t_gr_stale != NULL) {
12034 json_object_int_add(json_timer,
12035 "stalePathTimerRemaining",
12036 thread_timer_remain_second(
12037 peer->t_gr_stale));
a53ca37b
DA
12038 }
12039
df8d723c
DA
12040 /* Display Configured Selection
12041 * Deferral only when when
12042 * Gr mode is enabled.
12043 */
12044 if (CHECK_FLAG(peer->flags,
12045 PEER_FLAG_GRACEFUL_RESTART)) {
13909c4f 12046 json_object_int_add(json_timer,
df8d723c 12047 "selectionDeferralTimer",
13909c4f 12048 peer->bgp->stalepath_time);
df8d723c 12049 }
2986cac2 12050
df8d723c
DA
12051 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
12052 NULL) {
2986cac2 12053
df8d723c
DA
12054 json_object_int_add(
12055 json_timer,
12056 "selectionDeferralTimerRemaining",
12057 thread_timer_remain_second(
12058 peer->bgp->gr_info[afi][safi]
12059 .t_select_deferral));
12060 }
12061 } else {
12062 vty_out(vty, " Timers:\n");
12063 vty_out(vty,
12064 " Configured Stale Path Time(sec): %u\n",
12065 peer->bgp->stalepath_time);
2986cac2 12066
df8d723c 12067 if (peer->t_gr_stale != NULL)
13909c4f 12068 vty_out(vty,
df8d723c
DA
12069 " Stale Path Remaining(sec): %ld\n",
12070 thread_timer_remain_second(
12071 peer->t_gr_stale));
12072 /* Display Configured Selection
12073 * Deferral only when when
12074 * Gr mode is enabled.
12075 */
12076 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
12077 vty_out(vty,
12078 " Configured Selection Deferral Time(sec): %u\n",
12079 peer->bgp->select_defer_time);
2986cac2 12080
df8d723c
DA
12081 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
12082 NULL)
12083 vty_out(vty,
12084 " Selection Deferral Time Remaining(sec): %ld\n",
12085 thread_timer_remain_second(
12086 peer->bgp->gr_info[afi][safi]
12087 .t_select_deferral));
12088 }
12089 if (use_json) {
12090 json_object_object_add(json_afi_safi, "endOfRibStatus",
12091 json_endofrib_status);
12092 json_object_object_add(json_afi_safi, "timers",
12093 json_timer);
12094 json_object_object_add(
12095 json, get_afi_safi_str(afi, safi, true),
12096 json_afi_safi);
2986cac2 12097 }
12098 }
12099}
12100
36235319
QY
12101static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
12102 struct peer *p,
12103 bool use_json,
12104 json_object *json)
2986cac2 12105{
12106 if (use_json) {
12107 json_object *json_timer = NULL;
12108
12109 json_timer = json_object_new_object();
12110
13909c4f
DS
12111 json_object_int_add(json_timer, "configuredRestartTimer",
12112 p->bgp->restart_time);
2986cac2 12113
13909c4f
DS
12114 json_object_int_add(json_timer, "receivedRestartTimer",
12115 p->v_gr_restart);
2986cac2 12116
13909c4f
DS
12117 if (p->t_gr_restart != NULL)
12118 json_object_int_add(
12119 json_timer, "restartTimerRemaining",
12120 thread_timer_remain_second(p->t_gr_restart));
2986cac2 12121
12122 json_object_object_add(json, "timers", json_timer);
12123 } else {
12124
a53ca37b
DA
12125 vty_out(vty, " Timers:\n");
12126 vty_out(vty, " Configured Restart Time(sec): %u\n",
13909c4f 12127 p->bgp->restart_time);
2986cac2 12128
a53ca37b 12129 vty_out(vty, " Received Restart Time(sec): %u\n",
13909c4f
DS
12130 p->v_gr_restart);
12131 if (p->t_gr_restart != NULL)
a53ca37b 12132 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
13909c4f 12133 thread_timer_remain_second(p->t_gr_restart));
36235319 12134 if (p->t_gr_restart != NULL) {
a53ca37b 12135 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
36235319
QY
12136 thread_timer_remain_second(p->t_gr_restart));
12137 }
2986cac2 12138 }
12139}
12140
12141static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
36235319 12142 bool use_json, json_object *json)
2986cac2 12143{
2986cac2 12144 char dn_flag[2] = {0};
2b7165e7
QY
12145 /* '*' + v6 address of neighbor */
12146 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
2986cac2 12147
2986cac2 12148 if (!p->conf_if && peer_dynamic_neighbor(p))
12149 dn_flag[0] = '*';
12150
12151 if (p->conf_if) {
12152 if (use_json)
47e12884
DA
12153 json_object_string_addf(json, "neighborAddr", "%pSU",
12154 &p->su);
2986cac2 12155 else
47e12884
DA
12156 vty_out(vty, "BGP neighbor on %s: %pSU\n", p->conf_if,
12157 &p->su);
2986cac2 12158 } else {
772270f3
QY
12159 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
12160 p->host);
2986cac2 12161
12162 if (use_json)
36235319
QY
12163 json_object_string_add(json, "neighborAddr",
12164 neighborAddr);
2986cac2 12165 else
36235319 12166 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
2986cac2 12167 }
12168
12169 /* more gr info in new format */
12170 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
12171}
12172
d62a17ae 12173static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 12174 safi_t safi, bool use_json,
d62a17ae 12175 json_object *json_neigh)
12176{
0291c246
MK
12177 struct bgp_filter *filter;
12178 struct peer_af *paf;
12179 char orf_pfx_name[BUFSIZ];
12180 int orf_pfx_count;
12181 json_object *json_af = NULL;
12182 json_object *json_prefA = NULL;
12183 json_object *json_prefB = NULL;
12184 json_object *json_addr = NULL;
fa36596c 12185 json_object *json_advmap = NULL;
d62a17ae 12186
12187 if (use_json) {
12188 json_addr = json_object_new_object();
12189 json_af = json_object_new_object();
12190 filter = &p->filter[afi][safi];
12191
12192 if (peer_group_active(p))
12193 json_object_string_add(json_addr, "peerGroupMember",
12194 p->group->name);
12195
12196 paf = peer_af_find(p, afi, safi);
12197 if (paf && PAF_SUBGRP(paf)) {
12198 json_object_int_add(json_addr, "updateGroupId",
12199 PAF_UPDGRP(paf)->id);
12200 json_object_int_add(json_addr, "subGroupId",
12201 PAF_SUBGRP(paf)->id);
12202 json_object_int_add(json_addr, "packetQueueLength",
12203 bpacket_queue_virtual_length(paf));
12204 }
12205
12206 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12207 || CHECK_FLAG(p->af_cap[afi][safi],
12208 PEER_CAP_ORF_PREFIX_SM_RCV)
12209 || CHECK_FLAG(p->af_cap[afi][safi],
12210 PEER_CAP_ORF_PREFIX_RM_ADV)
12211 || CHECK_FLAG(p->af_cap[afi][safi],
12212 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12213 json_object_int_add(json_af, "orfType",
12214 ORF_TYPE_PREFIX);
12215 json_prefA = json_object_new_object();
12216 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
12217 PEER_CAP_ORF_PREFIX_SM_ADV,
12218 PEER_CAP_ORF_PREFIX_RM_ADV,
12219 PEER_CAP_ORF_PREFIX_SM_RCV,
12220 PEER_CAP_ORF_PREFIX_RM_RCV,
12221 use_json, json_prefA);
12222 json_object_object_add(json_af, "orfPrefixList",
12223 json_prefA);
12224 }
12225
12226 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12227 || CHECK_FLAG(p->af_cap[afi][safi],
12228 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12229 || CHECK_FLAG(p->af_cap[afi][safi],
12230 PEER_CAP_ORF_PREFIX_RM_ADV)
12231 || CHECK_FLAG(p->af_cap[afi][safi],
12232 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12233 json_object_int_add(json_af, "orfOldType",
12234 ORF_TYPE_PREFIX_OLD);
12235 json_prefB = json_object_new_object();
12236 bgp_show_peer_afi_orf_cap(
12237 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12238 PEER_CAP_ORF_PREFIX_RM_ADV,
12239 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12240 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
12241 json_prefB);
12242 json_object_object_add(json_af, "orfOldPrefixList",
12243 json_prefB);
12244 }
12245
12246 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12247 || CHECK_FLAG(p->af_cap[afi][safi],
12248 PEER_CAP_ORF_PREFIX_SM_RCV)
12249 || CHECK_FLAG(p->af_cap[afi][safi],
12250 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12251 || CHECK_FLAG(p->af_cap[afi][safi],
12252 PEER_CAP_ORF_PREFIX_RM_ADV)
12253 || CHECK_FLAG(p->af_cap[afi][safi],
12254 PEER_CAP_ORF_PREFIX_RM_RCV)
12255 || CHECK_FLAG(p->af_cap[afi][safi],
12256 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12257 json_object_object_add(json_addr, "afDependentCap",
12258 json_af);
12259 else
12260 json_object_free(json_af);
12261
772270f3
QY
12262 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12263 p->host, afi, safi);
d62a17ae 12264 orf_pfx_count = prefix_bgp_show_prefix_list(
12265 NULL, afi, orf_pfx_name, use_json);
12266
12267 if (CHECK_FLAG(p->af_sflags[afi][safi],
12268 PEER_STATUS_ORF_PREFIX_SEND)
12269 || orf_pfx_count) {
12270 if (CHECK_FLAG(p->af_sflags[afi][safi],
12271 PEER_STATUS_ORF_PREFIX_SEND))
12272 json_object_boolean_true_add(json_neigh,
12273 "orfSent");
12274 if (orf_pfx_count)
12275 json_object_int_add(json_addr, "orfRecvCounter",
12276 orf_pfx_count);
12277 }
12278 if (CHECK_FLAG(p->af_sflags[afi][safi],
12279 PEER_STATUS_ORF_WAIT_REFRESH))
12280 json_object_string_add(
12281 json_addr, "orfFirstUpdate",
12282 "deferredUntilORFOrRouteRefreshRecvd");
12283
12284 if (CHECK_FLAG(p->af_flags[afi][safi],
12285 PEER_FLAG_REFLECTOR_CLIENT))
12286 json_object_boolean_true_add(json_addr,
12287 "routeReflectorClient");
12288 if (CHECK_FLAG(p->af_flags[afi][safi],
12289 PEER_FLAG_RSERVER_CLIENT))
12290 json_object_boolean_true_add(json_addr,
12291 "routeServerClient");
12292 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12293 json_object_boolean_true_add(json_addr,
12294 "inboundSoftConfigPermit");
12295
12296 if (CHECK_FLAG(p->af_flags[afi][safi],
12297 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12298 json_object_boolean_true_add(
12299 json_addr,
12300 "privateAsNumsAllReplacedInUpdatesToNbr");
12301 else if (CHECK_FLAG(p->af_flags[afi][safi],
12302 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12303 json_object_boolean_true_add(
12304 json_addr,
12305 "privateAsNumsReplacedInUpdatesToNbr");
12306 else if (CHECK_FLAG(p->af_flags[afi][safi],
12307 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12308 json_object_boolean_true_add(
12309 json_addr,
12310 "privateAsNumsAllRemovedInUpdatesToNbr");
12311 else if (CHECK_FLAG(p->af_flags[afi][safi],
12312 PEER_FLAG_REMOVE_PRIVATE_AS))
12313 json_object_boolean_true_add(
12314 json_addr,
12315 "privateAsNumsRemovedInUpdatesToNbr");
12316
b2ac1d0d
MS
12317 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN)) {
12318 if (CHECK_FLAG(p->af_flags[afi][safi],
12319 PEER_FLAG_ALLOWAS_IN_ORIGIN))
12320 json_object_boolean_true_add(json_addr,
12321 "allowAsInOrigin");
12322 else
12323 json_object_int_add(json_addr, "allowAsInCount",
12324 p->allowas_in[afi][safi]);
12325 }
12326
dcc68b5e
MS
12327 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12328 json_object_boolean_true_add(
12329 json_addr,
12330 bgp_addpath_names(p->addpath_type[afi][safi])
12331 ->type_json_name);
d62a17ae 12332
12333 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12334 json_object_string_add(json_addr,
12335 "overrideASNsInOutboundUpdates",
12336 "ifAspathEqualRemoteAs");
12337
12338 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12339 || CHECK_FLAG(p->af_flags[afi][safi],
12340 PEER_FLAG_FORCE_NEXTHOP_SELF))
12341 json_object_boolean_true_add(json_addr,
12342 "routerAlwaysNextHop");
12343 if (CHECK_FLAG(p->af_flags[afi][safi],
12344 PEER_FLAG_AS_PATH_UNCHANGED))
12345 json_object_boolean_true_add(
12346 json_addr, "unchangedAsPathPropogatedToNbr");
12347 if (CHECK_FLAG(p->af_flags[afi][safi],
12348 PEER_FLAG_NEXTHOP_UNCHANGED))
12349 json_object_boolean_true_add(
12350 json_addr, "unchangedNextHopPropogatedToNbr");
12351 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12352 json_object_boolean_true_add(
12353 json_addr, "unchangedMedPropogatedToNbr");
12354 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12355 || CHECK_FLAG(p->af_flags[afi][safi],
12356 PEER_FLAG_SEND_EXT_COMMUNITY)) {
12357 if (CHECK_FLAG(p->af_flags[afi][safi],
12358 PEER_FLAG_SEND_COMMUNITY)
12359 && CHECK_FLAG(p->af_flags[afi][safi],
12360 PEER_FLAG_SEND_EXT_COMMUNITY))
12361 json_object_string_add(json_addr,
12362 "commAttriSentToNbr",
12363 "extendedAndStandard");
12364 else if (CHECK_FLAG(p->af_flags[afi][safi],
12365 PEER_FLAG_SEND_EXT_COMMUNITY))
12366 json_object_string_add(json_addr,
12367 "commAttriSentToNbr",
12368 "extended");
12369 else
12370 json_object_string_add(json_addr,
12371 "commAttriSentToNbr",
12372 "standard");
12373 }
12374 if (CHECK_FLAG(p->af_flags[afi][safi],
12375 PEER_FLAG_DEFAULT_ORIGINATE)) {
12376 if (p->default_rmap[afi][safi].name)
12377 json_object_string_add(
12378 json_addr, "defaultRouteMap",
12379 p->default_rmap[afi][safi].name);
12380
12381 if (paf && PAF_SUBGRP(paf)
12382 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12383 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12384 json_object_boolean_true_add(json_addr,
12385 "defaultSent");
12386 else
12387 json_object_boolean_true_add(json_addr,
12388 "defaultNotSent");
12389 }
12390
dff8f48d 12391 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 12392 if (is_evpn_enabled())
60466a63
QY
12393 json_object_boolean_true_add(
12394 json_addr, "advertiseAllVnis");
dff8f48d
MK
12395 }
12396
d62a17ae 12397 if (filter->plist[FILTER_IN].name
12398 || filter->dlist[FILTER_IN].name
12399 || filter->aslist[FILTER_IN].name
12400 || filter->map[RMAP_IN].name)
12401 json_object_boolean_true_add(json_addr,
12402 "inboundPathPolicyConfig");
12403 if (filter->plist[FILTER_OUT].name
12404 || filter->dlist[FILTER_OUT].name
12405 || filter->aslist[FILTER_OUT].name
12406 || filter->map[RMAP_OUT].name || filter->usmap.name)
12407 json_object_boolean_true_add(
12408 json_addr, "outboundPathPolicyConfig");
12409
12410 /* prefix-list */
12411 if (filter->plist[FILTER_IN].name)
12412 json_object_string_add(json_addr,
12413 "incomingUpdatePrefixFilterList",
12414 filter->plist[FILTER_IN].name);
12415 if (filter->plist[FILTER_OUT].name)
12416 json_object_string_add(json_addr,
12417 "outgoingUpdatePrefixFilterList",
12418 filter->plist[FILTER_OUT].name);
12419
12420 /* distribute-list */
12421 if (filter->dlist[FILTER_IN].name)
12422 json_object_string_add(
12423 json_addr, "incomingUpdateNetworkFilterList",
12424 filter->dlist[FILTER_IN].name);
12425 if (filter->dlist[FILTER_OUT].name)
12426 json_object_string_add(
12427 json_addr, "outgoingUpdateNetworkFilterList",
12428 filter->dlist[FILTER_OUT].name);
12429
12430 /* filter-list. */
12431 if (filter->aslist[FILTER_IN].name)
12432 json_object_string_add(json_addr,
12433 "incomingUpdateAsPathFilterList",
12434 filter->aslist[FILTER_IN].name);
12435 if (filter->aslist[FILTER_OUT].name)
12436 json_object_string_add(json_addr,
12437 "outgoingUpdateAsPathFilterList",
12438 filter->aslist[FILTER_OUT].name);
12439
12440 /* route-map. */
12441 if (filter->map[RMAP_IN].name)
12442 json_object_string_add(
12443 json_addr, "routeMapForIncomingAdvertisements",
12444 filter->map[RMAP_IN].name);
12445 if (filter->map[RMAP_OUT].name)
12446 json_object_string_add(
12447 json_addr, "routeMapForOutgoingAdvertisements",
12448 filter->map[RMAP_OUT].name);
12449
9dac9fc8 12450 /* ebgp-requires-policy (inbound) */
1d3fdccf 12451 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12452 && !bgp_inbound_policy_exists(p, filter))
12453 json_object_string_add(
12454 json_addr, "inboundEbgpRequiresPolicy",
12455 "Inbound updates discarded due to missing policy");
12456
12457 /* ebgp-requires-policy (outbound) */
1d3fdccf 12458 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12459 && (!bgp_outbound_policy_exists(p, filter)))
12460 json_object_string_add(
12461 json_addr, "outboundEbgpRequiresPolicy",
12462 "Outbound updates discarded due to missing policy");
12463
d62a17ae 12464 /* unsuppress-map */
12465 if (filter->usmap.name)
12466 json_object_string_add(json_addr,
12467 "selectiveUnsuppressRouteMap",
12468 filter->usmap.name);
12469
fa36596c
MK
12470 /* advertise-map */
12471 if (filter->advmap.aname) {
12472 json_advmap = json_object_new_object();
12473 json_object_string_add(json_advmap, "condition",
12474 filter->advmap.condition
12475 ? "EXIST"
12476 : "NON_EXIST");
12477 json_object_string_add(json_advmap, "conditionMap",
12478 filter->advmap.cname);
12479 json_object_string_add(json_advmap, "advertiseMap",
12480 filter->advmap.aname);
ecf2b628
QY
12481 json_object_string_add(
12482 json_advmap, "advertiseStatus",
12483 filter->advmap.update_type ==
12484 UPDATE_TYPE_ADVERTISE
12485 ? "Advertise"
12486 : "Withdraw");
fa36596c
MK
12487 json_object_object_add(json_addr, "advertiseMap",
12488 json_advmap);
12489 }
12490
d62a17ae 12491 /* Receive prefix count */
12492 json_object_int_add(json_addr, "acceptedPrefixCounter",
12493 p->pcount[afi][safi]);
50e05855
AD
12494 if (paf && PAF_SUBGRP(paf))
12495 json_object_int_add(json_addr, "sentPrefixCounter",
12496 (PAF_SUBGRP(paf))->scount);
d62a17ae 12497
fde246e8
DA
12498 /* Maximum prefix */
12499 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12500 json_object_int_add(json_addr, "prefixOutAllowedMax",
12501 p->pmax_out[afi][safi]);
12502
d62a17ae 12503 /* Maximum prefix */
12504 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12505 json_object_int_add(json_addr, "prefixAllowedMax",
12506 p->pmax[afi][safi]);
12507 if (CHECK_FLAG(p->af_flags[afi][safi],
12508 PEER_FLAG_MAX_PREFIX_WARNING))
12509 json_object_boolean_true_add(
12510 json_addr, "prefixAllowedMaxWarning");
12511 json_object_int_add(json_addr,
12512 "prefixAllowedWarningThresh",
12513 p->pmax_threshold[afi][safi]);
12514 if (p->pmax_restart[afi][safi])
12515 json_object_int_add(
12516 json_addr,
12517 "prefixAllowedRestartIntervalMsecs",
12518 p->pmax_restart[afi][safi] * 60000);
12519 }
2986cac2 12520 json_object_object_add(json_neigh,
36235319 12521 get_afi_safi_str(afi, safi, true),
d62a17ae 12522 json_addr);
12523
12524 } else {
12525 filter = &p->filter[afi][safi];
12526
12527 vty_out(vty, " For address family: %s\n",
5cb5f4d0 12528 get_afi_safi_str(afi, safi, false));
d62a17ae 12529
12530 if (peer_group_active(p))
12531 vty_out(vty, " %s peer-group member\n",
12532 p->group->name);
12533
12534 paf = peer_af_find(p, afi, safi);
12535 if (paf && PAF_SUBGRP(paf)) {
6cde4b45 12536 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
d62a17ae 12537 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12538 vty_out(vty, " Packet Queue length %d\n",
12539 bpacket_queue_virtual_length(paf));
12540 } else {
12541 vty_out(vty, " Not part of any update group\n");
12542 }
12543 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12544 || CHECK_FLAG(p->af_cap[afi][safi],
12545 PEER_CAP_ORF_PREFIX_SM_RCV)
12546 || CHECK_FLAG(p->af_cap[afi][safi],
12547 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12548 || CHECK_FLAG(p->af_cap[afi][safi],
12549 PEER_CAP_ORF_PREFIX_RM_ADV)
12550 || CHECK_FLAG(p->af_cap[afi][safi],
12551 PEER_CAP_ORF_PREFIX_RM_RCV)
12552 || CHECK_FLAG(p->af_cap[afi][safi],
12553 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12554 vty_out(vty, " AF-dependant capabilities:\n");
12555
12556 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12557 || CHECK_FLAG(p->af_cap[afi][safi],
12558 PEER_CAP_ORF_PREFIX_SM_RCV)
12559 || CHECK_FLAG(p->af_cap[afi][safi],
12560 PEER_CAP_ORF_PREFIX_RM_ADV)
12561 || CHECK_FLAG(p->af_cap[afi][safi],
12562 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12563 vty_out(vty,
12564 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12565 ORF_TYPE_PREFIX);
12566 bgp_show_peer_afi_orf_cap(
12567 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12568 PEER_CAP_ORF_PREFIX_RM_ADV,
12569 PEER_CAP_ORF_PREFIX_SM_RCV,
12570 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12571 }
12572 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12573 || CHECK_FLAG(p->af_cap[afi][safi],
12574 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12575 || CHECK_FLAG(p->af_cap[afi][safi],
12576 PEER_CAP_ORF_PREFIX_RM_ADV)
12577 || CHECK_FLAG(p->af_cap[afi][safi],
12578 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12579 vty_out(vty,
12580 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12581 ORF_TYPE_PREFIX_OLD);
12582 bgp_show_peer_afi_orf_cap(
12583 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12584 PEER_CAP_ORF_PREFIX_RM_ADV,
12585 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12586 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12587 }
12588
772270f3
QY
12589 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12590 p->host, afi, safi);
d62a17ae 12591 orf_pfx_count = prefix_bgp_show_prefix_list(
12592 NULL, afi, orf_pfx_name, use_json);
12593
12594 if (CHECK_FLAG(p->af_sflags[afi][safi],
12595 PEER_STATUS_ORF_PREFIX_SEND)
12596 || orf_pfx_count) {
12597 vty_out(vty, " Outbound Route Filter (ORF):");
12598 if (CHECK_FLAG(p->af_sflags[afi][safi],
12599 PEER_STATUS_ORF_PREFIX_SEND))
12600 vty_out(vty, " sent;");
12601 if (orf_pfx_count)
12602 vty_out(vty, " received (%d entries)",
12603 orf_pfx_count);
12604 vty_out(vty, "\n");
12605 }
12606 if (CHECK_FLAG(p->af_sflags[afi][safi],
12607 PEER_STATUS_ORF_WAIT_REFRESH))
12608 vty_out(vty,
12609 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12610
12611 if (CHECK_FLAG(p->af_flags[afi][safi],
12612 PEER_FLAG_REFLECTOR_CLIENT))
12613 vty_out(vty, " Route-Reflector Client\n");
12614 if (CHECK_FLAG(p->af_flags[afi][safi],
12615 PEER_FLAG_RSERVER_CLIENT))
12616 vty_out(vty, " Route-Server Client\n");
70cd87ca
MK
12617
12618 if (peer_af_flag_check(p, afi, safi, PEER_FLAG_ORR_GROUP))
12619 vty_out(vty, " ORR group (configured) : %s\n",
12620 p->orr_group_name[afi][safi]);
12621
d62a17ae 12622 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12623 vty_out(vty,
12624 " Inbound soft reconfiguration allowed\n");
12625
12626 if (CHECK_FLAG(p->af_flags[afi][safi],
12627 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12628 vty_out(vty,
12629 " Private AS numbers (all) replaced in updates to this neighbor\n");
12630 else if (CHECK_FLAG(p->af_flags[afi][safi],
12631 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12632 vty_out(vty,
12633 " Private AS numbers replaced in updates to this neighbor\n");
12634 else if (CHECK_FLAG(p->af_flags[afi][safi],
12635 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12636 vty_out(vty,
12637 " Private AS numbers (all) removed in updates to this neighbor\n");
12638 else if (CHECK_FLAG(p->af_flags[afi][safi],
12639 PEER_FLAG_REMOVE_PRIVATE_AS))
12640 vty_out(vty,
12641 " Private AS numbers removed in updates to this neighbor\n");
12642
b2ac1d0d
MS
12643 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN)) {
12644 if (CHECK_FLAG(p->af_flags[afi][safi],
12645 PEER_FLAG_ALLOWAS_IN_ORIGIN))
12646 vty_out(vty,
12647 " Local AS allowed as path origin\n");
12648 else
12649 vty_out(vty,
12650 " Local AS allowed in path, %d occurrences\n",
12651 p->allowas_in[afi][safi]);
12652 }
12653
dcc68b5e
MS
12654 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12655 vty_out(vty, " %s\n",
12656 bgp_addpath_names(p->addpath_type[afi][safi])
12657 ->human_description);
d62a17ae 12658
12659 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12660 vty_out(vty,
12661 " Override ASNs in outbound updates if aspath equals remote-as\n");
12662
12663 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12664 || CHECK_FLAG(p->af_flags[afi][safi],
12665 PEER_FLAG_FORCE_NEXTHOP_SELF))
12666 vty_out(vty, " NEXT_HOP is always this router\n");
12667 if (CHECK_FLAG(p->af_flags[afi][safi],
12668 PEER_FLAG_AS_PATH_UNCHANGED))
12669 vty_out(vty,
12670 " AS_PATH is propagated unchanged to this neighbor\n");
12671 if (CHECK_FLAG(p->af_flags[afi][safi],
12672 PEER_FLAG_NEXTHOP_UNCHANGED))
12673 vty_out(vty,
12674 " NEXT_HOP is propagated unchanged to this neighbor\n");
12675 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12676 vty_out(vty,
12677 " MED is propagated unchanged to this neighbor\n");
12678 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12679 || CHECK_FLAG(p->af_flags[afi][safi],
12680 PEER_FLAG_SEND_EXT_COMMUNITY)
12681 || CHECK_FLAG(p->af_flags[afi][safi],
12682 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12683 vty_out(vty,
12684 " Community attribute sent to this neighbor");
12685 if (CHECK_FLAG(p->af_flags[afi][safi],
12686 PEER_FLAG_SEND_COMMUNITY)
12687 && CHECK_FLAG(p->af_flags[afi][safi],
12688 PEER_FLAG_SEND_EXT_COMMUNITY)
12689 && CHECK_FLAG(p->af_flags[afi][safi],
12690 PEER_FLAG_SEND_LARGE_COMMUNITY))
12691 vty_out(vty, "(all)\n");
12692 else if (CHECK_FLAG(p->af_flags[afi][safi],
12693 PEER_FLAG_SEND_LARGE_COMMUNITY))
12694 vty_out(vty, "(large)\n");
12695 else if (CHECK_FLAG(p->af_flags[afi][safi],
12696 PEER_FLAG_SEND_EXT_COMMUNITY))
12697 vty_out(vty, "(extended)\n");
12698 else
12699 vty_out(vty, "(standard)\n");
12700 }
12701 if (CHECK_FLAG(p->af_flags[afi][safi],
12702 PEER_FLAG_DEFAULT_ORIGINATE)) {
12703 vty_out(vty, " Default information originate,");
12704
12705 if (p->default_rmap[afi][safi].name)
12706 vty_out(vty, " default route-map %s%s,",
12707 p->default_rmap[afi][safi].map ? "*"
12708 : "",
12709 p->default_rmap[afi][safi].name);
12710 if (paf && PAF_SUBGRP(paf)
12711 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12712 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12713 vty_out(vty, " default sent\n");
12714 else
12715 vty_out(vty, " default not sent\n");
12716 }
12717
dff8f48d
MK
12718 /* advertise-vni-all */
12719 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 12720 if (is_evpn_enabled())
dff8f48d
MK
12721 vty_out(vty, " advertise-all-vni\n");
12722 }
12723
d62a17ae 12724 if (filter->plist[FILTER_IN].name
12725 || filter->dlist[FILTER_IN].name
12726 || filter->aslist[FILTER_IN].name
12727 || filter->map[RMAP_IN].name)
12728 vty_out(vty, " Inbound path policy configured\n");
12729 if (filter->plist[FILTER_OUT].name
12730 || filter->dlist[FILTER_OUT].name
12731 || filter->aslist[FILTER_OUT].name
12732 || filter->map[RMAP_OUT].name || filter->usmap.name)
12733 vty_out(vty, " Outbound path policy configured\n");
12734
12735 /* prefix-list */
12736 if (filter->plist[FILTER_IN].name)
12737 vty_out(vty,
12738 " Incoming update prefix filter list is %s%s\n",
12739 filter->plist[FILTER_IN].plist ? "*" : "",
12740 filter->plist[FILTER_IN].name);
12741 if (filter->plist[FILTER_OUT].name)
12742 vty_out(vty,
12743 " Outgoing update prefix filter list is %s%s\n",
12744 filter->plist[FILTER_OUT].plist ? "*" : "",
12745 filter->plist[FILTER_OUT].name);
12746
12747 /* distribute-list */
12748 if (filter->dlist[FILTER_IN].name)
12749 vty_out(vty,
12750 " Incoming update network filter list is %s%s\n",
12751 filter->dlist[FILTER_IN].alist ? "*" : "",
12752 filter->dlist[FILTER_IN].name);
12753 if (filter->dlist[FILTER_OUT].name)
12754 vty_out(vty,
12755 " Outgoing update network filter list is %s%s\n",
12756 filter->dlist[FILTER_OUT].alist ? "*" : "",
12757 filter->dlist[FILTER_OUT].name);
12758
12759 /* filter-list. */
12760 if (filter->aslist[FILTER_IN].name)
12761 vty_out(vty,
12762 " Incoming update AS path filter list is %s%s\n",
12763 filter->aslist[FILTER_IN].aslist ? "*" : "",
12764 filter->aslist[FILTER_IN].name);
12765 if (filter->aslist[FILTER_OUT].name)
12766 vty_out(vty,
12767 " Outgoing update AS path filter list is %s%s\n",
12768 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12769 filter->aslist[FILTER_OUT].name);
12770
12771 /* route-map. */
12772 if (filter->map[RMAP_IN].name)
12773 vty_out(vty,
12774 " Route map for incoming advertisements is %s%s\n",
12775 filter->map[RMAP_IN].map ? "*" : "",
12776 filter->map[RMAP_IN].name);
12777 if (filter->map[RMAP_OUT].name)
12778 vty_out(vty,
12779 " Route map for outgoing advertisements is %s%s\n",
12780 filter->map[RMAP_OUT].map ? "*" : "",
12781 filter->map[RMAP_OUT].name);
12782
9dac9fc8 12783 /* ebgp-requires-policy (inbound) */
1d3fdccf 12784 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12785 && !bgp_inbound_policy_exists(p, filter))
12786 vty_out(vty,
12787 " Inbound updates discarded due to missing policy\n");
12788
12789 /* ebgp-requires-policy (outbound) */
1d3fdccf 12790 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12791 && !bgp_outbound_policy_exists(p, filter))
12792 vty_out(vty,
12793 " Outbound updates discarded due to missing policy\n");
12794
d62a17ae 12795 /* unsuppress-map */
12796 if (filter->usmap.name)
12797 vty_out(vty,
12798 " Route map for selective unsuppress is %s%s\n",
12799 filter->usmap.map ? "*" : "",
12800 filter->usmap.name);
12801
7f7940e6
MK
12802 /* advertise-map */
12803 if (filter->advmap.aname && filter->advmap.cname)
12804 vty_out(vty,
12805 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12806 filter->advmap.condition ? "EXIST"
12807 : "NON_EXIST",
12808 filter->advmap.cmap ? "*" : "",
12809 filter->advmap.cname,
12810 filter->advmap.amap ? "*" : "",
12811 filter->advmap.aname,
ecf2b628
QY
12812 filter->advmap.update_type ==
12813 UPDATE_TYPE_ADVERTISE
c385f82a
MK
12814 ? "Advertise"
12815 : "Withdraw");
7f7940e6 12816
d62a17ae 12817 /* Receive prefix count */
6cde4b45 12818 vty_out(vty, " %u accepted prefixes\n",
a0a87037 12819 p->pcount[afi][safi]);
d62a17ae 12820
fde246e8
DA
12821 /* maximum-prefix-out */
12822 if (CHECK_FLAG(p->af_flags[afi][safi],
12823 PEER_FLAG_MAX_PREFIX_OUT))
12824 vty_out(vty,
6cde4b45 12825 " Maximum allowed prefixes sent %u\n",
fde246e8
DA
12826 p->pmax_out[afi][safi]);
12827
d62a17ae 12828 /* Maximum prefix */
12829 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
a0a87037 12830 vty_out(vty,
6cde4b45 12831 " Maximum prefixes allowed %u%s\n",
d62a17ae 12832 p->pmax[afi][safi],
12833 CHECK_FLAG(p->af_flags[afi][safi],
12834 PEER_FLAG_MAX_PREFIX_WARNING)
12835 ? " (warning-only)"
12836 : "");
12837 vty_out(vty, " Threshold for warning message %d%%",
12838 p->pmax_threshold[afi][safi]);
12839 if (p->pmax_restart[afi][safi])
12840 vty_out(vty, ", restart interval %d min",
12841 p->pmax_restart[afi][safi]);
12842 vty_out(vty, "\n");
12843 }
12844
12845 vty_out(vty, "\n");
12846 }
12847}
12848
9f049418 12849static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 12850 json_object *json)
718e3744 12851{
d62a17ae 12852 struct bgp *bgp;
47e12884 12853 char buf1[PREFIX2STR_BUFFER];
d62a17ae 12854 char timebuf[BGP_UPTIME_LEN];
12855 char dn_flag[2];
d62a17ae 12856 afi_t afi;
12857 safi_t safi;
d7c0a89a
QY
12858 uint16_t i;
12859 uint8_t *msg;
d62a17ae 12860 json_object *json_neigh = NULL;
12861 time_t epoch_tbuf;
4ab46701 12862 uint32_t sync_tcp_mss;
718e3744 12863
d62a17ae 12864 bgp = p->bgp;
12865
12866 if (use_json)
12867 json_neigh = json_object_new_object();
12868
12869 memset(dn_flag, '\0', sizeof(dn_flag));
12870 if (!p->conf_if && peer_dynamic_neighbor(p))
12871 dn_flag[0] = '*';
12872
12873 if (!use_json) {
12874 if (p->conf_if) /* Configured interface name. */
47e12884
DA
12875 vty_out(vty, "BGP neighbor on %s: %pSU, ", p->conf_if,
12876 &p->su);
d62a17ae 12877 else /* Configured IP address. */
12878 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12879 p->host);
12880 }
12881
12882 if (use_json) {
12883 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12884 json_object_string_add(json_neigh, "bgpNeighborAddr",
12885 "none");
12886 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
47e12884
DA
12887 json_object_string_addf(json_neigh, "bgpNeighborAddr",
12888 "%pSU", &p->su);
d62a17ae 12889
12890 json_object_int_add(json_neigh, "remoteAs", p->as);
12891
12892 if (p->change_local_as)
12893 json_object_int_add(json_neigh, "localAs",
12894 p->change_local_as);
12895 else
12896 json_object_int_add(json_neigh, "localAs", p->local_as);
12897
12898 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12899 json_object_boolean_true_add(json_neigh,
12900 "localAsNoPrepend");
12901
12902 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12903 json_object_boolean_true_add(json_neigh,
12904 "localAsReplaceAs");
12905 } else {
12906 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12907 || (p->as_type == AS_INTERNAL))
12908 vty_out(vty, "remote AS %u, ", p->as);
12909 else
12910 vty_out(vty, "remote AS Unspecified, ");
12911 vty_out(vty, "local AS %u%s%s, ",
12912 p->change_local_as ? p->change_local_as : p->local_as,
12913 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12914 ? " no-prepend"
12915 : "",
12916 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12917 ? " replace-as"
12918 : "");
12919 }
faa16034
DS
12920 /* peer type internal or confed-internal */
12921 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
d62a17ae 12922 if (use_json) {
12923 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12924 json_object_boolean_true_add(
12925 json_neigh, "nbrConfedInternalLink");
12926 else
12927 json_object_boolean_true_add(json_neigh,
12928 "nbrInternalLink");
12929 } else {
12930 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12931 vty_out(vty, "confed-internal link\n");
12932 else
12933 vty_out(vty, "internal link\n");
12934 }
faa16034
DS
12935 /* peer type external or confed-external */
12936 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
d62a17ae 12937 if (use_json) {
12938 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12939 json_object_boolean_true_add(
12940 json_neigh, "nbrConfedExternalLink");
12941 else
12942 json_object_boolean_true_add(json_neigh,
12943 "nbrExternalLink");
12944 } else {
12945 if (bgp_confederation_peers_check(bgp, p->as))
12946 vty_out(vty, "confed-external link\n");
12947 else
12948 vty_out(vty, "external link\n");
12949 }
faa16034
DS
12950 } else {
12951 if (use_json)
12952 json_object_boolean_true_add(json_neigh,
12953 "nbrUnspecifiedLink");
12954 else
12955 vty_out(vty, "unspecified link\n");
d62a17ae 12956 }
12957
d864dd9e
EB
12958 /* Roles */
12959 if (use_json) {
12960 json_object_string_add(json_neigh, "localRole",
8f2d6021
EB
12961 bgp_get_name_by_role(p->local_role));
12962 json_object_string_add(json_neigh, "remoteRole",
12963 bgp_get_name_by_role(p->remote_role));
d864dd9e
EB
12964 } else {
12965 vty_out(vty, " Local Role: %s\n",
8f2d6021
EB
12966 bgp_get_name_by_role(p->local_role));
12967 vty_out(vty, " Remote Role: %s\n",
12968 bgp_get_name_by_role(p->remote_role));
d864dd9e
EB
12969 }
12970
12971
d62a17ae 12972 /* Description. */
12973 if (p->desc) {
12974 if (use_json)
12975 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12976 else
12977 vty_out(vty, " Description: %s\n", p->desc);
12978 }
12979
12980 if (p->hostname) {
12981 if (use_json) {
12982 if (p->hostname)
12983 json_object_string_add(json_neigh, "hostname",
12984 p->hostname);
12985
12986 if (p->domainname)
12987 json_object_string_add(json_neigh, "domainname",
12988 p->domainname);
12989 } else {
12990 if (p->domainname && (p->domainname[0] != '\0'))
12991 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
12992 p->domainname);
12993 else
12994 vty_out(vty, "Hostname: %s\n", p->hostname);
12995 }
12996 }
12997
12998 /* Peer-group */
12999 if (p->group) {
13000 if (use_json) {
13001 json_object_string_add(json_neigh, "peerGroup",
13002 p->group->name);
13003
13004 if (dn_flag[0]) {
13005 struct prefix prefix, *range = NULL;
13006
0154d8ce
DS
13007 if (sockunion2hostprefix(&(p->su), &prefix))
13008 range = peer_group_lookup_dynamic_neighbor_range(
13009 p->group, &prefix);
d62a17ae 13010
13011 if (range) {
67d7e256 13012 json_object_string_addf(
d62a17ae 13013 json_neigh,
67d7e256
DA
13014 "peerSubnetRangeGroup", "%pFX",
13015 range);
d62a17ae 13016 }
13017 }
13018 } else {
13019 vty_out(vty,
13020 " Member of peer-group %s for session parameters\n",
13021 p->group->name);
13022
13023 if (dn_flag[0]) {
13024 struct prefix prefix, *range = NULL;
13025
0154d8ce
DS
13026 if (sockunion2hostprefix(&(p->su), &prefix))
13027 range = peer_group_lookup_dynamic_neighbor_range(
13028 p->group, &prefix);
d62a17ae 13029
13030 if (range) {
d62a17ae 13031 vty_out(vty,
1b78780b
DL
13032 " Belongs to the subnet range group: %pFX\n",
13033 range);
d62a17ae 13034 }
13035 }
13036 }
13037 }
13038
13039 if (use_json) {
13040 /* Administrative shutdown. */
cb9196e7
DS
13041 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13042 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 13043 json_object_boolean_true_add(json_neigh,
13044 "adminShutDown");
13045
13046 /* BGP Version. */
13047 json_object_int_add(json_neigh, "bgpVersion", 4);
c949c771
DA
13048 json_object_string_addf(json_neigh, "remoteRouterId", "%pI4",
13049 &p->remote_id);
13050 json_object_string_addf(json_neigh, "localRouterId", "%pI4",
13051 &bgp->router_id);
d62a17ae 13052
13053 /* Confederation */
13054 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13055 && bgp_confederation_peers_check(bgp, p->as))
13056 json_object_boolean_true_add(json_neigh,
13057 "nbrCommonAdmin");
13058
13059 /* Status. */
13060 json_object_string_add(
13061 json_neigh, "bgpState",
13062 lookup_msg(bgp_status_msg, p->status, NULL));
13063
feb17238 13064 if (peer_established(p)) {
d62a17ae 13065 time_t uptime;
d62a17ae 13066
083ec940 13067 uptime = monotime(NULL);
d62a17ae 13068 uptime -= p->uptime;
d62a17ae 13069 epoch_tbuf = time(NULL) - uptime;
13070
d3c7efed
DS
13071 json_object_int_add(json_neigh, "bgpTimerUpMsec",
13072 uptime * 1000);
d62a17ae 13073 json_object_string_add(json_neigh, "bgpTimerUpString",
13074 peer_uptime(p->uptime, timebuf,
13075 BGP_UPTIME_LEN, 0,
13076 NULL));
13077 json_object_int_add(json_neigh,
13078 "bgpTimerUpEstablishedEpoch",
13079 epoch_tbuf);
13080 }
13081
13082 else if (p->status == Active) {
13083 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13084 json_object_string_add(json_neigh, "bgpStateIs",
13085 "passive");
13086 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13087 json_object_string_add(json_neigh, "bgpStateIs",
13088 "passiveNSF");
13089 }
13090
13091 /* read timer */
13092 time_t uptime;
a2700b50 13093 struct tm tm;
d62a17ae 13094
083ec940 13095 uptime = monotime(NULL);
d62a17ae 13096 uptime -= p->readtime;
a2700b50
MS
13097 gmtime_r(&uptime, &tm);
13098
d62a17ae 13099 json_object_int_add(json_neigh, "bgpTimerLastRead",
a2700b50
MS
13100 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13101 + (tm.tm_hour * 3600000));
d62a17ae 13102
083ec940 13103 uptime = monotime(NULL);
d62a17ae 13104 uptime -= p->last_write;
a2700b50
MS
13105 gmtime_r(&uptime, &tm);
13106
d62a17ae 13107 json_object_int_add(json_neigh, "bgpTimerLastWrite",
a2700b50
MS
13108 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13109 + (tm.tm_hour * 3600000));
d62a17ae 13110
083ec940 13111 uptime = monotime(NULL);
d62a17ae 13112 uptime -= p->update_time;
a2700b50
MS
13113 gmtime_r(&uptime, &tm);
13114
d62a17ae 13115 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
a2700b50
MS
13116 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13117 + (tm.tm_hour * 3600000));
d62a17ae 13118
13119 /* Configured timer values. */
9b1b9623
TA
13120 json_object_int_add(json_neigh,
13121 "bgpTimerConfiguredHoldTimeMsecs",
e93d5c29
TA
13122 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13123 ? p->holdtime * 1000
13124 : bgp->default_holdtime * 1000);
13125 json_object_int_add(json_neigh,
13126 "bgpTimerConfiguredKeepAliveIntervalMsecs",
13127 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13128 ? p->keepalive * 1000
13129 : bgp->default_keepalive * 1000);
d62a17ae 13130 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
13131 p->v_holdtime * 1000);
13132 json_object_int_add(json_neigh,
13133 "bgpTimerKeepAliveIntervalMsecs",
13134 p->v_keepalive * 1000);
d43114f3
DS
13135 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
13136 json_object_int_add(json_neigh,
13137 "bgpTimerDelayOpenTimeMsecs",
13138 p->v_delayopen * 1000);
13139 }
13140
4ab46701
AR
13141 /* Configured and Synced tcp-mss value for peer */
13142 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13143 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13144 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
13145 p->tcp_mss);
13146 json_object_int_add(json_neigh, "bgpTcpMssSynced",
13147 sync_tcp_mss);
13148 }
13149
d08c0c80
DA
13150 /* Extended Optional Parameters Length for BGP OPEN Message */
13151 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
13152 json_object_boolean_true_add(
13153 json_neigh, "extendedOptionalParametersLength");
13154 else
13155 json_object_boolean_false_add(
13156 json_neigh, "extendedOptionalParametersLength");
6e37924b
DA
13157
13158 /* Conditional advertisements */
13159 json_object_int_add(
13160 json_neigh,
13161 "bgpTimerConfiguredConditionalAdvertisementsSec",
13162 bgp->condition_check_period);
13163 if (thread_is_scheduled(bgp->t_condition_check))
13164 json_object_int_add(
13165 json_neigh,
13166 "bgpTimerUntilConditionalAdvertisementsSec",
13167 thread_timer_remain_second(
13168 bgp->t_condition_check));
d62a17ae 13169 } else {
13170 /* Administrative shutdown. */
cb9196e7
DS
13171 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13172 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 13173 vty_out(vty, " Administratively shut down\n");
13174
13175 /* BGP Version. */
13176 vty_out(vty, " BGP version 4");
0e38aeb4 13177 vty_out(vty, ", remote router ID %s",
d62a17ae 13178 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
0e38aeb4
AD
13179 vty_out(vty, ", local router ID %s\n",
13180 inet_ntop(AF_INET, &bgp->router_id, buf1,
13181 sizeof(buf1)));
d62a17ae 13182
13183 /* Confederation */
13184 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13185 && bgp_confederation_peers_check(bgp, p->as))
13186 vty_out(vty,
13187 " Neighbor under common administration\n");
13188
13189 /* Status. */
13190 vty_out(vty, " BGP state = %s",
13191 lookup_msg(bgp_status_msg, p->status, NULL));
13192
feb17238 13193 if (peer_established(p))
d62a17ae 13194 vty_out(vty, ", up for %8s",
13195 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
13196 0, NULL));
13197
13198 else if (p->status == Active) {
13199 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13200 vty_out(vty, " (passive)");
13201 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13202 vty_out(vty, " (NSF passive)");
13203 }
13204 vty_out(vty, "\n");
13205
13206 /* read timer */
13207 vty_out(vty, " Last read %s",
13208 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
13209 NULL));
13210 vty_out(vty, ", Last write %s\n",
13211 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
13212 NULL));
13213
13214 /* Configured timer values. */
13215 vty_out(vty,
e93d5c29 13216 " Hold time is %d seconds, keepalive interval is %d seconds\n",
d62a17ae 13217 p->v_holdtime, p->v_keepalive);
e93d5c29
TA
13218 vty_out(vty, " Configured hold time is %d seconds",
13219 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13220 ? p->holdtime
13221 : bgp->default_holdtime);
9b1b9623 13222 vty_out(vty, ", keepalive interval is %d seconds\n",
e93d5c29
TA
13223 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13224 ? p->keepalive
13225 : bgp->default_keepalive);
d43114f3
DS
13226 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
13227 vty_out(vty,
13228 " Configured DelayOpenTime is %d seconds\n",
13229 p->delayopen);
4ab46701
AR
13230
13231 /* Configured and synced tcp-mss value for peer */
13232 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13233 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13234 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
13235 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
13236 }
d08c0c80
DA
13237
13238 /* Extended Optional Parameters Length for BGP OPEN Message */
13239 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
13240 vty_out(vty,
13241 " Extended Optional Parameters Length is enabled\n");
6e37924b
DA
13242
13243 /* Conditional advertisements */
13244 vty_out(vty,
13245 " Configured conditional advertisements interval is %d seconds\n",
13246 bgp->condition_check_period);
13247 if (thread_is_scheduled(bgp->t_condition_check))
13248 vty_out(vty,
13249 " Time until conditional advertisements begin is %lu seconds\n",
13250 thread_timer_remain_second(
13251 bgp->t_condition_check));
d62a17ae 13252 }
13253 /* Capability. */
10711563
DA
13254 if (peer_established(p) &&
13255 (p->cap || peer_afc_advertised(p) || peer_afc_received(p))) {
13256 if (use_json) {
13257 json_object *json_cap = NULL;
d62a17ae 13258
10711563 13259 json_cap = json_object_new_object();
d62a17ae 13260
10711563
DA
13261 /* AS4 */
13262 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13263 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13264 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV) &&
13265 CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
ef56aee4 13266 json_object_string_add(
10711563 13267 json_cap, "4byteAs",
ef56aee4 13268 "advertisedAndReceived");
10711563
DA
13269 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13270 json_object_string_add(json_cap,
13271 "4byteAs",
13272 "advertised");
13273 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13274 json_object_string_add(json_cap,
13275 "4byteAs",
13276 "received");
13277 }
ef56aee4 13278
10711563
DA
13279 /* Extended Message Support */
13280 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV) &&
13281 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV))
13282 json_object_string_add(json_cap,
13283 "extendedMessage",
13284 "advertisedAndReceived");
13285 else if (CHECK_FLAG(p->cap,
13286 PEER_CAP_EXTENDED_MESSAGE_ADV))
13287 json_object_string_add(json_cap,
13288 "extendedMessage",
13289 "advertised");
13290 else if (CHECK_FLAG(p->cap,
13291 PEER_CAP_EXTENDED_MESSAGE_RCV))
13292 json_object_string_add(json_cap,
13293 "extendedMessage",
13294 "received");
ef56aee4 13295
10711563
DA
13296 /* AddPath */
13297 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13298 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13299 json_object *json_add = NULL;
13300 const char *print_store;
d62a17ae 13301
10711563 13302 json_add = json_object_new_object();
d62a17ae 13303
10711563
DA
13304 FOREACH_AFI_SAFI (afi, safi) {
13305 json_object *json_sub = NULL;
13306 json_sub = json_object_new_object();
13307 print_store = get_afi_safi_str(
13308 afi, safi, true);
d62a17ae 13309
10711563
DA
13310 if (CHECK_FLAG(
13311 p->af_cap[afi][safi],
13312 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13313 CHECK_FLAG(
13314 p->af_cap[afi][safi],
13315 PEER_CAP_ADDPATH_AF_TX_RCV)) {
05c7a1cc
QY
13316 if (CHECK_FLAG(
13317 p->af_cap[afi]
13318 [safi],
10711563
DA
13319 PEER_CAP_ADDPATH_AF_TX_ADV) &&
13320 CHECK_FLAG(
05c7a1cc
QY
13321 p->af_cap[afi]
13322 [safi],
10711563
DA
13323 PEER_CAP_ADDPATH_AF_TX_RCV))
13324 json_object_boolean_true_add(
13325 json_sub,
13326 "txAdvertisedAndReceived");
13327 else if (
13328 CHECK_FLAG(
13329 p->af_cap[afi]
13330 [safi],
13331 PEER_CAP_ADDPATH_AF_TX_ADV))
13332 json_object_boolean_true_add(
13333 json_sub,
13334 "txAdvertised");
13335 else if (
13336 CHECK_FLAG(
13337 p->af_cap[afi]
13338 [safi],
13339 PEER_CAP_ADDPATH_AF_TX_RCV))
13340 json_object_boolean_true_add(
13341 json_sub,
13342 "txReceived");
13343 }
d62a17ae 13344
10711563
DA
13345 if (CHECK_FLAG(
13346 p->af_cap[afi][safi],
13347 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13348 CHECK_FLAG(
13349 p->af_cap[afi][safi],
13350 PEER_CAP_ADDPATH_AF_RX_RCV)) {
05c7a1cc
QY
13351 if (CHECK_FLAG(
13352 p->af_cap[afi]
13353 [safi],
10711563
DA
13354 PEER_CAP_ADDPATH_AF_RX_ADV) &&
13355 CHECK_FLAG(
13356 p->af_cap[afi]
13357 [safi],
13358 PEER_CAP_ADDPATH_AF_RX_RCV))
13359 json_object_boolean_true_add(
13360 json_sub,
13361 "rxAdvertisedAndReceived");
13362 else if (
13363 CHECK_FLAG(
13364 p->af_cap[afi]
13365 [safi],
13366 PEER_CAP_ADDPATH_AF_RX_ADV))
13367 json_object_boolean_true_add(
13368 json_sub,
13369 "rxAdvertised");
13370 else if (
13371 CHECK_FLAG(
13372 p->af_cap[afi]
13373 [safi],
13374 PEER_CAP_ADDPATH_AF_RX_RCV))
13375 json_object_boolean_true_add(
13376 json_sub,
13377 "rxReceived");
05c7a1cc
QY
13378 }
13379
10711563
DA
13380 if (CHECK_FLAG(
13381 p->af_cap[afi][safi],
13382 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13383 CHECK_FLAG(
13384 p->af_cap[afi][safi],
13385 PEER_CAP_ADDPATH_AF_TX_RCV) ||
13386 CHECK_FLAG(
13387 p->af_cap[afi][safi],
13388 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13389 CHECK_FLAG(
13390 p->af_cap[afi][safi],
13391 PEER_CAP_ADDPATH_AF_RX_RCV))
13392 json_object_object_add(
13393 json_add, print_store,
13394 json_sub);
13395 else
13396 json_object_free(json_sub);
d62a17ae 13397 }
13398
10711563
DA
13399 json_object_object_add(json_cap, "addPath",
13400 json_add);
13401 }
d62a17ae 13402
10711563
DA
13403 /* Dynamic */
13404 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13405 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13406 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV) &&
13407 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13408 json_object_string_add(
13409 json_cap, "dynamic",
13410 "advertisedAndReceived");
13411 else if (CHECK_FLAG(p->cap,
13412 PEER_CAP_DYNAMIC_ADV))
13413 json_object_string_add(json_cap,
13414 "dynamic",
13415 "advertised");
13416 else if (CHECK_FLAG(p->cap,
13417 PEER_CAP_DYNAMIC_RCV))
13418 json_object_string_add(json_cap,
13419 "dynamic",
13420 "received");
13421 }
d62a17ae 13422
d864dd9e
EB
13423 /* Role */
13424 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13425 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13426 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV) &&
13427 CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13428 json_object_string_add(
13429 json_cap, "role",
13430 "advertisedAndReceived");
13431 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13432 json_object_string_add(json_cap, "role",
13433 "advertised");
13434 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13435 json_object_string_add(json_cap, "role",
13436 "received");
13437 }
13438
10711563
DA
13439 /* Extended nexthop */
13440 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13441 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13442 json_object *json_nxt = NULL;
13443 const char *print_store;
d62a17ae 13444
d62a17ae 13445
10711563
DA
13446 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV) &&
13447 CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13448 json_object_string_add(
13449 json_cap, "extendedNexthop",
13450 "advertisedAndReceived");
13451 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13452 json_object_string_add(
13453 json_cap, "extendedNexthop",
13454 "advertised");
13455 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13456 json_object_string_add(
13457 json_cap, "extendedNexthop",
13458 "received");
d62a17ae 13459
10711563
DA
13460 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13461 json_nxt = json_object_new_object();
d62a17ae 13462
10711563
DA
13463 for (safi = SAFI_UNICAST;
13464 safi < SAFI_MAX; safi++) {
13465 if (CHECK_FLAG(
13466 p->af_cap[AFI_IP]
13467 [safi],
13468 PEER_CAP_ENHE_AF_RCV)) {
13469 print_store =
13470 get_afi_safi_str(
d62a17ae 13471 AFI_IP,
10711563
DA
13472 safi,
13473 true);
13474 json_object_string_add(
13475 json_nxt,
13476 print_store,
13477 "recieved"); /* misspelled for compatibility */
d62a17ae 13478 }
d62a17ae 13479 }
10711563
DA
13480 json_object_object_add(
13481 json_cap,
13482 "extendedNexthopFamililesByPeer",
13483 json_nxt);
d62a17ae 13484 }
10711563 13485 }
d62a17ae 13486
10711563
DA
13487 /* Long-lived Graceful Restart */
13488 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13489 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13490 json_object *json_llgr = NULL;
13491 const char *afi_safi_str;
8606be87 13492
10711563
DA
13493 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV) &&
13494 CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13495 json_object_string_add(
13496 json_cap,
13497 "longLivedGracefulRestart",
13498 "advertisedAndReceived");
13499 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13500 json_object_string_add(
13501 json_cap,
13502 "longLivedGracefulRestart",
13503 "advertised");
13504 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13505 json_object_string_add(
13506 json_cap,
13507 "longLivedGracefulRestart",
13508 "received");
8606be87 13509
10711563
DA
13510 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13511 json_llgr = json_object_new_object();
8606be87 13512
10711563
DA
13513 FOREACH_AFI_SAFI (afi, safi) {
13514 if (CHECK_FLAG(
13515 p->af_cap[afi]
13516 [safi],
13517 PEER_CAP_ENHE_AF_RCV)) {
13518 afi_safi_str =
13519 get_afi_safi_str(
8606be87
DA
13520 afi,
13521 safi,
13522 true);
10711563
DA
13523 json_object_string_add(
13524 json_llgr,
13525 afi_safi_str,
13526 "received");
8606be87 13527 }
8606be87 13528 }
10711563
DA
13529 json_object_object_add(
13530 json_cap,
13531 "longLivedGracefulRestartByPeer",
13532 json_llgr);
8606be87 13533 }
10711563 13534 }
8606be87 13535
10711563
DA
13536 /* Route Refresh */
13537 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13538 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13539 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13540 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) &&
13541 (CHECK_FLAG(p->cap,
13542 PEER_CAP_REFRESH_NEW_RCV) ||
13543 CHECK_FLAG(p->cap,
13544 PEER_CAP_REFRESH_OLD_RCV))) {
13545 if (CHECK_FLAG(
13546 p->cap,
13547 PEER_CAP_REFRESH_OLD_RCV) &&
13548 CHECK_FLAG(
13549 p->cap,
13550 PEER_CAP_REFRESH_NEW_RCV))
13551 json_object_string_add(
13552 json_cap,
13553 "routeRefresh",
13554 "advertisedAndReceivedOldNew");
13555 else {
d62a17ae 13556 if (CHECK_FLAG(
13557 p->cap,
10711563 13558 PEER_CAP_REFRESH_OLD_RCV))
d62a17ae 13559 json_object_string_add(
13560 json_cap,
13561 "routeRefresh",
10711563
DA
13562 "advertisedAndReceivedOld");
13563 else
13564 json_object_string_add(
13565 json_cap,
13566 "routeRefresh",
13567 "advertisedAndReceivedNew");
d62a17ae 13568 }
10711563
DA
13569 } else if (CHECK_FLAG(p->cap,
13570 PEER_CAP_REFRESH_ADV))
13571 json_object_string_add(json_cap,
13572 "routeRefresh",
13573 "advertised");
13574 else if (CHECK_FLAG(p->cap,
13575 PEER_CAP_REFRESH_NEW_RCV) ||
13576 CHECK_FLAG(p->cap,
13577 PEER_CAP_REFRESH_OLD_RCV))
13578 json_object_string_add(json_cap,
13579 "routeRefresh",
13580 "received");
13581 }
d62a17ae 13582
10711563
DA
13583 /* Enhanced Route Refresh */
13584 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13585 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13586 if (CHECK_FLAG(p->cap,
13587 PEER_CAP_ENHANCED_RR_ADV) &&
13588 CHECK_FLAG(p->cap,
13589 PEER_CAP_ENHANCED_RR_RCV))
d77114b7 13590 json_object_string_add(
10711563
DA
13591 json_cap,
13592 "enhancedRouteRefresh",
13593 "advertisedAndReceived");
13594 else if (CHECK_FLAG(p->cap,
13595 PEER_CAP_ENHANCED_RR_ADV))
d77114b7 13596 json_object_string_add(
10711563
DA
13597 json_cap,
13598 "enhancedRouteRefresh",
13599 "advertised");
13600 else if (CHECK_FLAG(p->cap,
9af52ccf 13601 PEER_CAP_ENHANCED_RR_RCV))
10711563
DA
13602 json_object_string_add(
13603 json_cap,
13604 "enhancedRouteRefresh",
13605 "received");
13606 }
d77114b7 13607
10711563
DA
13608 /* Multiprotocol Extensions */
13609 json_object *json_multi = NULL;
d77114b7 13610
10711563 13611 json_multi = json_object_new_object();
d77114b7 13612
10711563
DA
13613 FOREACH_AFI_SAFI (afi, safi) {
13614 if (p->afc_adv[afi][safi] ||
13615 p->afc_recv[afi][safi]) {
13616 json_object *json_exten = NULL;
13617 json_exten = json_object_new_object();
13618
13619 if (p->afc_adv[afi][safi] &&
13620 p->afc_recv[afi][safi])
13621 json_object_boolean_true_add(
13622 json_exten,
9af52ccf 13623 "advertisedAndReceived");
10711563
DA
13624 else if (p->afc_adv[afi][safi])
13625 json_object_boolean_true_add(
13626 json_exten,
9af52ccf 13627 "advertised");
10711563
DA
13628 else if (p->afc_recv[afi][safi])
13629 json_object_boolean_true_add(
13630 json_exten, "received");
9af52ccf 13631
10711563
DA
13632 json_object_object_add(
13633 json_multi,
13634 get_afi_safi_str(afi, safi,
13635 true),
13636 json_exten);
13637 }
13638 }
13639 json_object_object_add(json_cap,
13640 "multiprotocolExtensions",
13641 json_multi);
d62a17ae 13642
10711563
DA
13643 /* Hostname capabilities */
13644 json_object *json_hname = NULL;
d62a17ae 13645
10711563 13646 json_hname = json_object_new_object();
d62a17ae 13647
10711563
DA
13648 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13649 json_object_string_add(
13650 json_hname, "advHostName",
13651 bgp->peer_self->hostname
13652 ? bgp->peer_self->hostname
13653 : "n/a");
13654 json_object_string_add(
13655 json_hname, "advDomainName",
13656 bgp->peer_self->domainname
13657 ? bgp->peer_self->domainname
13658 : "n/a");
13659 }
d77114b7 13660
d77114b7 13661
10711563
DA
13662 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13663 json_object_string_add(
13664 json_hname, "rcvHostName",
13665 p->hostname ? p->hostname : "n/a");
13666 json_object_string_add(
13667 json_hname, "rcvDomainName",
13668 p->domainname ? p->domainname : "n/a");
13669 }
d77114b7 13670
10711563
DA
13671 json_object_object_add(json_cap, "hostName",
13672 json_hname);
d77114b7 13673
17be83bf 13674 /* Graceful Restart */
10711563
DA
13675 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13676 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13677 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) &&
13678 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
d77114b7 13679 json_object_string_add(
10711563
DA
13680 json_cap, "gracefulRestart",
13681 "advertisedAndReceived");
13682 else if (CHECK_FLAG(p->cap,
13683 PEER_CAP_RESTART_ADV))
d77114b7 13684 json_object_string_add(
10711563
DA
13685 json_cap,
13686 "gracefulRestartCapability",
13687 "advertised");
13688 else if (CHECK_FLAG(p->cap,
13689 PEER_CAP_RESTART_RCV))
13690 json_object_string_add(
13691 json_cap,
13692 "gracefulRestartCapability",
13693 "received");
d77114b7 13694
10711563
DA
13695 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13696 int restart_af_count = 0;
13697 json_object *json_restart = NULL;
13698 json_restart = json_object_new_object();
d62a17ae 13699
10711563
DA
13700 json_object_int_add(
13701 json_cap,
13702 "gracefulRestartRemoteTimerMsecs",
13703 p->v_gr_restart * 1000);
d62a17ae 13704
10711563 13705 FOREACH_AFI_SAFI (afi, safi) {
05c7a1cc
QY
13706 if (CHECK_FLAG(
13707 p->af_cap[afi]
13708 [safi],
10711563
DA
13709 PEER_CAP_RESTART_AF_RCV)) {
13710 json_object *json_sub =
13711 NULL;
13712 json_sub =
13713 json_object_new_object();
d62a17ae 13714
05c7a1cc
QY
13715 if (CHECK_FLAG(
13716 p->af_cap
13717 [afi]
13718 [safi],
10711563
DA
13719 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13720 json_object_boolean_true_add(
13721 json_sub,
13722 "preserved");
13723 restart_af_count++;
d62a17ae 13724 json_object_object_add(
10711563
DA
13725 json_restart,
13726 get_afi_safi_str(
13727 afi,
13728 safi,
13729 true),
13730 json_sub);
d62a17ae 13731 }
d62a17ae 13732 }
10711563
DA
13733 if (!restart_af_count) {
13734 json_object_string_add(
13735 json_cap,
13736 "addressFamiliesByPeer",
13737 "none");
13738 json_object_free(json_restart);
13739 } else
13740 json_object_object_add(
13741 json_cap,
13742 "addressFamiliesByPeer",
13743 json_restart);
d62a17ae 13744 }
10711563
DA
13745 }
13746 json_object_object_add(
13747 json_neigh, "neighborCapabilities", json_cap);
13748 } else {
13749 vty_out(vty, " Neighbor capabilities:\n");
13750
13751 /* AS4 */
13752 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13753 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13754 vty_out(vty, " 4 Byte AS:");
13755 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13756 vty_out(vty, " advertised");
13757 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13758 vty_out(vty, " %sreceived",
13759 CHECK_FLAG(p->cap,
13760 PEER_CAP_AS4_ADV)
13761 ? "and "
13762 : "");
13763 vty_out(vty, "\n");
13764 }
d62a17ae 13765
10711563
DA
13766 /* Extended Message Support */
13767 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV) ||
13768 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13769 vty_out(vty, " Extended Message:");
ef56aee4 13770 if (CHECK_FLAG(p->cap,
10711563
DA
13771 PEER_CAP_EXTENDED_MESSAGE_ADV))
13772 vty_out(vty, " advertised");
13773 if (CHECK_FLAG(p->cap,
13774 PEER_CAP_EXTENDED_MESSAGE_RCV))
13775 vty_out(vty, " %sreceived",
13776 CHECK_FLAG(
13777 p->cap,
13778 PEER_CAP_EXTENDED_MESSAGE_ADV)
13779 ? "and "
13780 : "");
13781 vty_out(vty, "\n");
13782 }
d62a17ae 13783
10711563
DA
13784 /* AddPath */
13785 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13786 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13787 vty_out(vty, " AddPath:\n");
d62a17ae 13788
10711563 13789 FOREACH_AFI_SAFI (afi, safi) {
ef56aee4 13790 if (CHECK_FLAG(
10711563
DA
13791 p->af_cap[afi][safi],
13792 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13793 CHECK_FLAG(
13794 p->af_cap[afi][safi],
13795 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13796 vty_out(vty, " %s: TX ",
13797 get_afi_safi_str(
13798 afi, safi,
13799 false));
ef56aee4 13800
10711563
DA
13801 if (CHECK_FLAG(
13802 p->af_cap[afi]
13803 [safi],
13804 PEER_CAP_ADDPATH_AF_TX_ADV))
13805 vty_out(vty,
13806 "advertised");
d62a17ae 13807
05c7a1cc
QY
13808 if (CHECK_FLAG(
13809 p->af_cap[afi]
13810 [safi],
10711563 13811 PEER_CAP_ADDPATH_AF_TX_RCV))
05c7a1cc 13812 vty_out(vty,
10711563
DA
13813 "%sreceived",
13814 CHECK_FLAG(
13815 p->af_cap
13816 [afi]
13817 [safi],
13818 PEER_CAP_ADDPATH_AF_TX_ADV)
13819 ? " and "
13820 : "");
05c7a1cc 13821
10711563
DA
13822 vty_out(vty, "\n");
13823 }
d62a17ae 13824
9af52ccf 13825 if (CHECK_FLAG(
10711563
DA
13826 p->af_cap[afi][safi],
13827 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13828 CHECK_FLAG(
13829 p->af_cap[afi][safi],
13830 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13831 vty_out(vty, " %s: RX ",
5cb5f4d0 13832 get_afi_safi_str(
10711563
DA
13833 afi, safi,
13834 false));
d62a17ae 13835
05c7a1cc
QY
13836 if (CHECK_FLAG(
13837 p->af_cap[afi]
13838 [safi],
10711563 13839 PEER_CAP_ADDPATH_AF_RX_ADV))
05c7a1cc 13840 vty_out(vty,
10711563 13841 "advertised");
d62a17ae 13842
10711563
DA
13843 if (CHECK_FLAG(
13844 p->af_cap[afi]
13845 [safi],
13846 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc 13847 vty_out(vty,
10711563
DA
13848 "%sreceived",
13849 CHECK_FLAG(
13850 p->af_cap
13851 [afi]
13852 [safi],
13853 PEER_CAP_ADDPATH_AF_RX_ADV)
13854 ? " and "
05c7a1cc 13855 : "");
d62a17ae 13856
05c7a1cc 13857 vty_out(vty, "\n");
05c7a1cc 13858 }
d62a17ae 13859 }
10711563 13860 }
d62a17ae 13861
10711563
DA
13862 /* Dynamic */
13863 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13864 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13865 vty_out(vty, " Dynamic:");
13866 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV))
13867 vty_out(vty, " advertised");
13868 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13869 vty_out(vty, " %sreceived",
13870 CHECK_FLAG(p->cap,
13871 PEER_CAP_DYNAMIC_ADV)
13872 ? "and "
13873 : "");
13874 vty_out(vty, "\n");
13875 }
d62a17ae 13876
d864dd9e
EB
13877 /* Role */
13878 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13879 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13880 vty_out(vty, " Role:");
13881 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13882 vty_out(vty, " advertised");
13883 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13884 vty_out(vty, " %sreceived",
13885 CHECK_FLAG(p->cap,
13886 PEER_CAP_ROLE_ADV)
13887 ? "and "
13888 : "");
13889 vty_out(vty, "\n");
13890 }
13891
10711563
DA
13892 /* Extended nexthop */
13893 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13894 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13895 vty_out(vty, " Extended nexthop:");
13896 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13897 vty_out(vty, " advertised");
13898 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13899 vty_out(vty, " %sreceived",
13900 CHECK_FLAG(p->cap,
13901 PEER_CAP_ENHE_ADV)
13902 ? "and "
13903 : "");
13904 vty_out(vty, "\n");
d62a17ae 13905
10711563 13906 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
57f7feb6 13907 vty_out(vty,
10711563
DA
13908 " Address families by peer:\n ");
13909 for (safi = SAFI_UNICAST;
13910 safi < SAFI_MAX; safi++)
13911 if (CHECK_FLAG(
13912 p->af_cap[AFI_IP]
13913 [safi],
13914 PEER_CAP_ENHE_AF_RCV))
13915 vty_out(vty,
13916 " %s\n",
13917 get_afi_safi_str(
13918 AFI_IP,
13919 safi,
13920 false));
d62a17ae 13921 }
10711563 13922 }
d62a17ae 13923
10711563
DA
13924 /* Long-lived Graceful Restart */
13925 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13926 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13927 vty_out(vty,
13928 " Long-lived Graceful Restart:");
13929 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13930 vty_out(vty, " advertised");
13931 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13932 vty_out(vty, " %sreceived",
13933 CHECK_FLAG(p->cap,
13934 PEER_CAP_LLGR_ADV)
13935 ? "and "
13936 : "");
13937 vty_out(vty, "\n");
8606be87 13938
10711563 13939 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
57f7feb6 13940 vty_out(vty,
10711563
DA
13941 " Address families by peer:\n");
13942 FOREACH_AFI_SAFI (afi, safi)
13943 if (CHECK_FLAG(
13944 p->af_cap[afi]
13945 [safi],
13946 PEER_CAP_LLGR_AF_RCV))
13947 vty_out(vty,
13948 " %s\n",
13949 get_afi_safi_str(
13950 afi,
13951 safi,
13952 false));
8606be87 13953 }
10711563 13954 }
8606be87 13955
10711563
DA
13956 /* Route Refresh */
13957 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13958 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13959 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13960 vty_out(vty, " Route refresh:");
13961 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV))
13962 vty_out(vty, " advertised");
13963 if (CHECK_FLAG(p->cap,
13964 PEER_CAP_REFRESH_NEW_RCV) ||
13965 CHECK_FLAG(p->cap,
13966 PEER_CAP_REFRESH_OLD_RCV))
13967 vty_out(vty, " %sreceived(%s)",
13968 CHECK_FLAG(p->cap,
13969 PEER_CAP_REFRESH_ADV)
13970 ? "and "
13971 : "",
13972 (CHECK_FLAG(
13973 p->cap,
13974 PEER_CAP_REFRESH_OLD_RCV) &&
13975 CHECK_FLAG(
13976 p->cap,
13977 PEER_CAP_REFRESH_NEW_RCV))
13978 ? "old & new"
13979 : CHECK_FLAG(
13980 p->cap,
13981 PEER_CAP_REFRESH_OLD_RCV)
13982 ? "old"
13983 : "new");
d62a17ae 13984
d77114b7 13985 vty_out(vty, "\n");
10711563 13986 }
d62a17ae 13987
10711563
DA
13988 /* Enhanced Route Refresh */
13989 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13990 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13991 vty_out(vty, " Enhanced Route Refresh:");
13992 if (CHECK_FLAG(p->cap,
13993 PEER_CAP_ENHANCED_RR_ADV))
13994 vty_out(vty, " advertised");
13995 if (CHECK_FLAG(p->cap,
13996 PEER_CAP_ENHANCED_RR_RCV))
13997 vty_out(vty, " %sreceived",
13998 CHECK_FLAG(p->cap,
13999 PEER_CAP_REFRESH_ADV)
14000 ? "and "
14001 : "");
14002 vty_out(vty, "\n");
14003 }
14004
14005 /* Multiprotocol Extensions */
14006 FOREACH_AFI_SAFI (afi, safi)
14007 if (p->afc_adv[afi][safi] ||
14008 p->afc_recv[afi][safi]) {
14009 vty_out(vty, " Address Family %s:",
14010 get_afi_safi_str(afi, safi,
14011 false));
14012 if (p->afc_adv[afi][safi])
9af52ccf 14013 vty_out(vty, " advertised");
10711563 14014 if (p->afc_recv[afi][safi])
9af52ccf 14015 vty_out(vty, " %sreceived",
10711563 14016 p->afc_adv[afi][safi]
9af52ccf
DA
14017 ? "and "
14018 : "");
14019 vty_out(vty, "\n");
14020 }
14021
10711563
DA
14022 /* Hostname capability */
14023 vty_out(vty, " Hostname Capability:");
d62a17ae 14024
10711563
DA
14025 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
14026 vty_out(vty,
14027 " advertised (name: %s,domain name: %s)",
14028 bgp->peer_self->hostname
14029 ? bgp->peer_self->hostname
14030 : "n/a",
14031 bgp->peer_self->domainname
14032 ? bgp->peer_self->domainname
14033 : "n/a");
14034 } else {
14035 vty_out(vty, " not advertised");
14036 }
d77114b7 14037
10711563
DA
14038 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
14039 vty_out(vty,
14040 " received (name: %s,domain name: %s)",
14041 p->hostname ? p->hostname : "n/a",
14042 p->domainname ? p->domainname : "n/a");
14043 } else {
14044 vty_out(vty, " not received");
d62a17ae 14045 }
d62a17ae 14046
10711563 14047 vty_out(vty, "\n");
d77114b7 14048
10711563
DA
14049 /* Graceful Restart */
14050 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
14051 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
14052 vty_out(vty,
14053 " Graceful Restart Capability:");
14054 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV))
14055 vty_out(vty, " advertised");
14056 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
14057 vty_out(vty, " %sreceived",
14058 CHECK_FLAG(p->cap,
14059 PEER_CAP_RESTART_ADV)
14060 ? "and "
14061 : "");
d77114b7
MK
14062 vty_out(vty, "\n");
14063
10711563
DA
14064 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14065 int restart_af_count = 0;
d62a17ae 14066
10711563
DA
14067 vty_out(vty,
14068 " Remote Restart timer is %d seconds\n",
14069 p->v_gr_restart);
14070 vty_out(vty,
14071 " Address families by peer:\n ");
d62a17ae 14072
10711563
DA
14073 FOREACH_AFI_SAFI (afi, safi)
14074 if (CHECK_FLAG(
14075 p->af_cap[afi]
14076 [safi],
14077 PEER_CAP_RESTART_AF_RCV)) {
14078 vty_out(vty, "%s%s(%s)",
14079 restart_af_count
14080 ? ", "
14081 : "",
14082 get_afi_safi_str(
14083 afi,
14084 safi,
14085 false),
14086 CHECK_FLAG(
14087 p->af_cap
14088 [afi]
14089 [safi],
14090 PEER_CAP_RESTART_AF_PRESERVE_RCV)
14091 ? "preserved"
14092 : "not preserved");
14093 restart_af_count++;
14094 }
14095 if (!restart_af_count)
14096 vty_out(vty, "none");
14097 vty_out(vty, "\n");
14098 }
17be83bf 14099 } /* Graceful Restart */
d62a17ae 14100 }
14101 }
14102
14103 /* graceful restart information */
10711563
DA
14104 json_object *json_grace = NULL;
14105 json_object *json_grace_send = NULL;
14106 json_object *json_grace_recv = NULL;
14107 int eor_send_af_count = 0;
14108 int eor_receive_af_count = 0;
d62a17ae 14109
10711563
DA
14110 if (use_json) {
14111 json_grace = json_object_new_object();
14112 json_grace_send = json_object_new_object();
14113 json_grace_recv = json_object_new_object();
14114
14115 if ((peer_established(p)) &&
14116 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14117 FOREACH_AFI_SAFI (afi, safi) {
14118 if (CHECK_FLAG(p->af_sflags[afi][safi],
14119 PEER_STATUS_EOR_SEND)) {
14120 json_object_boolean_true_add(
14121 json_grace_send,
14122 get_afi_safi_str(afi, safi,
14123 true));
14124 eor_send_af_count++;
d62a17ae 14125 }
10711563
DA
14126 }
14127 FOREACH_AFI_SAFI (afi, safi) {
14128 if (CHECK_FLAG(p->af_sflags[afi][safi],
14129 PEER_STATUS_EOR_RECEIVED)) {
14130 json_object_boolean_true_add(
14131 json_grace_recv,
14132 get_afi_safi_str(afi, safi,
14133 true));
14134 eor_receive_af_count++;
d62a17ae 14135 }
14136 }
10711563
DA
14137 }
14138 json_object_object_add(json_grace, "endOfRibSend",
14139 json_grace_send);
14140 json_object_object_add(json_grace, "endOfRibRecv",
14141 json_grace_recv);
d62a17ae 14142
d62a17ae 14143
10711563
DA
14144 if (p->t_gr_restart)
14145 json_object_int_add(
14146 json_grace, "gracefulRestartTimerMsecs",
14147 thread_timer_remain_second(p->t_gr_restart) *
14148 1000);
2986cac2 14149
10711563
DA
14150 if (p->t_gr_stale)
14151 json_object_int_add(
14152 json_grace, "gracefulStalepathTimerMsecs",
14153 thread_timer_remain_second(p->t_gr_stale) *
14154 1000);
14155 /* more gr info in new format */
14156 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json_grace);
14157 json_object_object_add(json_neigh, "gracefulRestartInfo",
14158 json_grace);
14159 } else {
14160 vty_out(vty, " Graceful restart information:\n");
14161 if ((peer_established(p)) &&
14162 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14163
14164 vty_out(vty, " End-of-RIB send: ");
14165 FOREACH_AFI_SAFI (afi, safi) {
14166 if (CHECK_FLAG(p->af_sflags[afi][safi],
14167 PEER_STATUS_EOR_SEND)) {
14168 vty_out(vty, "%s%s",
14169 eor_send_af_count ? ", " : "",
14170 get_afi_safi_str(afi, safi,
14171 false));
14172 eor_send_af_count++;
d62a17ae 14173 }
10711563
DA
14174 }
14175 vty_out(vty, "\n");
14176 vty_out(vty, " End-of-RIB received: ");
14177 FOREACH_AFI_SAFI (afi, safi) {
14178 if (CHECK_FLAG(p->af_sflags[afi][safi],
14179 PEER_STATUS_EOR_RECEIVED)) {
14180 vty_out(vty, "%s%s",
14181 eor_receive_af_count ? ", "
14182 : "",
14183 get_afi_safi_str(afi, safi,
14184 false));
14185 eor_receive_af_count++;
d62a17ae 14186 }
d62a17ae 14187 }
10711563
DA
14188 vty_out(vty, "\n");
14189 }
d62a17ae 14190
10711563
DA
14191 if (p->t_gr_restart)
14192 vty_out(vty,
14193 " The remaining time of restart timer is %ld\n",
14194 thread_timer_remain_second(p->t_gr_restart));
d62a17ae 14195
10711563
DA
14196 if (p->t_gr_stale)
14197 vty_out(vty,
14198 " The remaining time of stalepath timer is %ld\n",
14199 thread_timer_remain_second(p->t_gr_stale));
2986cac2 14200
10711563
DA
14201 /* more gr info in new format */
14202 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
14203 }
2986cac2 14204
d62a17ae 14205 if (use_json) {
14206 json_object *json_stat = NULL;
14207 json_stat = json_object_new_object();
14208 /* Packet counts. */
43aa5965
QY
14209
14210 atomic_size_t outq_count, inq_count;
14211 outq_count = atomic_load_explicit(&p->obuf->count,
14212 memory_order_relaxed);
14213 inq_count = atomic_load_explicit(&p->ibuf->count,
14214 memory_order_relaxed);
14215
14216 json_object_int_add(json_stat, "depthInq",
14217 (unsigned long)inq_count);
d62a17ae 14218 json_object_int_add(json_stat, "depthOutq",
43aa5965 14219 (unsigned long)outq_count);
0112e9e0
QY
14220 json_object_int_add(json_stat, "opensSent",
14221 atomic_load_explicit(&p->open_out,
14222 memory_order_relaxed));
14223 json_object_int_add(json_stat, "opensRecv",
14224 atomic_load_explicit(&p->open_in,
14225 memory_order_relaxed));
d62a17ae 14226 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
14227 atomic_load_explicit(&p->notify_out,
14228 memory_order_relaxed));
d62a17ae 14229 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
14230 atomic_load_explicit(&p->notify_in,
14231 memory_order_relaxed));
14232 json_object_int_add(json_stat, "updatesSent",
14233 atomic_load_explicit(&p->update_out,
14234 memory_order_relaxed));
14235 json_object_int_add(json_stat, "updatesRecv",
14236 atomic_load_explicit(&p->update_in,
14237 memory_order_relaxed));
d62a17ae 14238 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
14239 atomic_load_explicit(&p->keepalive_out,
14240 memory_order_relaxed));
d62a17ae 14241 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
14242 atomic_load_explicit(&p->keepalive_in,
14243 memory_order_relaxed));
d62a17ae 14244 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
14245 atomic_load_explicit(&p->refresh_out,
14246 memory_order_relaxed));
d62a17ae 14247 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
14248 atomic_load_explicit(&p->refresh_in,
14249 memory_order_relaxed));
d62a17ae 14250 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
14251 atomic_load_explicit(&p->dynamic_cap_out,
14252 memory_order_relaxed));
d62a17ae 14253 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
14254 atomic_load_explicit(&p->dynamic_cap_in,
14255 memory_order_relaxed));
14256 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
14257 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 14258 json_object_object_add(json_neigh, "messageStats", json_stat);
14259 } else {
cb93e0a2
IS
14260 atomic_size_t outq_count, inq_count, open_out, open_in,
14261 notify_out, notify_in, update_out, update_in,
14262 keepalive_out, keepalive_in, refresh_out, refresh_in,
14263 dynamic_cap_out, dynamic_cap_in;
43aa5965
QY
14264 outq_count = atomic_load_explicit(&p->obuf->count,
14265 memory_order_relaxed);
14266 inq_count = atomic_load_explicit(&p->ibuf->count,
14267 memory_order_relaxed);
cb93e0a2
IS
14268 open_out = atomic_load_explicit(&p->open_out,
14269 memory_order_relaxed);
14270 open_in =
14271 atomic_load_explicit(&p->open_in, memory_order_relaxed);
14272 notify_out = atomic_load_explicit(&p->notify_out,
14273 memory_order_relaxed);
14274 notify_in = atomic_load_explicit(&p->notify_in,
14275 memory_order_relaxed);
14276 update_out = atomic_load_explicit(&p->update_out,
14277 memory_order_relaxed);
14278 update_in = atomic_load_explicit(&p->update_in,
14279 memory_order_relaxed);
14280 keepalive_out = atomic_load_explicit(&p->keepalive_out,
14281 memory_order_relaxed);
14282 keepalive_in = atomic_load_explicit(&p->keepalive_in,
14283 memory_order_relaxed);
14284 refresh_out = atomic_load_explicit(&p->refresh_out,
14285 memory_order_relaxed);
14286 refresh_in = atomic_load_explicit(&p->refresh_in,
14287 memory_order_relaxed);
14288 dynamic_cap_out = atomic_load_explicit(&p->dynamic_cap_out,
14289 memory_order_relaxed);
14290 dynamic_cap_in = atomic_load_explicit(&p->dynamic_cap_in,
14291 memory_order_relaxed);
43aa5965 14292
d62a17ae 14293 /* Packet counts. */
14294 vty_out(vty, " Message statistics:\n");
43aa5965
QY
14295 vty_out(vty, " Inq depth is %zu\n", inq_count);
14296 vty_out(vty, " Outq depth is %zu\n", outq_count);
d62a17ae 14297 vty_out(vty, " Sent Rcvd\n");
cb93e0a2
IS
14298 vty_out(vty, " Opens: %10zu %10zu\n", open_out,
14299 open_in);
14300 vty_out(vty, " Notifications: %10zu %10zu\n", notify_out,
14301 notify_in);
14302 vty_out(vty, " Updates: %10zu %10zu\n", update_out,
14303 update_in);
14304 vty_out(vty, " Keepalives: %10zu %10zu\n", keepalive_out,
14305 keepalive_in);
14306 vty_out(vty, " Route Refresh: %10zu %10zu\n", refresh_out,
14307 refresh_in);
14308 vty_out(vty, " Capability: %10zu %10zu\n",
14309 dynamic_cap_out, dynamic_cap_in);
14310 vty_out(vty, " Total: %10u %10u\n",
14311 (uint32_t)PEER_TOTAL_TX(p), (uint32_t)PEER_TOTAL_RX(p));
d62a17ae 14312 }
14313
14314 if (use_json) {
14315 /* advertisement-interval */
14316 json_object_int_add(json_neigh,
14317 "minBtwnAdvertisementRunsTimerMsecs",
14318 p->v_routeadv * 1000);
14319
14320 /* Update-source. */
14321 if (p->update_if || p->update_source) {
14322 if (p->update_if)
14323 json_object_string_add(json_neigh,
14324 "updateSource",
14325 p->update_if);
14326 else if (p->update_source)
47e12884
DA
14327 json_object_string_addf(json_neigh,
14328 "updateSource", "%pSU",
14329 p->update_source);
d62a17ae 14330 }
14331 } else {
14332 /* advertisement-interval */
14333 vty_out(vty,
14334 " Minimum time between advertisement runs is %d seconds\n",
14335 p->v_routeadv);
14336
14337 /* Update-source. */
14338 if (p->update_if || p->update_source) {
14339 vty_out(vty, " Update source is ");
14340 if (p->update_if)
14341 vty_out(vty, "%s", p->update_if);
14342 else if (p->update_source)
47e12884 14343 vty_out(vty, "%pSU", p->update_source);
d62a17ae 14344 vty_out(vty, "\n");
14345 }
14346
14347 vty_out(vty, "\n");
14348 }
14349
14350 /* Address Family Information */
14351 json_object *json_hold = NULL;
14352
14353 if (use_json)
14354 json_hold = json_object_new_object();
14355
05c7a1cc
QY
14356 FOREACH_AFI_SAFI (afi, safi)
14357 if (p->afc[afi][safi])
14358 bgp_show_peer_afi(vty, p, afi, safi, use_json,
14359 json_hold);
d62a17ae 14360
14361 if (use_json) {
14362 json_object_object_add(json_neigh, "addressFamilyInfo",
14363 json_hold);
14364 json_object_int_add(json_neigh, "connectionsEstablished",
14365 p->established);
14366 json_object_int_add(json_neigh, "connectionsDropped",
14367 p->dropped);
14368 } else
14369 vty_out(vty, " Connections established %d; dropped %d\n",
14370 p->established, p->dropped);
14371
14372 if (!p->last_reset) {
14373 if (use_json)
14374 json_object_string_add(json_neigh, "lastReset",
14375 "never");
14376 else
14377 vty_out(vty, " Last reset never\n");
14378 } else {
14379 if (use_json) {
14380 time_t uptime;
a2700b50 14381 struct tm tm;
d62a17ae 14382
083ec940 14383 uptime = monotime(NULL);
d62a17ae 14384 uptime -= p->resettime;
a2700b50
MS
14385 gmtime_r(&uptime, &tm);
14386
d62a17ae 14387 json_object_int_add(json_neigh, "lastResetTimerMsecs",
a2700b50
MS
14388 (tm.tm_sec * 1000)
14389 + (tm.tm_min * 60000)
14390 + (tm.tm_hour * 3600000));
3577f1c5 14391 bgp_show_peer_reset(NULL, p, json_neigh, true);
d62a17ae 14392 } else {
14393 vty_out(vty, " Last reset %s, ",
14394 peer_uptime(p->resettime, timebuf,
14395 BGP_UPTIME_LEN, 0, NULL));
14396
3577f1c5 14397 bgp_show_peer_reset(vty, p, NULL, false);
d62a17ae 14398 if (p->last_reset_cause_size) {
14399 msg = p->last_reset_cause;
14400 vty_out(vty,
14401 " Message received that caused BGP to send a NOTIFICATION:\n ");
14402 for (i = 1; i <= p->last_reset_cause_size;
14403 i++) {
14404 vty_out(vty, "%02X", *msg++);
14405
14406 if (i != p->last_reset_cause_size) {
14407 if (i % 16 == 0) {
14408 vty_out(vty, "\n ");
14409 } else if (i % 4 == 0) {
14410 vty_out(vty, " ");
14411 }
14412 }
14413 }
14414 vty_out(vty, "\n");
14415 }
14416 }
14417 }
14418
14419 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
14420 if (use_json)
14421 json_object_boolean_true_add(json_neigh,
14422 "prefixesConfigExceedMax");
14423 else
14424 vty_out(vty,
14425 " Peer had exceeded the max. no. of prefixes configured.\n");
14426
14427 if (p->t_pmax_restart) {
14428 if (use_json) {
14429 json_object_boolean_true_add(
14430 json_neigh, "reducePrefixNumFrom");
14431 json_object_int_add(json_neigh,
14432 "restartInTimerMsec",
14433 thread_timer_remain_second(
14434 p->t_pmax_restart)
14435 * 1000);
14436 } else
14437 vty_out(vty,
14438 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
14439 p->host, thread_timer_remain_second(
14440 p->t_pmax_restart));
d62a17ae 14441 } else {
14442 if (use_json)
14443 json_object_boolean_true_add(
14444 json_neigh,
14445 "reducePrefixNumAndClearIpBgp");
14446 else
14447 vty_out(vty,
14448 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
14449 p->host);
14450 }
14451 }
14452
14453 /* EBGP Multihop and GTSM */
14454 if (p->sort != BGP_PEER_IBGP) {
14455 if (use_json) {
e2521429 14456 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14457 json_object_int_add(json_neigh,
14458 "externalBgpNbrMaxHopsAway",
14459 p->gtsm_hops);
be8d1733 14460 else
d62a17ae 14461 json_object_int_add(json_neigh,
14462 "externalBgpNbrMaxHopsAway",
14463 p->ttl);
14464 } else {
e2521429 14465 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14466 vty_out(vty,
14467 " External BGP neighbor may be up to %d hops away.\n",
14468 p->gtsm_hops);
be8d1733 14469 else
d62a17ae 14470 vty_out(vty,
14471 " External BGP neighbor may be up to %d hops away.\n",
14472 p->ttl);
14473 }
14474 } else {
be8d1733
DA
14475 if (use_json) {
14476 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14477 json_object_int_add(json_neigh,
14478 "internalBgpNbrMaxHopsAway",
14479 p->gtsm_hops);
14480 else
be8d1733
DA
14481 json_object_int_add(json_neigh,
14482 "internalBgpNbrMaxHopsAway",
14483 p->ttl);
14484 } else {
14485 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14486 vty_out(vty,
14487 " Internal BGP neighbor may be up to %d hops away.\n",
14488 p->gtsm_hops);
be8d1733
DA
14489 else
14490 vty_out(vty,
14491 " Internal BGP neighbor may be up to %d hops away.\n",
14492 p->ttl);
d62a17ae 14493 }
14494 }
14495
14496 /* Local address. */
14497 if (p->su_local) {
14498 if (use_json) {
47e12884
DA
14499 json_object_string_addf(json_neigh, "hostLocal", "%pSU",
14500 p->su_local);
d62a17ae 14501 json_object_int_add(json_neigh, "portLocal",
14502 ntohs(p->su_local->sin.sin_port));
14503 } else
47e12884
DA
14504 vty_out(vty, "Local host: %pSU, Local port: %d\n",
14505 p->su_local, ntohs(p->su_local->sin.sin_port));
1e592331
DS
14506 } else {
14507 if (use_json) {
14508 json_object_string_add(json_neigh, "hostLocal",
14509 "Unknown");
14510 json_object_int_add(json_neigh, "portLocal", -1);
14511 }
d62a17ae 14512 }
14513
14514 /* Remote address. */
14515 if (p->su_remote) {
14516 if (use_json) {
47e12884
DA
14517 json_object_string_addf(json_neigh, "hostForeign",
14518 "%pSU", p->su_remote);
d62a17ae 14519 json_object_int_add(json_neigh, "portForeign",
14520 ntohs(p->su_remote->sin.sin_port));
14521 } else
47e12884
DA
14522 vty_out(vty, "Foreign host: %pSU, Foreign port: %d\n",
14523 p->su_remote,
d62a17ae 14524 ntohs(p->su_remote->sin.sin_port));
1e592331
DS
14525 } else {
14526 if (use_json) {
14527 json_object_string_add(json_neigh, "hostForeign",
14528 "Unknown");
14529 json_object_int_add(json_neigh, "portForeign", -1);
14530 }
d62a17ae 14531 }
14532
14533 /* Nexthop display. */
14534 if (p->su_local) {
14535 if (use_json) {
c949c771
DA
14536 json_object_string_addf(json_neigh, "nexthop", "%pI4",
14537 &p->nexthop.v4);
14538 json_object_string_addf(json_neigh, "nexthopGlobal",
14539 "%pI6", &p->nexthop.v6_global);
14540 json_object_string_addf(json_neigh, "nexthopLocal",
14541 "%pI6", &p->nexthop.v6_local);
d62a17ae 14542 if (p->shared_network)
14543 json_object_string_add(json_neigh,
14544 "bgpConnection",
14545 "sharedNetwork");
14546 else
14547 json_object_string_add(json_neigh,
14548 "bgpConnection",
14549 "nonSharedNetwork");
14550 } else {
14551 vty_out(vty, "Nexthop: %s\n",
14552 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
14553 sizeof(buf1)));
14554 vty_out(vty, "Nexthop global: %s\n",
14555 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
14556 sizeof(buf1)));
14557 vty_out(vty, "Nexthop local: %s\n",
14558 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
14559 sizeof(buf1)));
14560 vty_out(vty, "BGP connection: %s\n",
14561 p->shared_network ? "shared network"
14562 : "non shared network");
14563 }
14564 }
14565
14566 /* Timer information. */
14567 if (use_json) {
14568 json_object_int_add(json_neigh, "connectRetryTimer",
14569 p->v_connect);
f41255a0 14570 if (peer_established(p)) {
d62a17ae 14571 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14572 p->rtt);
f41255a0
DA
14573 if (CHECK_FLAG(p->flags, PEER_FLAG_RTT_SHUTDOWN)) {
14574 json_object_int_add(json_neigh,
14575 "shutdownRttInMsecs",
14576 p->rtt_expected);
14577 json_object_int_add(json_neigh,
14578 "shutdownRttAfterCount",
14579 p->rtt_keepalive_rcv);
14580 }
14581 }
d62a17ae 14582 if (p->t_start)
14583 json_object_int_add(
14584 json_neigh, "nextStartTimerDueInMsecs",
14585 thread_timer_remain_second(p->t_start) * 1000);
14586 if (p->t_connect)
14587 json_object_int_add(
14588 json_neigh, "nextConnectTimerDueInMsecs",
14589 thread_timer_remain_second(p->t_connect)
14590 * 1000);
14591 if (p->t_routeadv) {
14592 json_object_int_add(json_neigh, "mraiInterval",
14593 p->v_routeadv);
14594 json_object_int_add(
14595 json_neigh, "mraiTimerExpireInMsecs",
14596 thread_timer_remain_second(p->t_routeadv)
14597 * 1000);
14598 }
14599 if (p->password)
14600 json_object_int_add(json_neigh, "authenticationEnabled",
14601 1);
14602
14603 if (p->t_read)
14604 json_object_string_add(json_neigh, "readThread", "on");
14605 else
14606 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
14607
14608 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 14609 json_object_string_add(json_neigh, "writeThread", "on");
14610 else
14611 json_object_string_add(json_neigh, "writeThread",
14612 "off");
14613 } else {
14614 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14615 p->v_connect);
f41255a0 14616 if (peer_established(p)) {
d62a17ae 14617 vty_out(vty, "Estimated round trip time: %d ms\n",
14618 p->rtt);
f41255a0
DA
14619 if (CHECK_FLAG(p->flags, PEER_FLAG_RTT_SHUTDOWN))
14620 vty_out(vty,
14621 "Shutdown when RTT > %dms, count > %u\n",
14622 p->rtt_expected, p->rtt_keepalive_rcv);
14623 }
d62a17ae 14624 if (p->t_start)
14625 vty_out(vty, "Next start timer due in %ld seconds\n",
14626 thread_timer_remain_second(p->t_start));
14627 if (p->t_connect)
14628 vty_out(vty, "Next connect timer due in %ld seconds\n",
14629 thread_timer_remain_second(p->t_connect));
14630 if (p->t_routeadv)
14631 vty_out(vty,
14632 "MRAI (interval %u) timer expires in %ld seconds\n",
14633 p->v_routeadv,
14634 thread_timer_remain_second(p->t_routeadv));
14635 if (p->password)
14636 vty_out(vty, "Peer Authentication Enabled\n");
14637
cac9e917 14638 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
49507a6f
QY
14639 p->t_read ? "on" : "off",
14640 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14641 ? "on"
cac9e917 14642 : "off", p->fd);
d62a17ae 14643 }
14644
14645 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14646 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14647 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14648
14649 if (!use_json)
14650 vty_out(vty, "\n");
14651
14652 /* BFD information. */
21bfce98
RZ
14653 if (p->bfd_config)
14654 bgp_bfd_show_info(vty, p, json_neigh);
d62a17ae 14655
14656 if (use_json) {
14657 if (p->conf_if) /* Configured interface name. */
14658 json_object_object_add(json, p->conf_if, json_neigh);
14659 else /* Configured IP address. */
14660 json_object_object_add(json, p->host, json_neigh);
14661 }
14662}
14663
36235319
QY
14664static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14665 enum show_type type,
14666 union sockunion *su,
14667 const char *conf_if, afi_t afi,
74a630b6 14668 bool use_json)
2986cac2 14669{
14670 struct listnode *node, *nnode;
14671 struct peer *peer;
14672 int find = 0;
14673 safi_t safi = SAFI_UNICAST;
74a630b6 14674 json_object *json = NULL;
2986cac2 14675 json_object *json_neighbor = NULL;
14676
74a630b6
NT
14677 if (use_json) {
14678 json = json_object_new_object();
14679 json_neighbor = json_object_new_object();
14680 }
14681
2986cac2 14682 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14683
14684 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14685 continue;
14686
14687 if ((peer->afc[afi][safi]) == 0)
14688 continue;
14689
2ba1fe69 14690 if (type == show_all) {
2986cac2 14691 bgp_show_peer_gr_status(vty, peer, use_json,
13909c4f 14692 json_neighbor);
2986cac2 14693
74a630b6 14694 if (use_json) {
13909c4f
DS
14695 json_object_object_add(json, peer->host,
14696 json_neighbor);
74a630b6
NT
14697 json_neighbor = NULL;
14698 }
2986cac2 14699
2ba1fe69 14700 } else if (type == show_peer) {
2986cac2 14701 if (conf_if) {
14702 if ((peer->conf_if
13909c4f
DS
14703 && !strcmp(peer->conf_if, conf_if))
14704 || (peer->hostname
2986cac2 14705 && !strcmp(peer->hostname, conf_if))) {
14706 find = 1;
13909c4f
DS
14707 bgp_show_peer_gr_status(vty, peer,
14708 use_json,
14709 json_neighbor);
2986cac2 14710 }
14711 } else {
14712 if (sockunion_same(&peer->su, su)) {
14713 find = 1;
13909c4f
DS
14714 bgp_show_peer_gr_status(vty, peer,
14715 use_json,
14716 json_neighbor);
2986cac2 14717 }
14718 }
13909c4f
DS
14719 if (use_json && find)
14720 json_object_object_add(json, peer->host,
14721 json_neighbor);
2986cac2 14722 }
14723
74a630b6
NT
14724 if (find) {
14725 json_neighbor = NULL;
2986cac2 14726 break;
74a630b6 14727 }
2986cac2 14728 }
14729
14730 if (type == show_peer && !find) {
14731 if (use_json)
13909c4f 14732 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
2986cac2 14733 else
14734 vty_out(vty, "%% No such neighbor\n");
14735 }
14736 if (use_json) {
74a630b6
NT
14737 if (json_neighbor)
14738 json_object_free(json_neighbor);
75eeda93 14739 vty_json(vty, json);
2986cac2 14740 } else {
14741 vty_out(vty, "\n");
14742 }
14743
14744 return CMD_SUCCESS;
14745}
14746
d62a17ae 14747static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14748 enum show_type type, union sockunion *su,
9f049418 14749 const char *conf_if, bool use_json,
d62a17ae 14750 json_object *json)
14751{
14752 struct listnode *node, *nnode;
14753 struct peer *peer;
14754 int find = 0;
9f049418 14755 bool nbr_output = false;
d1927ebe
AS
14756 afi_t afi = AFI_MAX;
14757 safi_t safi = SAFI_MAX;
14758
14759 if (type == show_ipv4_peer || type == show_ipv4_all) {
14760 afi = AFI_IP;
14761 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14762 afi = AFI_IP6;
14763 }
d62a17ae 14764
14765 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14766 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14767 continue;
14768
14769 switch (type) {
14770 case show_all:
14771 bgp_show_peer(vty, peer, use_json, json);
9f049418 14772 nbr_output = true;
d62a17ae 14773 break;
14774 case show_peer:
14775 if (conf_if) {
14776 if ((peer->conf_if
14777 && !strcmp(peer->conf_if, conf_if))
14778 || (peer->hostname
14779 && !strcmp(peer->hostname, conf_if))) {
14780 find = 1;
14781 bgp_show_peer(vty, peer, use_json,
14782 json);
14783 }
14784 } else {
14785 if (sockunion_same(&peer->su, su)) {
14786 find = 1;
14787 bgp_show_peer(vty, peer, use_json,
14788 json);
14789 }
14790 }
14791 break;
d1927ebe
AS
14792 case show_ipv4_peer:
14793 case show_ipv6_peer:
14794 FOREACH_SAFI (safi) {
14795 if (peer->afc[afi][safi]) {
14796 if (conf_if) {
14797 if ((peer->conf_if
14798 && !strcmp(peer->conf_if, conf_if))
14799 || (peer->hostname
14800 && !strcmp(peer->hostname, conf_if))) {
14801 find = 1;
14802 bgp_show_peer(vty, peer, use_json,
14803 json);
14804 break;
14805 }
14806 } else {
14807 if (sockunion_same(&peer->su, su)) {
14808 find = 1;
14809 bgp_show_peer(vty, peer, use_json,
14810 json);
14811 break;
14812 }
14813 }
14814 }
14815 }
14816 break;
14817 case show_ipv4_all:
14818 case show_ipv6_all:
14819 FOREACH_SAFI (safi) {
14820 if (peer->afc[afi][safi]) {
14821 bgp_show_peer(vty, peer, use_json, json);
14822 nbr_output = true;
14823 break;
14824 }
14825 }
14826 break;
d62a17ae 14827 }
14828 }
14829
d1927ebe
AS
14830 if ((type == show_peer || type == show_ipv4_peer ||
14831 type == show_ipv6_peer) && !find) {
d62a17ae 14832 if (use_json)
14833 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14834 else
88b7d255 14835 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 14836 }
14837
d1927ebe
AS
14838 if (type != show_peer && type != show_ipv4_peer &&
14839 type != show_ipv6_peer && !nbr_output && !use_json)
94d4c685 14840 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 14841
d62a17ae 14842 if (use_json) {
996c9314
LB
14843 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14844 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 14845 } else {
14846 vty_out(vty, "\n");
14847 }
14848
14849 return CMD_SUCCESS;
14850}
14851
36235319
QY
14852static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14853 enum show_type type,
14854 const char *ip_str,
14855 afi_t afi, bool use_json)
2986cac2 14856{
14857
14858 int ret;
14859 struct bgp *bgp;
14860 union sockunion su;
2986cac2 14861
14862 bgp = bgp_get_default();
14863
13909c4f
DS
14864 if (!bgp)
14865 return;
2986cac2 14866
13909c4f
DS
14867 if (!use_json)
14868 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
14869 NULL);
2986cac2 14870
13909c4f
DS
14871 if (ip_str) {
14872 ret = str2sockunion(ip_str, &su);
14873 if (ret < 0)
13909c4f 14874 bgp_show_neighbor_graceful_restart(
74a630b6
NT
14875 vty, bgp, type, NULL, ip_str, afi, use_json);
14876 else
14877 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14878 NULL, afi, use_json);
13909c4f
DS
14879 } else
14880 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
74a630b6 14881 afi, use_json);
2986cac2 14882}
14883
d62a17ae 14884static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
14885 enum show_type type,
14886 const char *ip_str,
9f049418 14887 bool use_json)
d62a17ae 14888{
0291c246
MK
14889 struct listnode *node, *nnode;
14890 struct bgp *bgp;
71aedaa3 14891 union sockunion su;
0291c246 14892 json_object *json = NULL;
71aedaa3 14893 int ret, is_first = 1;
9f049418 14894 bool nbr_output = false;
d62a17ae 14895
14896 if (use_json)
14897 vty_out(vty, "{\n");
14898
14899 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 14900 nbr_output = true;
d62a17ae 14901 if (use_json) {
14902 if (!(json = json_object_new_object())) {
af4c2728 14903 flog_err(
e50f7cfd 14904 EC_BGP_JSON_MEM_ERROR,
d62a17ae 14905 "Unable to allocate memory for JSON object");
14906 vty_out(vty,
14907 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14908 return;
14909 }
14910
14911 json_object_int_add(json, "vrfId",
14912 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
14913 ? -1
14914 : (int64_t)bgp->vrf_id);
d62a17ae 14915 json_object_string_add(
14916 json, "vrfName",
14917 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14918 ? VRF_DEFAULT_NAME
d62a17ae 14919 : bgp->name);
14920
14921 if (!is_first)
14922 vty_out(vty, ",\n");
14923 else
14924 is_first = 0;
14925
14926 vty_out(vty, "\"%s\":",
14927 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14928 ? VRF_DEFAULT_NAME
d62a17ae 14929 : bgp->name);
14930 } else {
14931 vty_out(vty, "\nInstance %s:\n",
14932 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14933 ? VRF_DEFAULT_NAME
d62a17ae 14934 : bgp->name);
14935 }
71aedaa3 14936
d1927ebe
AS
14937 if (type == show_peer || type == show_ipv4_peer ||
14938 type == show_ipv6_peer) {
71aedaa3
DS
14939 ret = str2sockunion(ip_str, &su);
14940 if (ret < 0)
14941 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14942 use_json, json);
14943 else
14944 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14945 use_json, json);
14946 } else {
d1927ebe 14947 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
71aedaa3
DS
14948 use_json, json);
14949 }
b77004d6 14950 json_object_free(json);
121067e9 14951 json = NULL;
d62a17ae 14952 }
14953
3e78a6ce 14954 if (use_json)
d62a17ae 14955 vty_out(vty, "}\n");
9f049418
DS
14956 else if (!nbr_output)
14957 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 14958}
14959
14960static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14961 enum show_type type, const char *ip_str,
9f049418 14962 bool use_json)
d62a17ae 14963{
14964 int ret;
14965 struct bgp *bgp;
14966 union sockunion su;
14967 json_object *json = NULL;
14968
14969 if (name) {
14970 if (strmatch(name, "all")) {
71aedaa3
DS
14971 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14972 use_json);
d62a17ae 14973 return CMD_SUCCESS;
14974 } else {
14975 bgp = bgp_lookup_by_name(name);
14976 if (!bgp) {
14977 if (use_json) {
14978 json = json_object_new_object();
75eeda93 14979 vty_json(vty, json);
d62a17ae 14980 } else
14981 vty_out(vty,
9f049418 14982 "%% BGP instance not found\n");
d62a17ae 14983
14984 return CMD_WARNING;
14985 }
14986 }
14987 } else {
14988 bgp = bgp_get_default();
14989 }
14990
14991 if (bgp) {
14992 json = json_object_new_object();
14993 if (ip_str) {
14994 ret = str2sockunion(ip_str, &su);
14995 if (ret < 0)
14996 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14997 use_json, json);
14998 else
14999 bgp_show_neighbor(vty, bgp, type, &su, NULL,
15000 use_json, json);
15001 } else {
15002 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
15003 json);
15004 }
15005 json_object_free(json);
ca61fd25
DS
15006 } else {
15007 if (use_json)
15008 vty_out(vty, "{}\n");
15009 else
15010 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 15011 }
15012
15013 return CMD_SUCCESS;
4fb25c53
DW
15014}
15015
2986cac2 15016
15017
15018/* "show [ip] bgp neighbors graceful-restart" commands. */
dcab9012 15019DEFUN (show_ip_bgp_neighbors_graceful_restart,
2986cac2 15020 show_ip_bgp_neighbors_graceful_restart_cmd,
15021 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
15022 SHOW_STR
15023 BGP_STR
15024 IP_STR
15025 IPV6_STR
15026 NEIGHBOR_STR
15027 "Neighbor to display information about\n"
15028 "Neighbor to display information about\n"
15029 "Neighbor on BGP configured interface\n"
15030 GR_SHOW
15031 JSON_STR)
15032{
15033 char *sh_arg = NULL;
15034 enum show_type sh_type;
15035 int idx = 0;
15036 afi_t afi = AFI_MAX;
2986cac2 15037 bool uj = use_json(argc, argv);
15038
36235319 15039 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
2986cac2 15040 afi = AFI_MAX;
15041
15042 idx++;
15043
15044 if (argv_find(argv, argc, "A.B.C.D", &idx)
15045 || argv_find(argv, argc, "X:X::X:X", &idx)
15046 || argv_find(argv, argc, "WORD", &idx)) {
15047 sh_type = show_peer;
15048 sh_arg = argv[idx]->arg;
15049 } else
15050 sh_type = show_all;
15051
15052 if (!argv_find(argv, argc, "graceful-restart", &idx))
15053 return CMD_SUCCESS;
15054
15055
36235319
QY
15056 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
15057 afi, uj);
2986cac2 15058}
15059
716b2d8a 15060/* "show [ip] bgp neighbors" commands. */
718e3744 15061DEFUN (show_ip_bgp_neighbors,
15062 show_ip_bgp_neighbors_cmd,
24345e82 15063 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 15064 SHOW_STR
15065 IP_STR
15066 BGP_STR
f2a8972b 15067 BGP_INSTANCE_HELP_STR
00e6edb9
DA
15068 BGP_AF_STR
15069 BGP_AF_STR
718e3744 15070 "Detailed information on TCP and BGP neighbor connections\n"
15071 "Neighbor to display information about\n"
a80beece 15072 "Neighbor to display information about\n"
91d37724 15073 "Neighbor on BGP configured interface\n"
9973d184 15074 JSON_STR)
718e3744 15075{
d62a17ae 15076 char *vrf = NULL;
15077 char *sh_arg = NULL;
15078 enum show_type sh_type;
d1927ebe 15079 afi_t afi = AFI_MAX;
718e3744 15080
9f049418 15081 bool uj = use_json(argc, argv);
718e3744 15082
d62a17ae 15083 int idx = 0;
718e3744 15084
9a8bdf1c
PG
15085 /* [<vrf> VIEWVRFNAME] */
15086 if (argv_find(argv, argc, "vrf", &idx)) {
15087 vrf = argv[idx + 1]->arg;
15088 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15089 vrf = NULL;
15090 } else if (argv_find(argv, argc, "view", &idx))
15091 /* [<view> VIEWVRFNAME] */
d62a17ae 15092 vrf = argv[idx + 1]->arg;
718e3744 15093
d62a17ae 15094 idx++;
d1927ebe
AS
15095
15096 if (argv_find(argv, argc, "ipv4", &idx)) {
15097 sh_type = show_ipv4_all;
15098 afi = AFI_IP;
15099 } else if (argv_find(argv, argc, "ipv6", &idx)) {
15100 sh_type = show_ipv6_all;
15101 afi = AFI_IP6;
15102 } else {
15103 sh_type = show_all;
15104 }
15105
d62a17ae 15106 if (argv_find(argv, argc, "A.B.C.D", &idx)
15107 || argv_find(argv, argc, "X:X::X:X", &idx)
15108 || argv_find(argv, argc, "WORD", &idx)) {
15109 sh_type = show_peer;
15110 sh_arg = argv[idx]->arg;
d1927ebe
AS
15111 }
15112
15113 if (sh_type == show_peer && afi == AFI_IP) {
15114 sh_type = show_ipv4_peer;
15115 } else if (sh_type == show_peer && afi == AFI_IP6) {
15116 sh_type = show_ipv6_peer;
15117 }
856ca177 15118
d62a17ae 15119 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 15120}
15121
716b2d8a 15122/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 15123 paths' and `show ip mbgp paths'. Those functions results are the
15124 same.*/
f412b39a 15125DEFUN (show_ip_bgp_paths,
718e3744 15126 show_ip_bgp_paths_cmd,
46f296b4 15127 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 15128 SHOW_STR
15129 IP_STR
15130 BGP_STR
46f296b4 15131 BGP_SAFI_HELP_STR
718e3744 15132 "Path information\n")
15133{
d62a17ae 15134 vty_out(vty, "Address Refcnt Path\n");
15135 aspath_print_all_vty(vty);
15136 return CMD_SUCCESS;
718e3744 15137}
15138
718e3744 15139#include "hash.h"
15140
e3b78da8 15141static void community_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 15142 struct vty *vty)
718e3744 15143{
d62a17ae 15144 struct community *com;
718e3744 15145
e3b78da8 15146 com = (struct community *)bucket->data;
3f65c5b1 15147 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
c0945b78 15148 community_str(com, false, false));
718e3744 15149}
15150
15151/* Show BGP's community internal data. */
f412b39a 15152DEFUN (show_ip_bgp_community_info,
718e3744 15153 show_ip_bgp_community_info_cmd,
bec37ba5 15154 "show [ip] bgp community-info",
718e3744 15155 SHOW_STR
15156 IP_STR
15157 BGP_STR
15158 "List all bgp community information\n")
15159{
d62a17ae 15160 vty_out(vty, "Address Refcnt Community\n");
718e3744 15161
d62a17ae 15162 hash_iterate(community_hash(),
e3b78da8 15163 (void (*)(struct hash_bucket *,
d62a17ae 15164 void *))community_show_all_iterator,
15165 vty);
718e3744 15166
d62a17ae 15167 return CMD_SUCCESS;
718e3744 15168}
15169
e3b78da8 15170static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 15171 struct vty *vty)
57d187bc 15172{
d62a17ae 15173 struct lcommunity *lcom;
57d187bc 15174
e3b78da8 15175 lcom = (struct lcommunity *)bucket->data;
3f65c5b1 15176 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
c0945b78 15177 lcommunity_str(lcom, false, false));
57d187bc
JS
15178}
15179
15180/* Show BGP's community internal data. */
15181DEFUN (show_ip_bgp_lcommunity_info,
15182 show_ip_bgp_lcommunity_info_cmd,
15183 "show ip bgp large-community-info",
15184 SHOW_STR
15185 IP_STR
15186 BGP_STR
15187 "List all bgp large-community information\n")
15188{
d62a17ae 15189 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 15190
d62a17ae 15191 hash_iterate(lcommunity_hash(),
e3b78da8 15192 (void (*)(struct hash_bucket *,
d62a17ae 15193 void *))lcommunity_show_all_iterator,
15194 vty);
57d187bc 15195
d62a17ae 15196 return CMD_SUCCESS;
57d187bc 15197}
2986cac2 15198/* Graceful Restart */
15199
15200static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
36235319
QY
15201 struct bgp *bgp,
15202 bool use_json,
15203 json_object *json)
2986cac2 15204{
57d187bc
JS
15205
15206
2986cac2 15207 vty_out(vty, "\n%s", SHOW_GR_HEADER);
15208
7318ae88 15209 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
2986cac2 15210
15211 switch (bgp_global_gr_mode) {
15212
15213 case GLOBAL_HELPER:
13909c4f 15214 vty_out(vty, "Global BGP GR Mode : Helper\n");
2986cac2 15215 break;
15216
15217 case GLOBAL_GR:
13909c4f 15218 vty_out(vty, "Global BGP GR Mode : Restart\n");
2986cac2 15219 break;
15220
15221 case GLOBAL_DISABLE:
13909c4f 15222 vty_out(vty, "Global BGP GR Mode : Disable\n");
2986cac2 15223 break;
15224
15225 case GLOBAL_INVALID:
2986cac2 15226 vty_out(vty,
2ba1fe69 15227 "Global BGP GR Mode Invalid\n");
2986cac2 15228 break;
15229 }
15230 vty_out(vty, "\n");
15231}
15232
36235319
QY
15233static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
15234 enum show_type type,
15235 const char *ip_str,
15236 afi_t afi, bool use_json)
2986cac2 15237{
15238 if ((afi == AFI_MAX) && (ip_str == NULL)) {
15239 afi = AFI_IP;
15240
15241 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
15242
36235319
QY
15243 bgp_show_neighbor_graceful_restart_vty(
15244 vty, type, ip_str, afi, use_json);
2986cac2 15245 afi++;
15246 }
15247 } else if (afi != AFI_MAX) {
36235319
QY
15248 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
15249 use_json);
2986cac2 15250 } else {
15251 return CMD_ERR_INCOMPLETE;
15252 }
15253
15254 return CMD_SUCCESS;
15255}
15256/* Graceful Restart */
15257
f412b39a 15258DEFUN (show_ip_bgp_attr_info,
718e3744 15259 show_ip_bgp_attr_info_cmd,
bec37ba5 15260 "show [ip] bgp attribute-info",
718e3744 15261 SHOW_STR
15262 IP_STR
15263 BGP_STR
15264 "List all bgp attribute information\n")
15265{
d62a17ae 15266 attr_show_all(vty);
15267 return CMD_SUCCESS;
718e3744 15268}
6b0655a2 15269
03915806
CS
15270static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
15271 afi_t afi, safi_t safi,
15272 bool use_json, json_object *json)
53089bec 15273{
15274 struct bgp *bgp;
15275 struct listnode *node;
15276 char *vname;
53089bec 15277 char *ecom_str;
9c2fd3fe 15278 enum vpn_policy_direction dir;
53089bec 15279
03915806 15280 if (json) {
b46dfd20
DS
15281 json_object *json_import_vrfs = NULL;
15282 json_object *json_export_vrfs = NULL;
15283
b46dfd20
DS
15284 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15285
53089bec 15286 if (!bgp) {
75eeda93 15287 vty_json(vty, json);
b46dfd20 15288
53089bec 15289 return CMD_WARNING;
15290 }
b46dfd20 15291
94d4c685
DS
15292 /* Provide context for the block */
15293 json_object_string_add(json, "vrf", name ? name : "default");
15294 json_object_string_add(json, "afiSafi",
5cb5f4d0 15295 get_afi_safi_str(afi, safi, true));
94d4c685 15296
b46dfd20
DS
15297 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15298 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
15299 json_object_string_add(json, "importFromVrfs", "none");
15300 json_object_string_add(json, "importRts", "none");
15301 } else {
6ce24e52
DS
15302 json_import_vrfs = json_object_new_array();
15303
b46dfd20
DS
15304 for (ALL_LIST_ELEMENTS_RO(
15305 bgp->vpn_policy[afi].import_vrf,
15306 node, vname))
15307 json_object_array_add(json_import_vrfs,
15308 json_object_new_string(vname));
15309
b20875ea
CS
15310 json_object_object_add(json, "importFromVrfs",
15311 json_import_vrfs);
b46dfd20 15312 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
15313 if (bgp->vpn_policy[afi].rtlist[dir]) {
15314 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15315 bgp->vpn_policy[afi].rtlist[dir],
15316 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
15317 json_object_string_add(json, "importRts",
15318 ecom_str);
15319 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15320 } else
15321 json_object_string_add(json, "importRts",
15322 "none");
b46dfd20
DS
15323 }
15324
15325 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15326 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
15327 json_object_string_add(json, "exportToVrfs", "none");
15328 json_object_string_add(json, "routeDistinguisher",
15329 "none");
15330 json_object_string_add(json, "exportRts", "none");
15331 } else {
6ce24e52
DS
15332 json_export_vrfs = json_object_new_array();
15333
b46dfd20
DS
15334 for (ALL_LIST_ELEMENTS_RO(
15335 bgp->vpn_policy[afi].export_vrf,
15336 node, vname))
15337 json_object_array_add(json_export_vrfs,
15338 json_object_new_string(vname));
15339 json_object_object_add(json, "exportToVrfs",
15340 json_export_vrfs);
c4f64ea9
DA
15341 json_object_string_addf(json, "routeDistinguisher",
15342 "%pRD",
15343 &bgp->vpn_policy[afi].tovpn_rd);
b46dfd20
DS
15344
15345 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
15346 if (bgp->vpn_policy[afi].rtlist[dir]) {
15347 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15348 bgp->vpn_policy[afi].rtlist[dir],
15349 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
15350 json_object_string_add(json, "exportRts",
15351 ecom_str);
15352 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15353 } else
15354 json_object_string_add(json, "exportRts",
15355 "none");
b46dfd20
DS
15356 }
15357
03915806 15358 if (use_json) {
75eeda93 15359 vty_json(vty, json);
03915806 15360 }
53089bec 15361 } else {
b46dfd20
DS
15362 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15363
53089bec 15364 if (!bgp) {
b46dfd20 15365 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 15366 return CMD_WARNING;
15367 }
53089bec 15368
b46dfd20
DS
15369 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15370 BGP_CONFIG_VRF_TO_VRF_IMPORT))
15371 vty_out(vty,
15372 "This VRF is not importing %s routes from any other VRF\n",
5cb5f4d0 15373 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15374 else {
15375 vty_out(vty,
15376 "This VRF is importing %s routes from the following VRFs:\n",
5cb5f4d0 15377 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15378
15379 for (ALL_LIST_ELEMENTS_RO(
15380 bgp->vpn_policy[afi].import_vrf,
15381 node, vname))
15382 vty_out(vty, " %s\n", vname);
15383
15384 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
15385 ecom_str = NULL;
15386 if (bgp->vpn_policy[afi].rtlist[dir]) {
15387 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15388 bgp->vpn_policy[afi].rtlist[dir],
15389 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea 15390 vty_out(vty, "Import RT(s): %s\n", ecom_str);
b46dfd20 15391
b20875ea
CS
15392 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15393 } else
15394 vty_out(vty, "Import RT(s):\n");
53089bec 15395 }
53089bec 15396
b46dfd20
DS
15397 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15398 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15399 vty_out(vty,
15400 "This VRF is not exporting %s routes to any other VRF\n",
5cb5f4d0 15401 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15402 else {
15403 vty_out(vty,
04c9077f 15404 "This VRF is exporting %s routes to the following VRFs:\n",
5cb5f4d0 15405 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15406
15407 for (ALL_LIST_ELEMENTS_RO(
15408 bgp->vpn_policy[afi].export_vrf,
15409 node, vname))
15410 vty_out(vty, " %s\n", vname);
15411
c4f64ea9
DA
15412 vty_out(vty, "RD: %pRD\n",
15413 &bgp->vpn_policy[afi].tovpn_rd);
b46dfd20
DS
15414
15415 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
15416 if (bgp->vpn_policy[afi].rtlist[dir]) {
15417 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15418 bgp->vpn_policy[afi].rtlist[dir],
15419 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
15420 vty_out(vty, "Export RT: %s\n", ecom_str);
15421 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15422 } else
15423 vty_out(vty, "Import RT(s):\n");
53089bec 15424 }
53089bec 15425 }
15426
15427 return CMD_SUCCESS;
15428}
15429
03915806
CS
15430static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
15431 safi_t safi, bool use_json)
15432{
15433 struct listnode *node, *nnode;
15434 struct bgp *bgp;
15435 char *vrf_name = NULL;
15436 json_object *json = NULL;
15437 json_object *json_vrf = NULL;
15438 json_object *json_vrfs = NULL;
15439
15440 if (use_json) {
15441 json = json_object_new_object();
15442 json_vrfs = json_object_new_object();
15443 }
15444
15445 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15446
15447 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
15448 vrf_name = bgp->name;
15449
15450 if (use_json) {
15451 json_vrf = json_object_new_object();
15452 } else {
15453 vty_out(vty, "\nInstance %s:\n",
15454 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15455 ? VRF_DEFAULT_NAME : bgp->name);
15456 }
15457 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
15458 if (use_json) {
15459 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15460 json_object_object_add(json_vrfs,
15461 VRF_DEFAULT_NAME, json_vrf);
15462 else
15463 json_object_object_add(json_vrfs, vrf_name,
15464 json_vrf);
15465 }
15466 }
15467
15468 if (use_json) {
15469 json_object_object_add(json, "vrfs", json_vrfs);
75eeda93 15470 vty_json(vty, json);
03915806
CS
15471 }
15472
15473 return CMD_SUCCESS;
15474}
15475
53089bec 15476/* "show [ip] bgp route-leak" command. */
15477DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
15478 show_ip_bgp_route_leak_cmd,
15479 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
15480 SHOW_STR
15481 IP_STR
15482 BGP_STR
15483 BGP_INSTANCE_HELP_STR
15484 BGP_AFI_HELP_STR
15485 BGP_SAFI_HELP_STR
15486 "Route leaking information\n"
15487 JSON_STR)
53089bec 15488{
15489 char *vrf = NULL;
15490 afi_t afi = AFI_MAX;
15491 safi_t safi = SAFI_MAX;
15492
9f049418 15493 bool uj = use_json(argc, argv);
53089bec 15494 int idx = 0;
03915806 15495 json_object *json = NULL;
53089bec 15496
15497 /* show [ip] bgp */
15498 if (argv_find(argv, argc, "ip", &idx)) {
15499 afi = AFI_IP;
15500 safi = SAFI_UNICAST;
15501 }
15502 /* [vrf VIEWVRFNAME] */
15503 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
15504 vty_out(vty,
15505 "%% This command is not applicable to BGP views\n");
53089bec 15506 return CMD_WARNING;
15507 }
15508
9a8bdf1c
PG
15509 if (argv_find(argv, argc, "vrf", &idx)) {
15510 vrf = argv[idx + 1]->arg;
15511 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15512 vrf = NULL;
15513 }
53089bec 15514 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
c48349e3 15515 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
53089bec 15516 argv_find_and_parse_safi(argv, argc, &idx, &safi);
53089bec 15517
15518 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
15519 vty_out(vty,
15520 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 15521 return CMD_WARNING;
15522 }
15523
03915806
CS
15524 if (vrf && strmatch(vrf, "all"))
15525 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15526
15527 if (uj)
15528 json = json_object_new_object();
15529
15530 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
53089bec 15531}
15532
d62a17ae 15533static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
fa5a9276 15534 safi_t safi, bool uj)
f186de26 15535{
d62a17ae 15536 struct listnode *node, *nnode;
15537 struct bgp *bgp;
f186de26 15538
d62a17ae 15539 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
fa5a9276
AR
15540 if (!uj)
15541 vty_out(vty, "\nInstance %s:\n",
15542 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15543 ? VRF_DEFAULT_NAME
15544 : bgp->name);
15545
15546 update_group_show(bgp, afi, safi, vty, 0, uj);
d62a17ae 15547 }
f186de26 15548}
15549
d62a17ae 15550static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
fa5a9276 15551 int safi, uint64_t subgrp_id, bool uj)
4fb25c53 15552{
d62a17ae 15553 struct bgp *bgp;
4fb25c53 15554
d62a17ae 15555 if (name) {
15556 if (strmatch(name, "all")) {
fa5a9276 15557 bgp_show_all_instances_updgrps_vty(vty, afi, safi, uj);
d62a17ae 15558 return CMD_SUCCESS;
15559 } else {
15560 bgp = bgp_lookup_by_name(name);
15561 }
15562 } else {
15563 bgp = bgp_get_default();
15564 }
4fb25c53 15565
d62a17ae 15566 if (bgp)
fa5a9276 15567 update_group_show(bgp, afi, safi, vty, subgrp_id, uj);
d62a17ae 15568 return CMD_SUCCESS;
4fb25c53
DW
15569}
15570
8fe8a7f6
DS
15571DEFUN (show_ip_bgp_updgrps,
15572 show_ip_bgp_updgrps_cmd,
fa5a9276 15573 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID] [json]",
8386ac43 15574 SHOW_STR
15575 IP_STR
15576 BGP_STR
15577 BGP_INSTANCE_HELP_STR
c9e571b4 15578 BGP_AFI_HELP_STR
9bedbb1e 15579 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956 15580 "Detailed info about dynamic update groups\n"
fa5a9276
AR
15581 "Specific subgroup to display detailed info for\n"
15582 JSON_STR)
8386ac43 15583{
d62a17ae 15584 char *vrf = NULL;
15585 afi_t afi = AFI_IP6;
15586 safi_t safi = SAFI_UNICAST;
15587 uint64_t subgrp_id = 0;
15588
15589 int idx = 0;
15590
fa5a9276
AR
15591 bool uj = use_json(argc, argv);
15592
d62a17ae 15593 /* show [ip] bgp */
15594 if (argv_find(argv, argc, "ip", &idx))
15595 afi = AFI_IP;
9a8bdf1c
PG
15596 /* [<vrf> VIEWVRFNAME] */
15597 if (argv_find(argv, argc, "vrf", &idx)) {
15598 vrf = argv[idx + 1]->arg;
15599 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15600 vrf = NULL;
15601 } else if (argv_find(argv, argc, "view", &idx))
15602 /* [<view> VIEWVRFNAME] */
15603 vrf = argv[idx + 1]->arg;
d62a17ae 15604 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15605 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15606 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15607 }
5bf15956 15608
d62a17ae 15609 /* get subgroup id, if provided */
15610 idx = argc - 1;
15611 if (argv[idx]->type == VARIABLE_TKN)
15612 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 15613
fa5a9276 15614 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id, uj));
8fe8a7f6
DS
15615}
15616
f186de26 15617DEFUN (show_bgp_instance_all_ipv6_updgrps,
15618 show_bgp_instance_all_ipv6_updgrps_cmd,
fa5a9276 15619 "show [ip] bgp <view|vrf> all update-groups [json]",
f186de26 15620 SHOW_STR
716b2d8a 15621 IP_STR
f186de26 15622 BGP_STR
15623 BGP_INSTANCE_ALL_HELP_STR
fa5a9276
AR
15624 "Detailed info about dynamic update groups\n"
15625 JSON_STR)
f186de26 15626{
fa5a9276
AR
15627 bool uj = use_json(argc, argv);
15628
15629 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST, uj);
d62a17ae 15630 return CMD_SUCCESS;
f186de26 15631}
15632
43d3f4fc
DS
15633DEFUN (show_bgp_l2vpn_evpn_updgrps,
15634 show_bgp_l2vpn_evpn_updgrps_cmd,
15635 "show [ip] bgp l2vpn evpn update-groups",
15636 SHOW_STR
15637 IP_STR
15638 BGP_STR
15639 "l2vpn address family\n"
15640 "evpn sub-address family\n"
15641 "Detailed info about dynamic update groups\n")
15642{
15643 char *vrf = NULL;
15644 uint64_t subgrp_id = 0;
15645
fa5a9276 15646 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id, 0);
43d3f4fc
DS
15647 return CMD_SUCCESS;
15648}
15649
5bf15956
DW
15650DEFUN (show_bgp_updgrps_stats,
15651 show_bgp_updgrps_stats_cmd,
716b2d8a 15652 "show [ip] bgp update-groups statistics",
3f9c7369 15653 SHOW_STR
716b2d8a 15654 IP_STR
3f9c7369 15655 BGP_STR
0c7b1b01 15656 "Detailed info about dynamic update groups\n"
3f9c7369
DS
15657 "Statistics\n")
15658{
d62a17ae 15659 struct bgp *bgp;
3f9c7369 15660
d62a17ae 15661 bgp = bgp_get_default();
15662 if (bgp)
15663 update_group_show_stats(bgp, vty);
3f9c7369 15664
d62a17ae 15665 return CMD_SUCCESS;
3f9c7369
DS
15666}
15667
8386ac43 15668DEFUN (show_bgp_instance_updgrps_stats,
15669 show_bgp_instance_updgrps_stats_cmd,
18c57037 15670 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 15671 SHOW_STR
716b2d8a 15672 IP_STR
8386ac43 15673 BGP_STR
15674 BGP_INSTANCE_HELP_STR
0c7b1b01 15675 "Detailed info about dynamic update groups\n"
8386ac43 15676 "Statistics\n")
15677{
d62a17ae 15678 int idx_word = 3;
15679 struct bgp *bgp;
8386ac43 15680
d62a17ae 15681 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15682 if (bgp)
15683 update_group_show_stats(bgp, vty);
8386ac43 15684
d62a17ae 15685 return CMD_SUCCESS;
8386ac43 15686}
15687
d62a17ae 15688static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15689 afi_t afi, safi_t safi,
15690 const char *what, uint64_t subgrp_id)
3f9c7369 15691{
d62a17ae 15692 struct bgp *bgp;
8386ac43 15693
d62a17ae 15694 if (name)
15695 bgp = bgp_lookup_by_name(name);
15696 else
15697 bgp = bgp_get_default();
8386ac43 15698
d62a17ae 15699 if (bgp) {
15700 if (!strcmp(what, "advertise-queue"))
15701 update_group_show_adj_queue(bgp, afi, safi, vty,
15702 subgrp_id);
15703 else if (!strcmp(what, "advertised-routes"))
15704 update_group_show_advertised(bgp, afi, safi, vty,
15705 subgrp_id);
15706 else if (!strcmp(what, "packet-queue"))
15707 update_group_show_packet_queue(bgp, afi, safi, vty,
15708 subgrp_id);
15709 }
3f9c7369
DS
15710}
15711
dc64bdec
QY
15712DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15713 show_ip_bgp_instance_updgrps_adj_s_cmd,
15714 "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",
15715 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15716 BGP_SAFI_HELP_STR
15717 "Detailed info about dynamic update groups\n"
15718 "Specific subgroup to display info for\n"
15719 "Advertisement queue\n"
15720 "Announced routes\n"
15721 "Packet queue\n")
3f9c7369 15722{
dc64bdec
QY
15723 uint64_t subgrp_id = 0;
15724 afi_t afiz;
15725 safi_t safiz;
15726 if (sgid)
15727 subgrp_id = strtoull(sgid, NULL, 10);
15728
15729 if (!ip && !afi)
15730 afiz = AFI_IP6;
15731 if (!ip && afi)
15732 afiz = bgp_vty_afi_from_str(afi);
15733 if (ip && !afi)
15734 afiz = AFI_IP;
15735 if (ip && afi) {
15736 afiz = bgp_vty_afi_from_str(afi);
15737 if (afiz != AFI_IP)
15738 vty_out(vty,
15739 "%% Cannot specify both 'ip' and 'ipv6'\n");
15740 return CMD_WARNING;
15741 }
d62a17ae 15742
dc64bdec 15743 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 15744
dc64bdec 15745 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 15746 return CMD_SUCCESS;
15747}
15748
6f4eacf3
DA
15749static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
15750 json_object *json)
d62a17ae 15751{
15752 struct listnode *node, *nnode;
15753 struct prefix *range;
15754 struct peer *conf;
15755 struct peer *peer;
d62a17ae 15756 afi_t afi;
15757 safi_t safi;
15758 const char *peer_status;
d62a17ae 15759 int lr_count;
15760 int dynamic;
6f4eacf3
DA
15761 bool af_cfgd;
15762 json_object *json_peer_group = NULL;
15763 json_object *json_peer_group_afc = NULL;
15764 json_object *json_peer_group_members = NULL;
15765 json_object *json_peer_group_dynamic = NULL;
15766 json_object *json_peer_group_dynamic_af = NULL;
15767 json_object *json_peer_group_ranges = NULL;
d62a17ae 15768
15769 conf = group->conf;
15770
6f4eacf3
DA
15771 if (json) {
15772 json_peer_group = json_object_new_object();
15773 json_peer_group_afc = json_object_new_array();
15774 }
15775
d62a17ae 15776 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
6f4eacf3
DA
15777 if (json)
15778 json_object_int_add(json_peer_group, "remoteAs",
15779 conf->as);
15780 else
15781 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15782 group->name, conf->as);
d62a17ae 15783 } else if (conf->as_type == AS_INTERNAL) {
6f4eacf3
DA
15784 if (json)
15785 json_object_int_add(json_peer_group, "remoteAs",
15786 group->bgp->as);
15787 else
15788 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15789 group->name, group->bgp->as);
d62a17ae 15790 } else {
6f4eacf3
DA
15791 if (!json)
15792 vty_out(vty, "\nBGP peer-group %s\n", group->name);
d62a17ae 15793 }
f14e6fdb 15794
6f4eacf3
DA
15795 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
15796 if (json)
15797 json_object_string_add(json_peer_group, "type",
15798 "internal");
15799 else
15800 vty_out(vty, " Peer-group type is internal\n");
15801 } else {
15802 if (json)
15803 json_object_string_add(json_peer_group, "type",
15804 "external");
15805 else
15806 vty_out(vty, " Peer-group type is external\n");
15807 }
d62a17ae 15808
15809 /* Display AFs configured. */
6f4eacf3
DA
15810 if (!json)
15811 vty_out(vty, " Configured address-families:");
15812
05c7a1cc
QY
15813 FOREACH_AFI_SAFI (afi, safi) {
15814 if (conf->afc[afi][safi]) {
6f4eacf3
DA
15815 af_cfgd = true;
15816 if (json)
15817 json_object_array_add(
15818 json_peer_group_afc,
15819 json_object_new_string(get_afi_safi_str(
15820 afi, safi, false)));
15821 else
15822 vty_out(vty, " %s;",
15823 get_afi_safi_str(afi, safi, false));
d62a17ae 15824 }
05c7a1cc 15825 }
6f4eacf3
DA
15826
15827 if (json) {
15828 json_object_object_add(json_peer_group,
15829 "addressFamiliesConfigured",
15830 json_peer_group_afc);
15831 } else {
15832 if (!af_cfgd)
15833 vty_out(vty, " none\n");
15834 else
15835 vty_out(vty, "\n");
15836 }
d62a17ae 15837
15838 /* Display listen ranges (for dynamic neighbors), if any */
15839 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
d62a17ae 15840 lr_count = listcount(group->listen_range[afi]);
15841 if (lr_count) {
6f4eacf3
DA
15842 if (json) {
15843 if (!json_peer_group_dynamic)
15844 json_peer_group_dynamic =
15845 json_object_new_object();
15846
15847 json_peer_group_dynamic_af =
15848 json_object_new_object();
15849 json_peer_group_ranges =
15850 json_object_new_array();
15851 json_object_int_add(json_peer_group_dynamic_af,
15852 "count", lr_count);
15853 } else {
15854 vty_out(vty, " %d %s listen range(s)\n",
15855 lr_count, afi2str(afi));
15856 }
d62a17ae 15857
15858 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
6f4eacf3
DA
15859 nnode, range)) {
15860 if (json) {
15861 char buf[BUFSIZ];
15862
15863 snprintfrr(buf, sizeof(buf), "%pFX",
15864 range);
15865
15866 json_object_array_add(
15867 json_peer_group_ranges,
15868 json_object_new_string(buf));
15869 } else {
15870 vty_out(vty, " %pFX\n", range);
15871 }
15872 }
15873
15874 if (json) {
15875 json_object_object_add(
15876 json_peer_group_dynamic_af, "ranges",
15877 json_peer_group_ranges);
15878
15879 json_object_object_add(
15880 json_peer_group_dynamic, afi2str(afi),
15881 json_peer_group_dynamic_af);
15882 }
d62a17ae 15883 }
15884 }
f14e6fdb 15885
6f4eacf3
DA
15886 if (json_peer_group_dynamic)
15887 json_object_object_add(json_peer_group, "dynamicRanges",
15888 json_peer_group_dynamic);
15889
d62a17ae 15890 /* Display group members and their status */
15891 if (listcount(group->peer)) {
6f4eacf3
DA
15892 if (json)
15893 json_peer_group_members = json_object_new_object();
15894 else
15895 vty_out(vty, " Peer-group members:\n");
d62a17ae 15896 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
cb9196e7
DS
15897 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15898 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 15899 peer_status = "Idle (Admin)";
15900 else if (CHECK_FLAG(peer->sflags,
15901 PEER_STATUS_PREFIX_OVERFLOW))
15902 peer_status = "Idle (PfxCt)";
15903 else
15904 peer_status = lookup_msg(bgp_status_msg,
15905 peer->status, NULL);
15906
15907 dynamic = peer_dynamic_neighbor(peer);
6f4eacf3
DA
15908
15909 if (json) {
15910 json_object *json_peer_group_member =
15911 json_object_new_object();
15912
15913 json_object_string_add(json_peer_group_member,
15914 "status", peer_status);
15915
15916 if (dynamic)
15917 json_object_boolean_true_add(
15918 json_peer_group_member,
15919 "dynamic");
15920
15921 json_object_object_add(json_peer_group_members,
15922 peer->host,
15923 json_peer_group_member);
15924 } else {
15925 vty_out(vty, " %s %s %s \n", peer->host,
15926 dynamic ? "(dynamic)" : "",
15927 peer_status);
15928 }
d62a17ae 15929 }
6f4eacf3
DA
15930 if (json)
15931 json_object_object_add(json_peer_group, "members",
15932 json_peer_group_members);
d62a17ae 15933 }
f14e6fdb 15934
6f4eacf3
DA
15935 if (json)
15936 json_object_object_add(json, group->name, json_peer_group);
15937
d62a17ae 15938 return CMD_SUCCESS;
15939}
15940
ff9959b0 15941static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
6f4eacf3 15942 const char *group_name, bool uj)
d62a17ae 15943{
ff9959b0 15944 struct bgp *bgp;
d62a17ae 15945 struct listnode *node, *nnode;
15946 struct peer_group *group;
ff9959b0 15947 bool found = false;
6f4eacf3
DA
15948 json_object *json = NULL;
15949
15950 if (uj)
15951 json = json_object_new_object();
ff9959b0
QY
15952
15953 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15954
15955 if (!bgp) {
c48349e3 15956 if (uj)
75eeda93 15957 vty_json(vty, json);
c48349e3 15958 else
6f4eacf3 15959 vty_out(vty, "%% BGP instance not found\n");
6f4eacf3 15960
ff9959b0
QY
15961 return CMD_WARNING;
15962 }
d62a17ae 15963
15964 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
15965 if (group_name) {
15966 if (strmatch(group->name, group_name)) {
6f4eacf3 15967 bgp_show_one_peer_group(vty, group, json);
ff9959b0
QY
15968 found = true;
15969 break;
d62a17ae 15970 }
ff9959b0 15971 } else {
6f4eacf3 15972 bgp_show_one_peer_group(vty, group, json);
d62a17ae 15973 }
f14e6fdb 15974 }
f14e6fdb 15975
6f4eacf3 15976 if (group_name && !found && !uj)
d62a17ae 15977 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 15978
c48349e3 15979 if (uj)
75eeda93 15980 vty_json(vty, json);
6f4eacf3 15981
d62a17ae 15982 return CMD_SUCCESS;
f14e6fdb
DS
15983}
15984
6f4eacf3
DA
15985DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
15986 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
15987 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
15988 "Detailed information on BGP peer groups\n"
15989 "Peer group name\n" JSON_STR)
f14e6fdb 15990{
d62a17ae 15991 char *vrf, *pg;
d62a17ae 15992 int idx = 0;
6f4eacf3 15993 bool uj = use_json(argc, argv);
f14e6fdb 15994
a4d82a8a
PZ
15995 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
15996 : NULL;
d62a17ae 15997 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 15998
6f4eacf3 15999 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
f14e6fdb 16000}
3f9c7369 16001
d6e3c605 16002
718e3744 16003/* Redistribute VTY commands. */
16004
585f1adc
IR
16005DEFUN (bgp_redistribute_ipv4,
16006 bgp_redistribute_ipv4_cmd,
16007 "redistribute " FRR_IP_REDIST_STR_BGPD,
16008 "Redistribute information from another routing protocol\n"
16009 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 16010{
585f1adc 16011 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16012 int idx_protocol = 1;
585f1adc 16013 int type;
37a87b8f 16014
585f1adc
IR
16015 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16016 if (type < 0) {
16017 vty_out(vty, "%% Invalid route type\n");
16018 return CMD_WARNING_CONFIG_FAILED;
16019 }
7f323236 16020
585f1adc
IR
16021 bgp_redist_add(bgp, AFI_IP, type, 0);
16022 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
718e3744 16023}
16024
d62a17ae 16025ALIAS_HIDDEN(
16026 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
16027 "redistribute " FRR_IP_REDIST_STR_BGPD,
16028 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 16029
585f1adc
IR
16030DEFUN (bgp_redistribute_ipv4_rmap,
16031 bgp_redistribute_ipv4_rmap_cmd,
70dd370f 16032 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
585f1adc
IR
16033 "Redistribute information from another routing protocol\n"
16034 FRR_IP_REDIST_HELP_STR_BGPD
16035 "Route map reference\n"
16036 "Pointer to route-map entries\n")
718e3744 16037{
585f1adc 16038 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16039 int idx_protocol = 1;
16040 int idx_word = 3;
585f1adc
IR
16041 int type;
16042 struct bgp_redist *red;
16043 bool changed;
16044 struct route_map *route_map = route_map_lookup_warn_noexist(
16045 vty, argv[idx_word]->arg);
16046
16047 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16048 if (type < 0) {
16049 vty_out(vty, "%% Invalid route type\n");
16050 return CMD_WARNING_CONFIG_FAILED;
16051 }
37a87b8f 16052
585f1adc
IR
16053 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16054 changed =
16055 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16056 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
718e3744 16057}
16058
d62a17ae 16059ALIAS_HIDDEN(
16060 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
70dd370f 16061 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
d62a17ae 16062 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16063 "Route map reference\n"
16064 "Pointer to route-map entries\n")
596c17ba 16065
585f1adc
IR
16066DEFUN (bgp_redistribute_ipv4_metric,
16067 bgp_redistribute_ipv4_metric_cmd,
16068 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
16069 "Redistribute information from another routing protocol\n"
16070 FRR_IP_REDIST_HELP_STR_BGPD
16071 "Metric for redistributed routes\n"
16072 "Default metric\n")
718e3744 16073{
585f1adc 16074 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16075 int idx_protocol = 1;
16076 int idx_number = 3;
585f1adc
IR
16077 int type;
16078 uint32_t metric;
16079 struct bgp_redist *red;
16080 bool changed;
16081
16082 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16083 if (type < 0) {
16084 vty_out(vty, "%% Invalid route type\n");
16085 return CMD_WARNING_CONFIG_FAILED;
16086 }
16087 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 16088
585f1adc
IR
16089 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16090 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16091 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 16092}
16093
16094ALIAS_HIDDEN(
16095 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
16096 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
16097 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16098 "Metric for redistributed routes\n"
16099 "Default metric\n")
596c17ba 16100
585f1adc
IR
16101DEFUN (bgp_redistribute_ipv4_rmap_metric,
16102 bgp_redistribute_ipv4_rmap_metric_cmd,
70dd370f 16103 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
585f1adc
IR
16104 "Redistribute information from another routing protocol\n"
16105 FRR_IP_REDIST_HELP_STR_BGPD
16106 "Route map reference\n"
16107 "Pointer to route-map entries\n"
16108 "Metric for redistributed routes\n"
16109 "Default metric\n")
718e3744 16110{
585f1adc 16111 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16112 int idx_protocol = 1;
16113 int idx_word = 3;
16114 int idx_number = 5;
585f1adc
IR
16115 int type;
16116 uint32_t metric;
16117 struct bgp_redist *red;
16118 bool changed;
16119 struct route_map *route_map =
16120 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16121
16122 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16123 if (type < 0) {
16124 vty_out(vty, "%% Invalid route type\n");
16125 return CMD_WARNING_CONFIG_FAILED;
16126 }
16127 metric = strtoul(argv[idx_number]->arg, NULL, 10);
d62a17ae 16128
585f1adc
IR
16129 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16130 changed =
16131 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16132 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16133 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 16134}
16135
16136ALIAS_HIDDEN(
16137 bgp_redistribute_ipv4_rmap_metric,
16138 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
16139 "redistribute " FRR_IP_REDIST_STR_BGPD
70dd370f 16140 " route-map RMAP_NAME metric (0-4294967295)",
d62a17ae 16141 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16142 "Route map reference\n"
16143 "Pointer to route-map entries\n"
16144 "Metric for redistributed routes\n"
16145 "Default metric\n")
596c17ba 16146
585f1adc
IR
16147DEFUN (bgp_redistribute_ipv4_metric_rmap,
16148 bgp_redistribute_ipv4_metric_rmap_cmd,
70dd370f 16149 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
585f1adc
IR
16150 "Redistribute information from another routing protocol\n"
16151 FRR_IP_REDIST_HELP_STR_BGPD
16152 "Metric for redistributed routes\n"
16153 "Default metric\n"
16154 "Route map reference\n"
16155 "Pointer to route-map entries\n")
718e3744 16156{
585f1adc 16157 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16158 int idx_protocol = 1;
37a87b8f 16159 int idx_number = 3;
585f1adc
IR
16160 int idx_word = 5;
16161 int type;
16162 uint32_t metric;
16163 struct bgp_redist *red;
16164 bool changed;
16165 struct route_map *route_map =
16166 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16167
16168 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16169 if (type < 0) {
16170 vty_out(vty, "%% Invalid route type\n");
16171 return CMD_WARNING_CONFIG_FAILED;
16172 }
16173 metric = strtoul(argv[idx_number]->arg, NULL, 10);
d62a17ae 16174
585f1adc
IR
16175 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16176 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16177 changed |=
16178 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16179 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 16180}
16181
16182ALIAS_HIDDEN(
16183 bgp_redistribute_ipv4_metric_rmap,
16184 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
16185 "redistribute " FRR_IP_REDIST_STR_BGPD
70dd370f 16186 " metric (0-4294967295) route-map RMAP_NAME",
d62a17ae 16187 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16188 "Metric for redistributed routes\n"
16189 "Default metric\n"
16190 "Route map reference\n"
16191 "Pointer to route-map entries\n")
596c17ba 16192
585f1adc
IR
16193DEFUN (bgp_redistribute_ipv4_ospf,
16194 bgp_redistribute_ipv4_ospf_cmd,
16195 "redistribute <ospf|table> (1-65535)",
16196 "Redistribute information from another routing protocol\n"
16197 "Open Shortest Path First (OSPFv2)\n"
16198 "Non-main Kernel Routing Table\n"
16199 "Instance ID/Table ID\n")
7c8ff89e 16200{
585f1adc
IR
16201 VTY_DECLVAR_CONTEXT(bgp, bgp);
16202 int idx_ospf_table = 1;
d62a17ae 16203 int idx_number = 2;
585f1adc
IR
16204 unsigned short instance;
16205 unsigned short protocol;
7c8ff89e 16206
585f1adc 16207 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 16208
585f1adc
IR
16209 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16210 protocol = ZEBRA_ROUTE_OSPF;
16211 else
16212 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 16213
585f1adc
IR
16214 bgp_redist_add(bgp, AFI_IP, protocol, instance);
16215 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
7c8ff89e
DS
16216}
16217
d62a17ae 16218ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
16219 "redistribute <ospf|table> (1-65535)",
16220 "Redistribute information from another routing protocol\n"
16221 "Open Shortest Path First (OSPFv2)\n"
16222 "Non-main Kernel Routing Table\n"
16223 "Instance ID/Table ID\n")
596c17ba 16224
585f1adc
IR
16225DEFUN (bgp_redistribute_ipv4_ospf_rmap,
16226 bgp_redistribute_ipv4_ospf_rmap_cmd,
70dd370f 16227 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
585f1adc
IR
16228 "Redistribute information from another routing protocol\n"
16229 "Open Shortest Path First (OSPFv2)\n"
16230 "Non-main Kernel Routing Table\n"
16231 "Instance ID/Table ID\n"
16232 "Route map reference\n"
16233 "Pointer to route-map entries\n")
7c8ff89e 16234{
585f1adc
IR
16235 VTY_DECLVAR_CONTEXT(bgp, bgp);
16236 int idx_ospf_table = 1;
d62a17ae 16237 int idx_number = 2;
16238 int idx_word = 4;
585f1adc
IR
16239 struct bgp_redist *red;
16240 unsigned short instance;
16241 int protocol;
16242 bool changed;
16243 struct route_map *route_map =
16244 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16245
16246 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16247 protocol = ZEBRA_ROUTE_OSPF;
16248 else
16249 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 16250
585f1adc
IR
16251 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16252 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16253 changed =
16254 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16255 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 16256}
16257
16258ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
16259 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
70dd370f 16260 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
d62a17ae 16261 "Redistribute information from another routing protocol\n"
16262 "Open Shortest Path First (OSPFv2)\n"
16263 "Non-main Kernel Routing Table\n"
16264 "Instance ID/Table ID\n"
16265 "Route map reference\n"
16266 "Pointer to route-map entries\n")
596c17ba 16267
585f1adc
IR
16268DEFUN (bgp_redistribute_ipv4_ospf_metric,
16269 bgp_redistribute_ipv4_ospf_metric_cmd,
16270 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16271 "Redistribute information from another routing protocol\n"
16272 "Open Shortest Path First (OSPFv2)\n"
16273 "Non-main Kernel Routing Table\n"
16274 "Instance ID/Table ID\n"
16275 "Metric for redistributed routes\n"
16276 "Default metric\n")
7c8ff89e 16277{
585f1adc
IR
16278 VTY_DECLVAR_CONTEXT(bgp, bgp);
16279 int idx_ospf_table = 1;
d62a17ae 16280 int idx_number = 2;
16281 int idx_number_2 = 4;
585f1adc
IR
16282 uint32_t metric;
16283 struct bgp_redist *red;
16284 unsigned short instance;
16285 int protocol;
16286 bool changed;
16287
16288 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16289 protocol = ZEBRA_ROUTE_OSPF;
16290 else
16291 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 16292
585f1adc
IR
16293 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16294 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 16295
585f1adc
IR
16296 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16297 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16298 metric);
16299 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 16300}
16301
16302ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
16303 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
16304 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16305 "Redistribute information from another routing protocol\n"
16306 "Open Shortest Path First (OSPFv2)\n"
16307 "Non-main Kernel Routing Table\n"
16308 "Instance ID/Table ID\n"
16309 "Metric for redistributed routes\n"
16310 "Default metric\n")
596c17ba 16311
585f1adc
IR
16312DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
16313 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
70dd370f 16314 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
585f1adc
IR
16315 "Redistribute information from another routing protocol\n"
16316 "Open Shortest Path First (OSPFv2)\n"
16317 "Non-main Kernel Routing Table\n"
16318 "Instance ID/Table ID\n"
16319 "Route map reference\n"
16320 "Pointer to route-map entries\n"
16321 "Metric for redistributed routes\n"
16322 "Default metric\n")
7c8ff89e 16323{
585f1adc
IR
16324 VTY_DECLVAR_CONTEXT(bgp, bgp);
16325 int idx_ospf_table = 1;
d62a17ae 16326 int idx_number = 2;
16327 int idx_word = 4;
16328 int idx_number_2 = 6;
585f1adc
IR
16329 uint32_t metric;
16330 struct bgp_redist *red;
16331 unsigned short instance;
16332 int protocol;
16333 bool changed;
16334 struct route_map *route_map =
16335 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16336
16337 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16338 protocol = ZEBRA_ROUTE_OSPF;
16339 else
16340 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 16341
585f1adc
IR
16342 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16343 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 16344
585f1adc
IR
16345 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16346 changed =
16347 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16348 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16349 metric);
16350 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 16351}
16352
16353ALIAS_HIDDEN(
16354 bgp_redistribute_ipv4_ospf_rmap_metric,
16355 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
70dd370f 16356 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
d62a17ae 16357 "Redistribute information from another routing protocol\n"
16358 "Open Shortest Path First (OSPFv2)\n"
16359 "Non-main Kernel Routing Table\n"
16360 "Instance ID/Table ID\n"
16361 "Route map reference\n"
16362 "Pointer to route-map entries\n"
16363 "Metric for redistributed routes\n"
16364 "Default metric\n")
596c17ba 16365
585f1adc
IR
16366DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
16367 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
70dd370f 16368 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
585f1adc
IR
16369 "Redistribute information from another routing protocol\n"
16370 "Open Shortest Path First (OSPFv2)\n"
16371 "Non-main Kernel Routing Table\n"
16372 "Instance ID/Table ID\n"
16373 "Metric for redistributed routes\n"
16374 "Default metric\n"
16375 "Route map reference\n"
16376 "Pointer to route-map entries\n")
7c8ff89e 16377{
585f1adc
IR
16378 VTY_DECLVAR_CONTEXT(bgp, bgp);
16379 int idx_ospf_table = 1;
d62a17ae 16380 int idx_number = 2;
16381 int idx_number_2 = 4;
16382 int idx_word = 6;
585f1adc
IR
16383 uint32_t metric;
16384 struct bgp_redist *red;
16385 unsigned short instance;
16386 int protocol;
16387 bool changed;
16388 struct route_map *route_map =
16389 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16390
16391 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16392 protocol = ZEBRA_ROUTE_OSPF;
16393 else
16394 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 16395
585f1adc
IR
16396 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16397 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 16398
585f1adc
IR
16399 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16400 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16401 metric);
16402 changed |=
16403 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16404 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 16405}
16406
16407ALIAS_HIDDEN(
16408 bgp_redistribute_ipv4_ospf_metric_rmap,
16409 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
70dd370f 16410 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
d62a17ae 16411 "Redistribute information from another routing protocol\n"
16412 "Open Shortest Path First (OSPFv2)\n"
16413 "Non-main Kernel Routing Table\n"
16414 "Instance ID/Table ID\n"
16415 "Metric for redistributed routes\n"
16416 "Default metric\n"
16417 "Route map reference\n"
16418 "Pointer to route-map entries\n")
596c17ba 16419
585f1adc
IR
16420DEFUN (no_bgp_redistribute_ipv4_ospf,
16421 no_bgp_redistribute_ipv4_ospf_cmd,
70dd370f 16422 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
585f1adc
IR
16423 NO_STR
16424 "Redistribute information from another routing protocol\n"
16425 "Open Shortest Path First (OSPFv2)\n"
16426 "Non-main Kernel Routing Table\n"
16427 "Instance ID/Table ID\n"
16428 "Metric for redistributed routes\n"
16429 "Default metric\n"
16430 "Route map reference\n"
16431 "Pointer to route-map entries\n")
7c8ff89e 16432{
585f1adc
IR
16433 VTY_DECLVAR_CONTEXT(bgp, bgp);
16434 int idx_ospf_table = 2;
d62a17ae 16435 int idx_number = 3;
585f1adc
IR
16436 unsigned short instance;
16437 int protocol;
37a87b8f 16438
585f1adc
IR
16439 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16440 protocol = ZEBRA_ROUTE_OSPF;
16441 else
16442 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 16443
585f1adc
IR
16444 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16445 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
d62a17ae 16446}
16447
16448ALIAS_HIDDEN(
16449 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
70dd370f 16450 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
d62a17ae 16451 NO_STR
16452 "Redistribute information from another routing protocol\n"
16453 "Open Shortest Path First (OSPFv2)\n"
16454 "Non-main Kernel Routing Table\n"
16455 "Instance ID/Table ID\n"
16456 "Metric for redistributed routes\n"
16457 "Default metric\n"
16458 "Route map reference\n"
16459 "Pointer to route-map entries\n")
596c17ba 16460
585f1adc
IR
16461DEFUN (no_bgp_redistribute_ipv4,
16462 no_bgp_redistribute_ipv4_cmd,
70dd370f 16463 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
585f1adc
IR
16464 NO_STR
16465 "Redistribute information from another routing protocol\n"
16466 FRR_IP_REDIST_HELP_STR_BGPD
16467 "Metric for redistributed routes\n"
16468 "Default metric\n"
16469 "Route map reference\n"
16470 "Pointer to route-map entries\n")
718e3744 16471{
585f1adc 16472 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16473 int idx_protocol = 2;
585f1adc 16474 int type;
d62a17ae 16475
585f1adc
IR
16476 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16477 if (type < 0) {
16478 vty_out(vty, "%% Invalid route type\n");
16479 return CMD_WARNING_CONFIG_FAILED;
16480 }
16481 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
d62a17ae 16482}
16483
16484ALIAS_HIDDEN(
16485 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
16486 "no redistribute " FRR_IP_REDIST_STR_BGPD
70dd370f 16487 " [{metric (0-4294967295)|route-map RMAP_NAME}]",
d62a17ae 16488 NO_STR
16489 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16490 "Metric for redistributed routes\n"
16491 "Default metric\n"
16492 "Route map reference\n"
16493 "Pointer to route-map entries\n")
596c17ba 16494
585f1adc
IR
16495DEFUN (bgp_redistribute_ipv6,
16496 bgp_redistribute_ipv6_cmd,
16497 "redistribute " FRR_IP6_REDIST_STR_BGPD,
16498 "Redistribute information from another routing protocol\n"
16499 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 16500{
585f1adc 16501 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16502 int idx_protocol = 1;
585f1adc 16503 int type;
718e3744 16504
585f1adc
IR
16505 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16506 if (type < 0) {
16507 vty_out(vty, "%% Invalid route type\n");
16508 return CMD_WARNING_CONFIG_FAILED;
16509 }
718e3744 16510
585f1adc
IR
16511 bgp_redist_add(bgp, AFI_IP6, type, 0);
16512 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
718e3744 16513}
16514
585f1adc
IR
16515DEFUN (bgp_redistribute_ipv6_rmap,
16516 bgp_redistribute_ipv6_rmap_cmd,
70dd370f 16517 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME",
585f1adc
IR
16518 "Redistribute information from another routing protocol\n"
16519 FRR_IP6_REDIST_HELP_STR_BGPD
16520 "Route map reference\n"
16521 "Pointer to route-map entries\n")
718e3744 16522{
585f1adc 16523 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16524 int idx_protocol = 1;
16525 int idx_word = 3;
585f1adc
IR
16526 int type;
16527 struct bgp_redist *red;
16528 bool changed;
16529 struct route_map *route_map =
16530 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16531
16532 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16533 if (type < 0) {
16534 vty_out(vty, "%% Invalid route type\n");
16535 return CMD_WARNING_CONFIG_FAILED;
16536 }
37a87b8f 16537
585f1adc
IR
16538 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16539 changed =
16540 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16541 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 16542}
16543
585f1adc 16544DEFUN (bgp_redistribute_ipv6_metric,
718e3744 16545 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 16546 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 16547 "Redistribute information from another routing protocol\n"
ab0181ee 16548 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 16549 "Metric for redistributed routes\n"
16550 "Default metric\n")
16551{
585f1adc 16552 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16553 int idx_protocol = 1;
16554 int idx_number = 3;
585f1adc
IR
16555 int type;
16556 uint32_t metric;
16557 struct bgp_redist *red;
16558 bool changed;
16559
16560 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16561 if (type < 0) {
16562 vty_out(vty, "%% Invalid route type\n");
16563 return CMD_WARNING_CONFIG_FAILED;
16564 }
16565 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 16566
585f1adc
IR
16567 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16568 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
16569 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 16570}
16571
585f1adc
IR
16572DEFUN (bgp_redistribute_ipv6_rmap_metric,
16573 bgp_redistribute_ipv6_rmap_metric_cmd,
70dd370f 16574 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
585f1adc
IR
16575 "Redistribute information from another routing protocol\n"
16576 FRR_IP6_REDIST_HELP_STR_BGPD
16577 "Route map reference\n"
16578 "Pointer to route-map entries\n"
16579 "Metric for redistributed routes\n"
16580 "Default metric\n")
718e3744 16581{
585f1adc 16582 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16583 int idx_protocol = 1;
16584 int idx_word = 3;
16585 int idx_number = 5;
585f1adc
IR
16586 int type;
16587 uint32_t metric;
16588 struct bgp_redist *red;
16589 bool changed;
16590 struct route_map *route_map =
16591 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16592
16593 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16594 if (type < 0) {
16595 vty_out(vty, "%% Invalid route type\n");
16596 return CMD_WARNING_CONFIG_FAILED;
16597 }
16598 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 16599
585f1adc
IR
16600 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16601 changed =
16602 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16603 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
16604 metric);
16605 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 16606}
16607
585f1adc
IR
16608DEFUN (bgp_redistribute_ipv6_metric_rmap,
16609 bgp_redistribute_ipv6_metric_rmap_cmd,
70dd370f 16610 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
585f1adc
IR
16611 "Redistribute information from another routing protocol\n"
16612 FRR_IP6_REDIST_HELP_STR_BGPD
16613 "Metric for redistributed routes\n"
16614 "Default metric\n"
16615 "Route map reference\n"
16616 "Pointer to route-map entries\n")
718e3744 16617{
585f1adc 16618 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16619 int idx_protocol = 1;
37a87b8f 16620 int idx_number = 3;
585f1adc
IR
16621 int idx_word = 5;
16622 int type;
16623 uint32_t metric;
16624 struct bgp_redist *red;
16625 bool changed;
16626 struct route_map *route_map =
16627 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16628
16629 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16630 if (type < 0) {
16631 vty_out(vty, "%% Invalid route type\n");
16632 return CMD_WARNING_CONFIG_FAILED;
16633 }
16634 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 16635
585f1adc
IR
16636 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16637 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
16638 metric);
16639 changed |=
16640 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16641 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 16642}
16643
585f1adc
IR
16644DEFUN (no_bgp_redistribute_ipv6,
16645 no_bgp_redistribute_ipv6_cmd,
70dd370f 16646 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
585f1adc
IR
16647 NO_STR
16648 "Redistribute information from another routing protocol\n"
16649 FRR_IP6_REDIST_HELP_STR_BGPD
16650 "Metric for redistributed routes\n"
16651 "Default metric\n"
16652 "Route map reference\n"
16653 "Pointer to route-map entries\n")
718e3744 16654{
585f1adc 16655 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16656 int idx_protocol = 2;
585f1adc 16657 int type;
37a87b8f 16658
585f1adc
IR
16659 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16660 if (type < 0) {
16661 vty_out(vty, "%% Invalid route type\n");
16662 return CMD_WARNING_CONFIG_FAILED;
16663 }
718e3744 16664
585f1adc 16665 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
d62a17ae 16666}
16667
4ab46701
AR
16668/* Neighbor update tcp-mss. */
16669static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
16670 const char *tcp_mss_str)
16671{
16672 struct peer *peer;
16673 uint32_t tcp_mss_val = 0;
16674
16675 peer = peer_and_group_lookup_vty(vty, peer_str);
16676 if (!peer)
16677 return CMD_WARNING_CONFIG_FAILED;
16678
16679 if (tcp_mss_str) {
16680 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
16681 peer_tcp_mss_set(peer, tcp_mss_val);
16682 } else {
16683 peer_tcp_mss_unset(peer);
16684 }
16685
16686 return CMD_SUCCESS;
16687}
16688
16689DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
16690 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
16691 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16692 "TCP max segment size\n"
16693 "TCP MSS value\n")
16694{
16695 int peer_index = 1;
16696 int mss_index = 3;
16697
16698 vty_out(vty,
16699 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16700 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
16701 argv[mss_index]->arg);
16702}
16703
16704DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
16705 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
16706 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16707 "TCP max segment size\n"
16708 "TCP MSS value\n")
16709{
16710 int peer_index = 2;
16711
16712 vty_out(vty,
16713 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16714 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
16715}
16716
a486300b
PG
16717DEFPY(bgp_retain_route_target, bgp_retain_route_target_cmd,
16718 "[no$no] bgp retain route-target all",
16719 NO_STR BGP_STR
16720 "Retain BGP updates\n"
16721 "Retain BGP updates based on route-target values\n"
16722 "Retain all BGP updates\n")
16723{
16724 bool check;
16725 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
16726
16727 check = CHECK_FLAG(bgp->af_flags[bgp_node_afi(vty)][bgp_node_safi(vty)],
16728 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16729 if (check != !no) {
16730 if (!no)
16731 SET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16732 [bgp_node_safi(vty)],
16733 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16734 else
16735 UNSET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16736 [bgp_node_safi(vty)],
16737 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16738 /* trigger a flush to re-sync with ADJ-RIB-in */
16739 bgp_clear(vty, bgp, bgp_node_afi(vty), bgp_node_safi(vty),
16740 clear_all, BGP_CLEAR_SOFT_IN, NULL);
16741 }
16742 return CMD_SUCCESS;
16743}
16744
dd65f45e
DL
16745static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16746 afi_t afi, safi_t safi)
d62a17ae 16747{
16748 int i;
16749
16750 /* Unicast redistribution only. */
16751 if (safi != SAFI_UNICAST)
2b791107 16752 return;
d62a17ae 16753
16754 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16755 /* Redistribute BGP does not make sense. */
16756 if (i != ZEBRA_ROUTE_BGP) {
16757 struct list *red_list;
16758 struct listnode *node;
16759 struct bgp_redist *red;
16760
16761 red_list = bgp->redist[afi][i];
16762 if (!red_list)
16763 continue;
16764
16765 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 16766 /* "redistribute" configuration. */
16767 vty_out(vty, " redistribute %s",
16768 zebra_route_string(i));
16769 if (red->instance)
16770 vty_out(vty, " %d", red->instance);
16771 if (red->redist_metric_flag)
16772 vty_out(vty, " metric %u",
16773 red->redist_metric);
16774 if (red->rmap.name)
16775 vty_out(vty, " route-map %s",
16776 red->rmap.name);
16777 vty_out(vty, "\n");
16778 }
16779 }
16780 }
718e3744 16781}
6b0655a2 16782
dd65f45e
DL
16783/* peer-group helpers for config-write */
16784
83194f39 16785static bool peergroup_flag_check(struct peer *peer, uint64_t flag)
dd65f45e
DL
16786{
16787 if (!peer_group_active(peer)) {
16788 if (CHECK_FLAG(peer->flags_invert, flag))
16789 return !CHECK_FLAG(peer->flags, flag);
16790 else
16791 return !!CHECK_FLAG(peer->flags, flag);
16792 }
16793
16794 return !!CHECK_FLAG(peer->flags_override, flag);
16795}
16796
16797static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
da5e1a58 16798 uint64_t flag)
dd65f45e
DL
16799{
16800 if (!peer_group_active(peer)) {
16801 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16802 return !peer_af_flag_check(peer, afi, safi, flag);
16803 else
16804 return !!peer_af_flag_check(peer, afi, safi, flag);
16805 }
16806
16807 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16808}
16809
16810static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16811 uint8_t type, int direct)
16812{
16813 struct bgp_filter *filter;
16814
16815 if (peer_group_active(peer))
16816 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16817 type);
16818
16819 filter = &peer->filter[afi][safi];
16820 switch (type) {
16821 case PEER_FT_DISTRIBUTE_LIST:
16822 return !!(filter->dlist[direct].name);
16823 case PEER_FT_FILTER_LIST:
16824 return !!(filter->aslist[direct].name);
16825 case PEER_FT_PREFIX_LIST:
16826 return !!(filter->plist[direct].name);
16827 case PEER_FT_ROUTE_MAP:
16828 return !!(filter->map[direct].name);
16829 case PEER_FT_UNSUPPRESS_MAP:
16830 return !!(filter->usmap.name);
7f7940e6
MK
16831 case PEER_FT_ADVERTISE_MAP:
16832 return !!(filter->advmap.aname
16833 && ((filter->advmap.condition == direct)
16834 && filter->advmap.cname));
dd65f45e
DL
16835 default:
16836 return false;
16837 }
16838}
16839
16840/* Return true if the addpath type is set for peer and different from
16841 * peer-group.
16842 */
3dc339cd
DA
16843static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16844 safi_t safi)
dd65f45e
DL
16845{
16846 enum bgp_addpath_strat type, g_type;
16847
16848 type = peer->addpath_type[afi][safi];
16849
16850 if (type != BGP_ADDPATH_NONE) {
16851 if (peer_group_active(peer)) {
16852 g_type = peer->group->conf->addpath_type[afi][safi];
16853
16854 if (type != g_type)
3dc339cd 16855 return true;
dd65f45e 16856 else
3dc339cd 16857 return false;
dd65f45e
DL
16858 }
16859
3dc339cd 16860 return true;
dd65f45e
DL
16861 }
16862
3dc339cd 16863 return false;
dd65f45e
DL
16864}
16865
b9c7bc5a 16866/* This is part of the address-family block (unicast only) */
dd65f45e 16867static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
16868 afi_t afi)
16869{
b9c7bc5a 16870 int indent = 2;
53970de3 16871 uint32_t tovpn_sid_index = 0;
ddb5b488 16872
8a066a70 16873 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
ae6a6fb4
DS
16874 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16875 BGP_CONFIG_VRF_TO_VRF_IMPORT))
8a066a70
PG
16876 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16877 bgp->vpn_policy[afi]
bb4f6190 16878 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
16879 else
16880 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16881 bgp->vpn_policy[afi]
16882 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16883 }
12a844a5
DS
16884 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16885 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16886 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16887 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16888 return;
16889
e70e9f8e
PZ
16890 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16891 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16892
16893 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16894
16895 } else {
16896 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16897 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16898 bgp->vpn_policy[afi].tovpn_label);
16899 }
ddb5b488 16900 }
53970de3
RS
16901
16902 tovpn_sid_index = bgp->vpn_policy[afi].tovpn_sid_index;
16903 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16904 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
16905 vty_out(vty, "%*ssid vpn export %s\n", indent, "", "auto");
16906 } else if (tovpn_sid_index != 0) {
16907 vty_out(vty, "%*ssid vpn export %d\n", indent, "",
16908 tovpn_sid_index);
16909 }
16910
c4f64ea9
DA
16911 if (CHECK_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_RD_SET))
16912 vty_out(vty, "%*srd vpn export %pRD\n", indent, "",
16913 &bgp->vpn_policy[afi].tovpn_rd);
16914
ddb5b488
PZ
16915 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16916 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
16917
16918 char buf[PREFIX_STRLEN];
16919 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
16920 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
16921 sizeof(buf))) {
16922
b9c7bc5a
PZ
16923 vty_out(vty, "%*snexthop vpn export %s\n",
16924 indent, "", buf);
ddb5b488
PZ
16925 }
16926 }
16927 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
16928 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
16929 && ecommunity_cmp(
16930 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16931 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16932
16933 char *b = ecommunity_ecom2str(
16934 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16935 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16936 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
16937 XFREE(MTYPE_ECOMMUNITY_STR, b);
16938 } else {
16939 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16940 char *b = ecommunity_ecom2str(
16941 bgp->vpn_policy[afi]
16942 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16943 ECOMMUNITY_FORMAT_ROUTE_MAP,
16944 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16945 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
16946 XFREE(MTYPE_ECOMMUNITY_STR, b);
16947 }
16948 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16949 char *b = ecommunity_ecom2str(
16950 bgp->vpn_policy[afi]
16951 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16952 ECOMMUNITY_FORMAT_ROUTE_MAP,
16953 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16954 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
16955 XFREE(MTYPE_ECOMMUNITY_STR, b);
16956 }
16957 }
bb4f6190
DS
16958
16959 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 16960 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
16961 bgp->vpn_policy[afi]
16962 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 16963
301ad80a
PG
16964 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16965 char *b = ecommunity_ecom2str(
16966 bgp->vpn_policy[afi]
16967 .import_redirect_rtlist,
16968 ECOMMUNITY_FORMAT_ROUTE_MAP,
16969 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 16970
9a659715
PG
16971 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16972 != ECOMMUNITY_SIZE)
c6423c31 16973 vty_out(vty, "%*srt6 redirect import %s\n",
9a659715
PG
16974 indent, "", b);
16975 else
16976 vty_out(vty, "%*srt redirect import %s\n",
16977 indent, "", b);
301ad80a
PG
16978 XFREE(MTYPE_ECOMMUNITY_STR, b);
16979 }
ddb5b488
PZ
16980}
16981
dd65f45e
DL
16982static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
16983 afi_t afi, safi_t safi)
16984{
16985 struct bgp_filter *filter;
16986 char *addr;
16987
16988 addr = peer->host;
16989 filter = &peer->filter[afi][safi];
16990
16991 /* distribute-list. */
16992 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16993 FILTER_IN))
16994 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
16995 filter->dlist[FILTER_IN].name);
16996
16997 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16998 FILTER_OUT))
16999 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
17000 filter->dlist[FILTER_OUT].name);
17001
17002 /* prefix-list. */
17003 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
17004 FILTER_IN))
17005 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
17006 filter->plist[FILTER_IN].name);
17007
17008 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
17009 FILTER_OUT))
17010 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
17011 filter->plist[FILTER_OUT].name);
17012
17013 /* route-map. */
17014 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
17015 vty_out(vty, " neighbor %s route-map %s in\n", addr,
17016 filter->map[RMAP_IN].name);
17017
17018 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
17019 RMAP_OUT))
17020 vty_out(vty, " neighbor %s route-map %s out\n", addr,
17021 filter->map[RMAP_OUT].name);
17022
17023 /* unsuppress-map */
17024 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
17025 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
17026 filter->usmap.name);
17027
7f7940e6
MK
17028 /* advertise-map : always applied in OUT direction*/
17029 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
17030 CONDITION_NON_EXIST))
17031 vty_out(vty,
17032 " neighbor %s advertise-map %s non-exist-map %s\n",
17033 addr, filter->advmap.aname, filter->advmap.cname);
17034
17035 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
17036 CONDITION_EXIST))
17037 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
17038 addr, filter->advmap.aname, filter->advmap.cname);
17039
dd65f45e
DL
17040 /* filter-list. */
17041 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
17042 FILTER_IN))
17043 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
17044 filter->aslist[FILTER_IN].name);
17045
17046 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
17047 FILTER_OUT))
17048 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
17049 filter->aslist[FILTER_OUT].name);
17050}
17051
17052/* BGP peer configuration display function. */
17053static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
17054 struct peer *peer)
17055{
17056 struct peer *g_peer = NULL;
dd65f45e
DL
17057 char *addr;
17058 int if_pg_printed = false;
17059 int if_ras_printed = false;
17060
17061 /* Skip dynamic neighbors. */
17062 if (peer_dynamic_neighbor(peer))
17063 return;
17064
17065 if (peer->conf_if)
17066 addr = peer->conf_if;
17067 else
17068 addr = peer->host;
17069
17070 /************************************
17071 ****** Global to the neighbor ******
17072 ************************************/
17073 if (peer->conf_if) {
17074 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
17075 vty_out(vty, " neighbor %s interface v6only", addr);
17076 else
17077 vty_out(vty, " neighbor %s interface", addr);
17078
17079 if (peer_group_active(peer)) {
17080 vty_out(vty, " peer-group %s", peer->group->name);
17081 if_pg_printed = true;
17082 } else if (peer->as_type == AS_SPECIFIED) {
17083 vty_out(vty, " remote-as %u", peer->as);
17084 if_ras_printed = true;
17085 } else if (peer->as_type == AS_INTERNAL) {
17086 vty_out(vty, " remote-as internal");
17087 if_ras_printed = true;
17088 } else if (peer->as_type == AS_EXTERNAL) {
17089 vty_out(vty, " remote-as external");
17090 if_ras_printed = true;
17091 }
17092
17093 vty_out(vty, "\n");
17094 }
17095
17096 /* remote-as and peer-group */
17097 /* peer is a member of a peer-group */
17098 if (peer_group_active(peer)) {
17099 g_peer = peer->group->conf;
17100
17101 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
17102 if (peer->as_type == AS_SPECIFIED) {
17103 vty_out(vty, " neighbor %s remote-as %u\n",
17104 addr, peer->as);
17105 } else if (peer->as_type == AS_INTERNAL) {
17106 vty_out(vty,
17107 " neighbor %s remote-as internal\n",
17108 addr);
17109 } else if (peer->as_type == AS_EXTERNAL) {
17110 vty_out(vty,
17111 " neighbor %s remote-as external\n",
17112 addr);
17113 }
17114 }
17115
17116 /* For swpX peers we displayed the peer-group
17117 * via 'neighbor swpX interface peer-group PGNAME' */
17118 if (!if_pg_printed)
17119 vty_out(vty, " neighbor %s peer-group %s\n", addr,
17120 peer->group->name);
17121 }
17122
17123 /* peer is NOT a member of a peer-group */
17124 else {
17125 /* peer is a peer-group, declare the peer-group */
17126 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
17127 vty_out(vty, " neighbor %s peer-group\n", addr);
17128 }
17129
17130 if (!if_ras_printed) {
17131 if (peer->as_type == AS_SPECIFIED) {
17132 vty_out(vty, " neighbor %s remote-as %u\n",
17133 addr, peer->as);
17134 } else if (peer->as_type == AS_INTERNAL) {
17135 vty_out(vty,
17136 " neighbor %s remote-as internal\n",
17137 addr);
17138 } else if (peer->as_type == AS_EXTERNAL) {
17139 vty_out(vty,
17140 " neighbor %s remote-as external\n",
17141 addr);
17142 }
17143 }
17144 }
17145
17146 /* local-as */
17147 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
17148 vty_out(vty, " neighbor %s local-as %u", addr,
17149 peer->change_local_as);
17150 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
17151 vty_out(vty, " no-prepend");
17152 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
17153 vty_out(vty, " replace-as");
17154 vty_out(vty, "\n");
17155 }
17156
17157 /* description */
17158 if (peer->desc) {
17159 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
17160 }
17161
17162 /* shutdown */
17163 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
17164 if (peer->tx_shutdown_message)
17165 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
17166 peer->tx_shutdown_message);
17167 else
17168 vty_out(vty, " neighbor %s shutdown\n", addr);
17169 }
17170
8336c896
DA
17171 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
17172 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
17173 peer->rtt_expected, peer->rtt_keepalive_conf);
17174
dd65f45e 17175 /* bfd */
21bfce98
RZ
17176 if (peer->bfd_config)
17177 bgp_bfd_peer_config_write(vty, peer, addr);
dd65f45e
DL
17178
17179 /* password */
17180 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
17181 vty_out(vty, " neighbor %s password %s\n", addr,
17182 peer->password);
17183
17184 /* neighbor solo */
17185 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
17186 if (!peer_group_active(peer)) {
17187 vty_out(vty, " neighbor %s solo\n", addr);
17188 }
17189 }
17190
17191 /* BGP port */
17192 if (peer->port != BGP_PORT_DEFAULT) {
17193 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
17194 }
17195
17196 /* Local interface name */
17197 if (peer->ifname) {
17198 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
17199 }
17200
4ab46701
AR
17201 /* TCP max segment size */
17202 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
17203 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
17204
dd65f45e
DL
17205 /* passive */
17206 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
17207 vty_out(vty, " neighbor %s passive\n", addr);
17208
17209 /* ebgp-multihop */
17210 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
e2521429
DA
17211 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
17212 && peer->ttl == MAXTTL)) {
dd65f45e
DL
17213 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
17214 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
17215 peer->ttl);
17216 }
17217 }
17218
97a52c82
DA
17219 /* aigp */
17220 if (peergroup_flag_check(peer, PEER_FLAG_AIGP))
17221 vty_out(vty, " neighbor %s aigp\n", addr);
17222
d864dd9e 17223 /* role */
7dddd1f7
DA
17224 if (peergroup_flag_check(peer, PEER_FLAG_ROLE) &&
17225 peer->local_role != ROLE_UNDEFINED)
d864dd9e 17226 vty_out(vty, " neighbor %s local-role %s%s\n", addr,
8f2d6021 17227 bgp_get_name_by_role(peer->local_role),
7dddd1f7 17228 CHECK_FLAG(peer->flags, PEER_FLAG_ROLE_STRICT_MODE)
d864dd9e
EB
17229 ? " strict-mode"
17230 : "");
d864dd9e 17231
dd65f45e 17232 /* ttl-security hops */
e2521429 17233 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
dd65f45e
DL
17234 if (!peer_group_active(peer)
17235 || g_peer->gtsm_hops != peer->gtsm_hops) {
17236 vty_out(vty, " neighbor %s ttl-security hops %d\n",
17237 addr, peer->gtsm_hops);
17238 }
17239 }
17240
17241 /* disable-connected-check */
17242 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
17243 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
17244
27aa23a4
DA
17245 /* link-bw-encoding-ieee */
17246 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE))
17247 vty_out(vty, " neighbor %s disable-link-bw-encoding-ieee\n",
17248 addr);
17249
d08c0c80
DA
17250 /* extended-optional-parameters */
17251 if (peergroup_flag_check(peer, PEER_FLAG_EXTENDED_OPT_PARAMS))
17252 vty_out(vty, " neighbor %s extended-optional-parameters\n",
17253 addr);
17254
dd65f45e
DL
17255 /* enforce-first-as */
17256 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
17257 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
17258
17259 /* update-source */
17260 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
17261 if (peer->update_source)
47e12884
DA
17262 vty_out(vty, " neighbor %s update-source %pSU\n", addr,
17263 peer->update_source);
dd65f45e
DL
17264 else if (peer->update_if)
17265 vty_out(vty, " neighbor %s update-source %s\n", addr,
17266 peer->update_if);
17267 }
17268
17269 /* advertisement-interval */
17270 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
17271 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
17272 peer->routeadv);
17273
17274 /* timers */
17275 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
17276 vty_out(vty, " neighbor %s timers %u %u\n", addr,
17277 peer->keepalive, peer->holdtime);
17278
17279 /* timers connect */
17280 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
17281 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17282 peer->connect);
5d5393b9
DL
17283 /* need special-case handling for changed default values due to
17284 * config profile / version (because there is no "timers bgp connect"
17285 * command, we need to save this per-peer :/)
17286 */
17287 else if (!peer_group_active(peer) && !peer->connect &&
17288 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
17289 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17290 peer->bgp->default_connect_retry);
dd65f45e 17291
d43114f3
DS
17292 /* timers delayopen */
17293 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
17294 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17295 peer->delayopen);
17296 /* Save config even though flag is not set if default values have been
17297 * changed
17298 */
17299 else if (!peer_group_active(peer) && !peer->delayopen
17300 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
17301 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17302 peer->bgp->default_delayopen);
17303
dd65f45e
DL
17304 /* capability dynamic */
17305 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
17306 vty_out(vty, " neighbor %s capability dynamic\n", addr);
17307
17308 /* capability extended-nexthop */
17309 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
8e89adc1
DS
17310 if (CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE) &&
17311 !peer->conf_if)
843770f6
DA
17312 vty_out(vty,
17313 " no neighbor %s capability extended-nexthop\n",
17314 addr);
17315 else if (!peer->conf_if)
17316 vty_out(vty,
17317 " neighbor %s capability extended-nexthop\n",
17318 addr);
dd65f45e
DL
17319 }
17320
17321 /* dont-capability-negotiation */
17322 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
17323 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
17324
17325 /* override-capability */
17326 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
17327 vty_out(vty, " neighbor %s override-capability\n", addr);
17328
17329 /* strict-capability-match */
17330 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
17331 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
17332
17333 /* Sender side AS path loop detection. */
17334 if (peer->as_path_loop_detection)
17335 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
17336 addr);
cfd47646 17337
17338 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 17339 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
cfd47646 17340
17341 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 17342 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
cfd47646 17343 vty_out(vty,
17344 " neighbor %s graceful-restart-helper\n", addr);
13909c4f
DS
17345 } else if (CHECK_FLAG(
17346 peer->peer_gr_new_status_flag,
17347 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
cfd47646 17348 vty_out(vty,
17349 " neighbor %s graceful-restart\n", addr);
13909c4f
DS
17350 } else if (
17351 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
17352 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
17353 && !(CHECK_FLAG(
17354 peer->peer_gr_new_status_flag,
17355 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
17356 vty_out(vty, " neighbor %s graceful-restart-disable\n",
17357 addr);
cfd47646 17358 }
17359 }
dd65f45e
DL
17360}
17361
17362/* BGP peer configuration display function. */
17363static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
17364 struct peer *peer, afi_t afi, safi_t safi)
17365{
17366 struct peer *g_peer = NULL;
17367 char *addr;
17368 bool flag_scomm, flag_secomm, flag_slcomm;
17369
17370 /* Skip dynamic neighbors. */
17371 if (peer_dynamic_neighbor(peer))
17372 return;
17373
17374 if (peer->conf_if)
17375 addr = peer->conf_if;
17376 else
17377 addr = peer->host;
17378
17379 /************************************
17380 ****** Per AF to the neighbor ******
17381 ************************************/
17382 if (peer_group_active(peer)) {
17383 g_peer = peer->group->conf;
17384
17385 /* If the peer-group is active but peer is not, print a 'no
17386 * activate' */
17387 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
17388 vty_out(vty, " no neighbor %s activate\n", addr);
17389 }
17390
17391 /* If the peer-group is not active but peer is, print an
17392 'activate' */
17393 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
17394 vty_out(vty, " neighbor %s activate\n", addr);
17395 }
17396 } else {
17397 if (peer->afc[afi][safi]) {
38d11af5
TA
17398 if (safi == SAFI_ENCAP)
17399 vty_out(vty, " neighbor %s activate\n", addr);
17400 else if (!bgp->default_af[afi][safi])
dd65f45e
DL
17401 vty_out(vty, " neighbor %s activate\n", addr);
17402 } else {
38d11af5
TA
17403 if (bgp->default_af[afi][safi])
17404 vty_out(vty, " no neighbor %s activate\n",
17405 addr);
dd65f45e
DL
17406 }
17407 }
17408
17409 /* addpath TX knobs */
17410 if (peergroup_af_addpath_check(peer, afi, safi)) {
17411 switch (peer->addpath_type[afi][safi]) {
17412 case BGP_ADDPATH_ALL:
17413 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
17414 addr);
17415 break;
17416 case BGP_ADDPATH_BEST_PER_AS:
17417 vty_out(vty,
17418 " neighbor %s addpath-tx-bestpath-per-AS\n",
17419 addr);
17420 break;
17421 case BGP_ADDPATH_MAX:
17422 case BGP_ADDPATH_NONE:
17423 break;
17424 }
17425 }
17426
7c0e4312
DA
17427 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DISABLE_ADDPATH_RX))
17428 vty_out(vty, " neighbor %s disable-addpath-rx\n", addr);
17429
dd65f45e
DL
17430 /* ORF capability. */
17431 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
17432 || peergroup_af_flag_check(peer, afi, safi,
17433 PEER_FLAG_ORF_PREFIX_RM)) {
17434 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
17435
17436 if (peergroup_af_flag_check(peer, afi, safi,
17437 PEER_FLAG_ORF_PREFIX_SM)
17438 && peergroup_af_flag_check(peer, afi, safi,
17439 PEER_FLAG_ORF_PREFIX_RM))
17440 vty_out(vty, " both");
17441 else if (peergroup_af_flag_check(peer, afi, safi,
17442 PEER_FLAG_ORF_PREFIX_SM))
17443 vty_out(vty, " send");
17444 else
17445 vty_out(vty, " receive");
17446 vty_out(vty, "\n");
17447 }
17448
dd65f45e
DL
17449 /* Route reflector client. */
17450 if (peergroup_af_flag_check(peer, afi, safi,
17451 PEER_FLAG_REFLECTOR_CLIENT)) {
17452 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
17453 }
17454
17455 /* next-hop-self force */
17456 if (peergroup_af_flag_check(peer, afi, safi,
17457 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
17458 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
17459 }
17460
17461 /* next-hop-self */
17462 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
17463 vty_out(vty, " neighbor %s next-hop-self\n", addr);
17464 }
17465
17466 /* remove-private-AS */
17467 if (peergroup_af_flag_check(peer, afi, safi,
17468 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
17469 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
17470 addr);
17471 }
17472
17473 else if (peergroup_af_flag_check(peer, afi, safi,
17474 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
17475 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
17476 addr);
17477 }
17478
17479 else if (peergroup_af_flag_check(peer, afi, safi,
17480 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
17481 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
17482 }
17483
17484 else if (peergroup_af_flag_check(peer, afi, safi,
17485 PEER_FLAG_REMOVE_PRIVATE_AS)) {
17486 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
17487 }
17488
17489 /* as-override */
17490 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
17491 vty_out(vty, " neighbor %s as-override\n", addr);
17492 }
17493
17494 /* send-community print. */
17495 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
17496 PEER_FLAG_SEND_COMMUNITY);
17497 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
17498 PEER_FLAG_SEND_EXT_COMMUNITY);
17499 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
17500 PEER_FLAG_SEND_LARGE_COMMUNITY);
17501
17502 if (flag_scomm && flag_secomm && flag_slcomm) {
17503 vty_out(vty, " no neighbor %s send-community all\n", addr);
17504 } else {
17505 if (flag_scomm)
17506 vty_out(vty, " no neighbor %s send-community\n", addr);
17507 if (flag_secomm)
17508 vty_out(vty,
17509 " no neighbor %s send-community extended\n",
17510 addr);
17511
17512 if (flag_slcomm)
17513 vty_out(vty, " no neighbor %s send-community large\n",
17514 addr);
17515 }
17516
17517 /* Default information */
17518 if (peergroup_af_flag_check(peer, afi, safi,
17519 PEER_FLAG_DEFAULT_ORIGINATE)) {
17520 vty_out(vty, " neighbor %s default-originate", addr);
17521
17522 if (peer->default_rmap[afi][safi].name)
17523 vty_out(vty, " route-map %s",
17524 peer->default_rmap[afi][safi].name);
17525
17526 vty_out(vty, "\n");
17527 }
17528
17529 /* Soft reconfiguration inbound. */
17530 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
17531 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
17532 addr);
17533 }
17534
17535 /* maximum-prefix. */
17536 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
6cde4b45 17537 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
dd65f45e
DL
17538 peer->pmax[afi][safi]);
17539
17540 if (peer->pmax_threshold[afi][safi]
17541 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
17542 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
17543 if (peer_af_flag_check(peer, afi, safi,
17544 PEER_FLAG_MAX_PREFIX_WARNING))
17545 vty_out(vty, " warning-only");
17546 if (peer->pmax_restart[afi][safi])
17547 vty_out(vty, " restart %u",
17548 peer->pmax_restart[afi][safi]);
9cbd06e0
DA
17549 if (peer_af_flag_check(peer, afi, safi,
17550 PEER_FLAG_MAX_PREFIX_FORCE))
17551 vty_out(vty, " force");
dd65f45e
DL
17552
17553 vty_out(vty, "\n");
17554 }
17555
fde246e8
DA
17556 /* maximum-prefix-out */
17557 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
6cde4b45 17558 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
fde246e8
DA
17559 addr, peer->pmax_out[afi][safi]);
17560
dd65f45e
DL
17561 /* Route server client. */
17562 if (peergroup_af_flag_check(peer, afi, safi,
17563 PEER_FLAG_RSERVER_CLIENT)) {
17564 vty_out(vty, " neighbor %s route-server-client\n", addr);
17565 }
17566
17567 /* Nexthop-local unchanged. */
17568 if (peergroup_af_flag_check(peer, afi, safi,
17569 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
17570 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
17571 }
17572
17573 /* allowas-in <1-10> */
17574 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
17575 if (peer_af_flag_check(peer, afi, safi,
17576 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
17577 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
17578 } else if (peer->allowas_in[afi][safi] == 3) {
17579 vty_out(vty, " neighbor %s allowas-in\n", addr);
17580 } else {
17581 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
17582 peer->allowas_in[afi][safi]);
17583 }
17584 }
17585
46dbf9d0
DA
17586 /* accept-own */
17587 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ACCEPT_OWN))
17588 vty_out(vty, " neighbor %s accept-own\n", addr);
17589
01da2d26
DA
17590 /* soo */
17591 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOO)) {
17592 char *soo_str = ecommunity_ecom2str(
17593 peer->soo[afi][safi], ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
17594
17595 vty_out(vty, " neighbor %s soo %s\n", addr, soo_str);
17596 XFREE(MTYPE_ECOMMUNITY_STR, soo_str);
17597 }
17598
dd65f45e
DL
17599 /* weight */
17600 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
17601 vty_out(vty, " neighbor %s weight %lu\n", addr,
17602 peer->weight[afi][safi]);
17603
17604 /* Filter. */
17605 bgp_config_write_filter(vty, peer, afi, safi);
17606
17607 /* atribute-unchanged. */
17608 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
17609 || (safi != SAFI_EVPN
17610 && peer_af_flag_check(peer, afi, safi,
17611 PEER_FLAG_NEXTHOP_UNCHANGED))
17612 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
17613
17614 if (!peer_group_active(peer)
17615 || peergroup_af_flag_check(peer, afi, safi,
17616 PEER_FLAG_AS_PATH_UNCHANGED)
17617 || peergroup_af_flag_check(peer, afi, safi,
17618 PEER_FLAG_NEXTHOP_UNCHANGED)
17619 || peergroup_af_flag_check(peer, afi, safi,
17620 PEER_FLAG_MED_UNCHANGED)) {
17621
17622 vty_out(vty,
17623 " neighbor %s attribute-unchanged%s%s%s\n",
17624 addr,
17625 peer_af_flag_check(peer, afi, safi,
17626 PEER_FLAG_AS_PATH_UNCHANGED)
17627 ? " as-path"
17628 : "",
17629 peer_af_flag_check(peer, afi, safi,
17630 PEER_FLAG_NEXTHOP_UNCHANGED)
17631 ? " next-hop"
17632 : "",
17633 peer_af_flag_check(peer, afi, safi,
17634 PEER_FLAG_MED_UNCHANGED)
17635 ? " med"
17636 : "");
17637 }
17638 }
70cd87ca
MK
17639
17640 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_ORR_GROUP))
17641 vty_out(vty, " neighbor %s optimal-route-reflection %s\n",
5fcf01c9 17642 addr, peer->orr_group_name[afi][safi]);
dd65f45e
DL
17643}
17644
a486300b
PG
17645static void bgp_vpn_config_write(struct vty *vty, struct bgp *bgp, afi_t afi,
17646 safi_t safi)
17647{
17648 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
17649 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL))
17650 vty_out(vty, " no bgp retain route-target all\n");
17651}
17652
dd65f45e
DL
17653/* Address family based peer configuration display. */
17654static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
17655 safi_t safi)
17656{
17657 struct peer *peer;
17658 struct peer_group *group;
17659 struct listnode *node, *nnode;
17660
17661
17662 vty_frame(vty, " !\n address-family ");
17663 if (afi == AFI_IP) {
17664 if (safi == SAFI_UNICAST)
17665 vty_frame(vty, "ipv4 unicast");
17666 else if (safi == SAFI_LABELED_UNICAST)
17667 vty_frame(vty, "ipv4 labeled-unicast");
17668 else if (safi == SAFI_MULTICAST)
17669 vty_frame(vty, "ipv4 multicast");
17670 else if (safi == SAFI_MPLS_VPN)
17671 vty_frame(vty, "ipv4 vpn");
17672 else if (safi == SAFI_ENCAP)
17673 vty_frame(vty, "ipv4 encap");
17674 else if (safi == SAFI_FLOWSPEC)
17675 vty_frame(vty, "ipv4 flowspec");
17676 } else if (afi == AFI_IP6) {
17677 if (safi == SAFI_UNICAST)
17678 vty_frame(vty, "ipv6 unicast");
17679 else if (safi == SAFI_LABELED_UNICAST)
17680 vty_frame(vty, "ipv6 labeled-unicast");
17681 else if (safi == SAFI_MULTICAST)
17682 vty_frame(vty, "ipv6 multicast");
17683 else if (safi == SAFI_MPLS_VPN)
17684 vty_frame(vty, "ipv6 vpn");
17685 else if (safi == SAFI_ENCAP)
17686 vty_frame(vty, "ipv6 encap");
17687 else if (safi == SAFI_FLOWSPEC)
17688 vty_frame(vty, "ipv6 flowspec");
17689 } else if (afi == AFI_L2VPN) {
17690 if (safi == SAFI_EVPN)
17691 vty_frame(vty, "l2vpn evpn");
17692 }
17693 vty_frame(vty, "\n");
17694
17695 bgp_config_write_distance(vty, bgp, afi, safi);
17696
17697 bgp_config_write_network(vty, bgp, afi, safi);
17698
17699 bgp_config_write_redistribute(vty, bgp, afi, safi);
17700
8a4e7fe6
DA
17701 /* BGP flag dampening. */
17702 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
6c75f4b3 17703 bgp_config_write_damp(vty, afi, safi);
8a4e7fe6 17704
dd65f45e
DL
17705 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
17706 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
17707
17708 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dd65f45e
DL
17709 /* Do not display doppelganger peers */
17710 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17711 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
17712 }
17713
17714 bgp_config_write_maxpaths(vty, bgp, afi, safi);
17715 bgp_config_write_table_map(vty, bgp, afi, safi);
17716
17717 if (safi == SAFI_EVPN)
17718 bgp_config_write_evpn_info(vty, bgp, afi, safi);
17719
17720 if (safi == SAFI_FLOWSPEC)
17721 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
17722
a486300b
PG
17723 if (safi == SAFI_MPLS_VPN)
17724 bgp_vpn_config_write(vty, bgp, afi, safi);
17725
dd65f45e
DL
17726 if (safi == SAFI_UNICAST) {
17727 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
17728 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17729 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
17730
17731 vty_out(vty, " export vpn\n");
17732 }
17733 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17734 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
17735
17736 vty_out(vty, " import vpn\n");
17737 }
17738 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17739 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
17740 char *name;
17741
17742 for (ALL_LIST_ELEMENTS_RO(
17743 bgp->vpn_policy[afi].import_vrf, node,
17744 name))
17745 vty_out(vty, " import vrf %s\n", name);
17746 }
17747 }
17748
70cd87ca
MK
17749 /* Optimal Route Reflection */
17750 bgp_config_write_orr(vty, bgp, afi, safi);
17751
dd65f45e
DL
17752 vty_endframe(vty, " exit-address-family\n");
17753}
17754
17755int bgp_config_write(struct vty *vty)
17756{
17757 struct bgp *bgp;
17758 struct peer_group *group;
17759 struct peer *peer;
17760 struct listnode *node, *nnode;
17761 struct listnode *mnode, *mnnode;
b16bcbba
TA
17762 afi_t afi;
17763 safi_t safi;
efc9b57d 17764 uint32_t tovpn_sid_index = 0;
dd65f45e
DL
17765
17766 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
17767 vty_out(vty, "bgp route-map delay-timer %u\n",
17768 bm->rmap_update_timer);
17769
d70583f7
D
17770 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
17771 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17772 if (bm->v_update_delay != bm->v_establish_wait)
17773 vty_out(vty, " %d", bm->v_establish_wait);
17774 vty_out(vty, "\n");
17775 }
17776
9acb67cb
DS
17777 if (bm->wait_for_fib)
17778 vty_out(vty, "bgp suppress-fib-pending\n");
17779
05bd726c 17780 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17781 vty_out(vty, "bgp graceful-shutdown\n");
17782
c163f297
DS
17783 /* No-RIB (Zebra) option flag configuration */
17784 if (bgp_option_check(BGP_OPT_NO_FIB))
17785 vty_out(vty, "bgp no-rib\n");
17786
870791a3
IR
17787 if (CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
17788 vty_out(vty, "bgp send-extra-data zebra\n");
e46723a5 17789
425bd64b
PS
17790 /* BGP session DSCP value */
17791 if (bm->tcp_dscp != IPTOS_PREC_INTERNETCONTROL)
17792 vty_out(vty, "bgp session-dscp %u\n", bm->tcp_dscp >> 2);
17793
a0b937de
SW
17794 /* BGP InQ limit */
17795 if (bm->inq_limit != BM_DEFAULT_INQ_LIMIT)
17796 vty_out(vty, "bgp input-queue-limit %u\n", bm->inq_limit);
17797
dd65f45e
DL
17798 /* BGP configuration. */
17799 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17800
17801 /* skip all auto created vrf as they dont have user config */
17802 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17803 continue;
17804
17805 /* Router bgp ASN */
17806 vty_out(vty, "router bgp %u", bgp->as);
17807
17808 if (bgp->name)
17809 vty_out(vty, " %s %s",
17810 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17811 ? "view" : "vrf", bgp->name);
17812 vty_out(vty, "\n");
17813
17814 /* BGP fast-external-failover. */
17815 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17816 vty_out(vty, " no bgp fast-external-failover\n");
17817
17818 /* BGP router ID. */
3a6290bd 17819 if (bgp->router_id_static.s_addr != INADDR_ANY)
23d0a753
DA
17820 vty_out(vty, " bgp router-id %pI4\n",
17821 &bgp->router_id_static);
dd65f45e 17822
c208c586
S
17823 /* Suppress fib pending */
17824 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17825 vty_out(vty, " bgp suppress-fib-pending\n");
17826
dd65f45e 17827 /* BGP log-neighbor-changes. */
892fedb6 17828 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
5d5393b9 17829 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
dd65f45e 17830 vty_out(vty, " %sbgp log-neighbor-changes\n",
892fedb6
DA
17831 CHECK_FLAG(bgp->flags,
17832 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
dd65f45e
DL
17833 ? ""
17834 : "no ");
17835
17836 /* BGP configuration. */
892fedb6 17837 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
dd65f45e
DL
17838 vty_out(vty, " bgp always-compare-med\n");
17839
17840 /* RFC8212 default eBGP policy. */
1d3fdccf
DA
17841 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17842 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17843 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17844 CHECK_FLAG(bgp->flags,
17845 BGP_FLAG_EBGP_REQUIRES_POLICY)
17846 ? ""
17847 : "no ");
dd65f45e
DL
17848
17849 /* draft-ietf-idr-deprecate-as-set-confed-set */
7f972cd8 17850 if (bgp->reject_as_sets)
dd65f45e
DL
17851 vty_out(vty, " bgp reject-as-sets\n");
17852
2adac256
DA
17853 /* Suppress duplicate updates if the route actually not changed
17854 */
17855 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17856 != SAVE_BGP_SUPPRESS_DUPLICATES)
17857 vty_out(vty, " %sbgp suppress-duplicates\n",
17858 CHECK_FLAG(bgp->flags,
17859 BGP_FLAG_SUPPRESS_DUPLICATES)
17860 ? ""
17861 : "no ");
17862
1ae314be
DA
17863 /* Send Hard Reset CEASE Notification for 'Administrative Reset'
17864 */
17865 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET) !=
17866 SAVE_BGP_HARD_ADMIN_RESET)
17867 vty_out(vty, " %sbgp hard-administrative-reset\n",
17868 CHECK_FLAG(bgp->flags,
17869 BGP_FLAG_HARD_ADMIN_RESET)
17870 ? ""
17871 : "no ");
17872
b16bcbba
TA
17873 /* BGP default <afi>-<safi> */
17874 FOREACH_AFI_SAFI (afi, safi) {
17875 if (afi == AFI_IP && safi == SAFI_UNICAST) {
17876 if (!bgp->default_af[afi][safi])
17877 vty_out(vty, " no bgp default %s\n",
17878 get_bgp_default_af_flag(afi,
17879 safi));
17880 } else if (bgp->default_af[afi][safi])
17881 vty_out(vty, " bgp default %s\n",
17882 get_bgp_default_af_flag(afi, safi));
17883 }
e84c59af 17884
dd65f45e
DL
17885 /* BGP default local-preference. */
17886 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17887 vty_out(vty, " bgp default local-preference %u\n",
17888 bgp->default_local_pref);
17889
17890 /* BGP default show-hostname */
892fedb6 17891 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
5d5393b9 17892 != SAVE_BGP_SHOW_HOSTNAME)
dd65f45e 17893 vty_out(vty, " %sbgp default show-hostname\n",
892fedb6 17894 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
dd65f45e
DL
17895 ? ""
17896 : "no ");
17897
aef999a2
DA
17898 /* BGP default show-nexthop-hostname */
17899 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17900 != SAVE_BGP_SHOW_HOSTNAME)
17901 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17902 CHECK_FLAG(bgp->flags,
17903 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17904 ? ""
17905 : "no ");
17906
dd65f45e
DL
17907 /* BGP default subgroup-pkt-queue-max. */
17908 if (bgp->default_subgroup_pkt_queue_max
17909 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
17910 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
17911 bgp->default_subgroup_pkt_queue_max);
17912
17913 /* BGP client-to-client reflection. */
892fedb6 17914 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
dd65f45e
DL
17915 vty_out(vty, " no bgp client-to-client reflection\n");
17916
17917 /* BGP cluster ID. */
17918 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
23d0a753
DA
17919 vty_out(vty, " bgp cluster-id %pI4\n",
17920 &bgp->cluster_id);
dd65f45e
DL
17921
17922 /* Disable ebgp connected nexthop check */
892fedb6 17923 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
dd65f45e
DL
17924 vty_out(vty,
17925 " bgp disable-ebgp-connected-route-check\n");
17926
17927 /* Confederation identifier*/
17928 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
17929 vty_out(vty, " bgp confederation identifier %u\n",
17930 bgp->confed_id);
17931
17932 /* Confederation peer */
17933 if (bgp->confed_peers_cnt > 0) {
17934 int i;
17935
17936 vty_out(vty, " bgp confederation peers");
17937
17938 for (i = 0; i < bgp->confed_peers_cnt; i++)
17939 vty_out(vty, " %u", bgp->confed_peers[i]);
17940
17941 vty_out(vty, "\n");
17942 }
17943
17944 /* BGP deterministic-med. */
892fedb6 17945 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
5d5393b9 17946 != SAVE_BGP_DETERMINISTIC_MED)
dd65f45e 17947 vty_out(vty, " %sbgp deterministic-med\n",
892fedb6
DA
17948 CHECK_FLAG(bgp->flags,
17949 BGP_FLAG_DETERMINISTIC_MED)
dd65f45e
DL
17950 ? ""
17951 : "no ");
17952
17953 /* BGP update-delay. */
17954 bgp_config_write_update_delay(vty, bgp);
17955
17956 if (bgp->v_maxmed_onstartup
17957 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
17958 vty_out(vty, " bgp max-med on-startup %u",
17959 bgp->v_maxmed_onstartup);
17960 if (bgp->maxmed_onstartup_value
17961 != BGP_MAXMED_VALUE_DEFAULT)
17962 vty_out(vty, " %u",
17963 bgp->maxmed_onstartup_value);
17964 vty_out(vty, "\n");
17965 }
17966 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
17967 vty_out(vty, " bgp max-med administrative");
17968 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
17969 vty_out(vty, " %u", bgp->maxmed_admin_value);
17970 vty_out(vty, "\n");
17971 }
17972
17973 /* write quanta */
17974 bgp_config_write_wpkt_quanta(vty, bgp);
17975 /* read quanta */
17976 bgp_config_write_rpkt_quanta(vty, bgp);
17977
17978 /* coalesce time */
17979 bgp_config_write_coalesce_time(vty, bgp);
17980
05bd726c 17981 /* BGP per-instance graceful-shutdown */
17982 /* BGP-wide settings and per-instance settings are mutually
17983 * exclusive.
17984 */
17985 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17986 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
17987 vty_out(vty, " bgp graceful-shutdown\n");
17988
8606be87
DA
17989 /* Long-lived Graceful Restart */
17990 if (bgp->llgr_stale_time != BGP_DEFAULT_LLGR_STALE_TIME)
17991 vty_out(vty,
17992 " bgp long-lived-graceful-restart stale-time %u\n",
17993 bgp->llgr_stale_time);
17994
dd65f45e
DL
17995 /* BGP graceful-restart. */
17996 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
17997 vty_out(vty,
17998 " bgp graceful-restart stalepath-time %u\n",
17999 bgp->stalepath_time);
cfd47646 18000
dd65f45e
DL
18001 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
18002 vty_out(vty, " bgp graceful-restart restart-time %u\n",
18003 bgp->restart_time);
cfd47646 18004
f2ca5c5b
DA
18005 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION) !=
18006 SAVE_BGP_GRACEFUL_NOTIFICATION)
18007 vty_out(vty, " %sbgp graceful-restart notification\n",
18008 CHECK_FLAG(bgp->flags,
18009 BGP_FLAG_GRACEFUL_NOTIFICATION)
18010 ? ""
18011 : "no ");
18012
cfd47646 18013 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
18014 vty_out(vty,
18015 " bgp graceful-restart select-defer-time %u\n",
18016 bgp->select_defer_time);
18017
18018 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
dd65f45e
DL
18019 vty_out(vty, " bgp graceful-restart\n");
18020
cfd47646 18021 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
18022 vty_out(vty, " bgp graceful-restart-disable\n");
18023
dd65f45e 18024 /* BGP graceful-restart Preserve State F bit. */
892fedb6 18025 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
dd65f45e
DL
18026 vty_out(vty,
18027 " bgp graceful-restart preserve-fw-state\n");
18028
d1adb448
PG
18029 /* BGP TCP keepalive */
18030 bgp_config_tcp_keepalive(vty, bgp);
18031
dc95985f 18032 /* Stale timer for RIB */
18033 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
18034 vty_out(vty,
18035 " bgp graceful-restart rib-stale-time %u\n",
18036 bgp->rib_stale_time);
18037
dd65f45e 18038 /* BGP bestpath method. */
892fedb6 18039 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
dd65f45e 18040 vty_out(vty, " bgp bestpath as-path ignore\n");
892fedb6 18041 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
dd65f45e
DL
18042 vty_out(vty, " bgp bestpath as-path confed\n");
18043
892fedb6
DA
18044 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
18045 if (CHECK_FLAG(bgp->flags,
18046 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
dd65f45e
DL
18047 vty_out(vty,
18048 " bgp bestpath as-path multipath-relax as-set\n");
18049 } else {
18050 vty_out(vty,
18051 " bgp bestpath as-path multipath-relax\n");
18052 }
18053 }
18054
892fedb6 18055 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
dd65f45e
DL
18056 vty_out(vty,
18057 " bgp route-reflector allow-outbound-policy\n");
18058 }
892fedb6 18059 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
dd65f45e 18060 vty_out(vty, " bgp bestpath compare-routerid\n");
97a52c82
DA
18061 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_AIGP))
18062 vty_out(vty, " bgp bestpath aigp\n");
892fedb6
DA
18063 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
18064 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
dd65f45e 18065 vty_out(vty, " bgp bestpath med");
892fedb6 18066 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
dd65f45e 18067 vty_out(vty, " confed");
892fedb6
DA
18068 if (CHECK_FLAG(bgp->flags,
18069 BGP_FLAG_MED_MISSING_AS_WORST))
dd65f45e
DL
18070 vty_out(vty, " missing-as-worst");
18071 vty_out(vty, "\n");
18072 }
18073
ee88563a
JM
18074 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
18075 vty_out(vty,
18076 " bgp bestpath peer-type multipath-relax\n");
18077
f7e1c681 18078 /* Link bandwidth handling. */
18079 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
18080 vty_out(vty, " bgp bestpath bandwidth ignore\n");
18081 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
18082 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
18083 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
18084 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
18085
dd65f45e 18086 /* BGP network import check. */
892fedb6 18087 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
5d5393b9 18088 != SAVE_BGP_IMPORT_CHECK)
dd65f45e 18089 vty_out(vty, " %sbgp network import-check\n",
892fedb6 18090 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
dd65f45e
DL
18091 ? ""
18092 : "no ");
18093
18094 /* BGP timers configuration. */
5d5393b9 18095 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
9800cfff 18096 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
dd65f45e
DL
18097 vty_out(vty, " timers bgp %u %u\n",
18098 bgp->default_keepalive, bgp->default_holdtime);
18099
b042667a
TI
18100 /* BGP minimum holdtime configuration. */
18101 if (bgp->default_min_holdtime != SAVE_BGP_HOLDTIME
18102 && bgp->default_min_holdtime != 0)
18103 vty_out(vty, " bgp minimum-holdtime %u\n",
18104 bgp->default_min_holdtime);
18105
389e4f92
QY
18106 /* Conditional advertisement timer configuration */
18107 if (bgp->condition_check_period
18108 != DEFAULT_CONDITIONAL_ROUTES_POLL_TIME)
18109 vty_out(vty,
18110 " bgp conditional-advertisement timer %u\n",
18111 bgp->condition_check_period);
18112
dd65f45e
DL
18113 /* peer-group */
18114 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
18115 bgp_config_write_peer_global(vty, bgp, group->conf);
18116 }
18117
18118 /* Normal neighbor configuration. */
18119 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
18120 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
18121 bgp_config_write_peer_global(vty, bgp, peer);
18122 }
18123
18124 /* listen range and limit for dynamic BGP neighbors */
18125 bgp_config_write_listen(vty, bgp);
18126
18127 /*
18128 * BGP default autoshutdown neighbors
18129 *
18130 * This must be placed after any peer and peer-group
18131 * configuration, to avoid setting all peers to shutdown after
18132 * a daemon restart, which is undesired behavior. (see #2286)
18133 */
18134 if (bgp->autoshutdown)
18135 vty_out(vty, " bgp default shutdown\n");
18136
9cf59432
DS
18137 /* BGP instance administrative shutdown */
18138 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
18139 vty_out(vty, " bgp shutdown\n");
18140
8666265e
DS
18141 if (bgp->allow_martian)
18142 vty_out(vty, " bgp allow-martian-nexthop\n");
18143
f852eb98
PG
18144 if (bgp->fast_convergence)
18145 vty_out(vty, " bgp fast-convergence\n");
18146
a0281b2e
HS
18147 if (bgp->srv6_enabled) {
18148 vty_frame(vty, " !\n segment-routing srv6\n");
96db4340 18149 if (strlen(bgp->srv6_locator_name))
a0281b2e
HS
18150 vty_out(vty, " locator %s\n",
18151 bgp->srv6_locator_name);
ff7c3ee1 18152 vty_endframe(vty, " exit\n");
a0281b2e
HS
18153 }
18154
efc9b57d
CS
18155 tovpn_sid_index = bgp->tovpn_sid_index;
18156 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)) {
18157 vty_out(vty, " sid vpn per-vrf export auto\n");
18158 } else if (tovpn_sid_index != 0) {
18159 vty_out(vty, " sid vpn per-vrf export %d\n",
18160 tovpn_sid_index);
18161 }
a0281b2e 18162
dd65f45e
DL
18163 /* IPv4 unicast configuration. */
18164 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
18165
18166 /* IPv4 multicast configuration. */
18167 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
18168
18169 /* IPv4 labeled-unicast configuration. */
18170 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
18171
18172 /* IPv4 VPN configuration. */
18173 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
18174
18175 /* ENCAPv4 configuration. */
18176 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
18177
18178 /* FLOWSPEC v4 configuration. */
18179 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
18180
18181 /* IPv6 unicast configuration. */
18182 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
18183
18184 /* IPv6 multicast configuration. */
18185 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
18186
18187 /* IPv6 labeled-unicast configuration. */
18188 bgp_config_write_family(vty, bgp, AFI_IP6,
18189 SAFI_LABELED_UNICAST);
18190
18191 /* IPv6 VPN configuration. */
18192 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
18193
18194 /* ENCAPv6 configuration. */
18195 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
18196
18197 /* FLOWSPEC v6 configuration. */
18198 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
18199
18200 /* EVPN configuration. */
18201 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
18202
18203 hook_call(bgp_inst_config_write, bgp, vty);
18204
49e5a4a0 18205#ifdef ENABLE_BGP_VNC
dd65f45e
DL
18206 bgp_rfapi_cfg_write(vty, bgp);
18207#endif
18208
07679ad9 18209 vty_out(vty, "exit\n");
dd65f45e
DL
18210 vty_out(vty, "!\n");
18211 }
18212 return 0;
18213}
18214
ddb5b488 18215
718e3744 18216/* BGP node structure. */
d62a17ae 18217static struct cmd_node bgp_node = {
f4b8291f 18218 .name = "bgp",
62b346ee 18219 .node = BGP_NODE,
24389580 18220 .parent_node = CONFIG_NODE,
62b346ee 18221 .prompt = "%s(config-router)# ",
612c2c15 18222 .config_write = bgp_config_write,
718e3744 18223};
18224
d62a17ae 18225static struct cmd_node bgp_ipv4_unicast_node = {
f4b8291f 18226 .name = "bgp ipv4 unicast",
62b346ee 18227 .node = BGP_IPV4_NODE,
24389580 18228 .parent_node = BGP_NODE,
62b346ee 18229 .prompt = "%s(config-router-af)# ",
dd2c81b8 18230 .no_xpath = true,
718e3744 18231};
18232
d62a17ae 18233static struct cmd_node bgp_ipv4_multicast_node = {
f4b8291f 18234 .name = "bgp ipv4 multicast",
62b346ee 18235 .node = BGP_IPV4M_NODE,
24389580 18236 .parent_node = BGP_NODE,
62b346ee 18237 .prompt = "%s(config-router-af)# ",
dd2c81b8 18238 .no_xpath = true,
718e3744 18239};
18240
d62a17ae 18241static struct cmd_node bgp_ipv4_labeled_unicast_node = {
f4b8291f 18242 .name = "bgp ipv4 labeled unicast",
62b346ee 18243 .node = BGP_IPV4L_NODE,
24389580 18244 .parent_node = BGP_NODE,
62b346ee 18245 .prompt = "%s(config-router-af)# ",
dd2c81b8 18246 .no_xpath = true,
f51bae9c
DS
18247};
18248
d62a17ae 18249static struct cmd_node bgp_ipv6_unicast_node = {
a17cfb3f 18250 .name = "bgp ipv6 unicast",
62b346ee 18251 .node = BGP_IPV6_NODE,
24389580 18252 .parent_node = BGP_NODE,
62b346ee 18253 .prompt = "%s(config-router-af)# ",
dd2c81b8 18254 .no_xpath = true,
718e3744 18255};
18256
d62a17ae 18257static struct cmd_node bgp_ipv6_multicast_node = {
f4b8291f 18258 .name = "bgp ipv6 multicast",
62b346ee 18259 .node = BGP_IPV6M_NODE,
24389580 18260 .parent_node = BGP_NODE,
62b346ee 18261 .prompt = "%s(config-router-af)# ",
dd2c81b8 18262 .no_xpath = true,
25ffbdc1 18263};
18264
d62a17ae 18265static struct cmd_node bgp_ipv6_labeled_unicast_node = {
f4b8291f 18266 .name = "bgp ipv6 labeled unicast",
62b346ee 18267 .node = BGP_IPV6L_NODE,
24389580 18268 .parent_node = BGP_NODE,
62b346ee 18269 .prompt = "%s(config-router-af)# ",
dd2c81b8 18270 .no_xpath = true,
f51bae9c
DS
18271};
18272
62b346ee 18273static struct cmd_node bgp_vpnv4_node = {
f4b8291f 18274 .name = "bgp vpnv4",
62b346ee 18275 .node = BGP_VPNV4_NODE,
24389580 18276 .parent_node = BGP_NODE,
62b346ee 18277 .prompt = "%s(config-router-af)# ",
dd2c81b8 18278 .no_xpath = true,
62b346ee 18279};
6b0655a2 18280
62b346ee 18281static struct cmd_node bgp_vpnv6_node = {
f4b8291f 18282 .name = "bgp vpnv6",
62b346ee 18283 .node = BGP_VPNV6_NODE,
24389580 18284 .parent_node = BGP_NODE,
62b346ee 18285 .prompt = "%s(config-router-af-vpnv6)# ",
dd2c81b8 18286 .no_xpath = true,
62b346ee 18287};
8ecd3266 18288
62b346ee 18289static struct cmd_node bgp_evpn_node = {
f4b8291f 18290 .name = "bgp evpn",
62b346ee 18291 .node = BGP_EVPN_NODE,
24389580 18292 .parent_node = BGP_NODE,
62b346ee 18293 .prompt = "%s(config-router-evpn)# ",
dd2c81b8 18294 .no_xpath = true,
62b346ee 18295};
4e0b7b6d 18296
62b346ee 18297static struct cmd_node bgp_evpn_vni_node = {
f4b8291f 18298 .name = "bgp evpn vni",
62b346ee 18299 .node = BGP_EVPN_VNI_NODE,
24389580 18300 .parent_node = BGP_EVPN_NODE,
62b346ee 18301 .prompt = "%s(config-router-af-vni)# ",
62b346ee 18302};
90e60aa7 18303
62b346ee 18304static struct cmd_node bgp_flowspecv4_node = {
f4b8291f 18305 .name = "bgp ipv4 flowspec",
62b346ee 18306 .node = BGP_FLOWSPECV4_NODE,
24389580 18307 .parent_node = BGP_NODE,
62b346ee 18308 .prompt = "%s(config-router-af)# ",
dd2c81b8 18309 .no_xpath = true,
62b346ee 18310};
7c40bf39 18311
62b346ee 18312static struct cmd_node bgp_flowspecv6_node = {
f4b8291f 18313 .name = "bgp ipv6 flowspec",
62b346ee 18314 .node = BGP_FLOWSPECV6_NODE,
24389580 18315 .parent_node = BGP_NODE,
62b346ee 18316 .prompt = "%s(config-router-af-vpnv6)# ",
dd2c81b8 18317 .no_xpath = true,
62b346ee 18318};
7c40bf39 18319
bfaab44d
HS
18320static struct cmd_node bgp_srv6_node = {
18321 .name = "bgp srv6",
18322 .node = BGP_SRV6_NODE,
18323 .parent_node = BGP_NODE,
18324 .prompt = "%s(config-router-srv6)# ",
18325};
18326
d62a17ae 18327static void community_list_vty(void);
1f8ae70b 18328
8c20061f
DA
18329static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
18330{
18331 struct bgp *bgp;
18332 struct peer_group *group;
18333 struct listnode *lnbgp, *lnpeer;
18334
18335 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18336 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
18337 vector_set(comps,
18338 XSTRDUP(MTYPE_COMPLETION, group->name));
18339 }
18340}
18341
18342static void bgp_ac_peer(vector comps, struct cmd_token *token)
b8a815e5 18343{
d62a17ae 18344 struct bgp *bgp;
18345 struct peer *peer;
d62a17ae 18346 struct listnode *lnbgp, *lnpeer;
b8a815e5 18347
d62a17ae 18348 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18349 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
18350 /* only provide suggestions on the appropriate input
18351 * token type,
18352 * they'll otherwise show up multiple times */
18353 enum cmd_token_type match_type;
18354 char *name = peer->host;
d48ed3e0 18355
d62a17ae 18356 if (peer->conf_if) {
18357 match_type = VARIABLE_TKN;
18358 name = peer->conf_if;
18359 } else if (strchr(peer->host, ':'))
18360 match_type = IPV6_TKN;
18361 else
18362 match_type = IPV4_TKN;
d48ed3e0 18363
d62a17ae 18364 if (token->type != match_type)
18365 continue;
d48ed3e0 18366
d62a17ae 18367 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
18368 }
d62a17ae 18369 }
b8a815e5
DL
18370}
18371
8c20061f
DA
18372static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
18373{
18374 bgp_ac_peer(comps, token);
84de1483
DA
18375
18376 if (token->type == VARIABLE_TKN)
18377 bgp_ac_peergroup(comps, token);
8c20061f
DA
18378}
18379
b8a815e5 18380static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 18381 {.varname = "neighbor", .completions = bgp_ac_neighbor},
18382 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 18383 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 18384 {.completions = NULL}};
18385
47a306a0
DS
18386static const struct cmd_variable_handler bgp_var_peergroup[] = {
18387 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
18388 {.completions = NULL} };
18389
aa24a36a
DA
18390DEFINE_HOOK(bgp_config_end, (struct bgp *bgp), (bgp));
18391
18392static struct thread *t_bgp_cfg;
18393
18394bool bgp_config_inprocess(void)
18395{
18396 return thread_is_scheduled(t_bgp_cfg);
18397}
18398
18399static void bgp_config_finish(struct thread *t)
18400{
18401 struct listnode *node;
18402 struct bgp *bgp;
18403
18404 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp))
18405 hook_call(bgp_config_end, bgp);
18406}
18407
18408static void bgp_config_start(void)
18409{
18410#define BGP_PRE_CONFIG_MAX_WAIT_SECONDS 600
18411 THREAD_OFF(t_bgp_cfg);
18412 thread_add_timer(bm->master, bgp_config_finish, NULL,
18413 BGP_PRE_CONFIG_MAX_WAIT_SECONDS, &t_bgp_cfg);
18414}
18415
18416/* When we receive a hook the configuration is read,
18417 * we start a timer to make sure we postpone sending
18418 * EoR before route-maps are processed.
18419 * This is especially valid if using `bgp route-map delay-timer`.
18420 */
18421static void bgp_config_end(void)
18422{
18423#define BGP_POST_CONFIG_DELAY_SECONDS 1
18424 uint32_t bgp_post_config_delay =
18425 thread_is_scheduled(bm->t_rmap_update)
18426 ? thread_timer_remain_second(bm->t_rmap_update)
18427 : BGP_POST_CONFIG_DELAY_SECONDS;
18428
18429 /* If BGP config processing thread isn't running, then
18430 * we can return and rely it's properly handled.
18431 */
18432 if (!bgp_config_inprocess())
18433 return;
18434
18435 THREAD_OFF(t_bgp_cfg);
18436
18437 /* Start a new timer to make sure we don't send EoR
18438 * before route-maps are processed.
18439 */
18440 thread_add_timer(bm->master, bgp_config_finish, NULL,
18441 bgp_post_config_delay, &t_bgp_cfg);
18442}
18443
4cd690ae
PG
18444static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
18445{
18446 int write = 0;
18447 struct interface *ifp;
18448 struct bgp_interface *iifp;
18449
18450 FOR_ALL_INTERFACES (vrf, ifp) {
18451 iifp = ifp->info;
18452 if (!iifp)
18453 continue;
18454
18455 if_vty_config_start(vty, ifp);
18456
18457 if (CHECK_FLAG(iifp->flags,
18458 BGP_INTERFACE_MPLS_BGP_FORWARDING)) {
18459 vty_out(vty, " mpls bgp forwarding\n");
18460 write++;
18461 }
18462
18463 if_vty_config_end(vty);
18464 }
18465
18466 return write;
18467}
18468
18469/* Configuration write function for bgpd. */
18470static int config_write_interface(struct vty *vty)
18471{
18472 int write = 0;
18473 struct vrf *vrf = NULL;
18474
18475 /* Display all VRF aware OSPF interface configuration */
18476 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
18477 write += config_write_interface_one(vty, vrf);
18478 }
18479
18480 return write;
18481}
18482
18483DEFPY(mpls_bgp_forwarding, mpls_bgp_forwarding_cmd,
18484 "[no$no] mpls bgp forwarding",
18485 NO_STR MPLS_STR BGP_STR
18486 "Enable MPLS forwarding for eBGP directly connected peers\n")
18487{
18488 bool check;
18489 struct bgp_interface *iifp;
18490
18491 VTY_DECLVAR_CONTEXT(interface, ifp);
18492 iifp = ifp->info;
18493 if (!iifp) {
18494 vty_out(vty, "Interface %s not available\n", ifp->name);
18495 return CMD_WARNING_CONFIG_FAILED;
18496 }
18497 check = CHECK_FLAG(iifp->flags, BGP_INTERFACE_MPLS_BGP_FORWARDING);
18498 if (check != !no) {
18499 if (no)
18500 UNSET_FLAG(iifp->flags,
18501 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18502 else
18503 SET_FLAG(iifp->flags,
18504 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18505 /* trigger a nht update on eBGP sessions */
18506 if (if_is_operative(ifp))
18507 bgp_nht_ifp_up(ifp);
18508 }
18509 return CMD_SUCCESS;
18510}
18511
a0b937de
SW
18512DEFPY (bgp_inq_limit,
18513 bgp_inq_limit_cmd,
18514 "bgp input-queue-limit (1-4294967295)$limit",
18515 BGP_STR
18516 "Set the BGP Input Queue limit for all peers when message parsing\n"
18517 "Input-Queue limit\n")
18518{
18519 bm->inq_limit = limit;
18520
18521 return CMD_SUCCESS;
18522}
18523
18524DEFPY (no_bgp_inq_limit,
18525 no_bgp_inq_limit_cmd,
18526 "no bgp input-queue-limit [(1-4294967295)$limit]",
18527 NO_STR
18528 BGP_STR
18529 "Set the BGP Input Queue limit for all peers when message parsing\n"
18530 "Input-Queue limit\n")
18531{
18532 bm->inq_limit = BM_DEFAULT_INQ_LIMIT;
18533
18534 return CMD_SUCCESS;
18535}
18536
4cd690ae
PG
18537/* Initialization of BGP interface. */
18538static void bgp_vty_if_init(void)
18539{
18540 /* Install interface node. */
18541 if_cmd_init(config_write_interface);
18542
18543 /* "mpls bgp forwarding" commands. */
18544 install_element(INTERFACE_NODE, &mpls_bgp_forwarding_cmd);
18545}
18546
d62a17ae 18547void bgp_vty_init(void)
18548{
18549 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 18550 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 18551
aa24a36a
DA
18552 cmd_init_config_callbacks(bgp_config_start, bgp_config_end);
18553
d62a17ae 18554 /* Install bgp top node. */
612c2c15
DL
18555 install_node(&bgp_node);
18556 install_node(&bgp_ipv4_unicast_node);
18557 install_node(&bgp_ipv4_multicast_node);
18558 install_node(&bgp_ipv4_labeled_unicast_node);
18559 install_node(&bgp_ipv6_unicast_node);
18560 install_node(&bgp_ipv6_multicast_node);
18561 install_node(&bgp_ipv6_labeled_unicast_node);
18562 install_node(&bgp_vpnv4_node);
18563 install_node(&bgp_vpnv6_node);
18564 install_node(&bgp_evpn_node);
18565 install_node(&bgp_evpn_vni_node);
18566 install_node(&bgp_flowspecv4_node);
18567 install_node(&bgp_flowspecv6_node);
bfaab44d 18568 install_node(&bgp_srv6_node);
d62a17ae 18569
18570 /* Install default VTY commands to new nodes. */
18571 install_default(BGP_NODE);
18572 install_default(BGP_IPV4_NODE);
18573 install_default(BGP_IPV4M_NODE);
18574 install_default(BGP_IPV4L_NODE);
18575 install_default(BGP_IPV6_NODE);
18576 install_default(BGP_IPV6M_NODE);
18577 install_default(BGP_IPV6L_NODE);
18578 install_default(BGP_VPNV4_NODE);
18579 install_default(BGP_VPNV6_NODE);
7c40bf39 18580 install_default(BGP_FLOWSPECV4_NODE);
18581 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 18582 install_default(BGP_EVPN_NODE);
18583 install_default(BGP_EVPN_VNI_NODE);
bfaab44d 18584 install_default(BGP_SRV6_NODE);
d62a17ae 18585
a0b937de
SW
18586 /* "global bgp inq-limit command */
18587 install_element(CONFIG_NODE, &bgp_inq_limit_cmd);
18588 install_element(CONFIG_NODE, &no_bgp_inq_limit_cmd);
18589
8029b216
AK
18590 /* "bgp local-mac" hidden commands. */
18591 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
18592 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
18593
9acb67cb
DS
18594 /* "bgp suppress-fib-pending" global */
18595 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
18596
d62a17ae 18597 /* bgp route-map delay-timer commands. */
18598 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
18599 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18600
8666265e
DS
18601 install_element(BGP_NODE, &bgp_allow_martian_cmd);
18602
f852eb98
PG
18603 /* bgp fast-convergence command */
18604 install_element(BGP_NODE, &bgp_fast_convergence_cmd);
18605 install_element(BGP_NODE, &no_bgp_fast_convergence_cmd);
18606
d70583f7
D
18607 /* global bgp update-delay command */
18608 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
18609 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
18610
05bd726c 18611 /* global bgp graceful-shutdown command */
18612 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
18613 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
18614
d62a17ae 18615 /* Dummy commands (Currently not supported) */
18616 install_element(BGP_NODE, &no_synchronization_cmd);
18617 install_element(BGP_NODE, &no_auto_summary_cmd);
18618
18619 /* "router bgp" commands. */
18620 install_element(CONFIG_NODE, &router_bgp_cmd);
18621
18622 /* "no router bgp" commands. */
18623 install_element(CONFIG_NODE, &no_router_bgp_cmd);
18624
425bd64b
PS
18625 /* "bgp session-dscp command */
18626 install_element(CONFIG_NODE, &bgp_session_dscp_cmd);
18627 install_element(CONFIG_NODE, &no_bgp_session_dscp_cmd);
18628
d62a17ae 18629 /* "bgp router-id" commands. */
18630 install_element(BGP_NODE, &bgp_router_id_cmd);
18631 install_element(BGP_NODE, &no_bgp_router_id_cmd);
18632
c208c586
S
18633 /* "bgp suppress-fib-pending" command */
18634 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
18635
d62a17ae 18636 /* "bgp cluster-id" commands. */
18637 install_element(BGP_NODE, &bgp_cluster_id_cmd);
18638 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
18639
c163f297
DS
18640 /* "bgp no-rib" commands. */
18641 install_element(CONFIG_NODE, &bgp_norib_cmd);
18642 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
18643
e46723a5
DS
18644 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
18645
d62a17ae 18646 /* "bgp confederation" commands. */
18647 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
18648 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
18649
18650 /* "bgp confederation peers" commands. */
18651 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
18652 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
18653
18654 /* bgp max-med command */
18655 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
18656 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
18657 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
18658 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
18659 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
18660
d864dd9e
EB
18661 /* "neighbor role" commands. */
18662 install_element(BGP_NODE, &neighbor_role_cmd);
18663 install_element(BGP_NODE, &neighbor_role_strict_cmd);
18664 install_element(BGP_NODE, &no_neighbor_role_cmd);
18665
97a52c82
DA
18666 /* "neighbor aigp" commands. */
18667 install_element(BGP_NODE, &neighbor_aigp_cmd);
18668
d62a17ae 18669 /* bgp disable-ebgp-connected-nh-check */
18670 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
18671 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
18672
18673 /* bgp update-delay command */
18674 install_element(BGP_NODE, &bgp_update_delay_cmd);
18675 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
d62a17ae 18676
18677 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
555e09d4 18678 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
d62a17ae 18679
18680 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
18681 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
18682
18683 /* "maximum-paths" commands. */
18684 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
18685 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
18686 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
18687 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
18688 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
18689 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
18690 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
18691 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
18692 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
18693 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
18694 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18695 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
18696 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
18697 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18698 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
18699
39edabac
PG
18700 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
18701 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
18702 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
18703 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18704 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
d62a17ae 18705 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
18706 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
18707 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
18708 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18709 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18710
18711 /* "timers bgp" commands. */
18712 install_element(BGP_NODE, &bgp_timers_cmd);
18713 install_element(BGP_NODE, &no_bgp_timers_cmd);
18714
b042667a
TI
18715 /* "minimum-holdtime" commands. */
18716 install_element(BGP_NODE, &bgp_minimum_holdtime_cmd);
18717 install_element(BGP_NODE, &no_bgp_minimum_holdtime_cmd);
18718
d62a17ae 18719 /* route-map delay-timer commands - per instance for backwards compat.
18720 */
18721 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
18722 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18723
18724 /* "bgp client-to-client reflection" commands */
18725 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
18726 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
18727
18728 /* "bgp always-compare-med" commands */
18729 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
18730 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
18731
9dac9fc8
DA
18732 /* bgp ebgp-requires-policy */
18733 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
18734 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
18735
2adac256
DA
18736 /* bgp suppress-duplicates */
18737 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
18738 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
18739
fb29348a
DA
18740 /* bgp reject-as-sets */
18741 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
18742 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
18743
d62a17ae 18744 /* "bgp deterministic-med" commands */
18745 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
18746 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
18747
055679e9 18748 /* "bgp graceful-restart" command */
36235319
QY
18749 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
18750 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
055679e9 18751
18752 /* "bgp graceful-restart-disable" command */
36235319
QY
18753 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
18754 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
055679e9 18755
18756 /* "neighbor a:b:c:d graceful-restart" command */
36235319
QY
18757 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
18758 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
055679e9 18759
18760 /* "neighbor a:b:c:d graceful-restart-disable" command */
18761 install_element(BGP_NODE,
18762 &bgp_neighbor_graceful_restart_disable_set_cmd);
18763 install_element(BGP_NODE,
18764 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
18765
18766 /* "neighbor a:b:c:d graceful-restart-helper" command */
18767 install_element(BGP_NODE,
18768 &bgp_neighbor_graceful_restart_helper_set_cmd);
18769 install_element(BGP_NODE,
18770 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
18771
d62a17ae 18772 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
18773 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
18774 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
18775 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
cfd47646 18776 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
f009ff26 18777 install_element(BGP_NODE,
18778 &no_bgp_graceful_restart_select_defer_time_cmd);
d62a17ae 18779 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
18780 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
f2ca5c5b 18781 install_element(BGP_NODE, &bgp_graceful_restart_notification_cmd);
d62a17ae 18782
d6e3c15b 18783 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
18784 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
dc95985f 18785 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
18786 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
d6e3c15b 18787
a0b937de
SW
18788 /* "bgp inq-limit command */
18789 install_element(BGP_NODE, &bgp_inq_limit_cmd);
18790 install_element(BGP_NODE, &no_bgp_inq_limit_cmd);
18791
7f323236
DW
18792 /* "bgp graceful-shutdown" commands */
18793 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
18794 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
18795
1ae314be
DA
18796 /* "bgp hard-administrative-reset" commands */
18797 install_element(BGP_NODE, &bgp_administrative_reset_cmd);
18798
8606be87
DA
18799 /* "bgp long-lived-graceful-restart" commands */
18800 install_element(BGP_NODE, &bgp_llgr_stalepath_time_cmd);
18801 install_element(BGP_NODE, &no_bgp_llgr_stalepath_time_cmd);
18802
d62a17ae 18803 /* "bgp fast-external-failover" commands */
18804 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
18805 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
18806
97a52c82
DA
18807 /* "bgp bestpath aigp" commands */
18808 install_element(BGP_NODE, &bgp_bestpath_aigp_cmd);
18809
d62a17ae 18810 /* "bgp bestpath compare-routerid" commands */
18811 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
18812 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
18813
18814 /* "bgp bestpath as-path ignore" commands */
18815 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
18816 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
18817
18818 /* "bgp bestpath as-path confed" commands */
18819 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
18820 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
18821
18822 /* "bgp bestpath as-path multipath-relax" commands */
18823 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
18824 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
18825
ee88563a
JM
18826 /* "bgp bestpath peer-type multipath-relax" commands */
18827 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
18828 install_element(BGP_NODE,
18829 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
18830
d62a17ae 18831 /* "bgp log-neighbor-changes" commands */
18832 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
18833 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
18834
18835 /* "bgp bestpath med" commands */
18836 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
18837 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
18838
f7e1c681 18839 /* "bgp bestpath bandwidth" commands */
18840 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
ad36d216 18841 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
f7e1c681 18842
b16bcbba
TA
18843 /* "no bgp default <afi>-<safi>" commands. */
18844 install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
e84c59af 18845
d62a17ae 18846 /* "bgp network import-check" commands. */
18847 install_element(BGP_NODE, &bgp_network_import_check_cmd);
18848 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
18849 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
18850
18851 /* "bgp default local-preference" commands. */
18852 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
18853 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
18854
18855 /* bgp default show-hostname */
18856 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
18857 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
18858
aef999a2
DA
18859 /* bgp default show-nexthop-hostname */
18860 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
18861 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
18862
d62a17ae 18863 /* "bgp default subgroup-pkt-queue-max" commands. */
18864 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
18865 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
18866
18867 /* bgp ibgp-allow-policy-mods command */
18868 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
18869 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
18870
18871 /* "bgp listen limit" commands. */
18872 install_element(BGP_NODE, &bgp_listen_limit_cmd);
18873 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
18874
18875 /* "bgp listen range" commands. */
18876 install_element(BGP_NODE, &bgp_listen_range_cmd);
18877 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
18878
8175f54a 18879 /* "bgp default shutdown" command */
f26845f9 18880 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
9cf59432
DS
18881
18882 /* "bgp shutdown" commands */
18883 install_element(BGP_NODE, &bgp_shutdown_cmd);
8389c83a 18884 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
9cf59432 18885 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
1b6e7a88 18886 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
f26845f9 18887
d62a17ae 18888 /* "neighbor remote-as" commands. */
18889 install_element(BGP_NODE, &neighbor_remote_as_cmd);
18890 install_element(BGP_NODE, &neighbor_interface_config_cmd);
18891 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
18892 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
18893 install_element(BGP_NODE,
18894 &neighbor_interface_v6only_config_remote_as_cmd);
18895 install_element(BGP_NODE, &no_neighbor_cmd);
18896 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
18897
18898 /* "neighbor peer-group" commands. */
18899 install_element(BGP_NODE, &neighbor_peer_group_cmd);
18900 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
18901 install_element(BGP_NODE,
18902 &no_neighbor_interface_peer_group_remote_as_cmd);
18903
18904 /* "neighbor local-as" commands. */
18905 install_element(BGP_NODE, &neighbor_local_as_cmd);
18906 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
18907 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
18908 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
18909
18910 /* "neighbor solo" commands. */
18911 install_element(BGP_NODE, &neighbor_solo_cmd);
18912 install_element(BGP_NODE, &no_neighbor_solo_cmd);
18913
18914 /* "neighbor password" commands. */
18915 install_element(BGP_NODE, &neighbor_password_cmd);
18916 install_element(BGP_NODE, &no_neighbor_password_cmd);
18917
18918 /* "neighbor activate" commands. */
18919 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
18920 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
18921 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
18922 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
18923 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
18924 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
18925 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
18926 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
18927 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 18928 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
18929 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 18930 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
18931
18932 /* "no neighbor activate" commands. */
18933 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
18934 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
18935 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
18936 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
18937 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
18938 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
18939 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
18940 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
18941 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 18942 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
18943 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 18944 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
18945
18946 /* "neighbor peer-group" set commands. */
18947 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
18948 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18949 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
18950 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18951 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
18952 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
18953 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18954 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 18955 install_element(BGP_FLOWSPECV4_NODE,
18956 &neighbor_set_peer_group_hidden_cmd);
18957 install_element(BGP_FLOWSPECV6_NODE,
18958 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 18959
18960 /* "no neighbor peer-group unset" commands. */
18961 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
18962 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18963 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18964 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18965 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18966 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18967 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18968 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 18969 install_element(BGP_FLOWSPECV4_NODE,
18970 &no_neighbor_set_peer_group_hidden_cmd);
18971 install_element(BGP_FLOWSPECV6_NODE,
18972 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 18973
18974 /* "neighbor softreconfiguration inbound" commands.*/
18975 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
18976 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
18977 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
18978 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18979 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
18980 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18981 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
18982 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18983 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
18984 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18985 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
18986 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18987 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
18988 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18989 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
18990 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18991 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
18992 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 18993 install_element(BGP_FLOWSPECV4_NODE,
18994 &neighbor_soft_reconfiguration_cmd);
18995 install_element(BGP_FLOWSPECV4_NODE,
18996 &no_neighbor_soft_reconfiguration_cmd);
18997 install_element(BGP_FLOWSPECV6_NODE,
18998 &neighbor_soft_reconfiguration_cmd);
18999 install_element(BGP_FLOWSPECV6_NODE,
19000 &no_neighbor_soft_reconfiguration_cmd);
616c6ee8
PG
19001 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
19002 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 19003
19004 /* "neighbor attribute-unchanged" commands. */
19005 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
19006 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
19007 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
19008 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
19009 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
19010 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
19011 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
19012 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
19013 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
19014 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
19015 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
19016 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
19017 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
19018 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
19019 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
19020 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
19021 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
19022 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
19023
19024 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
19025 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
19026
b8ad84d2
PG
19027 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
19028 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
19029 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
19030 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
19031
d62a17ae 19032 /* "nexthop-local unchanged" commands */
19033 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
19034 install_element(BGP_IPV6_NODE,
19035 &no_neighbor_nexthop_local_unchanged_cmd);
19036
19037 /* "neighbor next-hop-self" commands. */
19038 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
19039 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
19040 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
19041 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
19042 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
19043 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
19044 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
19045 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
19046 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
19047 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
19048 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
19049 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
19050 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
19051 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
19052 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
19053 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
19054 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
19055 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
19056 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
19057 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 19058
19059 /* "neighbor next-hop-self force" commands. */
19060 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
19061 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
1bc4e531
DA
19062 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19063 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19064 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
19065 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19066 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19067 install_element(BGP_IPV4_NODE,
19068 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19069 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
19070 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19071 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19072 install_element(BGP_IPV4M_NODE,
19073 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19074 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
19075 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19076 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19077 install_element(BGP_IPV4L_NODE,
19078 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19079 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
19080 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19081 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19082 install_element(BGP_IPV6_NODE,
19083 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19084 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
19085 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19086 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19087 install_element(BGP_IPV6M_NODE,
19088 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19089 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
19090 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19091 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19092 install_element(BGP_IPV6L_NODE,
19093 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19094 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
19095 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19096 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19097 install_element(BGP_VPNV4_NODE,
19098 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19099 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
19100 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19101 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19102 install_element(BGP_VPNV6_NODE,
19103 &no_neighbor_nexthop_self_all_hidden_cmd);
be7e1fa3
MS
19104 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
19105 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
d62a17ae 19106
19107 /* "neighbor as-override" commands. */
19108 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
19109 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
19110 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
19111 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
19112 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
19113 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
19114 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
19115 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
19116 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
19117 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
19118 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
19119 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
19120 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
19121 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
19122 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
19123 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
19124 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
19125 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
19126
19127 /* "neighbor remove-private-AS" commands. */
19128 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
19129 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
19130 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
19131 install_element(BGP_NODE,
19132 &no_neighbor_remove_private_as_all_hidden_cmd);
19133 install_element(BGP_NODE,
19134 &neighbor_remove_private_as_replace_as_hidden_cmd);
19135 install_element(BGP_NODE,
19136 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
19137 install_element(BGP_NODE,
19138 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
19139 install_element(
19140 BGP_NODE,
19141 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
19142 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
19143 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
19144 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
19145 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
19146 install_element(BGP_IPV4_NODE,
19147 &neighbor_remove_private_as_replace_as_cmd);
19148 install_element(BGP_IPV4_NODE,
19149 &no_neighbor_remove_private_as_replace_as_cmd);
19150 install_element(BGP_IPV4_NODE,
19151 &neighbor_remove_private_as_all_replace_as_cmd);
19152 install_element(BGP_IPV4_NODE,
19153 &no_neighbor_remove_private_as_all_replace_as_cmd);
19154 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
19155 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
19156 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
19157 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
19158 install_element(BGP_IPV4M_NODE,
19159 &neighbor_remove_private_as_replace_as_cmd);
19160 install_element(BGP_IPV4M_NODE,
19161 &no_neighbor_remove_private_as_replace_as_cmd);
19162 install_element(BGP_IPV4M_NODE,
19163 &neighbor_remove_private_as_all_replace_as_cmd);
19164 install_element(BGP_IPV4M_NODE,
19165 &no_neighbor_remove_private_as_all_replace_as_cmd);
19166 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
19167 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
19168 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
19169 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
19170 install_element(BGP_IPV4L_NODE,
19171 &neighbor_remove_private_as_replace_as_cmd);
19172 install_element(BGP_IPV4L_NODE,
19173 &no_neighbor_remove_private_as_replace_as_cmd);
19174 install_element(BGP_IPV4L_NODE,
19175 &neighbor_remove_private_as_all_replace_as_cmd);
19176 install_element(BGP_IPV4L_NODE,
19177 &no_neighbor_remove_private_as_all_replace_as_cmd);
19178 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
19179 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
19180 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
19181 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
19182 install_element(BGP_IPV6_NODE,
19183 &neighbor_remove_private_as_replace_as_cmd);
19184 install_element(BGP_IPV6_NODE,
19185 &no_neighbor_remove_private_as_replace_as_cmd);
19186 install_element(BGP_IPV6_NODE,
19187 &neighbor_remove_private_as_all_replace_as_cmd);
19188 install_element(BGP_IPV6_NODE,
19189 &no_neighbor_remove_private_as_all_replace_as_cmd);
19190 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
19191 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
19192 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
19193 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
19194 install_element(BGP_IPV6M_NODE,
19195 &neighbor_remove_private_as_replace_as_cmd);
19196 install_element(BGP_IPV6M_NODE,
19197 &no_neighbor_remove_private_as_replace_as_cmd);
19198 install_element(BGP_IPV6M_NODE,
19199 &neighbor_remove_private_as_all_replace_as_cmd);
19200 install_element(BGP_IPV6M_NODE,
19201 &no_neighbor_remove_private_as_all_replace_as_cmd);
19202 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
19203 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
19204 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
19205 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
19206 install_element(BGP_IPV6L_NODE,
19207 &neighbor_remove_private_as_replace_as_cmd);
19208 install_element(BGP_IPV6L_NODE,
19209 &no_neighbor_remove_private_as_replace_as_cmd);
19210 install_element(BGP_IPV6L_NODE,
19211 &neighbor_remove_private_as_all_replace_as_cmd);
19212 install_element(BGP_IPV6L_NODE,
19213 &no_neighbor_remove_private_as_all_replace_as_cmd);
19214 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
19215 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
19216 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
19217 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
19218 install_element(BGP_VPNV4_NODE,
19219 &neighbor_remove_private_as_replace_as_cmd);
19220 install_element(BGP_VPNV4_NODE,
19221 &no_neighbor_remove_private_as_replace_as_cmd);
19222 install_element(BGP_VPNV4_NODE,
19223 &neighbor_remove_private_as_all_replace_as_cmd);
19224 install_element(BGP_VPNV4_NODE,
19225 &no_neighbor_remove_private_as_all_replace_as_cmd);
19226 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
19227 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
19228 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
19229 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
19230 install_element(BGP_VPNV6_NODE,
19231 &neighbor_remove_private_as_replace_as_cmd);
19232 install_element(BGP_VPNV6_NODE,
19233 &no_neighbor_remove_private_as_replace_as_cmd);
19234 install_element(BGP_VPNV6_NODE,
19235 &neighbor_remove_private_as_all_replace_as_cmd);
19236 install_element(BGP_VPNV6_NODE,
19237 &no_neighbor_remove_private_as_all_replace_as_cmd);
19238
19239 /* "neighbor send-community" commands.*/
19240 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
19241 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
19242 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
19243 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
19244 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
19245 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
19246 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
19247 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
19248 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
19249 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
19250 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
19251 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
19252 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
19253 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
19254 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
19255 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
19256 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
19257 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
19258 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
19259 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
19260 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
19261 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
19262 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
19263 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
19264 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
19265 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
19266 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
19267 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
19268 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
19269 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
19270 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
19271 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
19272 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
19273 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
19274 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
19275 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
19276
19277 /* "neighbor route-reflector" commands.*/
19278 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
19279 install_element(BGP_NODE,
19280 &no_neighbor_route_reflector_client_hidden_cmd);
19281 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
19282 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
19283 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
19284 install_element(BGP_IPV4M_NODE,
19285 &no_neighbor_route_reflector_client_cmd);
19286 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
19287 install_element(BGP_IPV4L_NODE,
19288 &no_neighbor_route_reflector_client_cmd);
19289 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
19290 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
19291 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
19292 install_element(BGP_IPV6M_NODE,
19293 &no_neighbor_route_reflector_client_cmd);
19294 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
19295 install_element(BGP_IPV6L_NODE,
19296 &no_neighbor_route_reflector_client_cmd);
19297 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
19298 install_element(BGP_VPNV4_NODE,
19299 &no_neighbor_route_reflector_client_cmd);
19300 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
19301 install_element(BGP_VPNV6_NODE,
19302 &no_neighbor_route_reflector_client_cmd);
7c40bf39 19303 install_element(BGP_FLOWSPECV4_NODE,
19304 &neighbor_route_reflector_client_cmd);
19305 install_element(BGP_FLOWSPECV4_NODE,
19306 &no_neighbor_route_reflector_client_cmd);
19307 install_element(BGP_FLOWSPECV6_NODE,
19308 &neighbor_route_reflector_client_cmd);
19309 install_element(BGP_FLOWSPECV6_NODE,
19310 &no_neighbor_route_reflector_client_cmd);
d62a17ae 19311 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
19312 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
19313
70cd87ca
MK
19314 /* "optimal-route-reflection" commands */
19315 install_element(BGP_IPV4_NODE, &optimal_route_reflection_cmd);
19316 install_element(BGP_IPV4M_NODE, &optimal_route_reflection_cmd);
19317 install_element(BGP_IPV4L_NODE, &optimal_route_reflection_cmd);
19318 install_element(BGP_IPV6_NODE, &optimal_route_reflection_cmd);
19319 install_element(BGP_IPV6M_NODE, &optimal_route_reflection_cmd);
19320 install_element(BGP_IPV6L_NODE, &optimal_route_reflection_cmd);
19321 install_element(BGP_VPNV4_NODE, &optimal_route_reflection_cmd);
19322 install_element(BGP_VPNV6_NODE, &optimal_route_reflection_cmd);
19323 install_element(BGP_FLOWSPECV4_NODE, &optimal_route_reflection_cmd);
19324 install_element(BGP_FLOWSPECV6_NODE, &optimal_route_reflection_cmd);
19325 install_element(BGP_EVPN_NODE, &optimal_route_reflection_cmd);
19326
19327 /* "neighbor optimal-route-reflection" commands */
19328 install_element(BGP_IPV4_NODE, &neighbor_optimal_route_reflection_cmd);
19329 install_element(BGP_IPV4M_NODE, &neighbor_optimal_route_reflection_cmd);
19330 install_element(BGP_IPV4L_NODE, &neighbor_optimal_route_reflection_cmd);
19331 install_element(BGP_IPV6_NODE, &neighbor_optimal_route_reflection_cmd);
19332 install_element(BGP_IPV6M_NODE, &neighbor_optimal_route_reflection_cmd);
19333 install_element(BGP_IPV6L_NODE, &neighbor_optimal_route_reflection_cmd);
19334 install_element(BGP_VPNV4_NODE, &neighbor_optimal_route_reflection_cmd);
19335 install_element(BGP_VPNV6_NODE, &neighbor_optimal_route_reflection_cmd);
19336 install_element(BGP_FLOWSPECV4_NODE,
19337 &neighbor_optimal_route_reflection_cmd);
19338 install_element(BGP_FLOWSPECV6_NODE,
19339 &neighbor_optimal_route_reflection_cmd);
19340 install_element(BGP_EVPN_NODE, &neighbor_optimal_route_reflection_cmd);
19341
d62a17ae 19342 /* "neighbor route-server" commands.*/
19343 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
19344 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
19345 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
19346 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
19347 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
19348 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
19349 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
19350 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
19351 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
19352 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
19353 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
19354 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
19355 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
19356 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
19357 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
19358 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
19359 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
19360 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
19361 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
19362 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 19363 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
19364 install_element(BGP_FLOWSPECV4_NODE,
19365 &no_neighbor_route_server_client_cmd);
19366 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
19367 install_element(BGP_FLOWSPECV6_NODE,
19368 &no_neighbor_route_server_client_cmd);
d62a17ae 19369
7c0e4312
DA
19370 /* "neighbor disable-addpath-rx" commands. */
19371 install_element(BGP_IPV4_NODE, &neighbor_disable_addpath_rx_cmd);
19372 install_element(BGP_IPV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19373 install_element(BGP_IPV4M_NODE, &neighbor_disable_addpath_rx_cmd);
19374 install_element(BGP_IPV4M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19375 install_element(BGP_IPV4L_NODE, &neighbor_disable_addpath_rx_cmd);
19376 install_element(BGP_IPV4L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19377 install_element(BGP_IPV6_NODE, &neighbor_disable_addpath_rx_cmd);
19378 install_element(BGP_IPV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19379 install_element(BGP_IPV6M_NODE, &neighbor_disable_addpath_rx_cmd);
19380 install_element(BGP_IPV6M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19381 install_element(BGP_IPV6L_NODE, &neighbor_disable_addpath_rx_cmd);
19382 install_element(BGP_IPV6L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19383 install_element(BGP_VPNV4_NODE, &neighbor_disable_addpath_rx_cmd);
19384 install_element(BGP_VPNV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19385 install_element(BGP_VPNV6_NODE, &neighbor_disable_addpath_rx_cmd);
19386 install_element(BGP_VPNV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19387
d62a17ae 19388 /* "neighbor addpath-tx-all-paths" commands.*/
19389 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
19390 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
19391 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19392 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19393 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19394 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19395 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19396 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19397 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19398 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19399 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19400 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19401 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19402 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19403 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19404 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19405 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19406 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19407
19408 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
19409 install_element(BGP_NODE,
19410 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19411 install_element(BGP_NODE,
19412 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19413 install_element(BGP_IPV4_NODE,
19414 &neighbor_addpath_tx_bestpath_per_as_cmd);
19415 install_element(BGP_IPV4_NODE,
19416 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19417 install_element(BGP_IPV4M_NODE,
19418 &neighbor_addpath_tx_bestpath_per_as_cmd);
19419 install_element(BGP_IPV4M_NODE,
19420 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19421 install_element(BGP_IPV4L_NODE,
19422 &neighbor_addpath_tx_bestpath_per_as_cmd);
19423 install_element(BGP_IPV4L_NODE,
19424 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19425 install_element(BGP_IPV6_NODE,
19426 &neighbor_addpath_tx_bestpath_per_as_cmd);
19427 install_element(BGP_IPV6_NODE,
19428 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19429 install_element(BGP_IPV6M_NODE,
19430 &neighbor_addpath_tx_bestpath_per_as_cmd);
19431 install_element(BGP_IPV6M_NODE,
19432 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19433 install_element(BGP_IPV6L_NODE,
19434 &neighbor_addpath_tx_bestpath_per_as_cmd);
19435 install_element(BGP_IPV6L_NODE,
19436 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19437 install_element(BGP_VPNV4_NODE,
19438 &neighbor_addpath_tx_bestpath_per_as_cmd);
19439 install_element(BGP_VPNV4_NODE,
19440 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19441 install_element(BGP_VPNV6_NODE,
19442 &neighbor_addpath_tx_bestpath_per_as_cmd);
19443 install_element(BGP_VPNV6_NODE,
19444 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19445
2b31007c
RZ
19446 /* "neighbor sender-as-path-loop-detection" commands. */
19447 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
19448 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
19449
d62a17ae 19450 /* "neighbor passive" commands. */
19451 install_element(BGP_NODE, &neighbor_passive_cmd);
19452 install_element(BGP_NODE, &no_neighbor_passive_cmd);
19453
19454
19455 /* "neighbor shutdown" commands. */
19456 install_element(BGP_NODE, &neighbor_shutdown_cmd);
19457 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
19458 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
19459 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
8336c896
DA
19460 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
19461 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
d62a17ae 19462
19463 /* "neighbor capability extended-nexthop" commands.*/
19464 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
19465 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
19466
19467 /* "neighbor capability orf prefix-list" commands.*/
19468 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
19469 install_element(BGP_NODE,
19470 &no_neighbor_capability_orf_prefix_hidden_cmd);
19471 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
19472 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
19473 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
19474 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19475 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
19476 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19477 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
19478 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
19479 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
19480 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19481 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
19482 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19483
19484 /* "neighbor capability dynamic" commands.*/
19485 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
19486 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
19487
19488 /* "neighbor dont-capability-negotiate" commands. */
19489 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
19490 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
19491
19492 /* "neighbor ebgp-multihop" commands. */
19493 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
19494 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
19495 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
19496
19497 /* "neighbor disable-connected-check" commands. */
19498 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
19499 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
19500
7ab294ea
DA
19501 /* "neighbor disable-link-bw-encoding-ieee" commands. */
19502 install_element(BGP_NODE, &neighbor_disable_link_bw_encoding_ieee_cmd);
19503 install_element(BGP_NODE,
19504 &no_neighbor_disable_link_bw_encoding_ieee_cmd);
27aa23a4 19505
d08c0c80
DA
19506 /* "neighbor extended-optional-parameters" commands. */
19507 install_element(BGP_NODE, &neighbor_extended_optional_parameters_cmd);
19508 install_element(BGP_NODE,
19509 &no_neighbor_extended_optional_parameters_cmd);
19510
47cbc09b
PM
19511 /* "neighbor enforce-first-as" commands. */
19512 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
19513 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
19514
d62a17ae 19515 /* "neighbor description" commands. */
19516 install_element(BGP_NODE, &neighbor_description_cmd);
19517 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 19518 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 19519
19520 /* "neighbor update-source" commands. "*/
19521 install_element(BGP_NODE, &neighbor_update_source_cmd);
19522 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
19523
19524 /* "neighbor default-originate" commands. */
19525 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
19526 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
19527 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
19528 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
19529 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
19530 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
19531 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
19532 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
19533 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
19534 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
19535 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
19536 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
19537 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
19538 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
19539 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
19540 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
19541 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
19542 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
19543 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
19544 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
19545 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
19546
19547 /* "neighbor port" commands. */
19548 install_element(BGP_NODE, &neighbor_port_cmd);
19549 install_element(BGP_NODE, &no_neighbor_port_cmd);
19550
19551 /* "neighbor weight" commands. */
19552 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
19553 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
19554
19555 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
19556 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
19557 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
19558 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
19559 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
19560 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
19561 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
19562 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
19563 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
19564 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
19565 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
19566 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
19567 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
19568 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
19569 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
19570 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
19571
19572 /* "neighbor override-capability" commands. */
19573 install_element(BGP_NODE, &neighbor_override_capability_cmd);
19574 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
19575
19576 /* "neighbor strict-capability-match" commands. */
19577 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
19578 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
19579
19580 /* "neighbor timers" commands. */
19581 install_element(BGP_NODE, &neighbor_timers_cmd);
19582 install_element(BGP_NODE, &no_neighbor_timers_cmd);
19583
19584 /* "neighbor timers connect" commands. */
19585 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
19586 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
19587
d43114f3
DS
19588 /* "neighbor timers delayopen" commands. */
19589 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
19590 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
19591
d62a17ae 19592 /* "neighbor advertisement-interval" commands. */
19593 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
19594 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
19595
19596 /* "neighbor interface" commands. */
19597 install_element(BGP_NODE, &neighbor_interface_cmd);
19598 install_element(BGP_NODE, &no_neighbor_interface_cmd);
19599
19600 /* "neighbor distribute" commands. */
19601 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
19602 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
19603 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
19604 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
19605 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
19606 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
19607 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
19608 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
19609 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
19610 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
19611 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
19612 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
19613 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
19614 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
19615 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
19616 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
19617 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
19618 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
19619
19620 /* "neighbor prefix-list" commands. */
19621 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
642ef664 19622 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
d62a17ae 19623 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
642ef664 19624 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 19625 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
642ef664 19626 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 19627 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
642ef664 19628 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 19629 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
642ef664 19630 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 19631 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
642ef664 19632 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 19633 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
642ef664 19634 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 19635 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
642ef664 19636 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 19637 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
642ef664 19638 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 19639 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
642ef664 19640 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 19641 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
642ef664 19642 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 19643
19644 /* "neighbor filter-list" commands. */
19645 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
19646 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
19647 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
19648 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
19649 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
19650 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
19651 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
19652 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
19653 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
19654 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
19655 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
19656 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
19657 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
19658 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
19659 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
19660 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
19661 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
19662 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 19663 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
19664 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
19665 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
19666 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 19667
19668 /* "neighbor route-map" commands. */
d6d7ed37
IR
19669 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
19670 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
d62a17ae 19671 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
0ea8d871 19672 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
d62a17ae 19673 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
0ea8d871 19674 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
d62a17ae 19675 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
0ea8d871 19676 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
d62a17ae 19677 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
0ea8d871 19678 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
d62a17ae 19679 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
0ea8d871 19680 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
d62a17ae 19681 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
0ea8d871 19682 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
d62a17ae 19683 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
0ea8d871 19684 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
d62a17ae 19685 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
0ea8d871 19686 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 19687 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
0ea8d871 19688 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
7c40bf39 19689 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
0ea8d871 19690 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549 19691 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
0ea8d871 19692 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 19693
19694 /* "neighbor unsuppress-map" commands. */
19695 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
19696 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
19697 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
19698 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
19699 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
19700 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
19701 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
19702 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
19703 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
19704 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
19705 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
19706 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
19707 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
19708 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
19709 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
19710 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
19711 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
19712 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
19713
7f7940e6 19714 /* "neighbor advertise-map" commands. */
389e4f92 19715 install_element(BGP_NODE, &bgp_condadv_period_cmd);
7f7940e6 19716 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
7f7940e6 19717 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19718 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19719 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19720 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19721 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19722 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19723 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19724 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19725
fde246e8
DA
19726 /* neighbor maximum-prefix-out commands. */
19727 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
19728 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
19729 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
19730 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19731 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
19732 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19733 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
19734 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19735 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
19736 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19737 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
19738 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19739 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
19740 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19741 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
19742 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19743 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
19744 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19745
d62a17ae 19746 /* "neighbor maximum-prefix" commands. */
19747 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
19748 install_element(BGP_NODE,
19749 &neighbor_maximum_prefix_threshold_hidden_cmd);
19750 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
19751 install_element(BGP_NODE,
19752 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
19753 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
19754 install_element(BGP_NODE,
19755 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
19756 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
19757 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
19758 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19759 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19760 install_element(BGP_IPV4_NODE,
19761 &neighbor_maximum_prefix_threshold_warning_cmd);
19762 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19763 install_element(BGP_IPV4_NODE,
19764 &neighbor_maximum_prefix_threshold_restart_cmd);
19765 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
19766 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
19767 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19768 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
19769 install_element(BGP_IPV4M_NODE,
19770 &neighbor_maximum_prefix_threshold_warning_cmd);
19771 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
19772 install_element(BGP_IPV4M_NODE,
19773 &neighbor_maximum_prefix_threshold_restart_cmd);
19774 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
19775 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
19776 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19777 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
19778 install_element(BGP_IPV4L_NODE,
19779 &neighbor_maximum_prefix_threshold_warning_cmd);
19780 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
19781 install_element(BGP_IPV4L_NODE,
19782 &neighbor_maximum_prefix_threshold_restart_cmd);
19783 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
19784 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
19785 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19786 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19787 install_element(BGP_IPV6_NODE,
19788 &neighbor_maximum_prefix_threshold_warning_cmd);
19789 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19790 install_element(BGP_IPV6_NODE,
19791 &neighbor_maximum_prefix_threshold_restart_cmd);
19792 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
19793 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
19794 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19795 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
19796 install_element(BGP_IPV6M_NODE,
19797 &neighbor_maximum_prefix_threshold_warning_cmd);
19798 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
19799 install_element(BGP_IPV6M_NODE,
19800 &neighbor_maximum_prefix_threshold_restart_cmd);
19801 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
19802 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
19803 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19804 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
19805 install_element(BGP_IPV6L_NODE,
19806 &neighbor_maximum_prefix_threshold_warning_cmd);
19807 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
19808 install_element(BGP_IPV6L_NODE,
19809 &neighbor_maximum_prefix_threshold_restart_cmd);
19810 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
19811 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
19812 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19813 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19814 install_element(BGP_VPNV4_NODE,
19815 &neighbor_maximum_prefix_threshold_warning_cmd);
19816 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19817 install_element(BGP_VPNV4_NODE,
19818 &neighbor_maximum_prefix_threshold_restart_cmd);
19819 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
19820 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
19821 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19822 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19823 install_element(BGP_VPNV6_NODE,
19824 &neighbor_maximum_prefix_threshold_warning_cmd);
19825 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19826 install_element(BGP_VPNV6_NODE,
19827 &neighbor_maximum_prefix_threshold_restart_cmd);
19828 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
19829
19830 /* "neighbor allowas-in" */
19831 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
19832 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
19833 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
19834 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
19835 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
19836 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
19837 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
19838 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
19839 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
19840 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
19841 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
19842 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
19843 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
19844 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
19845 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
19846 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
19847 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
19848 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
19849 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
19850 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
19851
46dbf9d0
DA
19852 /* neighbor accept-own */
19853 install_element(BGP_VPNV4_NODE, &neighbor_accept_own_cmd);
19854 install_element(BGP_VPNV6_NODE, &neighbor_accept_own_cmd);
19855
01da2d26
DA
19856 /* "neighbor soo" */
19857 install_element(BGP_IPV4_NODE, &neighbor_soo_cmd);
19858 install_element(BGP_IPV4_NODE, &no_neighbor_soo_cmd);
19859 install_element(BGP_IPV4M_NODE, &neighbor_soo_cmd);
19860 install_element(BGP_IPV4M_NODE, &no_neighbor_soo_cmd);
19861 install_element(BGP_IPV4L_NODE, &neighbor_soo_cmd);
19862 install_element(BGP_IPV4L_NODE, &no_neighbor_soo_cmd);
19863 install_element(BGP_IPV6_NODE, &neighbor_soo_cmd);
19864 install_element(BGP_IPV6_NODE, &no_neighbor_soo_cmd);
19865 install_element(BGP_IPV6M_NODE, &neighbor_soo_cmd);
19866 install_element(BGP_IPV6M_NODE, &no_neighbor_soo_cmd);
19867 install_element(BGP_IPV6L_NODE, &neighbor_soo_cmd);
19868 install_element(BGP_IPV6L_NODE, &no_neighbor_soo_cmd);
19869 install_element(BGP_VPNV4_NODE, &neighbor_soo_cmd);
19870 install_element(BGP_VPNV4_NODE, &no_neighbor_soo_cmd);
19871 install_element(BGP_VPNV6_NODE, &neighbor_soo_cmd);
19872 install_element(BGP_VPNV6_NODE, &no_neighbor_soo_cmd);
19873 install_element(BGP_EVPN_NODE, &neighbor_soo_cmd);
19874 install_element(BGP_EVPN_NODE, &no_neighbor_soo_cmd);
19875
d62a17ae 19876 /* address-family commands. */
19877 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
19878 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 19879#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 19880 install_element(BGP_NODE, &address_family_vpnv4_cmd);
19881 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 19882#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 19883
d62a17ae 19884 install_element(BGP_NODE, &address_family_evpn_cmd);
19885
19886 /* "exit-address-family" command. */
19887 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
19888 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
19889 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
19890 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
19891 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
19892 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
19893 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
19894 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 19895 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
19896 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 19897 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
19898
a486300b
PG
19899 /* BGP retain all route-target */
19900 install_element(BGP_VPNV4_NODE, &bgp_retain_route_target_cmd);
19901 install_element(BGP_VPNV6_NODE, &bgp_retain_route_target_cmd);
19902
d62a17ae 19903 /* "clear ip bgp commands" */
19904 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
19905
19906 /* clear ip bgp prefix */
19907 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
19908 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
19909 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
19910
19911 /* "show [ip] bgp summary" commands. */
19912 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 19913 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 19914 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 19915 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 19916 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
19917 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 19918 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
19919
19920 /* "show [ip] bgp neighbors" commands. */
19921 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
19922
36235319 19923 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
2986cac2 19924
d62a17ae 19925 /* "show [ip] bgp peer-group" commands. */
19926 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
19927
19928 /* "show [ip] bgp paths" commands. */
19929 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
19930
19931 /* "show [ip] bgp community" commands. */
19932 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
19933
19934 /* "show ip bgp large-community" commands. */
19935 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
19936 /* "show [ip] bgp attribute-info" commands. */
19937 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 19938 /* "show [ip] bgp route-leak" command */
19939 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 19940
19941 /* "redistribute" commands. */
19942 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
19943 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
19944 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
19945 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
19946 install_element(BGP_NODE,
19947 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
19948 install_element(BGP_NODE,
19949 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
19950 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
19951 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
19952 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
19953 install_element(BGP_NODE,
19954 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
19955 install_element(BGP_NODE,
19956 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
19957 install_element(BGP_NODE,
19958 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
19959 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
19960 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
19961 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
19962 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
19963 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
19964 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
19965 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
19966 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
19967 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
19968 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
19969 install_element(BGP_IPV4_NODE,
19970 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
19971 install_element(BGP_IPV4_NODE,
19972 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
19973 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
19974 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
19975 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
19976 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
19977 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
19978 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
19979
70dd370f 19980 /* import|export vpn [route-map RMAP_NAME] */
b9c7bc5a
PZ
19981 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
19982 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 19983
12a844a5
DS
19984 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
19985 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
19986
d62a17ae 19987 /* ttl_security commands */
19988 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
19989 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
19990
d1adb448
PG
19991 /* "bgp tcp-keepalive" commands */
19992 install_element(BGP_NODE, &bgp_tcp_keepalive_cmd);
19993 install_element(BGP_NODE, &no_bgp_tcp_keepalive_cmd);
19994
d62a17ae 19995 /* "show [ip] bgp memory" commands. */
19996 install_element(VIEW_NODE, &show_bgp_memory_cmd);
19997
acf71666
MK
19998 /* "show bgp martian next-hop" */
19999 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
20000
48ecf8f5
DS
20001 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
20002
d62a17ae 20003 /* "show [ip] bgp views" commands. */
20004 install_element(VIEW_NODE, &show_bgp_views_cmd);
20005
20006 /* "show [ip] bgp vrfs" commands. */
20007 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
20008
20009 /* Community-list. */
20010 community_list_vty();
ddb5b488 20011
ed0e57e3
DA
20012 community_alias_vty();
20013
ddb5b488 20014 /* vpn-policy commands */
b9c7bc5a
PZ
20015 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
20016 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
20017 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
20018 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
20019 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
20020 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
20021 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
20022 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
20023 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
20024 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
20025 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
20026 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 20027
301ad80a
PG
20028 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
20029 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
20030
b9c7bc5a
PZ
20031 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
20032 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
20033 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
20034 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
b9c7bc5a
PZ
20035 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
20036 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
20037 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
20038 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
20039 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
20040 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
4ab46701
AR
20041
20042 /* tcp-mss command */
20043 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
20044 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
bfaab44d
HS
20045
20046 /* srv6 commands */
ea372e81 20047 install_element(VIEW_NODE, &show_bgp_srv6_cmd);
bfaab44d 20048 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
0249b8b6 20049 install_element(BGP_NODE, &no_bgp_segment_routing_srv6_cmd);
a0281b2e 20050 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
0249b8b6 20051 install_element(BGP_SRV6_NODE, &no_bgp_srv6_locator_cmd);
b72c9e14
HS
20052 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
20053 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
527588aa 20054 install_element(BGP_NODE, &bgp_sid_vpn_export_cmd);
e606d8ec 20055 install_element(BGP_NODE, &no_bgp_sid_vpn_export_cmd);
4cd690ae
PG
20056
20057 bgp_vty_if_init();
718e3744 20058}
6b0655a2 20059
718e3744 20060#include "memory.h"
20061#include "bgp_regex.h"
20062#include "bgp_clist.h"
20063#include "bgp_ecommunity.h"
20064
20065/* VTY functions. */
20066
20067/* Direction value to string conversion. */
d62a17ae 20068static const char *community_direct_str(int direct)
20069{
20070 switch (direct) {
20071 case COMMUNITY_DENY:
20072 return "deny";
20073 case COMMUNITY_PERMIT:
20074 return "permit";
20075 default:
20076 return "unknown";
20077 }
718e3744 20078}
20079
20080/* Display error string. */
d62a17ae 20081static void community_list_perror(struct vty *vty, int ret)
20082{
20083 switch (ret) {
20084 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
20085 vty_out(vty, "%% Can't find community-list\n");
20086 break;
20087 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
20088 vty_out(vty, "%% Malformed community-list value\n");
20089 break;
20090 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
20091 vty_out(vty,
20092 "%% Community name conflict, previously defined as standard community\n");
20093 break;
20094 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
20095 vty_out(vty,
20096 "%% Community name conflict, previously defined as expanded community\n");
20097 break;
20098 }
718e3744 20099}
20100
5bf15956
DW
20101/* "community-list" keyword help string. */
20102#define COMMUNITY_LIST_STR "Add a community list entry\n"
20103
7336e101
SP
20104/*community-list standard */
20105DEFUN (community_list_standard,
20106 bgp_community_list_standard_cmd,
a2099c1d 20107 "bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 20108 BGP_STR
718e3744 20109 COMMUNITY_LIST_STR
20110 "Community list number (standard)\n"
5bf15956 20111 "Add an standard community-list entry\n"
718e3744 20112 "Community list name\n"
2f8cc0e5
DA
20113 "Sequence number of an entry\n"
20114 "Sequence number\n"
718e3744 20115 "Specify community to reject\n"
20116 "Specify community to accept\n"
20117 COMMUNITY_VAL_STR)
20118{
d62a17ae 20119 char *cl_name_or_number = NULL;
2f8cc0e5 20120 char *seq = NULL;
d62a17ae 20121 int direct = 0;
20122 int style = COMMUNITY_LIST_STANDARD;
d62a17ae 20123 int idx = 0;
7336e101 20124
e34627f9 20125 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20126 seq = argv[idx]->arg;
20127
20128 idx = 0;
d62a17ae 20129 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 20130 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 20131 cl_name_or_number = argv[idx]->arg;
20132 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20133 : COMMUNITY_DENY;
20134 argv_find(argv, argc, "AA:NN", &idx);
20135 char *str = argv_concat(argv, argc, idx);
42f914d4 20136
2f8cc0e5
DA
20137 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
20138 direct, style);
42f914d4 20139
d62a17ae 20140 XFREE(MTYPE_TMP, str);
42f914d4 20141
d62a17ae 20142 if (ret < 0) {
20143 /* Display error string. */
20144 community_list_perror(vty, ret);
20145 return CMD_WARNING_CONFIG_FAILED;
20146 }
42f914d4 20147
d62a17ae 20148 return CMD_SUCCESS;
718e3744 20149}
20150
7336e101
SP
20151DEFUN (no_community_list_standard_all,
20152 no_bgp_community_list_standard_all_cmd,
a2099c1d 20153 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
20154 NO_STR
20155 BGP_STR
20156 COMMUNITY_LIST_STR
20157 "Community list number (standard)\n"
20158 "Add an standard community-list entry\n"
20159 "Community list name\n"
2f8cc0e5
DA
20160 "Sequence number of an entry\n"
20161 "Sequence number\n"
7336e101
SP
20162 "Specify community to reject\n"
20163 "Specify community to accept\n"
20164 COMMUNITY_VAL_STR)
718e3744 20165{
d62a17ae 20166 char *cl_name_or_number = NULL;
174b5cb9 20167 char *str = NULL;
d62a17ae 20168 int direct = 0;
20169 int style = COMMUNITY_LIST_STANDARD;
2f8cc0e5 20170 char *seq = NULL;
d62a17ae 20171 int idx = 0;
7336e101 20172
e34627f9 20173 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20174 seq = argv[idx]->arg;
20175
20176 idx = 0;
174b5cb9
DA
20177 argv_find(argv, argc, "permit", &idx);
20178 argv_find(argv, argc, "deny", &idx);
20179
20180 if (idx) {
20181 direct = argv_find(argv, argc, "permit", &idx)
20182 ? COMMUNITY_PERMIT
20183 : COMMUNITY_DENY;
20184
20185 idx = 0;
20186 argv_find(argv, argc, "AA:NN", &idx);
20187 str = argv_concat(argv, argc, idx);
20188 }
20189
20190 idx = 0;
d62a17ae 20191 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 20192 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 20193 cl_name_or_number = argv[idx]->arg;
42f914d4 20194
2f8cc0e5 20195 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 20196 direct, style);
42f914d4 20197
d62a17ae 20198 XFREE(MTYPE_TMP, str);
daf9ddbb 20199
d62a17ae 20200 if (ret < 0) {
20201 community_list_perror(vty, ret);
20202 return CMD_WARNING_CONFIG_FAILED;
20203 }
42f914d4 20204
d62a17ae 20205 return CMD_SUCCESS;
718e3744 20206}
7336e101 20207
174b5cb9 20208ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
a2099c1d 20209 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME>",
174b5cb9
DA
20210 NO_STR BGP_STR COMMUNITY_LIST_STR
20211 "Community list number (standard)\n"
20212 "Add an standard community-list entry\n"
20213 "Community list name\n")
20214
7336e101
SP
20215/*community-list expanded */
20216DEFUN (community_list_expanded_all,
20217 bgp_community_list_expanded_all_cmd,
a2099c1d 20218 "bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
20219 BGP_STR
20220 COMMUNITY_LIST_STR
718e3744 20221 "Community list number (expanded)\n"
5bf15956 20222 "Add an expanded community-list entry\n"
718e3744 20223 "Community list name\n"
2f8cc0e5
DA
20224 "Sequence number of an entry\n"
20225 "Sequence number\n"
718e3744 20226 "Specify community to reject\n"
20227 "Specify community to accept\n"
20228 COMMUNITY_VAL_STR)
20229{
d62a17ae 20230 char *cl_name_or_number = NULL;
2f8cc0e5 20231 char *seq = NULL;
d62a17ae 20232 int direct = 0;
20233 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 20234 int idx = 0;
7b9a4750 20235
e34627f9 20236 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20237 seq = argv[idx]->arg;
20238
20239 idx = 0;
20240
d62a17ae 20241 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 20242 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 20243 cl_name_or_number = argv[idx]->arg;
20244 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20245 : COMMUNITY_DENY;
20246 argv_find(argv, argc, "AA:NN", &idx);
20247 char *str = argv_concat(argv, argc, idx);
42f914d4 20248
2f8cc0e5
DA
20249 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
20250 direct, style);
42f914d4 20251
d62a17ae 20252 XFREE(MTYPE_TMP, str);
42f914d4 20253
d62a17ae 20254 if (ret < 0) {
20255 /* Display error string. */
20256 community_list_perror(vty, ret);
20257 return CMD_WARNING_CONFIG_FAILED;
20258 }
42f914d4 20259
d62a17ae 20260 return CMD_SUCCESS;
718e3744 20261}
20262
7336e101
SP
20263DEFUN (no_community_list_expanded_all,
20264 no_bgp_community_list_expanded_all_cmd,
a2099c1d 20265 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
20266 NO_STR
20267 BGP_STR
20268 COMMUNITY_LIST_STR
20269 "Community list number (expanded)\n"
20270 "Add an expanded community-list entry\n"
20271 "Community list name\n"
2f8cc0e5
DA
20272 "Sequence number of an entry\n"
20273 "Sequence number\n"
7336e101
SP
20274 "Specify community to reject\n"
20275 "Specify community to accept\n"
20276 COMMUNITY_VAL_STR)
718e3744 20277{
d62a17ae 20278 char *cl_name_or_number = NULL;
2f8cc0e5 20279 char *seq = NULL;
174b5cb9 20280 char *str = NULL;
d62a17ae 20281 int direct = 0;
20282 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 20283 int idx = 0;
174b5cb9 20284
e34627f9 20285 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20286 seq = argv[idx]->arg;
20287
20288 idx = 0;
174b5cb9
DA
20289 argv_find(argv, argc, "permit", &idx);
20290 argv_find(argv, argc, "deny", &idx);
20291
20292 if (idx) {
20293 direct = argv_find(argv, argc, "permit", &idx)
20294 ? COMMUNITY_PERMIT
20295 : COMMUNITY_DENY;
20296
20297 idx = 0;
20298 argv_find(argv, argc, "AA:NN", &idx);
20299 str = argv_concat(argv, argc, idx);
7336e101 20300 }
174b5cb9
DA
20301
20302 idx = 0;
d62a17ae 20303 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 20304 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 20305 cl_name_or_number = argv[idx]->arg;
42f914d4 20306
2f8cc0e5 20307 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 20308 direct, style);
42f914d4 20309
d62a17ae 20310 XFREE(MTYPE_TMP, str);
daf9ddbb 20311
d62a17ae 20312 if (ret < 0) {
20313 community_list_perror(vty, ret);
20314 return CMD_WARNING_CONFIG_FAILED;
20315 }
42f914d4 20316
d62a17ae 20317 return CMD_SUCCESS;
718e3744 20318}
20319
36d4bb44
EB
20320ALIAS(no_community_list_expanded_all,
20321 no_bgp_community_list_expanded_all_list_cmd,
a2099c1d 20322 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME>",
36d4bb44 20323 NO_STR BGP_STR COMMUNITY_LIST_STR
174b5cb9
DA
20324 "Community list number (expanded)\n"
20325 "Add an expanded community-list entry\n"
20326 "Community list name\n")
20327
8d9b8ed9
PM
20328/* Return configuration string of community-list entry. */
20329static const char *community_list_config_str(struct community_entry *entry)
20330{
20331 const char *str;
20332
20333 if (entry->any)
20334 str = "";
20335 else {
20336 if (entry->style == COMMUNITY_LIST_STANDARD)
c0945b78 20337 str = community_str(entry->u.com, false, false);
8d9b8ed9 20338 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
c0945b78 20339 str = lcommunity_str(entry->u.lcom, false, false);
8d9b8ed9
PM
20340 else
20341 str = entry->config;
20342 }
20343 return str;
20344}
20345
d62a17ae 20346static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 20347{
d62a17ae 20348 struct community_entry *entry;
718e3744 20349
d62a17ae 20350 for (entry = list->head; entry; entry = entry->next) {
20351 if (entry == list->head) {
20352 if (all_digit(list->name))
20353 vty_out(vty, "Community %s list %s\n",
20354 entry->style == COMMUNITY_LIST_STANDARD
20355 ? "standard"
20356 : "(expanded) access",
20357 list->name);
20358 else
20359 vty_out(vty, "Named Community %s list %s\n",
20360 entry->style == COMMUNITY_LIST_STANDARD
20361 ? "standard"
20362 : "expanded",
20363 list->name);
20364 }
20365 if (entry->any)
20366 vty_out(vty, " %s\n",
20367 community_direct_str(entry->direct));
20368 else
20369 vty_out(vty, " %s %s\n",
20370 community_direct_str(entry->direct),
8d9b8ed9 20371 community_list_config_str(entry));
d62a17ae 20372 }
718e3744 20373}
20374
7336e101
SP
20375DEFUN (show_community_list,
20376 show_bgp_community_list_cmd,
20377 "show bgp community-list",
718e3744 20378 SHOW_STR
7336e101 20379 BGP_STR
718e3744 20380 "List community-list\n")
20381{
d62a17ae 20382 struct community_list *list;
20383 struct community_list_master *cm;
718e3744 20384
d62a17ae 20385 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20386 if (!cm)
20387 return CMD_SUCCESS;
718e3744 20388
d62a17ae 20389 for (list = cm->num.head; list; list = list->next)
20390 community_list_show(vty, list);
718e3744 20391
d62a17ae 20392 for (list = cm->str.head; list; list = list->next)
20393 community_list_show(vty, list);
718e3744 20394
d62a17ae 20395 return CMD_SUCCESS;
718e3744 20396}
20397
7336e101
SP
20398DEFUN (show_community_list_arg,
20399 show_bgp_community_list_arg_cmd,
a2099c1d 20400 "show bgp community-list <(1-500)|COMMUNITY_LIST_NAME> detail",
7336e101
SP
20401 SHOW_STR
20402 BGP_STR
718e3744 20403 "List community-list\n"
20404 "Community-list number\n"
960b69b9 20405 "Community-list name\n"
20406 "Detailed information on community-list\n")
718e3744 20407{
d62a17ae 20408 int idx_comm_list = 3;
20409 struct community_list *list;
718e3744 20410
e237b0d2 20411 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 20412 COMMUNITY_LIST_MASTER);
20413 if (!list) {
20414 vty_out(vty, "%% Can't find community-list\n");
20415 return CMD_WARNING;
20416 }
718e3744 20417
d62a17ae 20418 community_list_show(vty, list);
718e3744 20419
d62a17ae 20420 return CMD_SUCCESS;
718e3744 20421}
6b0655a2 20422
57d187bc
JS
20423/*
20424 * Large Community code.
20425 */
d62a17ae 20426static int lcommunity_list_set_vty(struct vty *vty, int argc,
20427 struct cmd_token **argv, int style,
20428 int reject_all_digit_name)
20429{
20430 int ret;
20431 int direct;
20432 char *str;
20433 int idx = 0;
20434 char *cl_name;
2f8cc0e5
DA
20435 char *seq = NULL;
20436
a08032fe 20437 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 20438 seq = argv[idx]->arg;
d62a17ae 20439
2f8cc0e5 20440 idx = 0;
d62a17ae 20441 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20442 : COMMUNITY_DENY;
20443
20444 /* All digit name check. */
20445 idx = 0;
a2099c1d 20446 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
d62a17ae 20447 argv_find(argv, argc, "(1-99)", &idx);
20448 argv_find(argv, argc, "(100-500)", &idx);
20449 cl_name = argv[idx]->arg;
20450 if (reject_all_digit_name && all_digit(cl_name)) {
20451 vty_out(vty, "%% Community name cannot have all digits\n");
20452 return CMD_WARNING_CONFIG_FAILED;
20453 }
20454
20455 idx = 0;
20456 argv_find(argv, argc, "AA:BB:CC", &idx);
20457 argv_find(argv, argc, "LINE", &idx);
20458 /* Concat community string argument. */
20459 if (idx)
20460 str = argv_concat(argv, argc, idx);
20461 else
20462 str = NULL;
20463
2f8cc0e5 20464 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
d62a17ae 20465
20466 /* Free temporary community list string allocated by
20467 argv_concat(). */
0a22ddfb 20468 XFREE(MTYPE_TMP, str);
d62a17ae 20469
20470 if (ret < 0) {
20471 community_list_perror(vty, ret);
20472 return CMD_WARNING_CONFIG_FAILED;
20473 }
20474 return CMD_SUCCESS;
20475}
20476
20477static int lcommunity_list_unset_vty(struct vty *vty, int argc,
20478 struct cmd_token **argv, int style)
20479{
20480 int ret;
20481 int direct = 0;
20482 char *str = NULL;
20483 int idx = 0;
2f8cc0e5 20484 char *seq = NULL;
d62a17ae 20485
a08032fe 20486 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 20487 seq = argv[idx]->arg;
d62a17ae 20488
2f8cc0e5 20489 idx = 0;
d62a17ae 20490 argv_find(argv, argc, "permit", &idx);
20491 argv_find(argv, argc, "deny", &idx);
20492
20493 if (idx) {
20494 /* Check the list direct. */
20495 if (strncmp(argv[idx]->arg, "p", 1) == 0)
20496 direct = COMMUNITY_PERMIT;
20497 else
20498 direct = COMMUNITY_DENY;
20499
20500 idx = 0;
20501 argv_find(argv, argc, "LINE", &idx);
20502 argv_find(argv, argc, "AA:AA:NN", &idx);
20503 /* Concat community string argument. */
20504 str = argv_concat(argv, argc, idx);
20505 }
20506
20507 idx = 0;
20508 argv_find(argv, argc, "(1-99)", &idx);
20509 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 20510 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
d62a17ae 20511
20512 /* Unset community list. */
2f8cc0e5 20513 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
d62a17ae 20514 style);
20515
20516 /* Free temporary community list string allocated by
20517 argv_concat(). */
0a22ddfb 20518 XFREE(MTYPE_TMP, str);
d62a17ae 20519
20520 if (ret < 0) {
20521 community_list_perror(vty, ret);
20522 return CMD_WARNING_CONFIG_FAILED;
20523 }
20524
20525 return CMD_SUCCESS;
57d187bc
JS
20526}
20527
20528/* "large-community-list" keyword help string. */
20529#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
20530#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
20531
7336e101
SP
20532DEFUN (lcommunity_list_standard,
20533 bgp_lcommunity_list_standard_cmd,
a08032fe 20534 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
20535 BGP_STR
20536 LCOMMUNITY_LIST_STR
20537 "Large Community list number (standard)\n"
2f8cc0e5
DA
20538 "Sequence number of an entry\n"
20539 "Sequence number\n"
7336e101
SP
20540 "Specify large community to reject\n"
20541 "Specify large community to accept\n"
20542 LCOMMUNITY_VAL_STR)
52951b63 20543{
d62a17ae 20544 return lcommunity_list_set_vty(vty, argc, argv,
20545 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
20546}
20547
7336e101
SP
20548DEFUN (lcommunity_list_expanded,
20549 bgp_lcommunity_list_expanded_cmd,
a08032fe 20550 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20551 BGP_STR
20552 LCOMMUNITY_LIST_STR
20553 "Large Community list number (expanded)\n"
2f8cc0e5
DA
20554 "Sequence number of an entry\n"
20555 "Sequence number\n"
7336e101
SP
20556 "Specify large community to reject\n"
20557 "Specify large community to accept\n"
20558 "An ordered list as a regular-expression\n")
57d187bc 20559{
d62a17ae 20560 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 20561 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
20562}
20563
7336e101
SP
20564DEFUN (lcommunity_list_name_standard,
20565 bgp_lcommunity_list_name_standard_cmd,
a2099c1d 20566 "bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
20567 BGP_STR
20568 LCOMMUNITY_LIST_STR
20569 "Specify standard large-community-list\n"
20570 "Large Community list name\n"
2f8cc0e5
DA
20571 "Sequence number of an entry\n"
20572 "Sequence number\n"
7336e101
SP
20573 "Specify large community to reject\n"
20574 "Specify large community to accept\n"
20575 LCOMMUNITY_VAL_STR)
52951b63 20576{
d62a17ae 20577 return lcommunity_list_set_vty(vty, argc, argv,
20578 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
20579}
20580
7336e101
SP
20581DEFUN (lcommunity_list_name_expanded,
20582 bgp_lcommunity_list_name_expanded_cmd,
a2099c1d 20583 "bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20584 BGP_STR
20585 LCOMMUNITY_LIST_STR
20586 "Specify expanded large-community-list\n"
20587 "Large Community list name\n"
2f8cc0e5
DA
20588 "Sequence number of an entry\n"
20589 "Sequence number\n"
7336e101
SP
20590 "Specify large community to reject\n"
20591 "Specify large community to accept\n"
20592 "An ordered list as a regular-expression\n")
57d187bc 20593{
d62a17ae 20594 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 20595 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
20596}
20597
4378f57c
DA
20598DEFUN (no_lcommunity_list_all,
20599 no_bgp_lcommunity_list_all_cmd,
a2099c1d 20600 "no bgp large-community-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME>",
7336e101
SP
20601 NO_STR
20602 BGP_STR
20603 LCOMMUNITY_LIST_STR
20604 "Large Community list number (standard)\n"
20605 "Large Community list number (expanded)\n"
20606 "Large Community list name\n")
57d187bc 20607{
7336e101
SP
20608 return lcommunity_list_unset_vty(vty, argc, argv,
20609 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
20610}
20611
4378f57c
DA
20612DEFUN (no_lcommunity_list_name_standard_all,
20613 no_bgp_lcommunity_list_name_standard_all_cmd,
a2099c1d 20614 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME",
4378f57c
DA
20615 NO_STR
20616 BGP_STR
20617 LCOMMUNITY_LIST_STR
20618 "Specify standard large-community-list\n"
20619 "Large Community list name\n")
20620{
20621 return lcommunity_list_unset_vty(vty, argc, argv,
20622 LARGE_COMMUNITY_LIST_STANDARD);
20623}
20624
7336e101
SP
20625DEFUN (no_lcommunity_list_name_expanded_all,
20626 no_bgp_lcommunity_list_name_expanded_all_cmd,
a2099c1d 20627 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME",
7336e101
SP
20628 NO_STR
20629 BGP_STR
20630 LCOMMUNITY_LIST_STR
20631 "Specify expanded large-community-list\n"
20632 "Large Community list name\n")
57d187bc 20633{
d62a17ae 20634 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 20635 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
20636}
20637
7336e101
SP
20638DEFUN (no_lcommunity_list_standard,
20639 no_bgp_lcommunity_list_standard_cmd,
a08032fe 20640 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
20641 NO_STR
20642 BGP_STR
20643 LCOMMUNITY_LIST_STR
20644 "Large Community list number (standard)\n"
2f8cc0e5
DA
20645 "Sequence number of an entry\n"
20646 "Sequence number\n"
7336e101
SP
20647 "Specify large community to reject\n"
20648 "Specify large community to accept\n"
20649 LCOMMUNITY_VAL_STR)
57d187bc 20650{
d62a17ae 20651 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 20652 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
20653}
20654
7336e101
SP
20655DEFUN (no_lcommunity_list_expanded,
20656 no_bgp_lcommunity_list_expanded_cmd,
a08032fe 20657 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20658 NO_STR
20659 BGP_STR
20660 LCOMMUNITY_LIST_STR
20661 "Large Community list number (expanded)\n"
2f8cc0e5
DA
20662 "Sequence number of an entry\n"
20663 "Sequence number\n"
7336e101
SP
20664 "Specify large community to reject\n"
20665 "Specify large community to accept\n"
20666 "An ordered list as a regular-expression\n")
57d187bc 20667{
d62a17ae 20668 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 20669 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
20670}
20671
7336e101
SP
20672DEFUN (no_lcommunity_list_name_standard,
20673 no_bgp_lcommunity_list_name_standard_cmd,
a2099c1d 20674 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
20675 NO_STR
20676 BGP_STR
20677 LCOMMUNITY_LIST_STR
20678 "Specify standard large-community-list\n"
20679 "Large Community list name\n"
2f8cc0e5
DA
20680 "Sequence number of an entry\n"
20681 "Sequence number\n"
7336e101
SP
20682 "Specify large community to reject\n"
20683 "Specify large community to accept\n"
20684 LCOMMUNITY_VAL_STR)
57d187bc 20685{
d62a17ae 20686 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 20687 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
20688}
20689
7336e101
SP
20690DEFUN (no_lcommunity_list_name_expanded,
20691 no_bgp_lcommunity_list_name_expanded_cmd,
a2099c1d 20692 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20693 NO_STR
20694 BGP_STR
20695 LCOMMUNITY_LIST_STR
20696 "Specify expanded large-community-list\n"
20697 "Large community list name\n"
2f8cc0e5
DA
20698 "Sequence number of an entry\n"
20699 "Sequence number\n"
7336e101
SP
20700 "Specify large community to reject\n"
20701 "Specify large community to accept\n"
20702 "An ordered list as a regular-expression\n")
57d187bc 20703{
d62a17ae 20704 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 20705 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
20706}
20707
d62a17ae 20708static void lcommunity_list_show(struct vty *vty, struct community_list *list)
20709{
20710 struct community_entry *entry;
20711
20712 for (entry = list->head; entry; entry = entry->next) {
20713 if (entry == list->head) {
20714 if (all_digit(list->name))
20715 vty_out(vty, "Large community %s list %s\n",
169b72c8 20716 entry->style ==
20717 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 20718 ? "standard"
20719 : "(expanded) access",
20720 list->name);
20721 else
20722 vty_out(vty,
20723 "Named large community %s list %s\n",
169b72c8 20724 entry->style ==
20725 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 20726 ? "standard"
20727 : "expanded",
20728 list->name);
20729 }
20730 if (entry->any)
20731 vty_out(vty, " %s\n",
20732 community_direct_str(entry->direct));
20733 else
20734 vty_out(vty, " %s %s\n",
20735 community_direct_str(entry->direct),
8d9b8ed9 20736 community_list_config_str(entry));
d62a17ae 20737 }
57d187bc
JS
20738}
20739
7336e101
SP
20740DEFUN (show_lcommunity_list,
20741 show_bgp_lcommunity_list_cmd,
20742 "show bgp large-community-list",
57d187bc 20743 SHOW_STR
7336e101 20744 BGP_STR
57d187bc
JS
20745 "List large-community list\n")
20746{
d62a17ae 20747 struct community_list *list;
20748 struct community_list_master *cm;
57d187bc 20749
d62a17ae 20750 cm = community_list_master_lookup(bgp_clist,
20751 LARGE_COMMUNITY_LIST_MASTER);
20752 if (!cm)
20753 return CMD_SUCCESS;
57d187bc 20754
d62a17ae 20755 for (list = cm->num.head; list; list = list->next)
20756 lcommunity_list_show(vty, list);
57d187bc 20757
d62a17ae 20758 for (list = cm->str.head; list; list = list->next)
20759 lcommunity_list_show(vty, list);
57d187bc 20760
d62a17ae 20761 return CMD_SUCCESS;
57d187bc
JS
20762}
20763
7336e101
SP
20764DEFUN (show_lcommunity_list_arg,
20765 show_bgp_lcommunity_list_arg_cmd,
a2099c1d 20766 "show bgp large-community-list <(1-500)|LCOMMUNITY_LIST_NAME> detail",
7336e101
SP
20767 SHOW_STR
20768 BGP_STR
57d187bc 20769 "List large-community list\n"
960b69b9 20770 "Large-community-list number\n"
20771 "Large-community-list name\n"
20772 "Detailed information on large-community-list\n")
57d187bc 20773{
d62a17ae 20774 struct community_list *list;
57d187bc 20775
e237b0d2 20776 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
d62a17ae 20777 LARGE_COMMUNITY_LIST_MASTER);
20778 if (!list) {
960b69b9 20779 vty_out(vty, "%% Can't find large-community-list\n");
d62a17ae 20780 return CMD_WARNING;
20781 }
57d187bc 20782
d62a17ae 20783 lcommunity_list_show(vty, list);
57d187bc 20784
d62a17ae 20785 return CMD_SUCCESS;
57d187bc
JS
20786}
20787
718e3744 20788/* "extcommunity-list" keyword help string. */
20789#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
20790#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
20791
7336e101
SP
20792DEFUN (extcommunity_list_standard,
20793 bgp_extcommunity_list_standard_cmd,
a2099c1d 20794 "bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 20795 BGP_STR
718e3744 20796 EXTCOMMUNITY_LIST_STR
20797 "Extended Community list number (standard)\n"
718e3744 20798 "Specify standard extcommunity-list\n"
5bf15956 20799 "Community list name\n"
2f8cc0e5
DA
20800 "Sequence number of an entry\n"
20801 "Sequence number\n"
718e3744 20802 "Specify community to reject\n"
20803 "Specify community to accept\n"
20804 EXTCOMMUNITY_VAL_STR)
20805{
d62a17ae 20806 int style = EXTCOMMUNITY_LIST_STANDARD;
20807 int direct = 0;
20808 char *cl_number_or_name = NULL;
2f8cc0e5 20809 char *seq = NULL;
42f914d4 20810
d62a17ae 20811 int idx = 0;
7b9a4750 20812
d62a17ae 20813 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 20814 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 20815 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 20816
a08032fe 20817 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20818 seq = argv[idx]->arg;
20819
d62a17ae 20820 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20821 : COMMUNITY_DENY;
20822 argv_find(argv, argc, "AA:NN", &idx);
20823 char *str = argv_concat(argv, argc, idx);
42f914d4 20824
2f8cc0e5 20825 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 20826 direct, style);
42f914d4 20827
d62a17ae 20828 XFREE(MTYPE_TMP, str);
42f914d4 20829
d62a17ae 20830 if (ret < 0) {
20831 community_list_perror(vty, ret);
20832 return CMD_WARNING_CONFIG_FAILED;
20833 }
42f914d4 20834
d62a17ae 20835 return CMD_SUCCESS;
718e3744 20836}
20837
7336e101
SP
20838DEFUN (extcommunity_list_name_expanded,
20839 bgp_extcommunity_list_name_expanded_cmd,
a2099c1d 20840 "bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20841 BGP_STR
20842 EXTCOMMUNITY_LIST_STR
5bf15956 20843 "Extended Community list number (expanded)\n"
718e3744 20844 "Specify expanded extcommunity-list\n"
20845 "Extended Community list name\n"
2f8cc0e5
DA
20846 "Sequence number of an entry\n"
20847 "Sequence number\n"
718e3744 20848 "Specify community to reject\n"
20849 "Specify community to accept\n"
20850 "An ordered list as a regular-expression\n")
20851{
d62a17ae 20852 int style = EXTCOMMUNITY_LIST_EXPANDED;
20853 int direct = 0;
20854 char *cl_number_or_name = NULL;
2f8cc0e5 20855 char *seq = NULL;
d62a17ae 20856 int idx = 0;
7336e101 20857
d62a17ae 20858 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 20859 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 20860 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 20861
a08032fe 20862 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20863 seq = argv[idx]->arg;
20864
d62a17ae 20865 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20866 : COMMUNITY_DENY;
20867 argv_find(argv, argc, "LINE", &idx);
20868 char *str = argv_concat(argv, argc, idx);
42f914d4 20869
2f8cc0e5 20870 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 20871 direct, style);
42f914d4 20872
d62a17ae 20873 XFREE(MTYPE_TMP, str);
42f914d4 20874
d62a17ae 20875 if (ret < 0) {
20876 community_list_perror(vty, ret);
20877 return CMD_WARNING_CONFIG_FAILED;
20878 }
42f914d4 20879
d62a17ae 20880 return CMD_SUCCESS;
718e3744 20881}
20882
7336e101
SP
20883DEFUN (no_extcommunity_list_standard_all,
20884 no_bgp_extcommunity_list_standard_all_cmd,
a2099c1d 20885 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
20886 NO_STR
20887 BGP_STR
20888 EXTCOMMUNITY_LIST_STR
813d4307 20889 "Extended Community list number (standard)\n"
718e3744 20890 "Specify standard extcommunity-list\n"
5bf15956 20891 "Community list name\n"
2f8cc0e5
DA
20892 "Sequence number of an entry\n"
20893 "Sequence number\n"
718e3744 20894 "Specify community to reject\n"
20895 "Specify community to accept\n"
20896 EXTCOMMUNITY_VAL_STR)
20897{
d62a17ae 20898 int style = EXTCOMMUNITY_LIST_STANDARD;
20899 int direct = 0;
20900 char *cl_number_or_name = NULL;
d4455c89 20901 char *str = NULL;
2f8cc0e5 20902 char *seq = NULL;
d62a17ae 20903 int idx = 0;
d4455c89 20904
a08032fe 20905 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20906 seq = argv[idx]->arg;
20907
20908 idx = 0;
d4455c89
DA
20909 argv_find(argv, argc, "permit", &idx);
20910 argv_find(argv, argc, "deny", &idx);
d4455c89
DA
20911 if (idx) {
20912 direct = argv_find(argv, argc, "permit", &idx)
20913 ? COMMUNITY_PERMIT
20914 : COMMUNITY_DENY;
20915
20916 idx = 0;
20917 argv_find(argv, argc, "AA:NN", &idx);
20918 str = argv_concat(argv, argc, idx);
20919 }
20920
20921 idx = 0;
d62a17ae 20922 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 20923 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 20924 cl_number_or_name = argv[idx]->arg;
42f914d4 20925
d62a17ae 20926 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 20927 seq, direct, style);
42f914d4 20928
d62a17ae 20929 XFREE(MTYPE_TMP, str);
42f914d4 20930
d62a17ae 20931 if (ret < 0) {
20932 community_list_perror(vty, ret);
20933 return CMD_WARNING_CONFIG_FAILED;
20934 }
42f914d4 20935
d62a17ae 20936 return CMD_SUCCESS;
718e3744 20937}
20938
d4455c89
DA
20939ALIAS(no_extcommunity_list_standard_all,
20940 no_bgp_extcommunity_list_standard_all_list_cmd,
a2099c1d 20941 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME>",
36d4bb44 20942 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
20943 "Extended Community list number (standard)\n"
20944 "Specify standard extcommunity-list\n"
20945 "Community list name\n")
20946
7336e101
SP
20947DEFUN (no_extcommunity_list_expanded_all,
20948 no_bgp_extcommunity_list_expanded_all_cmd,
a2099c1d 20949 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20950 NO_STR
20951 BGP_STR
20952 EXTCOMMUNITY_LIST_STR
718e3744 20953 "Extended Community list number (expanded)\n"
718e3744 20954 "Specify expanded extcommunity-list\n"
5bf15956 20955 "Extended Community list name\n"
2f8cc0e5
DA
20956 "Sequence number of an entry\n"
20957 "Sequence number\n"
718e3744 20958 "Specify community to reject\n"
20959 "Specify community to accept\n"
20960 "An ordered list as a regular-expression\n")
20961{
d62a17ae 20962 int style = EXTCOMMUNITY_LIST_EXPANDED;
20963 int direct = 0;
20964 char *cl_number_or_name = NULL;
d4455c89 20965 char *str = NULL;
2f8cc0e5 20966 char *seq = NULL;
d62a17ae 20967 int idx = 0;
d4455c89 20968
a08032fe 20969 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20970 seq = argv[idx]->arg;
20971
20972 idx = 0;
d4455c89
DA
20973 argv_find(argv, argc, "permit", &idx);
20974 argv_find(argv, argc, "deny", &idx);
20975
20976 if (idx) {
20977 direct = argv_find(argv, argc, "permit", &idx)
20978 ? COMMUNITY_PERMIT
20979 : COMMUNITY_DENY;
20980
20981 idx = 0;
20982 argv_find(argv, argc, "LINE", &idx);
20983 str = argv_concat(argv, argc, idx);
20984 }
20985
20986 idx = 0;
d62a17ae 20987 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 20988 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 20989 cl_number_or_name = argv[idx]->arg;
42f914d4 20990
d62a17ae 20991 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 20992 seq, direct, style);
42f914d4 20993
d62a17ae 20994 XFREE(MTYPE_TMP, str);
42f914d4 20995
d62a17ae 20996 if (ret < 0) {
20997 community_list_perror(vty, ret);
20998 return CMD_WARNING_CONFIG_FAILED;
20999 }
42f914d4 21000
d62a17ae 21001 return CMD_SUCCESS;
718e3744 21002}
21003
d4455c89
DA
21004ALIAS(no_extcommunity_list_expanded_all,
21005 no_bgp_extcommunity_list_expanded_all_list_cmd,
a2099c1d 21006 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME>",
36d4bb44 21007 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
21008 "Extended Community list number (expanded)\n"
21009 "Specify expanded extcommunity-list\n"
21010 "Extended Community list name\n")
21011
d62a17ae 21012static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 21013{
d62a17ae 21014 struct community_entry *entry;
718e3744 21015
d62a17ae 21016 for (entry = list->head; entry; entry = entry->next) {
21017 if (entry == list->head) {
21018 if (all_digit(list->name))
21019 vty_out(vty, "Extended community %s list %s\n",
21020 entry->style == EXTCOMMUNITY_LIST_STANDARD
21021 ? "standard"
21022 : "(expanded) access",
21023 list->name);
21024 else
21025 vty_out(vty,
21026 "Named extended community %s list %s\n",
21027 entry->style == EXTCOMMUNITY_LIST_STANDARD
21028 ? "standard"
21029 : "expanded",
21030 list->name);
21031 }
21032 if (entry->any)
21033 vty_out(vty, " %s\n",
21034 community_direct_str(entry->direct));
21035 else
21036 vty_out(vty, " %s %s\n",
21037 community_direct_str(entry->direct),
8d9b8ed9 21038 community_list_config_str(entry));
d62a17ae 21039 }
718e3744 21040}
21041
7336e101
SP
21042DEFUN (show_extcommunity_list,
21043 show_bgp_extcommunity_list_cmd,
21044 "show bgp extcommunity-list",
718e3744 21045 SHOW_STR
7336e101 21046 BGP_STR
718e3744 21047 "List extended-community list\n")
21048{
d62a17ae 21049 struct community_list *list;
21050 struct community_list_master *cm;
718e3744 21051
d62a17ae 21052 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
21053 if (!cm)
21054 return CMD_SUCCESS;
718e3744 21055
d62a17ae 21056 for (list = cm->num.head; list; list = list->next)
21057 extcommunity_list_show(vty, list);
718e3744 21058
d62a17ae 21059 for (list = cm->str.head; list; list = list->next)
21060 extcommunity_list_show(vty, list);
718e3744 21061
d62a17ae 21062 return CMD_SUCCESS;
718e3744 21063}
21064
7336e101
SP
21065DEFUN (show_extcommunity_list_arg,
21066 show_bgp_extcommunity_list_arg_cmd,
a2099c1d 21067 "show bgp extcommunity-list <(1-500)|EXTCOMMUNITY_LIST_NAME> detail",
7336e101
SP
21068 SHOW_STR
21069 BGP_STR
718e3744 21070 "List extended-community list\n"
21071 "Extcommunity-list number\n"
960b69b9 21072 "Extcommunity-list name\n"
21073 "Detailed information on extcommunity-list\n")
718e3744 21074{
d62a17ae 21075 int idx_comm_list = 3;
21076 struct community_list *list;
718e3744 21077
e237b0d2 21078 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 21079 EXTCOMMUNITY_LIST_MASTER);
21080 if (!list) {
21081 vty_out(vty, "%% Can't find extcommunity-list\n");
21082 return CMD_WARNING;
21083 }
718e3744 21084
d62a17ae 21085 extcommunity_list_show(vty, list);
718e3744 21086
d62a17ae 21087 return CMD_SUCCESS;
718e3744 21088}
6b0655a2 21089
718e3744 21090/* Display community-list and extcommunity-list configuration. */
d62a17ae 21091static int community_list_config_write(struct vty *vty)
21092{
21093 struct community_list *list;
21094 struct community_entry *entry;
21095 struct community_list_master *cm;
21096 int write = 0;
21097
21098 /* Community-list. */
21099 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
21100
21101 for (list = cm->num.head; list; list = list->next)
21102 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
21103 vty_out(vty,
21104 "bgp community-list %s seq %" PRId64 " %s %s\n",
21105 list->name, entry->seq,
d62a17ae 21106 community_direct_str(entry->direct),
21107 community_list_config_str(entry));
21108 write++;
21109 }
21110 for (list = cm->str.head; list; list = list->next)
21111 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
21112 vty_out(vty,
21113 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
d62a17ae 21114 entry->style == COMMUNITY_LIST_STANDARD
21115 ? "standard"
21116 : "expanded",
2f8cc0e5
DA
21117 list->name, entry->seq,
21118 community_direct_str(entry->direct),
d62a17ae 21119 community_list_config_str(entry));
21120 write++;
21121 }
21122
21123 /* Extcommunity-list. */
21124 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
21125
21126 for (list = cm->num.head; list; list = list->next)
21127 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
21128 vty_out(vty,
21129 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
21130 list->name, entry->seq,
21131 community_direct_str(entry->direct),
d62a17ae 21132 community_list_config_str(entry));
21133 write++;
21134 }
21135 for (list = cm->str.head; list; list = list->next)
21136 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 21137 vty_out(vty,
6cde4b45 21138 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
d62a17ae 21139 entry->style == EXTCOMMUNITY_LIST_STANDARD
21140 ? "standard"
21141 : "expanded",
2f8cc0e5
DA
21142 list->name, entry->seq,
21143 community_direct_str(entry->direct),
d62a17ae 21144 community_list_config_str(entry));
21145 write++;
21146 }
21147
21148
21149 /* lcommunity-list. */
21150 cm = community_list_master_lookup(bgp_clist,
21151 LARGE_COMMUNITY_LIST_MASTER);
21152
21153 for (list = cm->num.head; list; list = list->next)
21154 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 21155 vty_out(vty,
6cde4b45 21156 "bgp large-community-list %s seq %" PRId64" %s %s\n",
2f8cc0e5
DA
21157 list->name, entry->seq,
21158 community_direct_str(entry->direct),
d62a17ae 21159 community_list_config_str(entry));
21160 write++;
21161 }
21162 for (list = cm->str.head; list; list = list->next)
21163 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 21164 vty_out(vty,
6cde4b45 21165 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
2f8cc0e5 21166
d62a17ae 21167 entry->style == LARGE_COMMUNITY_LIST_STANDARD
21168 ? "standard"
21169 : "expanded",
2f8cc0e5 21170 list->name, entry->seq, community_direct_str(entry->direct),
d62a17ae 21171 community_list_config_str(entry));
21172 write++;
21173 }
21174
21175 return write;
21176}
21177
612c2c15 21178static int community_list_config_write(struct vty *vty);
d62a17ae 21179static struct cmd_node community_list_node = {
f4b8291f 21180 .name = "community list",
62b346ee
DL
21181 .node = COMMUNITY_LIST_NODE,
21182 .prompt = "",
612c2c15 21183 .config_write = community_list_config_write,
718e3744 21184};
21185
d62a17ae 21186static void community_list_vty(void)
21187{
612c2c15 21188 install_node(&community_list_node);
d62a17ae 21189
21190 /* Community-list. */
7336e101
SP
21191 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
21192 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
21193 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 21194 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 21195 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 21196 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
21197 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
21198 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 21199
21200 /* Extcommunity-list. */
7336e101
SP
21201 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
21202 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
21203 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
d4455c89
DA
21204 install_element(CONFIG_NODE,
21205 &no_bgp_extcommunity_list_standard_all_list_cmd);
7336e101 21206 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
d4455c89
DA
21207 install_element(CONFIG_NODE,
21208 &no_bgp_extcommunity_list_expanded_all_list_cmd);
7336e101
SP
21209 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
21210 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 21211
21212 /* Large Community List */
7336e101 21213 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
7336e101
SP
21214 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
21215 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
7336e101 21216 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
4378f57c
DA
21217 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
21218 install_element(CONFIG_NODE,
21219 &no_bgp_lcommunity_list_name_standard_all_cmd);
7336e101
SP
21220 install_element(CONFIG_NODE,
21221 &no_bgp_lcommunity_list_name_expanded_all_cmd);
21222 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
21223 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
21224 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
21225 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
21226 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
21227 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
225096bc
DA
21228
21229 bgp_community_list_command_completion_setup();
5bf15956 21230}
ed0e57e3
DA
21231
21232static struct cmd_node community_alias_node = {
21233 .name = "community alias",
21234 .node = COMMUNITY_ALIAS_NODE,
21235 .prompt = "",
21236 .config_write = bgp_community_alias_write,
21237};
21238
21239void community_alias_vty(void)
21240{
21241 install_node(&community_alias_node);
21242
21243 /* Community-list. */
21244 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
b4ad2fae
DS
21245
21246 bgp_community_alias_command_completion_setup();
ed0e57e3 21247}