]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
Merge pull request #12642 from anlancs/fix/bgpd-debug-name
[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 160static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
403e64f8 161 struct bgp *bgp);
2986cac2 162
36235319
QY
163static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
164 enum show_type type,
165 const char *ip_str,
166 afi_t afi, bool use_json);
2986cac2 167
d62a17ae 168static enum node_type bgp_node_type(afi_t afi, safi_t safi)
169{
170 switch (afi) {
171 case AFI_IP:
172 switch (safi) {
173 case SAFI_UNICAST:
174 return BGP_IPV4_NODE;
d62a17ae 175 case SAFI_MULTICAST:
176 return BGP_IPV4M_NODE;
d62a17ae 177 case SAFI_LABELED_UNICAST:
178 return BGP_IPV4L_NODE;
d62a17ae 179 case SAFI_MPLS_VPN:
180 return BGP_VPNV4_NODE;
7c40bf39 181 case SAFI_FLOWSPEC:
182 return BGP_FLOWSPECV4_NODE;
5c525538
RW
183 default:
184 /* not expected */
185 return BGP_IPV4_NODE;
d62a17ae 186 }
d62a17ae 187 case AFI_IP6:
188 switch (safi) {
189 case SAFI_UNICAST:
190 return BGP_IPV6_NODE;
d62a17ae 191 case SAFI_MULTICAST:
192 return BGP_IPV6M_NODE;
d62a17ae 193 case SAFI_LABELED_UNICAST:
194 return BGP_IPV6L_NODE;
d62a17ae 195 case SAFI_MPLS_VPN:
196 return BGP_VPNV6_NODE;
7c40bf39 197 case SAFI_FLOWSPEC:
198 return BGP_FLOWSPECV6_NODE;
5c525538
RW
199 default:
200 /* not expected */
201 return BGP_IPV4_NODE;
d62a17ae 202 }
d62a17ae 203 case AFI_L2VPN:
204 return BGP_EVPN_NODE;
b26f891d 205 case AFI_UNSPEC:
d62a17ae 206 case AFI_MAX:
207 // We should never be here but to clarify the switch statement..
208 return BGP_IPV4_NODE;
d62a17ae 209 }
210
211 // Impossible to happen
212 return BGP_IPV4_NODE;
f51bae9c 213}
20eb8864 214
5cb5f4d0
DD
215static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
216{
7d0d37de
DS
217 if (afi == AFI_IP) {
218 if (safi == SAFI_UNICAST)
219 return "IPv4 Unicast";
220 if (safi == SAFI_MULTICAST)
221 return "IPv4 Multicast";
222 if (safi == SAFI_LABELED_UNICAST)
223 return "IPv4 Labeled Unicast";
224 if (safi == SAFI_MPLS_VPN)
225 return "IPv4 VPN";
226 if (safi == SAFI_ENCAP)
227 return "IPv4 Encap";
228 if (safi == SAFI_FLOWSPEC)
229 return "IPv4 Flowspec";
230 } else if (afi == AFI_IP6) {
231 if (safi == SAFI_UNICAST)
232 return "IPv6 Unicast";
233 if (safi == SAFI_MULTICAST)
234 return "IPv6 Multicast";
235 if (safi == SAFI_LABELED_UNICAST)
236 return "IPv6 Labeled Unicast";
237 if (safi == SAFI_MPLS_VPN)
238 return "IPv6 VPN";
239 if (safi == SAFI_ENCAP)
240 return "IPv6 Encap";
241 if (safi == SAFI_FLOWSPEC)
242 return "IPv6 Flowspec";
243 } else if (afi == AFI_L2VPN) {
244 if (safi == SAFI_EVPN)
245 return "L2VPN EVPN";
246 }
247
248 return "Unknown";
5cb5f4d0
DD
249}
250
251/*
252 * Please note that we have intentionally camelCased
253 * the return strings here. So if you want
254 * to use this function, please ensure you
255 * are doing this within json output
256 */
257static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
258{
7d0d37de
DS
259 if (afi == AFI_IP) {
260 if (safi == SAFI_UNICAST)
261 return "ipv4Unicast";
262 if (safi == SAFI_MULTICAST)
263 return "ipv4Multicast";
264 if (safi == SAFI_LABELED_UNICAST)
265 return "ipv4LabeledUnicast";
266 if (safi == SAFI_MPLS_VPN)
267 return "ipv4Vpn";
268 if (safi == SAFI_ENCAP)
269 return "ipv4Encap";
270 if (safi == SAFI_FLOWSPEC)
271 return "ipv4Flowspec";
272 } else if (afi == AFI_IP6) {
273 if (safi == SAFI_UNICAST)
274 return "ipv6Unicast";
275 if (safi == SAFI_MULTICAST)
276 return "ipv6Multicast";
277 if (safi == SAFI_LABELED_UNICAST)
278 return "ipv6LabeledUnicast";
279 if (safi == SAFI_MPLS_VPN)
280 return "ipv6Vpn";
281 if (safi == SAFI_ENCAP)
282 return "ipv6Encap";
283 if (safi == SAFI_FLOWSPEC)
284 return "ipv6Flowspec";
285 } else if (afi == AFI_L2VPN) {
286 if (safi == SAFI_EVPN)
287 return "l2VpnEvpn";
288 }
289
290 return "Unknown";
5cb5f4d0
DD
291}
292
0249b8b6
HS
293/* unset srv6 locator */
294static int bgp_srv6_locator_unset(struct bgp *bgp)
295{
296 int ret;
297 struct listnode *node, *nnode;
efae8c26 298 struct srv6_locator_chunk *chunk;
0249b8b6
HS
299 struct bgp_srv6_function *func;
300 struct bgp *bgp_vrf;
0249b8b6
HS
301
302 /* release chunk notification via ZAPI */
303 ret = bgp_zebra_srv6_manager_release_locator_chunk(
304 bgp->srv6_locator_name);
305 if (ret < 0)
306 return -1;
307
308 /* refresh chunks */
03852f67 309 for (ALL_LIST_ELEMENTS(bgp->srv6_locator_chunks, node, nnode, chunk)) {
0249b8b6 310 listnode_delete(bgp->srv6_locator_chunks, chunk);
69467313 311 srv6_locator_chunk_free(&chunk);
03852f67 312 }
0249b8b6
HS
313
314 /* refresh functions */
bda15542 315 for (ALL_LIST_ELEMENTS(bgp->srv6_functions, node, nnode, func)) {
0249b8b6 316 listnode_delete(bgp->srv6_functions, func);
bda15542
CS
317 XFREE(MTYPE_BGP_SRV6_FUNCTION, func);
318 }
0249b8b6
HS
319
320 /* refresh tovpn_sid */
321 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
322 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
323 continue;
324
325 /* refresh vpnv4 tovpn_sid */
944909f4
CS
326 XFREE(MTYPE_BGP_SRV6_SID,
327 bgp_vrf->vpn_policy[AFI_IP].tovpn_sid);
0249b8b6
HS
328
329 /* refresh vpnv6 tovpn_sid */
944909f4
CS
330 XFREE(MTYPE_BGP_SRV6_SID,
331 bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid);
527588aa
CS
332
333 /* refresh per-vrf tovpn_sid */
334 XFREE(MTYPE_BGP_SRV6_SID, bgp_vrf->tovpn_sid);
0249b8b6
HS
335 }
336
337 /* update vpn bgp processes */
338 vpn_leak_postchange_all();
339
f8e9c702
CS
340 /* refresh tovpn_sid_locator */
341 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
342 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
343 continue;
344
345 /* refresh vpnv4 tovpn_sid_locator */
efae8c26
CS
346 srv6_locator_chunk_free(
347 &bgp_vrf->vpn_policy[AFI_IP].tovpn_sid_locator);
f8e9c702
CS
348
349 /* refresh vpnv6 tovpn_sid_locator */
efae8c26
CS
350 srv6_locator_chunk_free(
351 &bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid_locator);
527588aa
CS
352
353 /* refresh per-vrf tovpn_sid_locator */
69467313 354 srv6_locator_chunk_free(&bgp_vrf->tovpn_sid_locator);
f8e9c702
CS
355 }
356
0249b8b6
HS
357 /* clear locator name */
358 memset(bgp->srv6_locator_name, 0, sizeof(bgp->srv6_locator_name));
359
360 return 0;
361}
362
718e3744 363/* Utility function to get address family from current node. */
d62a17ae 364afi_t bgp_node_afi(struct vty *vty)
365{
366 afi_t afi;
367 switch (vty->node) {
368 case BGP_IPV6_NODE:
369 case BGP_IPV6M_NODE:
370 case BGP_IPV6L_NODE:
371 case BGP_VPNV6_NODE:
7c40bf39 372 case BGP_FLOWSPECV6_NODE:
d62a17ae 373 afi = AFI_IP6;
374 break;
375 case BGP_EVPN_NODE:
376 afi = AFI_L2VPN;
377 break;
378 default:
379 afi = AFI_IP;
380 break;
381 }
382 return afi;
718e3744 383}
384
385/* Utility function to get subsequent address family from current
386 node. */
d62a17ae 387safi_t bgp_node_safi(struct vty *vty)
388{
389 safi_t safi;
390 switch (vty->node) {
391 case BGP_VPNV4_NODE:
392 case BGP_VPNV6_NODE:
393 safi = SAFI_MPLS_VPN;
394 break;
395 case BGP_IPV4M_NODE:
396 case BGP_IPV6M_NODE:
397 safi = SAFI_MULTICAST;
398 break;
399 case BGP_EVPN_NODE:
400 safi = SAFI_EVPN;
401 break;
402 case BGP_IPV4L_NODE:
403 case BGP_IPV6L_NODE:
404 safi = SAFI_LABELED_UNICAST;
405 break;
7c40bf39 406 case BGP_FLOWSPECV4_NODE:
407 case BGP_FLOWSPECV6_NODE:
408 safi = SAFI_FLOWSPEC;
409 break;
d62a17ae 410 default:
411 safi = SAFI_UNICAST;
412 break;
413 }
414 return safi;
718e3744 415}
416
55f91488
QY
417/**
418 * Converts an AFI in string form to afi_t
419 *
420 * @param afi string, one of
421 * - "ipv4"
422 * - "ipv6"
81cf0de5 423 * - "l2vpn"
55f91488
QY
424 * @return the corresponding afi_t
425 */
d62a17ae 426afi_t bgp_vty_afi_from_str(const char *afi_str)
427{
428 afi_t afi = AFI_MAX; /* unknown */
429 if (strmatch(afi_str, "ipv4"))
430 afi = AFI_IP;
431 else if (strmatch(afi_str, "ipv6"))
432 afi = AFI_IP6;
81cf0de5
CS
433 else if (strmatch(afi_str, "l2vpn"))
434 afi = AFI_L2VPN;
d62a17ae 435 return afi;
436}
437
438int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
439 afi_t *afi)
440{
441 int ret = 0;
442 if (argv_find(argv, argc, "ipv4", index)) {
443 ret = 1;
444 if (afi)
445 *afi = AFI_IP;
446 } else if (argv_find(argv, argc, "ipv6", index)) {
447 ret = 1;
448 if (afi)
449 *afi = AFI_IP6;
8688b3e7
DS
450 } else if (argv_find(argv, argc, "l2vpn", index)) {
451 ret = 1;
452 if (afi)
453 *afi = AFI_L2VPN;
d62a17ae 454 }
455 return ret;
46f296b4
LB
456}
457
375a2e67 458/* supports <unicast|multicast|vpn|labeled-unicast> */
d62a17ae 459safi_t bgp_vty_safi_from_str(const char *safi_str)
460{
461 safi_t safi = SAFI_MAX; /* unknown */
462 if (strmatch(safi_str, "multicast"))
463 safi = SAFI_MULTICAST;
464 else if (strmatch(safi_str, "unicast"))
465 safi = SAFI_UNICAST;
466 else if (strmatch(safi_str, "vpn"))
467 safi = SAFI_MPLS_VPN;
81cf0de5
CS
468 else if (strmatch(safi_str, "evpn"))
469 safi = SAFI_EVPN;
d62a17ae 470 else if (strmatch(safi_str, "labeled-unicast"))
471 safi = SAFI_LABELED_UNICAST;
7c40bf39 472 else if (strmatch(safi_str, "flowspec"))
473 safi = SAFI_FLOWSPEC;
d62a17ae 474 return safi;
475}
476
477int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
478 safi_t *safi)
479{
480 int ret = 0;
481 if (argv_find(argv, argc, "unicast", index)) {
482 ret = 1;
483 if (safi)
484 *safi = SAFI_UNICAST;
485 } else if (argv_find(argv, argc, "multicast", index)) {
486 ret = 1;
487 if (safi)
488 *safi = SAFI_MULTICAST;
489 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
490 ret = 1;
491 if (safi)
492 *safi = SAFI_LABELED_UNICAST;
493 } else if (argv_find(argv, argc, "vpn", index)) {
494 ret = 1;
495 if (safi)
496 *safi = SAFI_MPLS_VPN;
8688b3e7
DS
497 } else if (argv_find(argv, argc, "evpn", index)) {
498 ret = 1;
499 if (safi)
500 *safi = SAFI_EVPN;
7c40bf39 501 } else if (argv_find(argv, argc, "flowspec", index)) {
502 ret = 1;
503 if (safi)
504 *safi = SAFI_FLOWSPEC;
d62a17ae 505 }
506 return ret;
46f296b4
LB
507}
508
b16bcbba
TA
509/*
510 * Convert an afi_t/safi_t pair to matching BGP_DEFAULT_AF* flag.
511 *
512 * afi
513 * address-family identifier
514 *
515 * safi
516 * subsequent address-family identifier
517 *
518 * Returns:
519 * default_af string corresponding to the supplied afi/safi pair.
520 * If afi/safi is invalid or if flag for afi/safi doesn't exist,
521 * return -1.
522 */
523static const char *get_bgp_default_af_flag(afi_t afi, safi_t safi)
524{
525 switch (afi) {
526 case AFI_IP:
527 switch (safi) {
528 case SAFI_UNICAST:
529 return "ipv4-unicast";
530 case SAFI_MULTICAST:
531 return "ipv4-multicast";
532 case SAFI_MPLS_VPN:
533 return "ipv4-vpn";
534 case SAFI_ENCAP:
535 return "ipv4-encap";
536 case SAFI_LABELED_UNICAST:
537 return "ipv4-labeled-unicast";
538 case SAFI_FLOWSPEC:
539 return "ipv4-flowspec";
540 default:
541 return "unknown-afi/safi";
542 }
543 break;
544 case AFI_IP6:
545 switch (safi) {
546 case SAFI_UNICAST:
547 return "ipv6-unicast";
548 case SAFI_MULTICAST:
549 return "ipv6-multicast";
550 case SAFI_MPLS_VPN:
551 return "ipv6-vpn";
552 case SAFI_ENCAP:
553 return "ipv6-encap";
554 case SAFI_LABELED_UNICAST:
555 return "ipv6-labeled-unicast";
556 case SAFI_FLOWSPEC:
557 return "ipv6-flowspec";
558 default:
559 return "unknown-afi/safi";
560 }
561 break;
562 case AFI_L2VPN:
563 switch (safi) {
564 case SAFI_EVPN:
565 return "l2vpn-evpn";
566 default:
567 return "unknown-afi/safi";
568 }
569 case AFI_UNSPEC:
570 case AFI_MAX:
571 return "unknown-afi/safi";
572 }
573 /* all AFIs are accounted for above, so this shouldn't happen */
574 return "unknown-afi/safi";
575}
576
5d5393b9
DL
577int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
578 enum bgp_instance_type inst_type)
579{
580 int ret = bgp_get(bgp, as, name, inst_type);
581
582 if (ret == BGP_CREATED) {
583 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
d43114f3 584 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
5d5393b9
DL
585
586 if (DFLT_BGP_IMPORT_CHECK)
892fedb6 587 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
5d5393b9 588 if (DFLT_BGP_SHOW_HOSTNAME)
892fedb6 589 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
aef999a2
DA
590 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
591 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
5d5393b9 592 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
892fedb6 593 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
5d5393b9 594 if (DFLT_BGP_DETERMINISTIC_MED)
892fedb6 595 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
1d3fdccf
DA
596 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
597 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2adac256
DA
598 if (DFLT_BGP_SUPPRESS_DUPLICATES)
599 SET_FLAG((*bgp)->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
f2ca5c5b
DA
600 if (DFLT_BGP_GRACEFUL_NOTIFICATION)
601 SET_FLAG((*bgp)->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
1ae314be
DA
602 if (DFLT_BGP_HARD_ADMIN_RESET)
603 SET_FLAG((*bgp)->flags, BGP_FLAG_HARD_ADMIN_RESET);
5d5393b9
DL
604
605 ret = BGP_SUCCESS;
606 }
607 return ret;
608}
609
7eeee51e 610/*
f212a857 611 * bgp_vty_find_and_parse_afi_safi_bgp
7eeee51e 612 *
f212a857
DS
613 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
614 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
7eeee51e
DS
615 * to appropriate values for the calling function. This is to allow the
616 * calling function to make decisions appropriate for the show command
617 * that is being parsed.
618 *
619 * The show commands are generally of the form:
d62a17ae 620 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
621 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
7eeee51e
DS
622 *
623 * Since we use argv_find if the show command in particular doesn't have:
624 * [ip]
18c57037 625 * [<view|vrf> VIEWVRFNAME]
375a2e67 626 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
7eeee51e
DS
627 * The command parsing should still be ok.
628 *
629 * vty -> The vty for the command so we can output some useful data in
630 * the event of a parse error in the vrf.
631 * argv -> The command tokens
632 * argc -> How many command tokens we have
d62a17ae 633 * idx -> The current place in the command, generally should be 0 for this
634 * function
7eeee51e
DS
635 * afi -> The parsed afi if it was included in the show command, returned here
636 * safi -> The parsed safi if it was included in the show command, returned here
f212a857 637 * bgp -> Pointer to the bgp data structure we need to fill in.
52e5b8c4 638 * use_json -> json is configured or not
7eeee51e
DS
639 *
640 * The function returns the correct location in the parse tree for the
641 * last token found.
0e37c258
DS
642 *
643 * Returns 0 for failure to parse correctly, else the idx position of where
644 * it found the last token.
7eeee51e 645 */
d62a17ae 646int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
647 struct cmd_token **argv, int argc,
648 int *idx, afi_t *afi, safi_t *safi,
9f049418 649 struct bgp **bgp, bool use_json)
d62a17ae 650{
651 char *vrf_name = NULL;
652
653 assert(afi);
654 assert(safi);
655 assert(bgp);
656
657 if (argv_find(argv, argc, "ip", idx))
658 *afi = AFI_IP;
659
9a8bdf1c 660 if (argv_find(argv, argc, "view", idx))
d62a17ae 661 vrf_name = argv[*idx + 1]->arg;
9a8bdf1c
PG
662 else if (argv_find(argv, argc, "vrf", idx)) {
663 vrf_name = argv[*idx + 1]->arg;
664 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
665 vrf_name = NULL;
666 }
667 if (vrf_name) {
d62a17ae 668 if (strmatch(vrf_name, "all"))
669 *bgp = NULL;
670 else {
671 *bgp = bgp_lookup_by_name(vrf_name);
672 if (!*bgp) {
52e5b8c4
SP
673 if (use_json) {
674 json_object *json = NULL;
675 json = json_object_new_object();
676 json_object_string_add(
677 json, "warning",
678 "View/Vrf is unknown");
75eeda93 679 vty_json(vty, json);
52e5b8c4 680 }
ca61fd25
DS
681 else
682 vty_out(vty, "View/Vrf %s is unknown\n",
683 vrf_name);
d62a17ae 684 *idx = 0;
685 return 0;
686 }
687 }
688 } else {
689 *bgp = bgp_get_default();
690 if (!*bgp) {
52e5b8c4
SP
691 if (use_json) {
692 json_object *json = NULL;
693 json = json_object_new_object();
694 json_object_string_add(
695 json, "warning",
696 "Default BGP instance not found");
75eeda93 697 vty_json(vty, json);
52e5b8c4 698 }
ca61fd25
DS
699 else
700 vty_out(vty,
701 "Default BGP instance not found\n");
d62a17ae 702 *idx = 0;
703 return 0;
704 }
705 }
706
707 if (argv_find_and_parse_afi(argv, argc, idx, afi))
708 argv_find_and_parse_safi(argv, argc, idx, safi);
709
710 *idx += 1;
711 return *idx;
712}
713
28c6e247 714static bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
d62a17ae 715{
716 struct interface *ifp = NULL;
4122b697
DA
717 struct listnode *node;
718 struct bgp_listener *listener;
719 union sockunion all_su;
d62a17ae 720
4122b697 721 if (su->sa.sa_family == AF_INET) {
3d2a2725 722 (void)str2sockunion("0.0.0.0", &all_su);
d62a17ae 723 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
4122b697 724 } else if (su->sa.sa_family == AF_INET6) {
3d2a2725 725 (void)str2sockunion("::", &all_su);
d62a17ae 726 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
727 su->sin6.sin6_scope_id,
728 bgp->vrf_id);
4122b697 729 }
d62a17ae 730
4122b697
DA
731 if (ifp) {
732 for (ALL_LIST_ELEMENTS_RO(bm->listen_sockets, node, listener)) {
733 if (sockunion_family(su) !=
734 sockunion_family(&listener->su))
735 continue;
736
737 /* If 0.0.0.0/:: is a listener, then treat as self and
738 * reject.
739 */
740 if (!sockunion_cmp(&listener->su, su) ||
741 !sockunion_cmp(&listener->su, &all_su))
742 return true;
743 }
744 }
d62a17ae 745
3dc339cd 746 return false;
718e3744 747}
748
28c6e247
IR
749/* Utility function for looking up peer from VTY. */
750/* This is used only for configuration, so disallow if attempted on
751 * a dynamic neighbor.
752 */
753static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
754{
755 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
756 int ret;
757 union sockunion su;
758 struct peer *peer;
759
760 if (!bgp) {
761 return NULL;
762 }
763
764 ret = str2sockunion(ip_str, &su);
765 if (ret < 0) {
766 peer = peer_lookup_by_conf_if(bgp, ip_str);
767 if (!peer) {
768 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
769 == NULL) {
770 vty_out(vty,
771 "%% Malformed address or name: %s\n",
772 ip_str);
773 return NULL;
774 }
775 }
776 } else {
777 peer = peer_lookup(bgp, &su);
778 if (!peer) {
779 vty_out(vty,
780 "%% Specify remote-as or peer-group commands first\n");
781 return NULL;
782 }
783 if (peer_dynamic_neighbor(peer)) {
784 vty_out(vty,
785 "%% Operation not allowed on a dynamic neighbor\n");
786 return NULL;
787 }
788 }
789 return peer;
790}
791
718e3744 792/* Utility function for looking up peer or peer group. */
f14e6fdb
DS
793/* This is used only for configuration, so disallow if attempted on
794 * a dynamic neighbor.
795 */
d62a17ae 796struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
797{
798 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
799 int ret;
800 union sockunion su;
801 struct peer *peer = NULL;
802 struct peer_group *group = NULL;
803
804 if (!bgp) {
805 return NULL;
806 }
807
808 ret = str2sockunion(peer_str, &su);
809 if (ret == 0) {
810 /* IP address, locate peer. */
811 peer = peer_lookup(bgp, &su);
812 } else {
813 /* Not IP, could match either peer configured on interface or a
814 * group. */
815 peer = peer_lookup_by_conf_if(bgp, peer_str);
816 if (!peer)
817 group = peer_group_lookup(bgp, peer_str);
818 }
819
820 if (peer) {
821 if (peer_dynamic_neighbor(peer)) {
3b56a646
DA
822 zlog_warn(
823 "%pBP: Operation not allowed on a dynamic neighbor",
824 peer);
d62a17ae 825 vty_out(vty,
826 "%% Operation not allowed on a dynamic neighbor\n");
827 return NULL;
828 }
829
830 return peer;
831 }
832
833 if (group)
834 return group->conf;
835
3b56a646
DA
836 zlog_warn("Specify remote-as or peer-group commands first before: %s",
837 vty->buf);
d62a17ae 838 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
839
840 return NULL;
841}
842
4b7e23e9 843int bgp_vty_return(struct vty *vty, enum bgp_create_error_code ret)
d62a17ae 844{
845 const char *str = NULL;
846
847 switch (ret) {
4b7e23e9
DS
848 case BGP_SUCCESS:
849 case BGP_CREATED:
850 case BGP_GR_NO_OPERATION:
851 break;
d62a17ae 852 case BGP_ERR_INVALID_VALUE:
853 str = "Invalid value";
854 break;
855 case BGP_ERR_INVALID_FLAG:
856 str = "Invalid flag";
857 break;
858 case BGP_ERR_PEER_GROUP_SHUTDOWN:
859 str = "Peer-group has been shutdown. Activate the peer-group first";
860 break;
861 case BGP_ERR_PEER_FLAG_CONFLICT:
862 str = "Can't set override-capability and strict-capability-match at the same time";
863 break;
864 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
865 str = "Specify remote-as or peer-group remote AS first";
866 break;
867 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
868 str = "Cannot change the peer-group. Deconfigure first";
869 break;
870 case BGP_ERR_PEER_GROUP_MISMATCH:
871 str = "Peer is not a member of this peer-group";
872 break;
873 case BGP_ERR_PEER_FILTER_CONFLICT:
874 str = "Prefix/distribute list can not co-exist";
875 break;
876 case BGP_ERR_NOT_INTERNAL_PEER:
877 str = "Invalid command. Not an internal neighbor";
878 break;
879 case BGP_ERR_REMOVE_PRIVATE_AS:
880 str = "remove-private-AS cannot be configured for IBGP peers";
881 break;
d62a17ae 882 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
883 str = "Cannot have local-as same as BGP AS number";
884 break;
885 case BGP_ERR_TCPSIG_FAILED:
886 str = "Error while applying TCP-Sig to session(s)";
887 break;
888 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
889 str = "ebgp-multihop and ttl-security cannot be configured together";
890 break;
891 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
892 str = "ttl-security only allowed for EBGP peers";
893 break;
894 case BGP_ERR_AS_OVERRIDE:
895 str = "as-override cannot be configured for IBGP peers";
896 break;
897 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
898 str = "Invalid limit for number of dynamic neighbors";
899 break;
900 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
901 str = "Dynamic neighbor listen range already exists";
902 break;
903 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
904 str = "Operation not allowed on a dynamic neighbor";
905 break;
906 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
907 str = "Operation not allowed on a directly connected neighbor";
908 break;
909 case BGP_ERR_PEER_SAFI_CONFLICT:
a59803d0 910 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
055679e9 911 break;
912 case BGP_ERR_GR_INVALID_CMD:
913 str = "The Graceful Restart command used is not valid at this moment.";
914 break;
915 case BGP_ERR_GR_OPERATION_FAILED:
916 str = "The Graceful Restart Operation failed due to an err.";
917 break;
6dcea6fe
DS
918 case BGP_ERR_PEER_GROUP_MEMBER:
919 str = "Peer-group member cannot override remote-as of peer-group.";
920 break;
921 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
922 str = "Peer-group members must be all internal or all external.";
923 break;
4b7e23e9
DS
924 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_NOT_FOUND:
925 str = "Range specified cannot be deleted because it is not part of current config.";
926 break;
927 case BGP_ERR_INSTANCE_MISMATCH:
928 str = "Instance specified does not match the current instance.";
929 break;
930 case BGP_ERR_NO_INTERFACE_CONFIG:
931 str = "Interface specified is not being used for interface based peer.";
932 break;
933 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
934 str = "No configuration already specified for soft reconfiguration.";
935 break;
936 case BGP_ERR_AS_MISMATCH:
937 str = "BGP is already running.";
938 break;
939 case BGP_ERR_AF_UNCONFIGURED:
940 str = "AFI/SAFI specified is not currently configured.";
941 break;
4b7e23e9
DS
942 case BGP_ERR_INVALID_AS:
943 str = "Confederation AS specified is the same AS as our AS.";
944 break;
d864dd9e
EB
945 case BGP_ERR_INVALID_ROLE_NAME:
946 str = "Invalid role name";
947 break;
948 case BGP_ERR_INVALID_INTERNAL_ROLE:
8f2d6021 949 str = "External roles can be set only on eBGP session";
d864dd9e 950 break;
70cd87ca 951 case BGP_ERR_PEER_ORR_CONFIGURED:
d6b27611 952 str = "Deconfigure optimal-route-reflection on this peer first";
70cd87ca 953 break;
d62a17ae 954 }
955 if (str) {
956 vty_out(vty, "%% %s\n", str);
957 return CMD_WARNING_CONFIG_FAILED;
958 }
959 return CMD_SUCCESS;
718e3744 960}
961
7aafcaca 962/* BGP clear sort. */
d62a17ae 963enum clear_sort {
964 clear_all,
965 clear_peer,
966 clear_group,
967 clear_external,
968 clear_as
7aafcaca
DS
969};
970
1ca2fd11
IR
971static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
972 safi_t safi, int error)
d62a17ae 973{
974 switch (error) {
975 case BGP_ERR_AF_UNCONFIGURED:
a486300b
PG
976 if (vty)
977 vty_out(vty,
978 "%% BGP: Enable %s address family for the neighbor %s\n",
979 get_afi_safi_str(afi, safi, false), peer->host);
980 else
981 zlog_warn(
1af6e82b 982 "%% BGP: Enable %s address family for the neighbor %s",
a486300b 983 get_afi_safi_str(afi, safi, false), peer->host);
d62a17ae 984 break;
985 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
a486300b
PG
986 if (vty)
987 vty_out(vty,
988 "%% BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
989 peer->host);
990 else
991 zlog_warn(
1af6e82b 992 "%% BGP: Inbound soft reconfig for %s not possible as it has neither refresh capability, nor inbound soft reconfig",
a486300b 993 peer->host);
d62a17ae 994 break;
995 default:
996 break;
997 }
7aafcaca
DS
998}
999
dc912615 1000static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
c368171c 1001 struct listnode **nnode, enum bgp_clear_type stype)
dc912615
DS
1002{
1003 int ret = 0;
2adac256 1004 struct peer_af *paf;
dc912615
DS
1005
1006 /* if afi/.safi not specified, spin thru all of them */
1007 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
1008 afi_t tmp_afi;
1009 safi_t tmp_safi;
0e5cdd59
DS
1010 enum bgp_af_index index;
1011
1012 for (index = BGP_AF_START; index < BGP_AF_MAX; index++) {
1013 paf = peer->peer_af_array[index];
1014 if (!paf)
1015 continue;
dc912615 1016
2adac256
DA
1017 if (paf && paf->subgroup)
1018 SET_FLAG(paf->subgroup->sflags,
1019 SUBGRP_STATUS_FORCE_UPDATES);
1020
0e5cdd59
DS
1021 tmp_afi = paf->afi;
1022 tmp_safi = paf->safi;
dc912615
DS
1023 if (!peer->afc[tmp_afi][tmp_safi])
1024 continue;
1025
1026 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 1027 ret = peer_clear(peer, nnode);
dc912615
DS
1028 else
1029 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
1030 stype);
1031 }
1032 /* if afi specified and safi not, spin thru safis on this afi */
1033 } else if (safi == SAFI_UNSPEC) {
1034 safi_t tmp_safi;
1035
1036 for (tmp_safi = SAFI_UNICAST;
1037 tmp_safi < SAFI_MAX; tmp_safi++) {
1038 if (!peer->afc[afi][tmp_safi])
1039 continue;
1040
2adac256
DA
1041 paf = peer_af_find(peer, afi, tmp_safi);
1042 if (paf && paf->subgroup)
1043 SET_FLAG(paf->subgroup->sflags,
1044 SUBGRP_STATUS_FORCE_UPDATES);
1045
dc912615 1046 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 1047 ret = peer_clear(peer, nnode);
dc912615
DS
1048 else
1049 ret = peer_clear_soft(peer, afi,
1050 tmp_safi, stype);
1051 }
1052 /* both afi/safi specified, let the caller know if not defined */
1053 } else {
1054 if (!peer->afc[afi][safi])
1055 return 1;
1056
2adac256
DA
1057 paf = peer_af_find(peer, afi, safi);
1058 if (paf && paf->subgroup)
1059 SET_FLAG(paf->subgroup->sflags,
1060 SUBGRP_STATUS_FORCE_UPDATES);
1061
dc912615 1062 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 1063 ret = peer_clear(peer, nnode);
dc912615
DS
1064 else
1065 ret = peer_clear_soft(peer, afi, safi, stype);
1066 }
1067
1068 return ret;
1069}
1070
7aafcaca 1071/* `clear ip bgp' functions. */
1ca2fd11 1072static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
d62a17ae 1073 enum clear_sort sort, enum bgp_clear_type stype,
1ca2fd11 1074 const char *arg)
d62a17ae 1075{
dc912615 1076 int ret = 0;
3ae8bfa5 1077 bool found = false;
d62a17ae 1078 struct peer *peer;
dc95985f 1079
1080 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
d62a17ae 1081
1082 /* Clear all neighbors. */
1083 /*
1084 * Pass along pointer to next node to peer_clear() when walking all
3ae8bfa5
PM
1085 * nodes on the BGP instance as that may get freed if it is a
1086 * doppelganger
d62a17ae 1087 */
1088 if (sort == clear_all) {
1089 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dc95985f 1090
1091 bgp_peer_gr_flags_update(peer);
1092
36235319 1093 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
dc95985f 1094 gr_router_detected = true;
1095
c368171c 1096 ret = bgp_peer_clear(peer, afi, safi, &nnode,
dc912615 1097 stype);
d62a17ae 1098
1099 if (ret < 0)
1ca2fd11 1100 bgp_clear_vty_error(vty, peer, afi, safi, ret);
dc95985f 1101 }
1102
36235319
QY
1103 if (gr_router_detected
1104 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1105 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1106 } else if (!gr_router_detected
1107 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1108 bgp_zebra_send_capabilities(bgp, true);
04b6bdc0 1109 }
d62a17ae 1110
1111 /* This is to apply read-only mode on this clear. */
1112 if (stype == BGP_CLEAR_SOFT_NONE)
1113 bgp->update_delay_over = 0;
1114
1115 return CMD_SUCCESS;
7aafcaca
DS
1116 }
1117
3ae8bfa5 1118 /* Clear specified neighbor. */
d62a17ae 1119 if (sort == clear_peer) {
1120 union sockunion su;
d62a17ae 1121
1122 /* Make sockunion for lookup. */
1123 ret = str2sockunion(arg, &su);
1124 if (ret < 0) {
1125 peer = peer_lookup_by_conf_if(bgp, arg);
1126 if (!peer) {
1127 peer = peer_lookup_by_hostname(bgp, arg);
1128 if (!peer) {
1ca2fd11
IR
1129 vty_out(vty,
1130 "Malformed address or name: %s\n",
d62a17ae 1131 arg);
1132 return CMD_WARNING;
1133 }
1134 }
1135 } else {
1136 peer = peer_lookup(bgp, &su);
1137 if (!peer) {
1ca2fd11 1138 vty_out(vty,
664b6f18 1139 "%% BGP: Unknown neighbor - \"%s\"\n",
1ca2fd11 1140 arg);
d62a17ae 1141 return CMD_WARNING;
1142 }
1143 }
7aafcaca 1144
dc95985f 1145 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1146 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1147
dc912615
DS
1148 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1149
1150 /* if afi/safi not defined for this peer, let caller know */
1151 if (ret == 1)
3ae8bfa5 1152 ret = BGP_ERR_AF_UNCONFIGURED;
7aafcaca 1153
d62a17ae 1154 if (ret < 0)
1ca2fd11 1155 bgp_clear_vty_error(vty, peer, afi, safi, ret);
7aafcaca 1156
d62a17ae 1157 return CMD_SUCCESS;
7aafcaca 1158 }
7aafcaca 1159
3ae8bfa5 1160 /* Clear all neighbors belonging to a specific peer-group. */
d62a17ae 1161 if (sort == clear_group) {
1162 struct peer_group *group;
7aafcaca 1163
d62a17ae 1164 group = peer_group_lookup(bgp, arg);
1165 if (!group) {
664b6f18 1166 vty_out(vty, "%% BGP: No such peer-group %s\n", arg);
d62a17ae 1167 return CMD_WARNING;
1168 }
1169
1170 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
c368171c 1171 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 1172
d62a17ae 1173 if (ret < 0)
1ca2fd11 1174 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
1175 else
1176 found = true;
d62a17ae 1177 }
3ae8bfa5
PM
1178
1179 if (!found)
1ca2fd11 1180 vty_out(vty,
664b6f18 1181 "%% BGP: No %s peer belonging to peer-group %s is configured\n",
5cb5f4d0 1182 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1183
d62a17ae 1184 return CMD_SUCCESS;
7aafcaca 1185 }
7aafcaca 1186
3ae8bfa5 1187 /* Clear all external (eBGP) neighbors. */
d62a17ae 1188 if (sort == clear_external) {
1189 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1190 if (peer->sort == BGP_PEER_IBGP)
1191 continue;
7aafcaca 1192
dc95985f 1193 bgp_peer_gr_flags_update(peer);
1194
36235319 1195 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 1196 gr_router_detected = true;
dc95985f 1197
c368171c 1198 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 1199
d62a17ae 1200 if (ret < 0)
1ca2fd11 1201 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
1202 else
1203 found = true;
d62a17ae 1204 }
3ae8bfa5 1205
36235319
QY
1206 if (gr_router_detected
1207 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1208 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1209 } else if (!gr_router_detected
1210 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1211 bgp_zebra_send_capabilities(bgp, true);
1212 }
1213
3ae8bfa5 1214 if (!found)
1ca2fd11 1215 vty_out(vty,
664b6f18 1216 "%% BGP: No external %s peer is configured\n",
1ca2fd11 1217 get_afi_safi_str(afi, safi, false));
3ae8bfa5 1218
d62a17ae 1219 return CMD_SUCCESS;
1220 }
1221
3ae8bfa5 1222 /* Clear all neighbors belonging to a specific AS. */
d62a17ae 1223 if (sort == clear_as) {
3ae8bfa5 1224 as_t as = strtoul(arg, NULL, 10);
d62a17ae 1225
1226 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1227 if (peer->as != as)
1228 continue;
1229
dc95985f 1230 bgp_peer_gr_flags_update(peer);
1231
36235319 1232 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 1233 gr_router_detected = true;
dc95985f 1234
c368171c 1235 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
d62a17ae 1236
1237 if (ret < 0)
1ca2fd11 1238 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
1239 else
1240 found = true;
d62a17ae 1241 }
3ae8bfa5 1242
36235319
QY
1243 if (gr_router_detected
1244 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1245 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1246 } else if (!gr_router_detected
1247 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1248 bgp_zebra_send_capabilities(bgp, true);
1249 }
1250
3ae8bfa5 1251 if (!found)
1ca2fd11 1252 vty_out(vty,
664b6f18 1253 "%% BGP: No %s peer is configured with AS %s\n",
1ca2fd11 1254 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1255
d62a17ae 1256 return CMD_SUCCESS;
1257 }
1258
1259 return CMD_SUCCESS;
1260}
1261
1ca2fd11
IR
1262static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
1263 safi_t safi, enum clear_sort sort,
1264 enum bgp_clear_type stype, const char *arg)
d62a17ae 1265{
1266 struct bgp *bgp;
1267
1268 /* BGP structure lookup. */
1269 if (name) {
1270 bgp = bgp_lookup_by_name(name);
1271 if (bgp == NULL) {
1ca2fd11 1272 vty_out(vty, "Can't find BGP instance %s\n", name);
d62a17ae 1273 return CMD_WARNING;
1274 }
1275 } else {
1276 bgp = bgp_get_default();
1277 if (bgp == NULL) {
1ca2fd11 1278 vty_out(vty, "No BGP process is configured\n");
d62a17ae 1279 return CMD_WARNING;
1280 }
1281 }
1282
1ca2fd11 1283 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
7aafcaca
DS
1284}
1285
1286/* clear soft inbound */
1ca2fd11 1287static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
7aafcaca 1288{
99b3ebd3
NS
1289 afi_t afi;
1290 safi_t safi;
1291
1ca2fd11
IR
1292 FOREACH_AFI_SAFI (afi, safi)
1293 bgp_clear_vty(vty, name, afi, safi, clear_all,
1294 BGP_CLEAR_SOFT_IN, NULL);
7aafcaca
DS
1295}
1296
1297/* clear soft outbound */
1ca2fd11 1298static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
7aafcaca 1299{
99b3ebd3
NS
1300 afi_t afi;
1301 safi_t safi;
1302
1ca2fd11
IR
1303 FOREACH_AFI_SAFI (afi, safi)
1304 bgp_clear_vty(vty, name, afi, safi, clear_all,
1305 BGP_CLEAR_SOFT_OUT, NULL);
7aafcaca
DS
1306}
1307
1308
a486300b
PG
1309void bgp_clear_soft_in(struct bgp *bgp, afi_t afi, safi_t safi)
1310{
1311 bgp_clear(NULL, bgp, afi, safi, clear_all, BGP_CLEAR_SOFT_IN, NULL);
1312}
1313
4f770cf1
DA
1314static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
1315 uint64_t flag, int set)
1316{
1317 int ret;
1318 struct peer *peer;
1319
1320 peer = peer_and_group_lookup_vty(vty, ip_str);
1321 if (!peer)
1322 return CMD_WARNING_CONFIG_FAILED;
1323
1324 /*
1325 * If 'neighbor <interface>', then this is for directly connected peers,
1326 * we should not accept disable-connected-check.
1327 */
1328 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
1329 vty_out(vty,
1330 "%s is directly connected peer, cannot accept disable-connected-check\n",
1331 ip_str);
1332 return CMD_WARNING_CONFIG_FAILED;
1333 }
1334
1335 if (!set && flag == PEER_FLAG_SHUTDOWN)
1336 peer_tx_shutdown_message_unset(peer);
1337
1338 if (set)
1339 ret = peer_flag_set(peer, flag);
1340 else
1341 ret = peer_flag_unset(peer, flag);
1342
1343 return bgp_vty_return(vty, ret);
1344}
1345
1346static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint64_t flag)
1347{
1348 return peer_flag_modify_vty(vty, ip_str, flag, 1);
1349}
1350
1351static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
1352 uint64_t flag)
1353{
1354 return peer_flag_modify_vty(vty, ip_str, flag, 0);
1355}
1356
2e4c2296 1357#include "bgpd/bgp_vty_clippy.c"
f787d7a0 1358
8029b216
AK
1359DEFUN_HIDDEN (bgp_local_mac,
1360 bgp_local_mac_cmd,
093e3f23 1361 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
8029b216
AK
1362 BGP_STR
1363 "Local MAC config\n"
1364 "VxLAN Network Identifier\n"
1365 "VNI number\n"
1366 "local mac\n"
1367 "mac address\n"
1368 "mac-mobility sequence\n"
1369 "seq number\n")
1370{
1371 int rv;
1372 vni_t vni;
1373 struct ethaddr mac;
1374 struct ipaddr ip;
1375 uint32_t seq;
1376 struct bgp *bgp;
1377
1378 vni = strtoul(argv[3]->arg, NULL, 10);
1379 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1380 vty_out(vty, "%% Malformed MAC address\n");
1381 return CMD_WARNING;
1382 }
1383 memset(&ip, 0, sizeof(ip));
1384 seq = strtoul(argv[7]->arg, NULL, 10);
1385
1386 bgp = bgp_get_default();
1387 if (!bgp) {
1388 vty_out(vty, "Default BGP instance is not there\n");
1389 return CMD_WARNING;
1390 }
1391
b5e140c8
AK
1392 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1393 zero_esi);
8029b216
AK
1394 if (rv < 0) {
1395 vty_out(vty, "Internal error\n");
1396 return CMD_WARNING;
1397 }
1398
1399 return CMD_SUCCESS;
1400}
1401
1402DEFUN_HIDDEN (no_bgp_local_mac,
1403 no_bgp_local_mac_cmd,
093e3f23 1404 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
8029b216
AK
1405 NO_STR
1406 BGP_STR
1407 "Local MAC config\n"
1408 "VxLAN Network Identifier\n"
1409 "VNI number\n"
1410 "local mac\n"
1411 "mac address\n")
1412{
1413 int rv;
1414 vni_t vni;
1415 struct ethaddr mac;
1416 struct ipaddr ip;
1417 struct bgp *bgp;
1418
1419 vni = strtoul(argv[4]->arg, NULL, 10);
1420 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1421 vty_out(vty, "%% Malformed MAC address\n");
1422 return CMD_WARNING;
1423 }
1424 memset(&ip, 0, sizeof(ip));
1425
1426 bgp = bgp_get_default();
1427 if (!bgp) {
1428 vty_out(vty, "Default BGP instance is not there\n");
1429 return CMD_WARNING;
1430 }
1431
ec0ab544 1432 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
8029b216
AK
1433 if (rv < 0) {
1434 vty_out(vty, "Internal error\n");
1435 return CMD_WARNING;
1436 }
1437
1438 return CMD_SUCCESS;
1439}
1440
718e3744 1441DEFUN (no_synchronization,
1442 no_synchronization_cmd,
1443 "no synchronization",
1444 NO_STR
1445 "Perform IGP synchronization\n")
1446{
d62a17ae 1447 return CMD_SUCCESS;
718e3744 1448}
1449
1450DEFUN (no_auto_summary,
1451 no_auto_summary_cmd,
1452 "no auto-summary",
1453 NO_STR
1454 "Enable automatic network number summarization\n")
1455{
d62a17ae 1456 return CMD_SUCCESS;
718e3744 1457}
3d515fd9 1458
718e3744 1459/* "router bgp" commands. */
1ca2fd11
IR
1460DEFUN_NOSH (router_bgp,
1461 router_bgp_cmd,
1462 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1463 ROUTER_STR
1464 BGP_STR
1465 AS_STR
1466 BGP_INSTANCE_HELP_STR)
718e3744 1467{
d62a17ae 1468 int idx_asn = 2;
1469 int idx_view_vrf = 3;
1470 int idx_vrf = 4;
1ca2fd11
IR
1471 int is_new_bgp = 0;
1472 int ret;
d62a17ae 1473 as_t as;
1474 struct bgp *bgp;
1475 const char *name = NULL;
1476 enum bgp_instance_type inst_type;
1477
1478 // "router bgp" without an ASN
1479 if (argc == 2) {
1480 // Pending: Make VRF option available for ASN less config
1abef40f 1481 bgp = bgp_get_default();
d62a17ae 1482
1abef40f 1483 if (bgp == NULL) {
d62a17ae 1484 vty_out(vty, "%% No BGP process is configured\n");
1485 return CMD_WARNING_CONFIG_FAILED;
1486 }
1487
1488 if (listcount(bm->bgp) > 1) {
996c9314 1489 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1490 return CMD_WARNING_CONFIG_FAILED;
1491 }
1492 }
1493
1494 // "router bgp X"
1495 else {
ff8a8a7a 1496 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1ca2fd11 1497
cc413e2a
DA
1498 if (as == BGP_PRIVATE_AS_MAX || as == BGP_AS4_MAX)
1499 vty_out(vty, "Reserved AS used (%u|%u); AS is %u\n",
1500 BGP_PRIVATE_AS_MAX, BGP_AS4_MAX, as);
1501
d62a17ae 1502 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1503 if (argc > 3) {
1504 name = argv[idx_vrf]->arg;
1505
9a8bdf1c
PG
1506 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1507 if (strmatch(name, VRF_DEFAULT_NAME))
1508 name = NULL;
1509 else
1510 inst_type = BGP_INSTANCE_TYPE_VRF;
1ca2fd11 1511 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
d62a17ae 1512 inst_type = BGP_INSTANCE_TYPE_VIEW;
d62a17ae 1513 }
1514
1ca2fd11
IR
1515 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1516 is_new_bgp = (bgp_lookup(as, name) == NULL);
3bd70bf8 1517
1ca2fd11
IR
1518 ret = bgp_get_vty(&bgp, &as, name, inst_type);
1519 switch (ret) {
1520 case BGP_ERR_AS_MISMATCH:
1521 vty_out(vty, "BGP is already running; AS is %u\n", as);
1522 return CMD_WARNING_CONFIG_FAILED;
1523 case BGP_ERR_INSTANCE_MISMATCH:
1524 vty_out(vty,
1525 "BGP instance name and AS number mismatch\n");
1526 vty_out(vty,
1527 "BGP instance is already running; AS is %u\n",
1528 as);
1529 return CMD_WARNING_CONFIG_FAILED;
ff8a8a7a 1530 }
1ca2fd11
IR
1531
1532 /*
1533 * If we just instantiated the default instance, complete
1534 * any pending VRF-VPN leaking that was configured via
1535 * earlier "router bgp X vrf FOO" blocks.
1536 */
1537 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1538 vpn_leak_postchange_all();
1539
1540 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1541 bgp_vpn_leak_export(bgp);
1542 /* Pending: handle when user tries to change a view to vrf n vv.
1543 */
d62a17ae 1544 }
1545
1ca2fd11
IR
1546 /* unset the auto created flag as the user config is now present */
1547 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1548 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1549
1550 return CMD_SUCCESS;
718e3744 1551}
1552
718e3744 1553/* "no router bgp" commands. */
1ca2fd11
IR
1554DEFUN (no_router_bgp,
1555 no_router_bgp_cmd,
1556 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1557 NO_STR
1558 ROUTER_STR
1559 BGP_STR
1560 AS_STR
1561 BGP_INSTANCE_HELP_STR)
718e3744 1562{
4fd9919e 1563 int idx_asn = 3;
d62a17ae 1564 int idx_vrf = 5;
1ca2fd11 1565 as_t as;
4fd9919e 1566 struct bgp *bgp;
d62a17ae 1567 const char *name = NULL;
718e3744 1568
d62a17ae 1569 // "no router bgp" without an ASN
1570 if (argc == 3) {
1571 // Pending: Make VRF option available for ASN less config
8382083a 1572 bgp = bgp_get_default();
718e3744 1573
8382083a 1574 if (bgp == NULL) {
d62a17ae 1575 vty_out(vty, "%% No BGP process is configured\n");
1576 return CMD_WARNING_CONFIG_FAILED;
1577 }
7fb21a9f 1578
d62a17ae 1579 if (listcount(bm->bgp) > 1) {
996c9314 1580 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1581 return CMD_WARNING_CONFIG_FAILED;
1582 }
4fd9919e 1583
4fd9919e 1584 if (bgp->l3vni) {
be125e6f 1585 vty_out(vty, "%% Please unconfigure l3vni %u\n",
4fd9919e
IR
1586 bgp->l3vni);
1587 return CMD_WARNING_CONFIG_FAILED;
1588 }
d62a17ae 1589 } else {
4fd9919e
IR
1590 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1591
1ca42c8d 1592 if (argc > 4) {
d62a17ae 1593 name = argv[idx_vrf]->arg;
1ca42c8d
IR
1594 if (strmatch(argv[idx_vrf - 1]->text, "vrf")
1595 && strmatch(name, VRF_DEFAULT_NAME))
1596 name = NULL;
1597 }
7fb21a9f 1598
4fd9919e
IR
1599 /* Lookup bgp structure. */
1600 bgp = bgp_lookup(as, name);
1601 if (!bgp) {
1602 vty_out(vty, "%% Can't find BGP instance\n");
1603 return CMD_WARNING_CONFIG_FAILED;
1604 }
1605
1606 if (bgp->l3vni) {
1607 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1608 bgp->l3vni);
1609 return CMD_WARNING_CONFIG_FAILED;
1610 }
1611
1612 /* Cannot delete default instance if vrf instances exist */
1613 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1614 struct listnode *node;
1615 struct bgp *tmp_bgp;
1616
1617 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1618 if (tmp_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
1619 continue;
1620 if (CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1621 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1622 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1623 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1624 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1625 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1626 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1627 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1628 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1629 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1630 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1631 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1632 (bgp == bgp_get_evpn() &&
1633 (CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1634 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST) ||
1635 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1636 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP) ||
1637 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1638 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST) ||
1639 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1640 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))) ||
f33bf7c0 1641 (hashcount(tmp_bgp->vnihash))) {
4fd9919e
IR
1642 vty_out(vty,
1643 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1644 return CMD_WARNING_CONFIG_FAILED;
1645 }
1646 }
1647 }
d62a17ae 1648 }
718e3744 1649
1ca2fd11 1650 bgp_delete(bgp);
718e3744 1651
1ca2fd11 1652 return CMD_SUCCESS;
718e3744 1653}
1654
425bd64b
PS
1655/* bgp session-dscp */
1656
1657DEFPY (bgp_session_dscp,
1658 bgp_session_dscp_cmd,
1659 "bgp session-dscp (0-63)$dscp",
1660 BGP_STR
1661 "Override default (C6) bgp TCP session DSCP value\n"
1662 "Manually configured dscp parameter\n")
1663{
1664 bm->tcp_dscp = dscp << 2;
1665
1666 return CMD_SUCCESS;
1667}
1668
1669DEFPY (no_bgp_session_dscp,
1670 no_bgp_session_dscp_cmd,
1671 "no bgp session-dscp [(0-63)]",
1672 NO_STR
1673 BGP_STR
1674 "Override default (C6) bgp TCP session DSCP value\n"
1675 "Manually configured dscp parameter\n")
1676{
1677 bm->tcp_dscp = IPTOS_PREC_INTERNETCONTROL;
1678
1679 return CMD_SUCCESS;
1680}
718e3744 1681
ff8a8a7a
CS
1682/* BGP router-id. */
1683
1ca2fd11
IR
1684DEFPY (bgp_router_id,
1685 bgp_router_id_cmd,
1686 "bgp router-id A.B.C.D",
1687 BGP_STR
1688 "Override configured router identifier\n"
1689 "Manually configured router identifier\n")
718e3744 1690{
1ca2fd11
IR
1691 VTY_DECLVAR_CONTEXT(bgp, bgp);
1692 bgp_router_id_static_set(bgp, router_id);
1693 return CMD_SUCCESS;
ff8a8a7a 1694}
718e3744 1695
1ca2fd11
IR
1696DEFPY (no_bgp_router_id,
1697 no_bgp_router_id_cmd,
1698 "no bgp router-id [A.B.C.D]",
1699 NO_STR
1700 BGP_STR
1701 "Override configured router identifier\n"
1702 "Manually configured router identifier\n")
ff8a8a7a 1703{
1ca2fd11 1704 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1705
1ca2fd11
IR
1706 if (router_id_str) {
1707 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1708 vty_out(vty, "%% BGP router-id doesn't match\n");
1709 return CMD_WARNING_CONFIG_FAILED;
1710 }
1711 }
718e3744 1712
1ca2fd11
IR
1713 router_id.s_addr = 0;
1714 bgp_router_id_static_set(bgp, router_id);
1715
1716 return CMD_SUCCESS;
ff8a8a7a 1717}
6b0655a2 1718
ed0e57e3 1719DEFPY(bgp_community_alias, bgp_community_alias_cmd,
b4ad2fae 1720 "[no$no] bgp community alias WORD$community ALIAS_NAME$alias_name",
ed0e57e3
DA
1721 NO_STR BGP_STR
1722 "Add community specific parameters\n"
1723 "Create an alias for a community\n"
1724 "Community (AA:BB or AA:BB:CC)\n"
1725 "Alias name\n")
1726{
8cfa1e78 1727 struct community_alias ca = {};
ed0e57e3
DA
1728 struct community_alias *lookup_community;
1729 struct community_alias *lookup_alias;
d13d137a
DA
1730 struct community *comm;
1731 struct lcommunity *lcomm;
1732 uint8_t invalid = 0;
ed0e57e3 1733
d13d137a
DA
1734 comm = community_str2com(community);
1735 if (!comm)
1736 invalid++;
1737 community_free(&comm);
1738
1739 lcomm = lcommunity_str2com(community);
1740 if (!lcomm)
1741 invalid++;
1742 lcommunity_free(&lcomm);
1743
1744 if (invalid > 1) {
ed0e57e3
DA
1745 vty_out(vty, "Invalid community format\n");
1746 return CMD_WARNING;
1747 }
1748
8cfa1e78
DA
1749 strlcpy(ca.community, community, sizeof(ca.community));
1750 strlcpy(ca.alias, alias_name, sizeof(ca.alias));
ed0e57e3 1751
8cfa1e78
DA
1752 lookup_community = bgp_ca_community_lookup(&ca);
1753 lookup_alias = bgp_ca_alias_lookup(&ca);
ed0e57e3
DA
1754
1755 if (no) {
8cfa1e78
DA
1756 bgp_ca_alias_delete(&ca);
1757 bgp_ca_community_delete(&ca);
ed0e57e3
DA
1758 } else {
1759 if (lookup_alias) {
1760 /* Lookup if community hash table has an item
1761 * with the same alias name.
1762 */
8cfa1e78
DA
1763 strlcpy(ca.community, lookup_alias->community,
1764 sizeof(ca.community));
1765 if (bgp_ca_community_lookup(&ca)) {
ed0e57e3
DA
1766 vty_out(vty,
1767 "community (%s) already has this alias (%s)\n",
1768 lookup_alias->community,
1769 lookup_alias->alias);
1770 return CMD_WARNING;
1771 }
8cfa1e78 1772 bgp_ca_alias_delete(&ca);
ed0e57e3
DA
1773 }
1774
8cfa1e78
DA
1775 if (lookup_community) {
1776 /* Lookup if alias hash table has an item
1777 * with the same community.
1778 */
1779 strlcpy(ca.alias, lookup_community->alias,
1780 sizeof(ca.alias));
1781 if (bgp_ca_alias_lookup(&ca)) {
1782 vty_out(vty,
1783 "alias (%s) already has this community (%s)\n",
1784 lookup_community->alias,
1785 lookup_community->community);
1786 return CMD_WARNING;
1787 }
1788 bgp_ca_community_delete(&ca);
1789 }
ed0e57e3 1790
8cfa1e78
DA
1791 bgp_ca_alias_insert(&ca);
1792 bgp_ca_community_insert(&ca);
ed0e57e3
DA
1793 }
1794
1795 return CMD_SUCCESS;
1796}
1797
9acb67cb
DS
1798DEFPY (bgp_global_suppress_fib_pending,
1799 bgp_global_suppress_fib_pending_cmd,
1800 "[no] bgp suppress-fib-pending",
1801 NO_STR
1802 BGP_STR
1803 "Advertise only routes that are programmed in kernel to peers globally\n")
1804{
1805 bm_wait_for_fib_set(!no);
1806
1807 return CMD_SUCCESS;
1808}
1809
c208c586
S
1810DEFPY (bgp_suppress_fib_pending,
1811 bgp_suppress_fib_pending_cmd,
1812 "[no] bgp suppress-fib-pending",
1813 NO_STR
1814 BGP_STR
1815 "Advertise only routes that are programmed in kernel to peers\n")
1816{
1817 VTY_DECLVAR_CONTEXT(bgp, bgp);
1818
1819 bgp_suppress_fib_pending_set(bgp, !no);
1820 return CMD_SUCCESS;
1821}
1822
1823
718e3744 1824/* BGP Cluster ID. */
1ca2fd11
IR
1825DEFUN (bgp_cluster_id,
1826 bgp_cluster_id_cmd,
1827 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1828 BGP_STR
1829 "Configure Route-Reflector Cluster-id\n"
1830 "Route-Reflector Cluster-id in IP address format\n"
1831 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1832{
1ca2fd11 1833 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1834 int idx_ipv4 = 2;
1ca2fd11
IR
1835 int ret;
1836 struct in_addr cluster;
1837
1838 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1839 if (!ret) {
1840 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1841 return CMD_WARNING_CONFIG_FAILED;
1842 }
718e3744 1843
1ca2fd11
IR
1844 bgp_cluster_id_set(bgp, &cluster);
1845 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1846
1ca2fd11 1847 return CMD_SUCCESS;
718e3744 1848}
1849
1ca2fd11
IR
1850DEFUN (no_bgp_cluster_id,
1851 no_bgp_cluster_id_cmd,
1852 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1853 NO_STR
1854 BGP_STR
1855 "Configure Route-Reflector Cluster-id\n"
1856 "Route-Reflector Cluster-id in IP address format\n"
1857 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1858{
1ca2fd11
IR
1859 VTY_DECLVAR_CONTEXT(bgp, bgp);
1860 bgp_cluster_id_unset(bgp);
1861 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1862
1ca2fd11 1863 return CMD_SUCCESS;
718e3744 1864}
1865
c163f297
DS
1866DEFPY (bgp_norib,
1867 bgp_norib_cmd,
1868 "bgp no-rib",
1869 BGP_STR
1870 "Disable BGP route installation to RIB (Zebra)\n")
1871{
1872 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1873 vty_out(vty,
1874 "%% No-RIB option is already set, nothing to do here.\n");
1875 return CMD_SUCCESS;
1876 }
1877
1878 bgp_option_norib_set_runtime();
1879
1880 return CMD_SUCCESS;
1881}
1882
1883DEFPY (no_bgp_norib,
1884 no_bgp_norib_cmd,
1885 "no bgp no-rib",
1886 NO_STR
1887 BGP_STR
1888 "Disable BGP route installation to RIB (Zebra)\n")
1889{
1890 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1891 vty_out(vty,
1892 "%% No-RIB option is not set, nothing to do here.\n");
1893 return CMD_SUCCESS;
1894 }
1895
1896 bgp_option_norib_unset_runtime();
1897
1898 return CMD_SUCCESS;
1899}
1900
e46723a5
DS
1901DEFPY (no_bgp_send_extra_data,
1902 no_bgp_send_extra_data_cmd,
1903 "[no] bgp send-extra-data zebra",
1904 NO_STR
1905 BGP_STR
1906 "Extra data to Zebra for display/use\n"
1907 "To zebra\n")
1908{
ec0acb80
DA
1909 if (no)
1910 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1911 else
1912 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
e46723a5
DS
1913
1914 return CMD_SUCCESS;
1915}
1916
1ca2fd11
IR
1917DEFUN (bgp_confederation_identifier,
1918 bgp_confederation_identifier_cmd,
1919 "bgp confederation identifier (1-4294967295)",
e9273987 1920 BGP_STR
1ca2fd11
IR
1921 "AS confederation parameters\n"
1922 "AS number\n"
1923 "Set routing domain confederation AS\n")
718e3744 1924{
1ca2fd11 1925 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1926 int idx_number = 3;
1ca2fd11 1927 as_t as;
718e3744 1928
1ca2fd11 1929 as = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 1930
1ca2fd11 1931 bgp_confederation_id_set(bgp, as);
718e3744 1932
1ca2fd11 1933 return CMD_SUCCESS;
718e3744 1934}
1935
1ca2fd11
IR
1936DEFUN (no_bgp_confederation_identifier,
1937 no_bgp_confederation_identifier_cmd,
1938 "no bgp confederation identifier [(1-4294967295)]",
1939 NO_STR
e9273987 1940 BGP_STR
1ca2fd11
IR
1941 "AS confederation parameters\n"
1942 "AS number\n"
1943 "Set routing domain confederation AS\n")
ff8a8a7a 1944{
1ca2fd11
IR
1945 VTY_DECLVAR_CONTEXT(bgp, bgp);
1946 bgp_confederation_id_unset(bgp);
1947
1948 return CMD_SUCCESS;
ff8a8a7a
CS
1949}
1950
1ca2fd11
IR
1951DEFUN (bgp_confederation_peers,
1952 bgp_confederation_peers_cmd,
1953 "bgp confederation peers (1-4294967295)...",
e9273987 1954 BGP_STR
1ca2fd11
IR
1955 "AS confederation parameters\n"
1956 "Peer ASs in BGP confederation\n"
1957 AS_STR)
718e3744 1958{
1ca2fd11 1959 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1960 int idx_asn = 3;
1ca2fd11 1961 as_t as;
d62a17ae 1962 int i;
718e3744 1963
1ca2fd11
IR
1964 for (i = idx_asn; i < argc; i++) {
1965 as = strtoul(argv[i]->arg, NULL, 10);
1ca2fd11
IR
1966 bgp_confederation_peers_add(bgp, as);
1967 }
1968 return CMD_SUCCESS;
718e3744 1969}
1970
1ca2fd11
IR
1971DEFUN (no_bgp_confederation_peers,
1972 no_bgp_confederation_peers_cmd,
1973 "no bgp confederation peers (1-4294967295)...",
1974 NO_STR
e9273987 1975 BGP_STR
1ca2fd11
IR
1976 "AS confederation parameters\n"
1977 "Peer ASs in BGP confederation\n"
1978 AS_STR)
718e3744 1979{
1ca2fd11 1980 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1981 int idx_asn = 4;
1ca2fd11 1982 as_t as;
d62a17ae 1983 int i;
718e3744 1984
1ca2fd11
IR
1985 for (i = idx_asn; i < argc; i++) {
1986 as = strtoul(argv[i]->arg, NULL, 10);
ff8a8a7a 1987
1ca2fd11
IR
1988 bgp_confederation_peers_remove(bgp, as);
1989 }
1990 return CMD_SUCCESS;
718e3744 1991}
6b0655a2 1992
5e242b0d
DS
1993/**
1994 * Central routine for maximum-paths configuration.
1995 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1996 * @set: 1 for setting values, 0 for removing the max-paths config.
1997 */
585f1adc
IR
1998static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1999 const char *mpaths, uint16_t options,
2000 int set)
d62a17ae 2001{
585f1adc
IR
2002 VTY_DECLVAR_CONTEXT(bgp, bgp);
2003 uint16_t maxpaths = 0;
d62a17ae 2004 int ret;
585f1adc
IR
2005 afi_t afi;
2006 safi_t safi;
2007
2008 afi = bgp_node_afi(vty);
2009 safi = bgp_node_safi(vty);
d62a17ae 2010
2011 if (set) {
585f1adc 2012 maxpaths = strtol(mpaths, NULL, 10);
d62a17ae 2013 if (maxpaths > multipath_num) {
585f1adc 2014 vty_out(vty,
d62a17ae 2015 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
2016 maxpaths, multipath_num);
2017 return CMD_WARNING_CONFIG_FAILED;
2018 }
2019 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
2020 options);
2021 } else
2022 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
2023
2024 if (ret < 0) {
585f1adc 2025 vty_out(vty,
d62a17ae 2026 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
2027 (set == 1) ? "" : "un",
2028 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
2029 maxpaths, afi, safi);
2030 return CMD_WARNING_CONFIG_FAILED;
2031 }
2032
2033 bgp_recalculate_all_bestpaths(bgp);
2034
2035 return CMD_SUCCESS;
165b5fff
JB
2036}
2037
1ca2fd11
IR
2038DEFUN (bgp_maxmed_admin,
2039 bgp_maxmed_admin_cmd,
2040 "bgp max-med administrative ",
2041 BGP_STR
2042 "Advertise routes with max-med\n"
2043 "Administratively applied, for an indefinite period\n")
abc920f8 2044{
1ca2fd11 2045 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 2046
1ca2fd11
IR
2047 bgp->v_maxmed_admin = 1;
2048 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
ff8a8a7a 2049
1ca2fd11 2050 bgp_maxmed_update(bgp);
abc920f8 2051
1ca2fd11 2052 return CMD_SUCCESS;
ff8a8a7a
CS
2053}
2054
1ca2fd11
IR
2055DEFUN (bgp_maxmed_admin_medv,
2056 bgp_maxmed_admin_medv_cmd,
2057 "bgp max-med administrative (0-4294967295)",
2058 BGP_STR
2059 "Advertise routes with max-med\n"
2060 "Administratively applied, for an indefinite period\n"
2061 "Max MED value to be used\n")
abc920f8 2062{
1ca2fd11 2063 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 2064 int idx_number = 3;
abc920f8 2065
1ca2fd11
IR
2066 bgp->v_maxmed_admin = 1;
2067 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
abc920f8 2068
1ca2fd11 2069 bgp_maxmed_update(bgp);
abc920f8 2070
1ca2fd11 2071 return CMD_SUCCESS;
abc920f8
DS
2072}
2073
1ca2fd11
IR
2074DEFUN (no_bgp_maxmed_admin,
2075 no_bgp_maxmed_admin_cmd,
2076 "no bgp max-med administrative [(0-4294967295)]",
2077 NO_STR
2078 BGP_STR
2079 "Advertise routes with max-med\n"
2080 "Administratively applied, for an indefinite period\n"
2081 "Max MED value to be used\n")
abc920f8 2082{
1ca2fd11
IR
2083 VTY_DECLVAR_CONTEXT(bgp, bgp);
2084 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
2085 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
2086 bgp_maxmed_update(bgp);
ff8a8a7a 2087
1ca2fd11 2088 return CMD_SUCCESS;
abc920f8
DS
2089}
2090
1ca2fd11
IR
2091DEFUN (bgp_maxmed_onstartup,
2092 bgp_maxmed_onstartup_cmd,
2093 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
2094 BGP_STR
2095 "Advertise routes with max-med\n"
2096 "Effective on a startup\n"
2097 "Time (seconds) period for max-med\n"
2098 "Max MED value to be used\n")
abc920f8 2099{
1ca2fd11 2100 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 2101 int idx = 0;
4668a151 2102
9b01d289
DA
2103 if (argv_find(argv, argc, "(5-86400)", &idx))
2104 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
d62a17ae 2105 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1ca2fd11 2106 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
d62a17ae 2107 else
1ca2fd11 2108 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 2109
1ca2fd11
IR
2110 bgp_maxmed_update(bgp);
2111
2112 return CMD_SUCCESS;
abc920f8
DS
2113}
2114
1ca2fd11
IR
2115DEFUN (no_bgp_maxmed_onstartup,
2116 no_bgp_maxmed_onstartup_cmd,
2117 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
2118 NO_STR
2119 BGP_STR
2120 "Advertise routes with max-med\n"
2121 "Effective on a startup\n"
2122 "Time (seconds) period for max-med\n"
2123 "Max MED value to be used\n")
abc920f8 2124{
1ca2fd11
IR
2125 VTY_DECLVAR_CONTEXT(bgp, bgp);
2126
2127 /* Cancel max-med onstartup if its on */
2128 if (bgp->t_maxmed_onstartup) {
c3aaa89a 2129 THREAD_OFF(bgp->t_maxmed_onstartup);
1ca2fd11
IR
2130 bgp->maxmed_onstartup_over = 1;
2131 }
abc920f8 2132
1ca2fd11
IR
2133 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
2134 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 2135
1ca2fd11
IR
2136 bgp_maxmed_update(bgp);
2137
2138 return CMD_SUCCESS;
abc920f8
DS
2139}
2140
d70583f7
D
2141static int bgp_global_update_delay_config_vty(struct vty *vty,
2142 uint16_t update_delay,
2143 uint16_t establish_wait)
2144{
2145 struct listnode *node, *nnode;
2146 struct bgp *bgp;
2147 bool vrf_cfg = false;
2148
2149 /*
2150 * See if update-delay is set per-vrf and warn user to delete it
2151 * Note that we only need to check this if this is the first time
2152 * setting the global config.
2153 */
2154 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
2155 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2156 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
2157 vty_out(vty,
2158 "%% update-delay configuration found in vrf %s\n",
2159 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
2160 ? VRF_DEFAULT_NAME
2161 : bgp->name);
2162 vrf_cfg = true;
2163 }
2164 }
2165 }
2166
2167 if (vrf_cfg) {
2168 vty_out(vty,
2169 "%%Failed: global update-delay config not permitted\n");
2170 return CMD_WARNING;
2171 }
2172
2173 if (!establish_wait) { /* update-delay <delay> */
2174 bm->v_update_delay = update_delay;
2175 bm->v_establish_wait = bm->v_update_delay;
2176 } else {
2177 /* update-delay <delay> <establish-wait> */
2178 if (update_delay < establish_wait) {
2179 vty_out(vty,
2180 "%%Failed: update-delay less than the establish-wait!\n");
2181 return CMD_WARNING_CONFIG_FAILED;
2182 }
2183
2184 bm->v_update_delay = update_delay;
2185 bm->v_establish_wait = establish_wait;
2186 }
2187
2188 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2189 bgp->v_update_delay = bm->v_update_delay;
2190 bgp->v_establish_wait = bm->v_establish_wait;
2191 }
2192
2193 return CMD_SUCCESS;
2194}
2195
2196static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
2197{
2198 struct listnode *node, *nnode;
2199 struct bgp *bgp;
2200
2201 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
2202 bm->v_establish_wait = bm->v_update_delay;
2203
2204 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2205 bgp->v_update_delay = bm->v_update_delay;
2206 bgp->v_establish_wait = bm->v_establish_wait;
2207 }
2208
2209 return CMD_SUCCESS;
2210}
2211
2212static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
2213 uint16_t establish_wait)
f188f2c4 2214{
d62a17ae 2215 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 2216
d70583f7
D
2217 /* if configured globally, per-instance config is not allowed */
2218 if (bm->v_update_delay) {
2219 vty_out(vty,
2220 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
2221 return CMD_WARNING_CONFIG_FAILED;
2222 }
2223
f188f2c4 2224
d70583f7 2225 if (!establish_wait) /* update-delay <delay> */
d62a17ae 2226 {
2227 bgp->v_update_delay = update_delay;
2228 bgp->v_establish_wait = bgp->v_update_delay;
2229 return CMD_SUCCESS;
2230 }
f188f2c4 2231
d62a17ae 2232 /* update-delay <delay> <establish-wait> */
d62a17ae 2233 if (update_delay < establish_wait) {
2234 vty_out(vty,
2235 "%%Failed: update-delay less than the establish-wait!\n");
2236 return CMD_WARNING_CONFIG_FAILED;
2237 }
f188f2c4 2238
d62a17ae 2239 bgp->v_update_delay = update_delay;
2240 bgp->v_establish_wait = establish_wait;
f188f2c4 2241
d62a17ae 2242 return CMD_SUCCESS;
f188f2c4
DS
2243}
2244
d62a17ae 2245static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 2246{
d62a17ae 2247 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 2248
d70583f7
D
2249 /* If configured globally, cannot remove from one bgp instance */
2250 if (bm->v_update_delay) {
2251 vty_out(vty,
2252 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2253 return CMD_WARNING_CONFIG_FAILED;
2254 }
d62a17ae 2255 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2256 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 2257
d62a17ae 2258 return CMD_SUCCESS;
f188f2c4
DS
2259}
2260
2b791107 2261void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 2262{
d70583f7
D
2263 /* If configured globally, no need to display per-instance value */
2264 if (bgp->v_update_delay != bm->v_update_delay) {
d62a17ae 2265 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2266 if (bgp->v_update_delay != bgp->v_establish_wait)
2267 vty_out(vty, " %d", bgp->v_establish_wait);
2268 vty_out(vty, "\n");
2269 }
f188f2c4
DS
2270}
2271
d70583f7
D
2272/* Global update-delay configuration */
2273DEFPY (bgp_global_update_delay,
2274 bgp_global_update_delay_cmd,
2275 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2276 BGP_STR
2277 "Force initial delay for best-path and updates for all bgp instances\n"
2278 "Max delay in seconds\n"
2279 "Establish wait in seconds\n")
2280{
2281 return bgp_global_update_delay_config_vty(vty, delay, wait);
2282}
f188f2c4 2283
d70583f7
D
2284/* Global update-delay deconfiguration */
2285DEFPY (no_bgp_global_update_delay,
2286 no_bgp_global_update_delay_cmd,
2287 "no bgp update-delay [(0-3600) [(1-3600)]]",
2288 NO_STR
2289 BGP_STR
f188f2c4 2290 "Force initial delay for best-path and updates\n"
d70583f7
D
2291 "Max delay in seconds\n"
2292 "Establish wait in seconds\n")
f188f2c4 2293{
d70583f7 2294 return bgp_global_update_delay_deconfig_vty(vty);
f188f2c4
DS
2295}
2296
d70583f7
D
2297/* Update-delay configuration */
2298
2299DEFPY (bgp_update_delay,
2300 bgp_update_delay_cmd,
2301 "update-delay (0-3600)$delay [(1-3600)$wait]",
f188f2c4 2302 "Force initial delay for best-path and updates\n"
d70583f7
D
2303 "Max delay in seconds\n"
2304 "Establish wait in seconds\n")
f188f2c4 2305{
d70583f7 2306 return bgp_update_delay_config_vty(vty, delay, wait);
f188f2c4
DS
2307}
2308
2309/* Update-delay deconfiguration */
d70583f7 2310DEFPY (no_bgp_update_delay,
f188f2c4 2311 no_bgp_update_delay_cmd,
838758ac
DW
2312 "no update-delay [(0-3600) [(1-3600)]]",
2313 NO_STR
f188f2c4 2314 "Force initial delay for best-path and updates\n"
d70583f7
D
2315 "Max delay in seconds\n"
2316 "Establish wait in seconds\n")
f188f2c4 2317{
d62a17ae 2318 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
2319}
2320
5e242b0d 2321
1ca2fd11
IR
2322static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2323 bool set)
cb1faec9 2324{
1ca2fd11
IR
2325 VTY_DECLVAR_CONTEXT(bgp, bgp);
2326
8fa7732f
QY
2327 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2328 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
555e09d4
QY
2329
2330 return CMD_SUCCESS;
2331}
2332
1ca2fd11
IR
2333static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2334 bool set)
555e09d4 2335{
1ca2fd11
IR
2336 VTY_DECLVAR_CONTEXT(bgp, bgp);
2337
8fa7732f
QY
2338 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2339 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
cb1faec9 2340
d62a17ae 2341 return CMD_SUCCESS;
cb1faec9
DS
2342}
2343
2b791107 2344void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 2345{
555e09d4
QY
2346 uint32_t quanta =
2347 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2348 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 2349 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
2350}
2351
555e09d4
QY
2352void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2353{
2354 uint32_t quanta =
2355 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2356 if (quanta != BGP_READ_PACKET_MAX)
152456fe 2357 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 2358}
cb1faec9 2359
8fa7732f
QY
2360/* Packet quanta configuration
2361 *
2362 * XXX: The value set here controls the size of a stack buffer in the IO
2363 * thread. When changing these limits be careful to prevent stack overflow.
2364 *
2365 * Furthermore, the maximums used here should correspond to
2366 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2367 */
1ca2fd11
IR
2368DEFPY (bgp_wpkt_quanta,
2369 bgp_wpkt_quanta_cmd,
2370 "[no] write-quanta (1-64)$quanta",
2371 NO_STR
2372 "How many packets to write to peer socket per run\n"
2373 "Number of packets\n")
2374{
2375 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
2376}
cb1faec9 2377
1ca2fd11
IR
2378DEFPY (bgp_rpkt_quanta,
2379 bgp_rpkt_quanta_cmd,
2380 "[no] read-quanta (1-10)$quanta",
2381 NO_STR
2382 "How many packets to read from peer socket per I/O cycle\n"
2383 "Number of packets\n")
2384{
2385 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
555e09d4
QY
2386}
2387
2b791107 2388void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 2389{
37a333fe 2390 if (!bgp->heuristic_coalesce)
d62a17ae 2391 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
2392}
2393
d1adb448
PG
2394/* BGP TCP keepalive */
2395static void bgp_config_tcp_keepalive(struct vty *vty, struct bgp *bgp)
2396{
2397 if (bgp->tcp_keepalive_idle) {
2398 vty_out(vty, " bgp tcp-keepalive %u %u %u\n",
2399 bgp->tcp_keepalive_idle, bgp->tcp_keepalive_intvl,
2400 bgp->tcp_keepalive_probes);
2401 }
2402}
4668a151 2403
1ca2fd11
IR
2404DEFUN (bgp_coalesce_time,
2405 bgp_coalesce_time_cmd,
2406 "coalesce-time (0-4294967295)",
2407 "Subgroup coalesce timer\n"
2408 "Subgroup coalesce timer value (in ms)\n")
ff8a8a7a 2409{
1ca2fd11 2410 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 2411
1ca2fd11 2412 int idx = 0;
9b01d289 2413
1ca2fd11 2414 bgp->heuristic_coalesce = false;
9b01d289
DA
2415
2416 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2417 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
2418
1ca2fd11 2419 return CMD_SUCCESS;
3f9c7369
DS
2420}
2421
1ca2fd11
IR
2422DEFUN (no_bgp_coalesce_time,
2423 no_bgp_coalesce_time_cmd,
2424 "no coalesce-time (0-4294967295)",
2425 NO_STR
2426 "Subgroup coalesce timer\n"
2427 "Subgroup coalesce timer value (in ms)\n")
3f9c7369 2428{
1ca2fd11 2429 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 2430
1ca2fd11
IR
2431 bgp->heuristic_coalesce = true;
2432 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
2433 return CMD_SUCCESS;
3f9c7369
DS
2434}
2435
5e242b0d 2436/* Maximum-paths configuration */
585f1adc
IR
2437DEFUN (bgp_maxpaths,
2438 bgp_maxpaths_cmd,
2439 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2440 "Forward packets over multiple paths\n"
2441 "Number of paths\n")
5e242b0d 2442{
d62a17ae 2443 int idx_number = 1;
585f1adc
IR
2444 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
2445 argv[idx_number]->arg, 0, 1);
5e242b0d
DS
2446}
2447
d62a17ae 2448ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2449 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2450 "Forward packets over multiple paths\n"
2451 "Number of paths\n")
596c17ba 2452
585f1adc
IR
2453DEFUN (bgp_maxpaths_ibgp,
2454 bgp_maxpaths_ibgp_cmd,
2455 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2456 "Forward packets over multiple paths\n"
2457 "iBGP-multipath\n"
2458 "Number of paths\n")
165b5fff 2459{
d62a17ae 2460 int idx_number = 2;
585f1adc
IR
2461 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2462 argv[idx_number]->arg, 0, 1);
5e242b0d 2463}
165b5fff 2464
d62a17ae 2465ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2466 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2467 "Forward packets over multiple paths\n"
2468 "iBGP-multipath\n"
2469 "Number of paths\n")
596c17ba 2470
585f1adc
IR
2471DEFUN (bgp_maxpaths_ibgp_cluster,
2472 bgp_maxpaths_ibgp_cluster_cmd,
2473 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2474 "Forward packets over multiple paths\n"
2475 "iBGP-multipath\n"
2476 "Number of paths\n"
2477 "Match the cluster length\n")
5e242b0d 2478{
d62a17ae 2479 int idx_number = 2;
aa53c036
DS
2480 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2481 argv[idx_number]->arg, true, 1);
165b5fff
JB
2482}
2483
d62a17ae 2484ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2485 "maximum-paths ibgp " CMD_RANGE_STR(
2486 1, MULTIPATH_NUM) " equal-cluster-length",
2487 "Forward packets over multiple paths\n"
2488 "iBGP-multipath\n"
2489 "Number of paths\n"
2490 "Match the cluster length\n")
596c17ba 2491
585f1adc
IR
2492DEFUN (no_bgp_maxpaths,
2493 no_bgp_maxpaths_cmd,
2494 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2495 NO_STR
2496 "Forward packets over multiple paths\n"
2497 "Number of paths\n")
165b5fff 2498{
585f1adc 2499 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
165b5fff
JB
2500}
2501
d62a17ae 2502ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 2503 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 2504 "Forward packets over multiple paths\n"
2505 "Number of paths\n")
596c17ba 2506
585f1adc
IR
2507DEFUN (no_bgp_maxpaths_ibgp,
2508 no_bgp_maxpaths_ibgp_cmd,
2509 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2510 NO_STR
2511 "Forward packets over multiple paths\n"
2512 "iBGP-multipath\n"
2513 "Number of paths\n"
2514 "Match the cluster length\n")
165b5fff 2515{
585f1adc 2516 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
2517}
2518
d62a17ae 2519ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2520 "no maximum-paths ibgp [" CMD_RANGE_STR(
2521 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2522 NO_STR
2523 "Forward packets over multiple paths\n"
2524 "iBGP-multipath\n"
2525 "Number of paths\n"
2526 "Match the cluster length\n")
596c17ba 2527
dd65f45e
DL
2528static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2529 afi_t afi, safi_t safi)
165b5fff 2530{
00908b7a 2531 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
d62a17ae 2532 vty_out(vty, " maximum-paths %d\n",
2533 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2534 }
165b5fff 2535
00908b7a 2536 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
d62a17ae 2537 vty_out(vty, " maximum-paths ibgp %d",
2538 bgp->maxpaths[afi][safi].maxpaths_ibgp);
aa53c036 2539 if (bgp->maxpaths[afi][safi].same_clusterlen)
d62a17ae 2540 vty_out(vty, " equal-cluster-length");
2541 vty_out(vty, "\n");
2542 }
165b5fff 2543}
6b0655a2 2544
718e3744 2545/* BGP timers. */
2546
1ca2fd11
IR
2547DEFUN (bgp_timers,
2548 bgp_timers_cmd,
2549 "timers bgp (0-65535) (0-65535)",
2550 "Adjust routing timers\n"
2551 "BGP timers\n"
2552 "Keepalive interval\n"
2553 "Holdtime\n")
718e3744 2554{
1ca2fd11 2555 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 2556 int idx_number = 2;
2557 int idx_number_2 = 3;
1ca2fd11
IR
2558 unsigned long keepalive = 0;
2559 unsigned long holdtime = 0;
718e3744 2560
1ca2fd11
IR
2561 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
2562 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
718e3744 2563
1ca2fd11
IR
2564 /* Holdtime value check. */
2565 if (holdtime < 3 && holdtime != 0) {
2566 vty_out(vty,
2567 "%% hold time value must be either 0 or greater than 3\n");
2568 return CMD_WARNING_CONFIG_FAILED;
2569 }
718e3744 2570
1ca2fd11
IR
2571 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY,
2572 BGP_DEFAULT_DELAYOPEN);
718e3744 2573
1ca2fd11 2574 return CMD_SUCCESS;
718e3744 2575}
2576
1ca2fd11
IR
2577DEFUN (no_bgp_timers,
2578 no_bgp_timers_cmd,
2579 "no timers bgp [(0-65535) (0-65535)]",
2580 NO_STR
2581 "Adjust routing timers\n"
2582 "BGP timers\n"
2583 "Keepalive interval\n"
2584 "Holdtime\n")
718e3744 2585{
1ca2fd11
IR
2586 VTY_DECLVAR_CONTEXT(bgp, bgp);
2587 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
2588 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
ff8a8a7a 2589
1ca2fd11 2590 return CMD_SUCCESS;
718e3744 2591}
2592
b042667a
TI
2593/* BGP minimum holdtime. */
2594
2595DEFUN(bgp_minimum_holdtime, bgp_minimum_holdtime_cmd,
2596 "bgp minimum-holdtime (1-65535)",
2597 "BGP specific commands\n"
2598 "BGP minimum holdtime\n"
2599 "Seconds\n")
2600{
2601 VTY_DECLVAR_CONTEXT(bgp, bgp);
2602 int idx_number = 2;
2603 unsigned long min_holdtime;
2604
2605 min_holdtime = strtoul(argv[idx_number]->arg, NULL, 10);
2606
2607 bgp->default_min_holdtime = min_holdtime;
2608
2609 return CMD_SUCCESS;
2610}
2611
2612DEFUN(no_bgp_minimum_holdtime, no_bgp_minimum_holdtime_cmd,
2613 "no bgp minimum-holdtime [(1-65535)]",
2614 NO_STR
2615 "BGP specific commands\n"
2616 "BGP minimum holdtime\n"
2617 "Seconds\n")
2618{
2619 VTY_DECLVAR_CONTEXT(bgp, bgp);
2620
2621 bgp->default_min_holdtime = 0;
2622
2623 return CMD_SUCCESS;
2624}
ff8a8a7a 2625
d1adb448
PG
2626DEFPY(bgp_tcp_keepalive, bgp_tcp_keepalive_cmd,
2627 "bgp tcp-keepalive (1-65535)$idle (1-65535)$intvl (1-30)$probes",
2628 BGP_STR
2629 "TCP keepalive parameters\n"
2630 "TCP keepalive idle time (seconds)\n"
2631 "TCP keepalive interval (seconds)\n"
2632 "TCP keepalive maximum probes\n")
2633{
2634 VTY_DECLVAR_CONTEXT(bgp, bgp);
2635
2636 bgp_tcp_keepalive_set(bgp, (uint16_t)idle, (uint16_t)intvl,
2637 (uint16_t)probes);
2638
2639 return CMD_SUCCESS;
2640}
2641
2642DEFPY(no_bgp_tcp_keepalive, no_bgp_tcp_keepalive_cmd,
2643 "no bgp tcp-keepalive [(1-65535) (1-65535) (1-30)]",
2644 NO_STR
2645 BGP_STR
2646 "TCP keepalive parameters\n"
2647 "TCP keepalive idle time (seconds)\n"
2648 "TCP keepalive interval (seconds)\n"
2649 "TCP keepalive maximum probes\n")
2650{
2651 VTY_DECLVAR_CONTEXT(bgp, bgp);
2652
2653 bgp_tcp_keepalive_unset(bgp);
2654
2655 return CMD_SUCCESS;
2656}
2657
1ca2fd11
IR
2658DEFUN (bgp_client_to_client_reflection,
2659 bgp_client_to_client_reflection_cmd,
2660 "bgp client-to-client reflection",
e9273987 2661 BGP_STR
1ca2fd11
IR
2662 "Configure client to client route reflection\n"
2663 "reflection of routes allowed\n")
718e3744 2664{
1ca2fd11
IR
2665 VTY_DECLVAR_CONTEXT(bgp, bgp);
2666 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2667 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 2668
1ca2fd11 2669 return CMD_SUCCESS;
718e3744 2670}
2671
1ca2fd11
IR
2672DEFUN (no_bgp_client_to_client_reflection,
2673 no_bgp_client_to_client_reflection_cmd,
2674 "no bgp client-to-client reflection",
2675 NO_STR
e9273987 2676 BGP_STR
1ca2fd11
IR
2677 "Configure client to client route reflection\n"
2678 "reflection of routes allowed\n")
718e3744 2679{
1ca2fd11
IR
2680 VTY_DECLVAR_CONTEXT(bgp, bgp);
2681 SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2682 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 2683
1ca2fd11 2684 return CMD_SUCCESS;
718e3744 2685}
2686
2687/* "bgp always-compare-med" configuration. */
1ca2fd11
IR
2688DEFUN (bgp_always_compare_med,
2689 bgp_always_compare_med_cmd,
2690 "bgp always-compare-med",
e9273987 2691 BGP_STR
1ca2fd11 2692 "Allow comparing MED from different neighbors\n")
718e3744 2693{
1ca2fd11
IR
2694 VTY_DECLVAR_CONTEXT(bgp, bgp);
2695 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2696 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2697
1ca2fd11 2698 return CMD_SUCCESS;
718e3744 2699}
2700
1ca2fd11
IR
2701DEFUN (no_bgp_always_compare_med,
2702 no_bgp_always_compare_med_cmd,
2703 "no bgp always-compare-med",
2704 NO_STR
e9273987 2705 BGP_STR
1ca2fd11 2706 "Allow comparing MED from different neighbors\n")
718e3744 2707{
1ca2fd11
IR
2708 VTY_DECLVAR_CONTEXT(bgp, bgp);
2709 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2710 bgp_recalculate_all_bestpaths(bgp);
6b0655a2 2711
1ca2fd11 2712 return CMD_SUCCESS;
2adac256
DA
2713}
2714
2adac256 2715
1ca2fd11
IR
2716DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2717 "bgp ebgp-requires-policy",
e9273987 2718 BGP_STR
1ca2fd11 2719 "Require in and out policy for eBGP peers (RFC8212)\n")
2adac256 2720{
1ca2fd11
IR
2721 VTY_DECLVAR_CONTEXT(bgp, bgp);
2722 SET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2723 return CMD_SUCCESS;
2adac256
DA
2724}
2725
1ca2fd11
IR
2726DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2727 "no bgp ebgp-requires-policy",
2728 NO_STR
e9273987 2729 BGP_STR
1ca2fd11 2730 "Require in and out policy for eBGP peers (RFC8212)\n")
ff8a8a7a 2731{
1ca2fd11
IR
2732 VTY_DECLVAR_CONTEXT(bgp, bgp);
2733 UNSET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2734 return CMD_SUCCESS;
ff8a8a7a 2735}
9dac9fc8 2736
1ca2fd11
IR
2737DEFUN(bgp_suppress_duplicates, bgp_suppress_duplicates_cmd,
2738 "bgp suppress-duplicates",
e9273987 2739 BGP_STR
1ca2fd11 2740 "Suppress duplicate updates if the route actually not changed\n")
9dac9fc8 2741{
1ca2fd11
IR
2742 VTY_DECLVAR_CONTEXT(bgp, bgp);
2743 SET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2744 return CMD_SUCCESS;
9dac9fc8
DA
2745}
2746
1ca2fd11
IR
2747DEFUN(no_bgp_suppress_duplicates, no_bgp_suppress_duplicates_cmd,
2748 "no bgp suppress-duplicates",
2749 NO_STR
e9273987 2750 BGP_STR
1ca2fd11 2751 "Suppress duplicate updates if the route actually not changed\n")
9dac9fc8 2752{
1ca2fd11
IR
2753 VTY_DECLVAR_CONTEXT(bgp, bgp);
2754 UNSET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2755 return CMD_SUCCESS;
9dac9fc8
DA
2756}
2757
fb29348a
DA
2758DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2759 "bgp reject-as-sets",
e9273987 2760 BGP_STR
fb29348a
DA
2761 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2762{
2763 VTY_DECLVAR_CONTEXT(bgp, bgp);
2764 struct listnode *node, *nnode;
2765 struct peer *peer;
2766
7f972cd8 2767 bgp->reject_as_sets = true;
fb29348a
DA
2768
2769 /* Reset existing BGP sessions to reject routes
2770 * with aspath containing AS_SET or AS_CONFED_SET.
2771 */
2772 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2773 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2774 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2775 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2776 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2777 }
2778 }
2779
2780 return CMD_SUCCESS;
2781}
2782
2783DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2784 "no bgp reject-as-sets",
2785 NO_STR
e9273987 2786 BGP_STR
fb29348a
DA
2787 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2788{
2789 VTY_DECLVAR_CONTEXT(bgp, bgp);
2790 struct listnode *node, *nnode;
2791 struct peer *peer;
2792
7f972cd8 2793 bgp->reject_as_sets = false;
fb29348a
DA
2794
2795 /* Reset existing BGP sessions to reject routes
2796 * with aspath containing AS_SET or AS_CONFED_SET.
2797 */
2798 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2799 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2800 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2801 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2802 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2803 }
2804 }
2805
2806 return CMD_SUCCESS;
2807}
9dac9fc8 2808
718e3744 2809/* "bgp deterministic-med" configuration. */
1ca2fd11 2810DEFUN (bgp_deterministic_med,
718e3744 2811 bgp_deterministic_med_cmd,
2812 "bgp deterministic-med",
e9273987 2813 BGP_STR
718e3744 2814 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2815{
1ca2fd11
IR
2816 VTY_DECLVAR_CONTEXT(bgp, bgp);
2817
2818 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2819 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2820 bgp_recalculate_all_bestpaths(bgp);
2821 }
7aafcaca 2822
1ca2fd11 2823 return CMD_SUCCESS;
718e3744 2824}
2825
1ca2fd11 2826DEFUN (no_bgp_deterministic_med,
718e3744 2827 no_bgp_deterministic_med_cmd,
2828 "no bgp deterministic-med",
2829 NO_STR
e9273987 2830 BGP_STR
718e3744 2831 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2832{
1ca2fd11
IR
2833 VTY_DECLVAR_CONTEXT(bgp, bgp);
2834 int bestpath_per_as_used;
2835 afi_t afi;
2836 safi_t safi;
2837 struct peer *peer;
2838 struct listnode *node, *nnode;
2839
2840 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2841 bestpath_per_as_used = 0;
2842
2843 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2844 FOREACH_AFI_SAFI (afi, safi)
2845 if (bgp_addpath_dmed_required(
2846 peer->addpath_type[afi][safi])) {
2847 bestpath_per_as_used = 1;
2848 break;
2849 }
2850
2851 if (bestpath_per_as_used)
2852 break;
2853 }
2854
2855 if (bestpath_per_as_used) {
2856 vty_out(vty,
2857 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2858 return CMD_WARNING_CONFIG_FAILED;
2859 } else {
2860 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2861 bgp_recalculate_all_bestpaths(bgp);
2862 }
2863 }
d62a17ae 2864
1ca2fd11 2865 return CMD_SUCCESS;
718e3744 2866}
538621f2 2867
055679e9 2868/* "bgp graceful-restart mode" configuration. */
538621f2 2869DEFUN (bgp_graceful_restart,
2ba1fe69 2870 bgp_graceful_restart_cmd,
2871 "bgp graceful-restart",
e9273987 2872 BGP_STR
2ba1fe69 2873 GR_CMD
055679e9 2874 )
538621f2 2875{
055679e9 2876 int ret = BGP_GR_FAILURE;
2877
2878 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2879 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
dc95985f 2880
d62a17ae 2881 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2882
2883 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2884
36235319
QY
2885 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2886 ret);
5cce3f05 2887
055679e9 2888 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2889 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
dc95985f 2890 vty_out(vty,
2891 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2892 return bgp_vty_return(vty, ret);
538621f2 2893}
2894
2895DEFUN (no_bgp_graceful_restart,
2ba1fe69 2896 no_bgp_graceful_restart_cmd,
2897 "no bgp graceful-restart",
2898 NO_STR
e9273987 2899 BGP_STR
2ba1fe69 2900 NO_GR_CMD
055679e9 2901 )
538621f2 2902{
d62a17ae 2903 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2904
2905 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2906 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
055679e9 2907
2908 int ret = BGP_GR_FAILURE;
2909
2910 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2911
36235319
QY
2912 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2913 ret);
5cce3f05 2914
055679e9 2915 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2916 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
dc95985f 2917 vty_out(vty,
2918 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2919
2920 return bgp_vty_return(vty, ret);
538621f2 2921}
2922
93406d87 2923DEFUN (bgp_graceful_restart_stalepath_time,
2ba1fe69 2924 bgp_graceful_restart_stalepath_time_cmd,
2925 "bgp graceful-restart stalepath-time (1-4095)",
e9273987 2926 BGP_STR
2ba1fe69 2927 "Graceful restart capability parameters\n"
2928 "Set the max time to hold onto restarting peer's stale paths\n"
2929 "Delay value (seconds)\n")
93406d87 2930{
d62a17ae 2931 VTY_DECLVAR_CONTEXT(bgp, bgp);
2932 int idx_number = 3;
d7c0a89a 2933 uint32_t stalepath;
93406d87 2934
d62a17ae 2935 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2936 bgp->stalepath_time = stalepath;
2937 return CMD_SUCCESS;
93406d87 2938}
2939
eb6f1b41 2940DEFUN (bgp_graceful_restart_restart_time,
2ba1fe69 2941 bgp_graceful_restart_restart_time_cmd,
dcbebfd3 2942 "bgp graceful-restart restart-time (0-4095)",
e9273987 2943 BGP_STR
2ba1fe69 2944 "Graceful restart capability parameters\n"
2945 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2946 "Delay value (seconds)\n")
eb6f1b41 2947{
d62a17ae 2948 VTY_DECLVAR_CONTEXT(bgp, bgp);
2949 int idx_number = 3;
d7c0a89a 2950 uint32_t restart;
eb6f1b41 2951
d62a17ae 2952 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2953 bgp->restart_time = restart;
2954 return CMD_SUCCESS;
eb6f1b41
PG
2955}
2956
cfd47646 2957DEFUN (bgp_graceful_restart_select_defer_time,
2958 bgp_graceful_restart_select_defer_time_cmd,
2959 "bgp graceful-restart select-defer-time (0-3600)",
e9273987 2960 BGP_STR
cfd47646 2961 "Graceful restart capability parameters\n"
2962 "Set the time to defer the BGP route selection after restart\n"
2963 "Delay value (seconds, 0 - disable)\n")
2964{
2965 VTY_DECLVAR_CONTEXT(bgp, bgp);
2966 int idx_number = 3;
2967 uint32_t defer_time;
2968
2969 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2970 bgp->select_defer_time = defer_time;
2971 if (defer_time == 0)
892fedb6 2972 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2973 else
892fedb6 2974 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2975
2976 return CMD_SUCCESS;
2977}
2978
93406d87 2979DEFUN (no_bgp_graceful_restart_stalepath_time,
2ba1fe69 2980 no_bgp_graceful_restart_stalepath_time_cmd,
2981 "no bgp graceful-restart stalepath-time [(1-4095)]",
2982 NO_STR
e9273987 2983 BGP_STR
2ba1fe69 2984 "Graceful restart capability parameters\n"
2985 "Set the max time to hold onto restarting peer's stale paths\n"
2986 "Delay value (seconds)\n")
93406d87 2987{
d62a17ae 2988 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 2989
d62a17ae 2990 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2991 return CMD_SUCCESS;
93406d87 2992}
2993
eb6f1b41 2994DEFUN (no_bgp_graceful_restart_restart_time,
2ba1fe69 2995 no_bgp_graceful_restart_restart_time_cmd,
dcbebfd3 2996 "no bgp graceful-restart restart-time [(0-4095)]",
2ba1fe69 2997 NO_STR
e9273987 2998 BGP_STR
2ba1fe69 2999 "Graceful restart capability parameters\n"
3000 "Set the time to wait to delete stale routes before a BGP open message is received\n"
3001 "Delay value (seconds)\n")
eb6f1b41 3002{
d62a17ae 3003 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 3004
d62a17ae 3005 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
3006 return CMD_SUCCESS;
eb6f1b41
PG
3007}
3008
cfd47646 3009DEFUN (no_bgp_graceful_restart_select_defer_time,
3010 no_bgp_graceful_restart_select_defer_time_cmd,
3011 "no bgp graceful-restart select-defer-time [(0-3600)]",
3012 NO_STR
e9273987 3013 BGP_STR
cfd47646 3014 "Graceful restart capability parameters\n"
3015 "Set the time to defer the BGP route selection after restart\n"
3016 "Delay value (seconds)\n")
3017{
3018 VTY_DECLVAR_CONTEXT(bgp, bgp);
3019
3020 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
892fedb6 3021 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 3022
3023 return CMD_SUCCESS;
3024}
3025
43fc21b3 3026DEFUN (bgp_graceful_restart_preserve_fw,
2ba1fe69 3027 bgp_graceful_restart_preserve_fw_cmd,
3028 "bgp graceful-restart preserve-fw-state",
e9273987 3029 BGP_STR
2ba1fe69 3030 "Graceful restart capability parameters\n"
3031 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 3032{
d62a17ae 3033 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3034 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 3035 return CMD_SUCCESS;
43fc21b3
JC
3036}
3037
3038DEFUN (no_bgp_graceful_restart_preserve_fw,
2ba1fe69 3039 no_bgp_graceful_restart_preserve_fw_cmd,
3040 "no bgp graceful-restart preserve-fw-state",
3041 NO_STR
e9273987 3042 BGP_STR
2ba1fe69 3043 "Graceful restart capability parameters\n"
3044 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 3045{
d62a17ae 3046 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3047 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 3048 return CMD_SUCCESS;
43fc21b3
JC
3049}
3050
f2ca5c5b
DA
3051DEFPY (bgp_graceful_restart_notification,
3052 bgp_graceful_restart_notification_cmd,
3053 "[no$no] bgp graceful-restart notification",
3054 NO_STR
3055 BGP_STR
3056 "Graceful restart capability parameters\n"
3057 "Indicate Graceful Restart support for BGP NOTIFICATION messages\n")
3058{
3059 VTY_DECLVAR_CONTEXT(bgp, bgp);
3060
3061 if (no)
3062 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
3063 else
3064 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
3065
3066 return CMD_SUCCESS;
3067}
3068
1ae314be
DA
3069DEFPY (bgp_administrative_reset,
3070 bgp_administrative_reset_cmd,
3071 "[no$no] bgp hard-administrative-reset",
3072 NO_STR
3073 BGP_STR
3074 "Send Hard Reset CEASE Notification for 'Administrative Reset'\n")
3075{
3076 VTY_DECLVAR_CONTEXT(bgp, bgp);
3077
3078 if (no)
3079 UNSET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3080 else
3081 SET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3082
3083 return CMD_SUCCESS;
3084}
3085
055679e9 3086DEFUN (bgp_graceful_restart_disable,
2ba1fe69 3087 bgp_graceful_restart_disable_cmd,
3088 "bgp graceful-restart-disable",
e9273987 3089 BGP_STR
2ba1fe69 3090 GR_DISABLE)
055679e9 3091{
3092 int ret = BGP_GR_FAILURE;
3093
3094 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3095 zlog_debug(
2ba1fe69 3096 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
dc95985f 3097
055679e9 3098 VTY_DECLVAR_CONTEXT(bgp, bgp);
3099
3100 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
3101
dc95985f 3102 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
3103 bgp->peer, ret);
5cce3f05 3104
055679e9 3105 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3106 zlog_debug(
2ba1fe69 3107 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
dc95985f 3108 vty_out(vty,
3109 "Graceful restart configuration changed, reset all peers to take effect\n");
3110
055679e9 3111 return bgp_vty_return(vty, ret);
3112}
3113
3114DEFUN (no_bgp_graceful_restart_disable,
2ba1fe69 3115 no_bgp_graceful_restart_disable_cmd,
3116 "no bgp graceful-restart-disable",
3117 NO_STR
e9273987 3118 BGP_STR
2ba1fe69 3119 NO_GR_DISABLE
055679e9 3120 )
3121{
3122 VTY_DECLVAR_CONTEXT(bgp, bgp);
3123
3124 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3125 zlog_debug(
2ba1fe69 3126 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
055679e9 3127
3128 int ret = BGP_GR_FAILURE;
3129
3130 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
3131
36235319
QY
3132 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
3133 ret);
5cce3f05 3134
055679e9 3135 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3136 zlog_debug(
2ba1fe69 3137 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
dc95985f 3138 vty_out(vty,
3139 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 3140
3141 return bgp_vty_return(vty, ret);
3142}
3143
3144DEFUN (bgp_neighbor_graceful_restart_set,
2ba1fe69 3145 bgp_neighbor_graceful_restart_set_cmd,
3146 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3147 NEIGHBOR_STR
3148 NEIGHBOR_ADDR_STR2
3149 GR_NEIGHBOR_CMD
055679e9 3150 )
3151{
3152 int idx_peer = 1;
3153 struct peer *peer;
3154 int ret = BGP_GR_FAILURE;
3155
dc95985f 3156 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3157
055679e9 3158 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3159 zlog_debug(
2ba1fe69 3160 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
dc95985f 3161
055679e9 3162 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3163 if (!peer)
3164 return CMD_WARNING_CONFIG_FAILED;
3165
3166 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
3167
dc95985f 3168 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3169 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3170
3171 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3172 zlog_debug(
2ba1fe69 3173 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 3174 vty_out(vty,
3175 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3176
3177 return bgp_vty_return(vty, ret);
3178}
3179
3180DEFUN (no_bgp_neighbor_graceful_restart,
2ba1fe69 3181 no_bgp_neighbor_graceful_restart_set_cmd,
3182 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3183 NO_STR
3184 NEIGHBOR_STR
3185 NEIGHBOR_ADDR_STR2
3186 NO_GR_NEIGHBOR_CMD
055679e9 3187 )
3188{
3189 int idx_peer = 2;
3190 int ret = BGP_GR_FAILURE;
3191 struct peer *peer;
3192
dc95985f 3193 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3194
055679e9 3195 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3196 if (!peer)
3197 return CMD_WARNING_CONFIG_FAILED;
3198
3199 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3200 zlog_debug(
2ba1fe69 3201 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
055679e9 3202
3203 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
3204
dc95985f 3205 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3206 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3207
3208 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3209 zlog_debug(
2ba1fe69 3210 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 3211 vty_out(vty,
3212 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3213
3214 return bgp_vty_return(vty, ret);
3215}
3216
3217DEFUN (bgp_neighbor_graceful_restart_helper_set,
2ba1fe69 3218 bgp_neighbor_graceful_restart_helper_set_cmd,
3219 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3220 NEIGHBOR_STR
3221 NEIGHBOR_ADDR_STR2
3222 GR_NEIGHBOR_HELPER_CMD
055679e9 3223 )
3224{
3225 int idx_peer = 1;
3226 struct peer *peer;
3227 int ret = BGP_GR_FAILURE;
3228
dc95985f 3229 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3230
055679e9 3231 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3232 zlog_debug(
2ba1fe69 3233 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
dc95985f 3234
055679e9 3235 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3236
055679e9 3237 if (!peer)
3238 return CMD_WARNING_CONFIG_FAILED;
3239
3240
3241 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
5cce3f05 3242
dc95985f 3243 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3244 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
5cce3f05 3245
055679e9 3246 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3247 zlog_debug(
2ba1fe69 3248 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 3249 vty_out(vty,
3250 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3251
3252 return bgp_vty_return(vty, ret);
3253}
3254
3255DEFUN (no_bgp_neighbor_graceful_restart_helper,
2ba1fe69 3256 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3257 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3258 NO_STR
3259 NEIGHBOR_STR
3260 NEIGHBOR_ADDR_STR2
3261 NO_GR_NEIGHBOR_HELPER_CMD
055679e9 3262 )
3263{
3264 int idx_peer = 2;
3265 int ret = BGP_GR_FAILURE;
3266 struct peer *peer;
3267
dc95985f 3268 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3269
055679e9 3270 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3271 if (!peer)
3272 return CMD_WARNING_CONFIG_FAILED;
3273
3274 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3275 zlog_debug(
2ba1fe69 3276 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
055679e9 3277
36235319 3278 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
055679e9 3279
dc95985f 3280 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3281 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3282
3283 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3284 zlog_debug(
2ba1fe69 3285 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_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 (bgp_neighbor_graceful_restart_disable_set,
2ba1fe69 3293 bgp_neighbor_graceful_restart_disable_set_cmd,
3294 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3295 NEIGHBOR_STR
3296 NEIGHBOR_ADDR_STR2
3297 GR_NEIGHBOR_DISABLE_CMD
055679e9 3298 )
3299{
3300 int idx_peer = 1;
3301 struct peer *peer;
3302 int ret = BGP_GR_FAILURE;
3303
dc95985f 3304 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3305
055679e9 3306 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3307 zlog_debug(
2ba1fe69 3308 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 3309
3310 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3311 if (!peer)
3312 return CMD_WARNING_CONFIG_FAILED;
3313
36235319 3314 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
055679e9 3315
3316 if (peer->bgp->t_startup)
3317 bgp_peer_gr_flags_update(peer);
3318
dc95985f 3319 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3320 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3321
055679e9 3322 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3323 zlog_debug(
2ba1fe69 3324 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3325 vty_out(vty,
3326 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3327
3328 return bgp_vty_return(vty, ret);
3329}
3330
3331DEFUN (no_bgp_neighbor_graceful_restart_disable,
2ba1fe69 3332 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3333 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3334 NO_STR
3335 NEIGHBOR_STR
3336 NEIGHBOR_ADDR_STR2
3337 NO_GR_NEIGHBOR_DISABLE_CMD
055679e9 3338 )
3339{
3340 int idx_peer = 2;
3341 int ret = BGP_GR_FAILURE;
3342 struct peer *peer;
3343
dc95985f 3344 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3345
055679e9 3346 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3347 if (!peer)
3348 return CMD_WARNING_CONFIG_FAILED;
3349
3350 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3351 zlog_debug(
2ba1fe69 3352 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 3353
3354 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3355
dc95985f 3356 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3357 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3358
3359 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3360 zlog_debug(
2ba1fe69 3361 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3362 vty_out(vty,
3363 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3364
3365 return bgp_vty_return(vty, ret);
3366}
3367
4f770cf1
DA
3368DEFPY (neighbor_graceful_shutdown,
3369 neighbor_graceful_shutdown_cmd,
3370 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor graceful-shutdown",
3371 NO_STR
3372 NEIGHBOR_STR
3373 NEIGHBOR_ADDR_STR2
3374 "Graceful shutdown\n")
3375{
3376 afi_t afi;
3377 safi_t safi;
3378 struct peer *peer;
3379 VTY_DECLVAR_CONTEXT(bgp, bgp);
3380 int ret;
3381
3382 peer = peer_and_group_lookup_vty(vty, neighbor);
3383 if (!peer)
3384 return CMD_WARNING_CONFIG_FAILED;
3385
3386 if (no)
3387 ret = peer_flag_unset_vty(vty, neighbor,
3388 PEER_FLAG_GRACEFUL_SHUTDOWN);
3389 else
3390 ret = peer_flag_set_vty(vty, neighbor,
3391 PEER_FLAG_GRACEFUL_SHUTDOWN);
3392
3393 FOREACH_AFI_SAFI (afi, safi) {
3394 if (!peer->afc[afi][safi])
3395 continue;
3396
3397 bgp_clear(vty, bgp, afi, safi, clear_peer, BGP_CLEAR_SOFT_IN,
3398 neighbor);
3399 }
3400
3401 return ret;
3402}
3403
d6e3c15b 3404DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3405 bgp_graceful_restart_disable_eor_cmd,
3406 "bgp graceful-restart disable-eor",
e9273987 3407 BGP_STR
d6e3c15b 3408 "Graceful restart configuration parameters\n"
3409 "Disable EOR Check\n")
3410{
3411 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3412 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3413
d6e3c15b 3414 return CMD_SUCCESS;
3415}
3416
3417DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3418 no_bgp_graceful_restart_disable_eor_cmd,
3419 "no bgp graceful-restart disable-eor",
3420 NO_STR
e9273987 3421 BGP_STR
d6e3c15b 3422 "Graceful restart configuration parameters\n"
3423 "Disable EOR Check\n")
3424{
3425 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3426 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3427
3428 return CMD_SUCCESS;
3429}
3430
3431DEFUN (bgp_graceful_restart_rib_stale_time,
3432 bgp_graceful_restart_rib_stale_time_cmd,
3433 "bgp graceful-restart rib-stale-time (1-3600)",
e9273987 3434 BGP_STR
dc95985f 3435 "Graceful restart configuration parameters\n"
3436 "Specify the stale route removal timer in rib\n"
3437 "Delay value (seconds)\n")
3438{
3439 VTY_DECLVAR_CONTEXT(bgp, bgp);
3440 int idx_number = 3;
3441 uint32_t stale_time;
3442
3443 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3444 bgp->rib_stale_time = stale_time;
3445 /* Send the stale timer update message to RIB */
3446 if (bgp_zebra_stale_timer_update(bgp))
3447 return CMD_WARNING;
3448
3449 return CMD_SUCCESS;
3450}
3451
3452DEFUN (no_bgp_graceful_restart_rib_stale_time,
3453 no_bgp_graceful_restart_rib_stale_time_cmd,
3454 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3455 NO_STR
e9273987 3456 BGP_STR
dc95985f 3457 "Graceful restart configuration parameters\n"
3458 "Specify the stale route removal timer in rib\n"
3459 "Delay value (seconds)\n")
3460{
3461 VTY_DECLVAR_CONTEXT(bgp, bgp);
3462
3463 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3464 /* Send the stale timer update message to RIB */
3465 if (bgp_zebra_stale_timer_update(bgp))
3466 return CMD_WARNING;
3467
d6e3c15b 3468 return CMD_SUCCESS;
3469}
3470
8606be87 3471DEFUN(bgp_llgr_stalepath_time, bgp_llgr_stalepath_time_cmd,
5970204c 3472 "bgp long-lived-graceful-restart stale-time (1-16777215)",
7f8a9a24 3473 BGP_STR
8606be87
DA
3474 "Enable Long-lived Graceful Restart\n"
3475 "Specifies maximum time to wait before purging long-lived stale routes\n"
3476 "Stale time value (seconds)\n")
3477{
3478 VTY_DECLVAR_CONTEXT(bgp, bgp);
3479
3480 uint32_t llgr_stale_time;
3481
3482 llgr_stale_time = strtoul(argv[3]->arg, NULL, 10);
3483 bgp->llgr_stale_time = llgr_stale_time;
3484
3485 return CMD_SUCCESS;
3486}
3487
3488DEFUN(no_bgp_llgr_stalepath_time, no_bgp_llgr_stalepath_time_cmd,
5970204c 3489 "no bgp long-lived-graceful-restart stale-time [(1-16777215)]",
8606be87
DA
3490 NO_STR BGP_STR
3491 "Enable Long-lived Graceful Restart\n"
3492 "Specifies maximum time to wait before purging long-lived stale routes\n"
3493 "Stale time value (seconds)\n")
3494{
3495 VTY_DECLVAR_CONTEXT(bgp, bgp);
3496
3497 bgp->llgr_stale_time = BGP_DEFAULT_LLGR_STALE_TIME;
3498
3499 return CMD_SUCCESS;
3500}
3501
1ca2fd11
IR
3502static inline void bgp_initiate_graceful_shut_unshut(struct vty *vty,
3503 struct bgp *bgp)
05bd726c 3504{
3505 bgp_static_redo_import_check(bgp);
3506 bgp_redistribute_redo(bgp);
1ca2fd11
IR
3507 bgp_clear_star_soft_out(vty, bgp->name);
3508 bgp_clear_star_soft_in(vty, bgp->name);
05bd726c 3509}
3510
3511static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3512{
3513 struct listnode *node, *nnode;
3514 struct bgp *bgp;
3515 bool vrf_cfg = false;
3516
3517 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3518 return CMD_SUCCESS;
3519
3520 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3521 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3522 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3523 vty_out(vty,
3524 "%% graceful-shutdown configuration found in vrf %s\n",
3525 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3526 VRF_DEFAULT_NAME : bgp->name);
3527 vrf_cfg = true;
3528 }
3529 }
3530
3531 if (vrf_cfg) {
3532 vty_out(vty,
3533 "%%Failed: global graceful-shutdown not permitted\n");
3534 return CMD_WARNING;
3535 }
3536
3537 /* Set flag globally */
3538 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3539
3540 /* Initiate processing for all BGP instances. */
1ca2fd11
IR
3541 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3542 bgp_initiate_graceful_shut_unshut(vty, bgp);
05bd726c 3543
3544 return CMD_SUCCESS;
3545}
3546
3547static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3548{
3549 struct listnode *node, *nnode;
3550 struct bgp *bgp;
3551
3552 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3553 return CMD_SUCCESS;
3554
3555 /* Unset flag globally */
3556 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3557
3558 /* Initiate processing for all BGP instances. */
1ca2fd11
IR
3559 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3560 bgp_initiate_graceful_shut_unshut(vty, bgp);
05bd726c 3561
3562 return CMD_SUCCESS;
3563}
3564
7f323236
DW
3565/* "bgp graceful-shutdown" configuration */
3566DEFUN (bgp_graceful_shutdown,
3567 bgp_graceful_shutdown_cmd,
3568 "bgp graceful-shutdown",
3569 BGP_STR
3570 "Graceful shutdown parameters\n")
3571{
05bd726c 3572 if (vty->node == CONFIG_NODE)
3573 return bgp_global_graceful_shutdown_config_vty(vty);
3574
1ca2fd11 3575 VTY_DECLVAR_CONTEXT(bgp, bgp);
7f323236 3576
1ca2fd11
IR
3577 /* if configured globally, per-instance config is not allowed */
3578 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3579 vty_out(vty,
3580 "%%Failed: per-vrf graceful-shutdown config not permitted with global graceful-shutdown\n");
3581 return CMD_WARNING_CONFIG_FAILED;
3582 }
3583
3584 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3585 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3586 bgp_initiate_graceful_shut_unshut(vty, bgp);
3587 }
3588
3589 return CMD_SUCCESS;
7f323236
DW
3590}
3591
1ca2fd11 3592DEFUN (no_bgp_graceful_shutdown,
7f323236
DW
3593 no_bgp_graceful_shutdown_cmd,
3594 "no bgp graceful-shutdown",
3595 NO_STR
3596 BGP_STR
3597 "Graceful shutdown parameters\n")
3598{
05bd726c 3599 if (vty->node == CONFIG_NODE)
3600 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3601
1ca2fd11 3602 VTY_DECLVAR_CONTEXT(bgp, bgp);
05bd726c 3603
1ca2fd11
IR
3604 /* If configured globally, cannot remove from one bgp instance */
3605 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3606 vty_out(vty,
3607 "%%Failed: bgp graceful-shutdown configured globally. Delete per-vrf not permitted\n");
3608 return CMD_WARNING_CONFIG_FAILED;
3609 }
7f323236 3610
1ca2fd11
IR
3611 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3612 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3613 bgp_initiate_graceful_shut_unshut(vty, bgp);
3614 }
3615
3616 return CMD_SUCCESS;
7f323236
DW
3617}
3618
718e3744 3619/* "bgp fast-external-failover" configuration. */
1ca2fd11 3620DEFUN (bgp_fast_external_failover,
718e3744 3621 bgp_fast_external_failover_cmd,
3622 "bgp fast-external-failover",
3623 BGP_STR
3624 "Immediately reset session if a link to a directly connected external peer goes down\n")
3625{
1ca2fd11
IR
3626 VTY_DECLVAR_CONTEXT(bgp, bgp);
3627 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3628 return CMD_SUCCESS;
718e3744 3629}
3630
1ca2fd11 3631DEFUN (no_bgp_fast_external_failover,
718e3744 3632 no_bgp_fast_external_failover_cmd,
3633 "no bgp fast-external-failover",
3634 NO_STR
3635 BGP_STR
3636 "Immediately reset session if a link to a directly connected external peer goes down\n")
3637{
1ca2fd11
IR
3638 VTY_DECLVAR_CONTEXT(bgp, bgp);
3639 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3640 return CMD_SUCCESS;
718e3744 3641}
6b0655a2 3642
97a52c82
DA
3643DEFPY (bgp_bestpath_aigp,
3644 bgp_bestpath_aigp_cmd,
3645 "[no$no] bgp bestpath aigp",
3646 NO_STR
3647 BGP_STR
3648 "Change the default bestpath selection\n"
3649 "Evaluate the AIGP attribute during the best path selection process\n")
3650{
3651 VTY_DECLVAR_CONTEXT(bgp, bgp);
3652
3653 if (no)
3654 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_AIGP);
3655 else
3656 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_AIGP);
3657
3658 bgp_recalculate_all_bestpaths(bgp);
3659
3660 return CMD_SUCCESS;
3661}
3662
718e3744 3663/* "bgp bestpath compare-routerid" configuration. */
1ca2fd11
IR
3664DEFUN (bgp_bestpath_compare_router_id,
3665 bgp_bestpath_compare_router_id_cmd,
3666 "bgp bestpath compare-routerid",
e9273987 3667 BGP_STR
1ca2fd11
IR
3668 "Change the default bestpath selection\n"
3669 "Compare router-id for identical EBGP paths\n")
718e3744 3670{
1ca2fd11
IR
3671 VTY_DECLVAR_CONTEXT(bgp, bgp);
3672 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3673 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3674
1ca2fd11 3675 return CMD_SUCCESS;
718e3744 3676}
3677
1ca2fd11
IR
3678DEFUN (no_bgp_bestpath_compare_router_id,
3679 no_bgp_bestpath_compare_router_id_cmd,
3680 "no bgp bestpath compare-routerid",
3681 NO_STR
e9273987 3682 BGP_STR
1ca2fd11
IR
3683 "Change the default bestpath selection\n"
3684 "Compare router-id for identical EBGP paths\n")
718e3744 3685{
1ca2fd11
IR
3686 VTY_DECLVAR_CONTEXT(bgp, bgp);
3687 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3688 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3689
1ca2fd11 3690 return CMD_SUCCESS;
718e3744 3691}
6b0655a2 3692
718e3744 3693/* "bgp bestpath as-path ignore" configuration. */
1ca2fd11
IR
3694DEFUN (bgp_bestpath_aspath_ignore,
3695 bgp_bestpath_aspath_ignore_cmd,
3696 "bgp bestpath as-path ignore",
e9273987 3697 BGP_STR
1ca2fd11
IR
3698 "Change the default bestpath selection\n"
3699 "AS-path attribute\n"
3700 "Ignore as-path length in selecting a route\n")
718e3744 3701{
1ca2fd11
IR
3702 VTY_DECLVAR_CONTEXT(bgp, bgp);
3703 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3704 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3705
1ca2fd11 3706 return CMD_SUCCESS;
718e3744 3707}
3708
1ca2fd11
IR
3709DEFUN (no_bgp_bestpath_aspath_ignore,
3710 no_bgp_bestpath_aspath_ignore_cmd,
3711 "no bgp bestpath as-path ignore",
3712 NO_STR
e9273987 3713 BGP_STR
1ca2fd11
IR
3714 "Change the default bestpath selection\n"
3715 "AS-path attribute\n"
3716 "Ignore as-path length in selecting a route\n")
718e3744 3717{
1ca2fd11
IR
3718 VTY_DECLVAR_CONTEXT(bgp, bgp);
3719 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3720 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3721
1ca2fd11 3722 return CMD_SUCCESS;
718e3744 3723}
6b0655a2 3724
6811845b 3725/* "bgp bestpath as-path confed" configuration. */
1ca2fd11 3726DEFUN (bgp_bestpath_aspath_confed,
6811845b 3727 bgp_bestpath_aspath_confed_cmd,
3728 "bgp bestpath as-path confed",
e9273987 3729 BGP_STR
6811845b 3730 "Change the default bestpath selection\n"
3731 "AS-path attribute\n"
3732 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3733{
1ca2fd11
IR
3734 VTY_DECLVAR_CONTEXT(bgp, bgp);
3735 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3736 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3737
1ca2fd11 3738 return CMD_SUCCESS;
6811845b 3739}
3740
1ca2fd11 3741DEFUN (no_bgp_bestpath_aspath_confed,
6811845b 3742 no_bgp_bestpath_aspath_confed_cmd,
3743 "no bgp bestpath as-path confed",
3744 NO_STR
e9273987 3745 BGP_STR
6811845b 3746 "Change the default bestpath selection\n"
3747 "AS-path attribute\n"
3748 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3749{
1ca2fd11
IR
3750 VTY_DECLVAR_CONTEXT(bgp, bgp);
3751 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3752 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3753
1ca2fd11 3754 return CMD_SUCCESS;
6811845b 3755}
6b0655a2 3756
2fdd455c 3757/* "bgp bestpath as-path multipath-relax" configuration. */
1ca2fd11 3758DEFUN (bgp_bestpath_aspath_multipath_relax,
2fdd455c 3759 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3760 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
e9273987 3761 BGP_STR
16fc1eec
DS
3762 "Change the default bestpath selection\n"
3763 "AS-path attribute\n"
3764 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3765 "Generate an AS_SET\n"
16fc1eec
DS
3766 "Do not generate an AS_SET\n")
3767{
1ca2fd11 3768 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 3769 int idx = 0;
1ca2fd11 3770 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6 3771
1ca2fd11
IR
3772 /* no-as-set is now the default behavior so we can silently
3773 * ignore it */
d62a17ae 3774 if (argv_find(argv, argc, "as-set", &idx))
1ca2fd11 3775 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
d62a17ae 3776 else
1ca2fd11 3777 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
7aafcaca 3778
1ca2fd11
IR
3779 bgp_recalculate_all_bestpaths(bgp);
3780
3781 return CMD_SUCCESS;
16fc1eec
DS
3782}
3783
1ca2fd11 3784DEFUN (no_bgp_bestpath_aspath_multipath_relax,
219178b6 3785 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3786 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec 3787 NO_STR
e9273987 3788 BGP_STR
16fc1eec
DS
3789 "Change the default bestpath selection\n"
3790 "AS-path attribute\n"
3791 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3792 "Generate an AS_SET\n"
16fc1eec
DS
3793 "Do not generate an AS_SET\n")
3794{
1ca2fd11
IR
3795 VTY_DECLVAR_CONTEXT(bgp, bgp);
3796 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3797 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3798 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3799
1ca2fd11 3800 return CMD_SUCCESS;
2fdd455c 3801}
6b0655a2 3802
ee88563a
JM
3803/* "bgp bestpath peer-type multipath-relax" configuration. */
3804DEFUN(bgp_bestpath_peer_type_multipath_relax,
3805 bgp_bestpath_peer_type_multipath_relax_cmd,
3806 "bgp bestpath peer-type multipath-relax",
3807 BGP_STR
3808 "Change the default bestpath selection\n"
3809 "Peer type\n"
3810 "Allow load sharing across routes learned from different peer types\n")
3811{
3812 VTY_DECLVAR_CONTEXT(bgp, bgp);
3813 SET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3814 bgp_recalculate_all_bestpaths(bgp);
3815
3816 return CMD_SUCCESS;
3817}
3818
3819DEFUN(no_bgp_bestpath_peer_type_multipath_relax,
3820 no_bgp_bestpath_peer_type_multipath_relax_cmd,
3821 "no bgp bestpath peer-type multipath-relax",
3822 NO_STR BGP_STR
3823 "Change the default bestpath selection\n"
3824 "Peer type\n"
3825 "Allow load sharing across routes learned from different peer types\n")
3826{
3827 VTY_DECLVAR_CONTEXT(bgp, bgp);
3828 UNSET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3829 bgp_recalculate_all_bestpaths(bgp);
3830
3831 return CMD_SUCCESS;
3832}
3833
848973c7 3834/* "bgp log-neighbor-changes" configuration. */
1ca2fd11
IR
3835DEFUN (bgp_log_neighbor_changes,
3836 bgp_log_neighbor_changes_cmd,
3837 "bgp log-neighbor-changes",
e9273987 3838 BGP_STR
1ca2fd11 3839 "Log neighbor up/down and reset reason\n")
848973c7 3840{
1ca2fd11
IR
3841 VTY_DECLVAR_CONTEXT(bgp, bgp);
3842 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3843 return CMD_SUCCESS;
848973c7 3844}
3845
1ca2fd11
IR
3846DEFUN (no_bgp_log_neighbor_changes,
3847 no_bgp_log_neighbor_changes_cmd,
3848 "no bgp log-neighbor-changes",
3849 NO_STR
e9273987 3850 BGP_STR
1ca2fd11 3851 "Log neighbor up/down and reset reason\n")
848973c7 3852{
1ca2fd11
IR
3853 VTY_DECLVAR_CONTEXT(bgp, bgp);
3854 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3855 return CMD_SUCCESS;
848973c7 3856}
6b0655a2 3857
718e3744 3858/* "bgp bestpath med" configuration. */
1ca2fd11 3859DEFUN (bgp_bestpath_med,
718e3744 3860 bgp_bestpath_med_cmd,
2d8c1a4d 3861 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
e9273987 3862 BGP_STR
718e3744 3863 "Change the default bestpath selection\n"
3864 "MED attribute\n"
3865 "Compare MED among confederation paths\n"
838758ac
DW
3866 "Treat missing MED as the least preferred one\n"
3867 "Treat missing MED as the least preferred one\n"
3868 "Compare MED among confederation paths\n")
718e3744 3869{
1ca2fd11 3870 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 3871
1ca2fd11 3872 int idx = 0;
d62a17ae 3873 if (argv_find(argv, argc, "confed", &idx))
1ca2fd11 3874 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
d62a17ae 3875 idx = 0;
3876 if (argv_find(argv, argc, "missing-as-worst", &idx))
1ca2fd11 3877 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
e52702f2 3878
1ca2fd11 3879 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3880
1ca2fd11 3881 return CMD_SUCCESS;
718e3744 3882}
3883
1ca2fd11 3884DEFUN (no_bgp_bestpath_med,
718e3744 3885 no_bgp_bestpath_med_cmd,
2d8c1a4d 3886 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 3887 NO_STR
e9273987 3888 BGP_STR
718e3744 3889 "Change the default bestpath selection\n"
3890 "MED attribute\n"
3891 "Compare MED among confederation paths\n"
3a2d747c
QY
3892 "Treat missing MED as the least preferred one\n"
3893 "Treat missing MED as the least preferred one\n"
3894 "Compare MED among confederation paths\n")
718e3744 3895{
1ca2fd11 3896 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 3897
1ca2fd11 3898 int idx = 0;
d62a17ae 3899 if (argv_find(argv, argc, "confed", &idx))
1ca2fd11 3900 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
d62a17ae 3901 idx = 0;
3902 if (argv_find(argv, argc, "missing-as-worst", &idx))
1ca2fd11
IR
3903 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3904
3905 bgp_recalculate_all_bestpaths(bgp);
718e3744 3906
1ca2fd11 3907 return CMD_SUCCESS;
718e3744 3908}
3909
f7e1c681 3910/* "bgp bestpath bandwidth" configuration. */
3911DEFPY (bgp_bestpath_bw,
3912 bgp_bestpath_bw_cmd,
ad36d216 3913 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
e9273987 3914 BGP_STR
f7e1c681 3915 "Change the default bestpath selection\n"
3916 "Link Bandwidth attribute\n"
3917 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3918 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3919 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3920{
3921 VTY_DECLVAR_CONTEXT(bgp, bgp);
3922 afi_t afi;
3923 safi_t safi;
3924
ad36d216
DS
3925 if (!bw_cfg) {
3926 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3927 return CMD_ERR_INCOMPLETE;
f7e1c681 3928 }
ad36d216
DS
3929 if (!strcmp(bw_cfg, "ignore"))
3930 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3931 else if (!strcmp(bw_cfg, "skip-missing"))
3932 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3933 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3934 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3935 else
3936 return CMD_ERR_NO_MATCH;
f7e1c681 3937
3938 /* This config is used in route install, so redo that. */
3939 FOREACH_AFI_SAFI (afi, safi) {
3940 if (!bgp_fibupd_safi(safi))
3941 continue;
3942 bgp_zebra_announce_table(bgp, afi, safi);
3943 }
3944
3945 return CMD_SUCCESS;
3946}
3947
ad36d216
DS
3948DEFPY (no_bgp_bestpath_bw,
3949 no_bgp_bestpath_bw_cmd,
3950 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3951 NO_STR
e9273987 3952 BGP_STR
ad36d216
DS
3953 "Change the default bestpath selection\n"
3954 "Link Bandwidth attribute\n"
3955 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3956 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3957 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3958{
3959 VTY_DECLVAR_CONTEXT(bgp, bgp);
3960 afi_t afi;
3961 safi_t safi;
3962
3963 bgp->lb_handling = BGP_LINK_BW_ECMP;
3964
3965 /* This config is used in route install, so redo that. */
3966 FOREACH_AFI_SAFI (afi, safi) {
3967 if (!bgp_fibupd_safi(safi))
3968 continue;
3969 bgp_zebra_announce_table(bgp, afi, safi);
3970 }
3971 return CMD_SUCCESS;
3972}
3973
b16bcbba 3974DEFPY(bgp_default_afi_safi, bgp_default_afi_safi_cmd,
38d11af5
TA
3975 "[no] bgp default <ipv4-unicast|"
3976 "ipv4-multicast|"
3977 "ipv4-vpn|"
3978 "ipv4-labeled-unicast|"
3979 "ipv4-flowspec|"
3980 "ipv6-unicast|"
3981 "ipv6-multicast|"
3982 "ipv6-vpn|"
3983 "ipv6-labeled-unicast|"
3984 "ipv6-flowspec|"
3985 "l2vpn-evpn>$afi_safi",
b16bcbba 3986 NO_STR
e9273987 3987 BGP_STR
e84c59af 3988 "Configure BGP defaults\n"
b16bcbba 3989 "Activate ipv4-unicast for a peer by default\n"
38d11af5
TA
3990 "Activate ipv4-multicast for a peer by default\n"
3991 "Activate ipv4-vpn for a peer by default\n"
3992 "Activate ipv4-labeled-unicast for a peer by default\n"
3993 "Activate ipv4-flowspec for a peer by default\n"
3994 "Activate ipv6-unicast for a peer by default\n"
3995 "Activate ipv6-multicast for a peer by default\n"
3996 "Activate ipv6-vpn for a peer by default\n"
3997 "Activate ipv6-labeled-unicast for a peer by default\n"
3998 "Activate ipv6-flowspec for a peer by default\n"
3999 "Activate l2vpn-evpn for a peer by default\n")
e84c59af
DA
4000{
4001 VTY_DECLVAR_CONTEXT(bgp, bgp);
b16bcbba
TA
4002 char afi_safi_str[strlen(afi_safi) + 1];
4003 char *afi_safi_str_tok;
e84c59af 4004
b16bcbba
TA
4005 strlcpy(afi_safi_str, afi_safi, sizeof(afi_safi_str));
4006 char *afi_str = strtok_r(afi_safi_str, "-", &afi_safi_str_tok);
4007 char *safi_str = strtok_r(NULL, "-", &afi_safi_str_tok);
4008 afi_t afi = bgp_vty_afi_from_str(afi_str);
38d11af5 4009 safi_t safi;
e84c59af 4010
d880a643
DS
4011 /*
4012 * Impossible situation but making coverity happy
4013 */
4014 assert(afi != AFI_MAX);
4015
38d11af5
TA
4016 if (strmatch(safi_str, "labeled"))
4017 safi = bgp_vty_safi_from_str("labeled-unicast");
4018 else
4019 safi = bgp_vty_safi_from_str(safi_str);
b16bcbba 4020
f609bcd6 4021 assert(safi != SAFI_MAX);
b16bcbba
TA
4022 if (no)
4023 bgp->default_af[afi][safi] = false;
38d11af5
TA
4024 else {
4025 if ((safi == SAFI_LABELED_UNICAST
4026 && bgp->default_af[afi][SAFI_UNICAST])
4027 || (safi == SAFI_UNICAST
4028 && bgp->default_af[afi][SAFI_LABELED_UNICAST]))
4029 bgp_vty_return(vty, BGP_ERR_PEER_SAFI_CONFLICT);
4030 else
4031 bgp->default_af[afi][safi] = true;
4032 }
718e3744 4033
d62a17ae 4034 return CMD_SUCCESS;
718e3744 4035}
6b0655a2 4036
04b6bdc0 4037/* Display hostname in certain command outputs */
1ca2fd11 4038DEFUN (bgp_default_show_hostname,
04b6bdc0
DW
4039 bgp_default_show_hostname_cmd,
4040 "bgp default show-hostname",
e9273987 4041 BGP_STR
04b6bdc0 4042 "Configure BGP defaults\n"
0437e105 4043 "Show hostname in certain command outputs\n")
04b6bdc0 4044{
1ca2fd11
IR
4045 VTY_DECLVAR_CONTEXT(bgp, bgp);
4046 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
4047 return CMD_SUCCESS;
ff8a8a7a
CS
4048}
4049
1ca2fd11
IR
4050DEFUN (no_bgp_default_show_hostname,
4051 no_bgp_default_show_hostname_cmd,
4052 "no bgp default show-hostname",
4053 NO_STR
e9273987 4054 BGP_STR
1ca2fd11
IR
4055 "Configure BGP defaults\n"
4056 "Show hostname in certain command outputs\n")
ff8a8a7a 4057{
1ca2fd11
IR
4058 VTY_DECLVAR_CONTEXT(bgp, bgp);
4059 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
4060 return CMD_SUCCESS;
04b6bdc0
DW
4061}
4062
aef999a2 4063/* Display hostname in certain command outputs */
1d80f243
IR
4064DEFUN (bgp_default_show_nexthop_hostname,
4065 bgp_default_show_nexthop_hostname_cmd,
4066 "bgp default show-nexthop-hostname",
e9273987 4067 BGP_STR
1d80f243
IR
4068 "Configure BGP defaults\n"
4069 "Show hostname for nexthop in certain command outputs\n")
aef999a2 4070{
1ca2fd11
IR
4071 VTY_DECLVAR_CONTEXT(bgp, bgp);
4072 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
4073 return CMD_SUCCESS;
aef999a2
DA
4074}
4075
4076DEFUN (no_bgp_default_show_nexthop_hostname,
4077 no_bgp_default_show_nexthop_hostname_cmd,
4078 "no bgp default show-nexthop-hostname",
4079 NO_STR
e9273987 4080 BGP_STR
aef999a2
DA
4081 "Configure BGP defaults\n"
4082 "Show hostname for nexthop in certain command outputs\n")
4083{
1ca2fd11
IR
4084 VTY_DECLVAR_CONTEXT(bgp, bgp);
4085 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
4086 return CMD_SUCCESS;
aef999a2
DA
4087}
4088
8233ef81 4089/* "bgp network import-check" configuration. */
1ca2fd11
IR
4090DEFUN (bgp_network_import_check,
4091 bgp_network_import_check_cmd,
4092 "bgp network import-check",
e9273987 4093 BGP_STR
1ca2fd11
IR
4094 "BGP network command\n"
4095 "Check BGP network route exists in IGP\n")
718e3744 4096{
1ca2fd11
IR
4097 VTY_DECLVAR_CONTEXT(bgp, bgp);
4098 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
4099 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
4100 bgp_static_redo_import_check(bgp);
4101 }
078430f6 4102
1ca2fd11 4103 return CMD_SUCCESS;
718e3744 4104}
4105
d62a17ae 4106ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
4107 "bgp network import-check exact",
e9273987 4108 BGP_STR
d62a17ae 4109 "BGP network command\n"
4110 "Check BGP network route exists in IGP\n"
4111 "Match route precisely\n")
8233ef81 4112
1ca2fd11
IR
4113DEFUN (no_bgp_network_import_check,
4114 no_bgp_network_import_check_cmd,
4115 "no bgp network import-check",
4116 NO_STR
e9273987 4117 BGP_STR
1ca2fd11
IR
4118 "BGP network command\n"
4119 "Check BGP network route exists in IGP\n")
718e3744 4120{
1ca2fd11
IR
4121 VTY_DECLVAR_CONTEXT(bgp, bgp);
4122 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
4123 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
4124 bgp_static_redo_import_check(bgp);
4125 }
6b0655a2 4126
1ca2fd11 4127 return CMD_SUCCESS;
ff8a8a7a 4128}
718e3744 4129
1ca2fd11
IR
4130DEFUN (bgp_default_local_preference,
4131 bgp_default_local_preference_cmd,
4132 "bgp default local-preference (0-4294967295)",
e9273987 4133 BGP_STR
1ca2fd11
IR
4134 "Configure BGP defaults\n"
4135 "local preference (higher=more preferred)\n"
4136 "Configure default local preference value\n")
ff8a8a7a 4137{
1ca2fd11 4138 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 4139 int idx_number = 3;
1ca2fd11 4140 uint32_t local_pref;
718e3744 4141
1ca2fd11 4142 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 4143
1ca2fd11
IR
4144 bgp_default_local_preference_set(bgp, local_pref);
4145 bgp_clear_star_soft_in(vty, bgp->name);
718e3744 4146
1ca2fd11 4147 return CMD_SUCCESS;
718e3744 4148}
4149
1ca2fd11
IR
4150DEFUN (no_bgp_default_local_preference,
4151 no_bgp_default_local_preference_cmd,
4152 "no bgp default local-preference [(0-4294967295)]",
4153 NO_STR
e9273987 4154 BGP_STR
1ca2fd11
IR
4155 "Configure BGP defaults\n"
4156 "local preference (higher=more preferred)\n"
4157 "Configure default local preference value\n")
ff8a8a7a 4158{
1ca2fd11
IR
4159 VTY_DECLVAR_CONTEXT(bgp, bgp);
4160 bgp_default_local_preference_unset(bgp);
4161 bgp_clear_star_soft_in(vty, bgp->name);
4162
4163 return CMD_SUCCESS;
ff8a8a7a 4164}
6b0655a2 4165
ff8a8a7a 4166
1ca2fd11
IR
4167DEFUN (bgp_default_subgroup_pkt_queue_max,
4168 bgp_default_subgroup_pkt_queue_max_cmd,
4169 "bgp default subgroup-pkt-queue-max (20-100)",
e9273987 4170 BGP_STR
1ca2fd11
IR
4171 "Configure BGP defaults\n"
4172 "subgroup-pkt-queue-max\n"
4173 "Configure subgroup packet queue max\n")
8bd9d948 4174{
1ca2fd11 4175 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4176 int idx_number = 3;
1ca2fd11 4177 uint32_t max_size;
3f9c7369 4178
1ca2fd11 4179 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3f9c7369 4180
1ca2fd11 4181 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
ff8a8a7a 4182
1ca2fd11 4183 return CMD_SUCCESS;
8bd9d948
DS
4184}
4185
1ca2fd11
IR
4186DEFUN (no_bgp_default_subgroup_pkt_queue_max,
4187 no_bgp_default_subgroup_pkt_queue_max_cmd,
4188 "no bgp default subgroup-pkt-queue-max [(20-100)]",
4189 NO_STR
e9273987 4190 BGP_STR
1ca2fd11
IR
4191 "Configure BGP defaults\n"
4192 "subgroup-pkt-queue-max\n"
4193 "Configure subgroup packet queue max\n")
ff8a8a7a 4194{
1ca2fd11
IR
4195 VTY_DECLVAR_CONTEXT(bgp, bgp);
4196 bgp_default_subgroup_pkt_queue_max_unset(bgp);
4197 return CMD_SUCCESS;
ff8a8a7a 4198}
813d4307 4199
8bd9d948 4200
1ca2fd11
IR
4201DEFUN (bgp_rr_allow_outbound_policy,
4202 bgp_rr_allow_outbound_policy_cmd,
4203 "bgp route-reflector allow-outbound-policy",
e9273987 4204 BGP_STR
1ca2fd11
IR
4205 "Allow modifications made by out route-map\n"
4206 "on ibgp neighbors\n")
ff8a8a7a 4207{
1ca2fd11 4208 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 4209
1ca2fd11
IR
4210 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4211 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4212 update_group_announce_rrclients(bgp);
4213 bgp_clear_star_soft_out(vty, bgp->name);
4214 }
8bd9d948 4215
1ca2fd11
IR
4216 return CMD_SUCCESS;
4217}
ff8a8a7a 4218
1ca2fd11
IR
4219DEFUN (no_bgp_rr_allow_outbound_policy,
4220 no_bgp_rr_allow_outbound_policy_cmd,
4221 "no bgp route-reflector allow-outbound-policy",
4222 NO_STR
e9273987 4223 BGP_STR
1ca2fd11
IR
4224 "Allow modifications made by out route-map\n"
4225 "on ibgp neighbors\n")
8bd9d948 4226{
1ca2fd11 4227 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 4228
1ca2fd11
IR
4229 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4230 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4231 update_group_announce_rrclients(bgp);
4232 bgp_clear_star_soft_out(vty, bgp->name);
d62a17ae 4233 }
8bd9d948 4234
1ca2fd11 4235 return CMD_SUCCESS;
8bd9d948
DS
4236}
4237
1ca2fd11
IR
4238DEFUN (bgp_listen_limit,
4239 bgp_listen_limit_cmd,
4240 "bgp listen limit (1-65535)",
e9273987 4241 BGP_STR
1ca2fd11
IR
4242 "BGP Dynamic Neighbors listen commands\n"
4243 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4244 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 4245{
1ca2fd11 4246 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4247 int idx_number = 3;
1ca2fd11
IR
4248 int listen_limit;
4249
4250 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
f14e6fdb 4251
1ca2fd11 4252 bgp_listen_limit_set(bgp, listen_limit);
f14e6fdb 4253
1ca2fd11 4254 return CMD_SUCCESS;
f14e6fdb
DS
4255}
4256
1ca2fd11
IR
4257DEFUN (no_bgp_listen_limit,
4258 no_bgp_listen_limit_cmd,
4259 "no bgp listen limit [(1-65535)]",
4260 NO_STR
e9273987 4261 BGP_STR
1ca2fd11
IR
4262 "BGP Dynamic Neighbors listen commands\n"
4263 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4264 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 4265{
1ca2fd11
IR
4266 VTY_DECLVAR_CONTEXT(bgp, bgp);
4267 bgp_listen_limit_unset(bgp);
4268 return CMD_SUCCESS;
f14e6fdb
DS
4269}
4270
4271
20eb8864 4272/*
4273 * Check if this listen range is already configured. Check for exact
4274 * match or overlap based on input.
4275 */
d62a17ae 4276static struct peer_group *listen_range_exists(struct bgp *bgp,
4277 struct prefix *range, int exact)
4278{
4279 struct listnode *node, *nnode;
4280 struct listnode *node1, *nnode1;
4281 struct peer_group *group;
4282 struct prefix *lr;
4283 afi_t afi;
4284 int match;
4285
4286 afi = family2afi(range->family);
4287 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4288 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
4289 lr)) {
4290 if (exact)
4291 match = prefix_same(range, lr);
4292 else
4293 match = (prefix_match(range, lr)
4294 || prefix_match(lr, range));
4295 if (match)
4296 return group;
4297 }
4298 }
4299
4300 return NULL;
20eb8864 4301}
4302
f14e6fdb
DS
4303DEFUN (bgp_listen_range,
4304 bgp_listen_range_cmd,
d7b9898c 4305 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
e9273987 4306 BGP_STR
d7fa34c1
QY
4307 "Configure BGP dynamic neighbors listen range\n"
4308 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
4309 NEIGHBOR_ADDR_STR
4310 "Member of the peer-group\n"
4311 "Peer-group name\n")
f14e6fdb 4312{
d62a17ae 4313 VTY_DECLVAR_CONTEXT(bgp, bgp);
4314 struct prefix range;
4315 struct peer_group *group, *existing_group;
4316 afi_t afi;
4317 int ret;
4318 int idx = 0;
4319
4320 argv_find(argv, argc, "A.B.C.D/M", &idx);
4321 argv_find(argv, argc, "X:X::X:X/M", &idx);
4322 char *prefix = argv[idx]->arg;
d7b9898c 4323 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 4324 char *peergroup = argv[idx]->arg;
4325
4326 /* Convert IP prefix string to struct prefix. */
4327 ret = str2prefix(prefix, &range);
4328 if (!ret) {
4329 vty_out(vty, "%% Malformed listen range\n");
4330 return CMD_WARNING_CONFIG_FAILED;
4331 }
4332
4333 afi = family2afi(range.family);
4334
4335 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4336 vty_out(vty,
4337 "%% Malformed listen range (link-local address)\n");
4338 return CMD_WARNING_CONFIG_FAILED;
4339 }
4340
4341 apply_mask(&range);
4342
4343 /* Check if same listen range is already configured. */
4344 existing_group = listen_range_exists(bgp, &range, 1);
4345 if (existing_group) {
4346 if (strcmp(existing_group->name, peergroup) == 0)
4347 return CMD_SUCCESS;
4348 else {
4349 vty_out(vty,
4350 "%% Same listen range is attached to peer-group %s\n",
4351 existing_group->name);
4352 return CMD_WARNING_CONFIG_FAILED;
4353 }
4354 }
4355
4356 /* Check if an overlapping listen range exists. */
4357 if (listen_range_exists(bgp, &range, 0)) {
4358 vty_out(vty,
4359 "%% Listen range overlaps with existing listen range\n");
4360 return CMD_WARNING_CONFIG_FAILED;
4361 }
4362
4363 group = peer_group_lookup(bgp, peergroup);
4364 if (!group) {
4365 vty_out(vty, "%% Configure the peer-group first\n");
4366 return CMD_WARNING_CONFIG_FAILED;
4367 }
4368
4369 ret = peer_group_listen_range_add(group, &range);
4370 return bgp_vty_return(vty, ret);
f14e6fdb
DS
4371}
4372
4373DEFUN (no_bgp_listen_range,
4374 no_bgp_listen_range_cmd,
d7b9898c 4375 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
d7fa34c1 4376 NO_STR
e9273987 4377 BGP_STR
d7fa34c1
QY
4378 "Unconfigure BGP dynamic neighbors listen range\n"
4379 "Unconfigure BGP dynamic neighbors listen range\n"
4380 NEIGHBOR_ADDR_STR
4381 "Member of the peer-group\n"
4382 "Peer-group name\n")
f14e6fdb 4383{
d62a17ae 4384 VTY_DECLVAR_CONTEXT(bgp, bgp);
4385 struct prefix range;
4386 struct peer_group *group;
4387 afi_t afi;
4388 int ret;
4389 int idx = 0;
4390
4391 argv_find(argv, argc, "A.B.C.D/M", &idx);
4392 argv_find(argv, argc, "X:X::X:X/M", &idx);
4393 char *prefix = argv[idx]->arg;
21d88a71 4394 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 4395 char *peergroup = argv[idx]->arg;
4396
4397 /* Convert IP prefix string to struct prefix. */
4398 ret = str2prefix(prefix, &range);
4399 if (!ret) {
4400 vty_out(vty, "%% Malformed listen range\n");
4401 return CMD_WARNING_CONFIG_FAILED;
4402 }
4403
4404 afi = family2afi(range.family);
4405
4406 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4407 vty_out(vty,
4408 "%% Malformed listen range (link-local address)\n");
4409 return CMD_WARNING_CONFIG_FAILED;
4410 }
4411
4412 apply_mask(&range);
4413
4414 group = peer_group_lookup(bgp, peergroup);
4415 if (!group) {
4416 vty_out(vty, "%% Peer-group does not exist\n");
4417 return CMD_WARNING_CONFIG_FAILED;
4418 }
4419
4420 ret = peer_group_listen_range_del(group, &range);
4421 return bgp_vty_return(vty, ret);
4422}
4423
2b791107 4424void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 4425{
4426 struct peer_group *group;
4427 struct listnode *node, *nnode, *rnode, *nrnode;
4428 struct prefix *range;
4429 afi_t afi;
d62a17ae 4430
4431 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4432 vty_out(vty, " bgp listen limit %d\n",
4433 bgp->dynamic_neighbors_limit);
4434
4435 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4436 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4437 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4438 nrnode, range)) {
d62a17ae 4439 vty_out(vty,
2dbe669b
DA
4440 " bgp listen range %pFX peer-group %s\n",
4441 range, group->name);
d62a17ae 4442 }
4443 }
4444 }
f14e6fdb
DS
4445}
4446
4447
1ca2fd11
IR
4448DEFUN (bgp_disable_connected_route_check,
4449 bgp_disable_connected_route_check_cmd,
4450 "bgp disable-ebgp-connected-route-check",
e9273987 4451 BGP_STR
1ca2fd11 4452 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4453{
1ca2fd11
IR
4454 VTY_DECLVAR_CONTEXT(bgp, bgp);
4455 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4456 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 4457
1ca2fd11 4458 return CMD_SUCCESS;
907f92c8
DS
4459}
4460
1ca2fd11
IR
4461DEFUN (no_bgp_disable_connected_route_check,
4462 no_bgp_disable_connected_route_check_cmd,
4463 "no bgp disable-ebgp-connected-route-check",
4464 NO_STR
e9273987 4465 BGP_STR
1ca2fd11 4466 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4467{
1ca2fd11
IR
4468 VTY_DECLVAR_CONTEXT(bgp, bgp);
4469 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4470 bgp_clear_star_soft_in(vty, bgp->name);
d62a17ae 4471
1ca2fd11 4472 return CMD_SUCCESS;
d62a17ae 4473}
4474
4475
28c6e247
IR
4476static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
4477 const char *as_str)
4478{
4479 VTY_DECLVAR_CONTEXT(bgp, bgp);
4480 int ret;
4481 as_t as;
4482 int as_type = AS_SPECIFIED;
4483 union sockunion su;
4484
4485 if (as_str[0] == 'i') {
4486 as = 0;
4487 as_type = AS_INTERNAL;
4488 } else if (as_str[0] == 'e') {
4489 as = 0;
4490 as_type = AS_EXTERNAL;
4491 } else {
4492 /* Get AS number. */
4493 as = strtoul(as_str, NULL, 10);
4494 }
4495
4496 /* If peer is peer group or interface peer, call proper function. */
4497 ret = str2sockunion(peer_str, &su);
4498 if (ret < 0) {
4499 struct peer *peer;
4500
4501 /* Check if existing interface peer */
4502 peer = peer_lookup_by_conf_if(bgp, peer_str);
4503
4504 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type);
4505
4506 /* if not interface peer, check peer-group settings */
4507 if (ret < 0 && !peer) {
4508 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
4509 if (ret < 0) {
4510 vty_out(vty,
4511 "%% Create the peer-group or interface first\n");
4512 return CMD_WARNING_CONFIG_FAILED;
4513 }
4514 return CMD_SUCCESS;
4515 }
4516 } else {
4517 if (peer_address_self_check(bgp, &su)) {
4518 vty_out(vty,
4519 "%% Can not configure the local system as neighbor\n");
4520 return CMD_WARNING_CONFIG_FAILED;
4521 }
4522 ret = peer_remote_as(bgp, &su, NULL, &as, as_type);
4523 }
4524
28c6e247
IR
4525 return bgp_vty_return(vty, ret);
4526}
4527
1ca2fd11
IR
4528DEFUN (bgp_default_shutdown,
4529 bgp_default_shutdown_cmd,
4530 "[no] bgp default shutdown",
4531 NO_STR
4532 BGP_STR
4533 "Configure BGP defaults\n"
4534 "Apply administrative shutdown to newly configured peers\n")
ff8a8a7a 4535{
1ca2fd11
IR
4536 VTY_DECLVAR_CONTEXT(bgp, bgp);
4537 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
4538 return CMD_SUCCESS;
f26845f9
QY
4539}
4540
736b68f3
DS
4541DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4542 BGP_STR
9ddf4b81 4543 "Administrative shutdown of the BGP instance\n"
736b68f3
DS
4544 "Add a shutdown message (RFC 8203)\n"
4545 "Shutdown message\n")
9cf59432 4546{
736b68f3 4547 char *msgstr = NULL;
8389c83a 4548
9cf59432
DS
4549 VTY_DECLVAR_CONTEXT(bgp, bgp);
4550
8389c83a 4551 if (argc > 3)
f80e35b6 4552 msgstr = argv_concat(argv, argc, 3);
8389c83a 4553
b776f48c
DA
4554 if (msgstr && strlen(msgstr) > BGP_ADMIN_SHUTDOWN_MSG_LEN) {
4555 vty_out(vty, "%% Shutdown message size exceeded %d\n",
4556 BGP_ADMIN_SHUTDOWN_MSG_LEN);
4557 return CMD_WARNING_CONFIG_FAILED;
4558 }
4559
8389c83a
DS
4560 bgp_shutdown_enable(bgp, msgstr);
4561 XFREE(MTYPE_TMP, msgstr);
9cf59432
DS
4562
4563 return CMD_SUCCESS;
4564}
4565
736b68f3 4566DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
9ddf4b81 4567 BGP_STR "Administrative shutdown of the BGP instance\n")
1e12ebbc
DS
4568{
4569 VTY_DECLVAR_CONTEXT(bgp, bgp);
4570
4571 bgp_shutdown_enable(bgp, NULL);
4572
4573 return CMD_SUCCESS;
4574}
8389c83a 4575
736b68f3 4576DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
9ddf4b81 4577 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
9cf59432
DS
4578{
4579 VTY_DECLVAR_CONTEXT(bgp, bgp);
4580
4581 bgp_shutdown_disable(bgp);
4582
4583 return CMD_SUCCESS;
4584}
4585
9ddf4b81 4586ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
1b6e7a88 4587 "no bgp shutdown message MSG...", NO_STR BGP_STR
9ddf4b81 4588 "Administrative shutdown of the BGP instance\n"
1b6e7a88 4589 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
1b6e7a88 4590
28c6e247
IR
4591DEFUN (neighbor_remote_as,
4592 neighbor_remote_as_cmd,
4593 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4594 NEIGHBOR_STR
4595 NEIGHBOR_ADDR_STR2
4596 "Specify a BGP neighbor\n"
4597 AS_STR
4598 "Internal BGP peer\n"
4599 "External BGP peer\n")
718e3744 4600{
d62a17ae 4601 int idx_peer = 1;
4602 int idx_remote_as = 3;
28c6e247
IR
4603 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
4604 argv[idx_remote_as]->arg);
d62a17ae 4605}
8666265e
DS
4606
4607DEFPY (bgp_allow_martian,
4608 bgp_allow_martian_cmd,
4609 "[no]$no bgp allow-martian-nexthop",
4610 NO_STR
4611 BGP_STR
4612 "Allow Martian nexthops to be received in the NLRI from a peer\n")
4613{
4614 VTY_DECLVAR_CONTEXT(bgp, bgp);
4615
4616 if (no)
4617 bgp->allow_martian = false;
4618 else
4619 bgp->allow_martian = true;
4620
4621 return CMD_SUCCESS;
4622}
4623
f852eb98
PG
4624/* Enable fast convergence of bgp sessions. If this is enabled, bgp
4625 * sessions do not wait for hold timer expiry to bring down the sessions
4626 * when nexthop becomes unreachable
4627 */
4628DEFUN(bgp_fast_convergence, bgp_fast_convergence_cmd, "bgp fast-convergence",
4629 BGP_STR "Fast convergence for bgp sessions\n")
4630{
4631 VTY_DECLVAR_CONTEXT(bgp, bgp);
4632 bgp->fast_convergence = true;
4633
4634 return CMD_SUCCESS;
4635}
4636
4637DEFUN(no_bgp_fast_convergence, no_bgp_fast_convergence_cmd,
4638 "no bgp fast-convergence",
4639 NO_STR BGP_STR "Fast convergence for bgp sessions\n")
4640{
4641 VTY_DECLVAR_CONTEXT(bgp, bgp);
4642 bgp->fast_convergence = false;
4643
4644 return CMD_SUCCESS;
4645}
d62a17ae 4646
28c6e247
IR
4647static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
4648 int v6only,
4649 const char *peer_group_name,
4650 const char *as_str)
d62a17ae 4651{
28c6e247
IR
4652 VTY_DECLVAR_CONTEXT(bgp, bgp);
4653 as_t as = 0;
4654 int as_type = AS_UNSPECIFIED;
d62a17ae 4655 struct peer *peer;
4656 struct peer_group *group;
4657 int ret = 0;
d62a17ae 4658
4659 group = peer_group_lookup(bgp, conf_if);
4660
4661 if (group) {
28c6e247
IR
4662 vty_out(vty, "%% Name conflict with peer-group \n");
4663 return CMD_WARNING_CONFIG_FAILED;
4664 }
4665
4666 if (as_str) {
4667 if (as_str[0] == 'i') {
4668 as_type = AS_INTERNAL;
4669 } else if (as_str[0] == 'e') {
4670 as_type = AS_EXTERNAL;
4671 } else {
4672 /* Get AS number. */
4673 as = strtoul(as_str, NULL, 10);
4674 as_type = AS_SPECIFIED;
4675 }
d62a17ae 4676 }
4677
4678 peer = peer_lookup_by_conf_if(bgp, conf_if);
4679 if (peer) {
28c6e247 4680 if (as_str)
e84c59af 4681 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type);
d62a17ae 4682 } else {
e84c59af 4683 peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
534db980 4684 NULL, true);
d62a17ae 4685
4686 if (!peer) {
28c6e247
IR
4687 vty_out(vty, "%% BGP failed to create peer\n");
4688 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4689 }
4690
4691 if (v6only)
527de3dc 4692 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4693
4694 /* Request zebra to initiate IPv6 RAs on this interface. We do
4695 * this
4696 * any unnumbered peer in order to not worry about run-time
4697 * transitions
4698 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4699 * address
4700 * gets deleted later etc.)
4701 */
4702 if (peer->ifp)
4703 bgp_zebra_initiate_radv(bgp, peer);
4704 }
4705
4706 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4707 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4708 if (v6only)
527de3dc 4709 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4710 else
527de3dc 4711 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4712
4713 /* v6only flag changed. Reset bgp seesion */
4714 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4715 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4716 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4717 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4718 } else
4719 bgp_session_reset(peer);
4720 }
4721
9fb964de
PM
4722 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4723 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4724 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
dc2f50f3 4725 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
9fb964de 4726 }
d62a17ae 4727
4728 if (peer_group_name) {
4729 group = peer_group_lookup(bgp, peer_group_name);
4730 if (!group) {
28c6e247
IR
4731 vty_out(vty, "%% Configure the peer-group first\n");
4732 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4733 }
4734
8395c1f8 4735 ret = peer_group_bind(bgp, NULL, peer, group, &as);
d62a17ae 4736 }
4737
28c6e247 4738 return bgp_vty_return(vty, ret);
a80beece
DS
4739}
4740
28c6e247
IR
4741DEFUN (neighbor_interface_config,
4742 neighbor_interface_config_cmd,
4743 "neighbor WORD interface [peer-group PGNAME]",
4744 NEIGHBOR_STR
4745 "Interface name or neighbor tag\n"
4746 "Enable BGP on interface\n"
4747 "Member of the peer-group\n"
4748 "Peer-group name\n")
4c48cf63 4749{
d62a17ae 4750 int idx_word = 1;
4751 int idx_peer_group_word = 4;
f4b8ec07 4752
d62a17ae 4753 if (argc > idx_peer_group_word)
28c6e247
IR
4754 return peer_conf_interface_get(
4755 vty, argv[idx_word]->arg, 0,
4756 argv[idx_peer_group_word]->arg, NULL);
4757 else
4758 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0,
4759 NULL, NULL);
4c48cf63
DW
4760}
4761
28c6e247
IR
4762DEFUN (neighbor_interface_config_v6only,
4763 neighbor_interface_config_v6only_cmd,
4764 "neighbor WORD interface v6only [peer-group PGNAME]",
4765 NEIGHBOR_STR
4766 "Interface name or neighbor tag\n"
4767 "Enable BGP on interface\n"
4768 "Enable BGP with v6 link-local only\n"
4769 "Member of the peer-group\n"
4770 "Peer-group name\n")
4c48cf63 4771{
d62a17ae 4772 int idx_word = 1;
4773 int idx_peer_group_word = 5;
31500417 4774
d62a17ae 4775 if (argc > idx_peer_group_word)
28c6e247
IR
4776 return peer_conf_interface_get(
4777 vty, argv[idx_word]->arg, 1,
4778 argv[idx_peer_group_word]->arg, NULL);
31500417 4779
28c6e247 4780 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL, NULL);
4c48cf63
DW
4781}
4782
a80beece 4783
28c6e247
IR
4784DEFUN (neighbor_interface_config_remote_as,
4785 neighbor_interface_config_remote_as_cmd,
4786 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4787 NEIGHBOR_STR
4788 "Interface name or neighbor tag\n"
4789 "Enable BGP on interface\n"
4790 "Specify a BGP neighbor\n"
4791 AS_STR
4792 "Internal BGP peer\n"
4793 "External BGP peer\n")
b3a39dc5 4794{
d62a17ae 4795 int idx_word = 1;
4796 int idx_remote_as = 4;
28c6e247
IR
4797 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0, NULL,
4798 argv[idx_remote_as]->arg);
b3a39dc5
DD
4799}
4800
28c6e247
IR
4801DEFUN (neighbor_interface_v6only_config_remote_as,
4802 neighbor_interface_v6only_config_remote_as_cmd,
4803 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4804 NEIGHBOR_STR
4805 "Interface name or neighbor tag\n"
4806 "Enable BGP with v6 link-local only\n"
4807 "Enable BGP on interface\n"
4808 "Specify a BGP neighbor\n"
4809 AS_STR
4810 "Internal BGP peer\n"
4811 "External BGP peer\n")
b3a39dc5 4812{
d62a17ae 4813 int idx_word = 1;
4814 int idx_remote_as = 5;
28c6e247
IR
4815 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL,
4816 argv[idx_remote_as]->arg);
b3a39dc5
DD
4817}
4818
28c6e247
IR
4819DEFUN (neighbor_peer_group,
4820 neighbor_peer_group_cmd,
4821 "neighbor WORD peer-group",
4822 NEIGHBOR_STR
4823 "Interface name or neighbor tag\n"
4824 "Configure peer-group\n")
718e3744 4825{
28c6e247 4826 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4827 int idx_word = 1;
28c6e247
IR
4828 struct peer *peer;
4829 struct peer_group *group;
718e3744 4830
28c6e247
IR
4831 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4832 if (peer) {
4833 vty_out(vty, "%% Name conflict with interface: \n");
4834 return CMD_WARNING_CONFIG_FAILED;
4835 }
718e3744 4836
28c6e247
IR
4837 group = peer_group_get(bgp, argv[idx_word]->arg);
4838 if (!group) {
4839 vty_out(vty, "%% BGP failed to find or create peer-group\n");
4840 return CMD_WARNING_CONFIG_FAILED;
4841 }
718e3744 4842
28c6e247 4843 return CMD_SUCCESS;
718e3744 4844}
4845
1d80f243
IR
4846DEFUN (no_neighbor,
4847 no_neighbor_cmd,
4848 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4849 NO_STR
4850 NEIGHBOR_STR
4851 NEIGHBOR_ADDR_STR2
4852 "Specify a BGP neighbor\n"
4853 AS_STR
4854 "Internal BGP peer\n"
4855 "External BGP peer\n")
718e3744 4856{
28c6e247 4857 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4858 int idx_peer = 2;
28c6e247 4859 int ret;
d62a17ae 4860 union sockunion su;
28c6e247
IR
4861 struct peer_group *group;
4862 struct peer *peer;
4863 struct peer *other;
d62a17ae 4864
28c6e247
IR
4865 ret = str2sockunion(argv[idx_peer]->arg, &su);
4866 if (ret < 0) {
4867 /* look up for neighbor by interface name config. */
4868 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4869 if (peer) {
4870 /* Request zebra to terminate IPv6 RAs on this
4871 * interface. */
4872 if (peer->ifp)
4873 bgp_zebra_terminate_radv(peer->bgp, peer);
4874 peer_notify_unconfig(peer);
4875 peer_delete(peer);
4876 return CMD_SUCCESS;
d62a17ae 4877 }
28c6e247
IR
4878
4879 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4880 if (group) {
4881 peer_group_notify_unconfig(group);
4882 peer_group_delete(group);
4e2786df 4883 } else {
28c6e247 4884 vty_out(vty, "%% Create the peer-group first\n");
d62a17ae 4885 return CMD_WARNING_CONFIG_FAILED;
4886 }
28c6e247
IR
4887 } else {
4888 peer = peer_lookup(bgp, &su);
4889 if (peer) {
4890 if (peer_dynamic_neighbor(peer)) {
4891 vty_out(vty,
4892 "%% Operation not allowed on a dynamic neighbor\n");
4893 return CMD_WARNING_CONFIG_FAILED;
4894 }
d62a17ae 4895
28c6e247 4896 other = peer->doppelganger;
f4b8ec07 4897
28c6e247
IR
4898 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4899 bgp_zebra_terminate_radv(peer->bgp, peer);
f4b8ec07 4900
28c6e247
IR
4901 peer_notify_unconfig(peer);
4902 peer_delete(peer);
4903 if (other && other->status != Deleted) {
4904 peer_notify_unconfig(other);
4905 peer_delete(other);
4906 }
4907 }
4908 }
4909
4910 return CMD_SUCCESS;
a80beece
DS
4911}
4912
28c6e247
IR
4913DEFUN (no_neighbor_interface_config,
4914 no_neighbor_interface_config_cmd,
4915 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4916 NO_STR
4917 NEIGHBOR_STR
4918 "Interface name\n"
4919 "Configure BGP on interface\n"
4920 "Enable BGP with v6 link-local only\n"
4921 "Member of the peer-group\n"
4922 "Peer-group name\n"
4923 "Specify a BGP neighbor\n"
4924 AS_STR
4925 "Internal BGP peer\n"
4926 "External BGP peer\n")
718e3744 4927{
28c6e247 4928 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4929 int idx_word = 2;
28c6e247 4930 struct peer *peer;
718e3744 4931
28c6e247
IR
4932 /* look up for neighbor by interface name config. */
4933 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4934 if (peer) {
4935 /* Request zebra to terminate IPv6 RAs on this interface. */
4936 if (peer->ifp)
4937 bgp_zebra_terminate_radv(peer->bgp, peer);
4938 peer_notify_unconfig(peer);
4939 peer_delete(peer);
4940 } else {
4941 vty_out(vty, "%% Create the bgp interface first\n");
4942 return CMD_WARNING_CONFIG_FAILED;
4943 }
4944 return CMD_SUCCESS;
718e3744 4945}
4946
28c6e247
IR
4947DEFUN (no_neighbor_peer_group,
4948 no_neighbor_peer_group_cmd,
4949 "no neighbor WORD peer-group",
4950 NO_STR
4951 NEIGHBOR_STR
4952 "Neighbor tag\n"
4953 "Configure peer-group\n")
718e3744 4954{
28c6e247
IR
4955 VTY_DECLVAR_CONTEXT(bgp, bgp);
4956 int idx_word = 2;
4957 struct peer_group *group;
f4b8ec07 4958
28c6e247
IR
4959 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4960 if (group) {
4961 peer_group_notify_unconfig(group);
4962 peer_group_delete(group);
f4b8ec07 4963 } else {
28c6e247 4964 vty_out(vty, "%% Create the peer-group first\n");
d62a17ae 4965 return CMD_WARNING_CONFIG_FAILED;
4966 }
28c6e247
IR
4967 return CMD_SUCCESS;
4968}
f4b8ec07 4969
28c6e247
IR
4970DEFUN (no_neighbor_interface_peer_group_remote_as,
4971 no_neighbor_interface_peer_group_remote_as_cmd,
4972 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4973 NO_STR
4974 NEIGHBOR_STR
4975 "Interface name or neighbor tag\n"
4976 "Specify a BGP neighbor\n"
4977 AS_STR
4978 "Internal BGP peer\n"
4979 "External BGP peer\n")
4980{
4981 VTY_DECLVAR_CONTEXT(bgp, bgp);
4982 int idx_word = 2;
4983 struct peer_group *group;
4984 struct peer *peer;
f4b8ec07 4985
28c6e247
IR
4986 /* look up for neighbor by interface name config. */
4987 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4988 if (peer) {
4989 peer_as_change(peer, 0, AS_UNSPECIFIED);
4990 return CMD_SUCCESS;
4991 }
f4b8ec07 4992
28c6e247
IR
4993 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4994 if (group)
4995 peer_group_remote_as_delete(group);
4996 else {
4997 vty_out(vty, "%% Create the peer-group or interface first\n");
4998 return CMD_WARNING_CONFIG_FAILED;
4999 }
5000 return CMD_SUCCESS;
718e3744 5001}
6b0655a2 5002
28c6e247
IR
5003DEFUN (neighbor_local_as,
5004 neighbor_local_as_cmd,
5005 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
5006 NEIGHBOR_STR
5007 NEIGHBOR_ADDR_STR2
5008 "Specify a local-as number\n"
5009 "AS number used as local AS\n")
718e3744 5010{
d62a17ae 5011 int idx_peer = 1;
5012 int idx_number = 3;
28c6e247
IR
5013 struct peer *peer;
5014 int ret;
5015 as_t as;
718e3744 5016
28c6e247
IR
5017 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5018 if (!peer)
d62a17ae 5019 return CMD_WARNING_CONFIG_FAILED;
718e3744 5020
28c6e247
IR
5021 as = strtoul(argv[idx_number]->arg, NULL, 10);
5022 ret = peer_local_as_set(peer, as, 0, 0);
5023 return bgp_vty_return(vty, ret);
718e3744 5024}
5025
28c6e247
IR
5026DEFUN (neighbor_local_as_no_prepend,
5027 neighbor_local_as_no_prepend_cmd,
5028 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
5029 NEIGHBOR_STR
5030 NEIGHBOR_ADDR_STR2
5031 "Specify a local-as number\n"
5032 "AS number used as local AS\n"
5033 "Do not prepend local-as to updates from ebgp peers\n")
718e3744 5034{
d62a17ae 5035 int idx_peer = 1;
5036 int idx_number = 3;
28c6e247
IR
5037 struct peer *peer;
5038 int ret;
5039 as_t as;
718e3744 5040
28c6e247
IR
5041 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5042 if (!peer)
d62a17ae 5043 return CMD_WARNING_CONFIG_FAILED;
718e3744 5044
28c6e247
IR
5045 as = strtoul(argv[idx_number]->arg, NULL, 10);
5046 ret = peer_local_as_set(peer, as, 1, 0);
5047 return bgp_vty_return(vty, ret);
718e3744 5048}
5049
28c6e247
IR
5050DEFUN (neighbor_local_as_no_prepend_replace_as,
5051 neighbor_local_as_no_prepend_replace_as_cmd,
5052 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
5053 NEIGHBOR_STR
5054 NEIGHBOR_ADDR_STR2
5055 "Specify a local-as number\n"
5056 "AS number used as local AS\n"
5057 "Do not prepend local-as to updates from ebgp peers\n"
5058 "Do not prepend local-as to updates from ibgp peers\n")
9d3f9705 5059{
d62a17ae 5060 int idx_peer = 1;
5061 int idx_number = 3;
28c6e247
IR
5062 struct peer *peer;
5063 int ret;
5064 as_t as;
9d3f9705 5065
28c6e247
IR
5066 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5067 if (!peer)
d62a17ae 5068 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 5069
28c6e247
IR
5070 as = strtoul(argv[idx_number]->arg, NULL, 10);
5071 ret = peer_local_as_set(peer, as, 1, 1);
5072 return bgp_vty_return(vty, ret);
9d3f9705
AC
5073}
5074
28c6e247
IR
5075DEFUN (no_neighbor_local_as,
5076 no_neighbor_local_as_cmd,
5077 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
5078 NO_STR
5079 NEIGHBOR_STR
5080 NEIGHBOR_ADDR_STR2
5081 "Specify a local-as number\n"
5082 "AS number used as local AS\n"
5083 "Do not prepend local-as to updates from ebgp peers\n"
5084 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 5085{
d62a17ae 5086 int idx_peer = 2;
28c6e247
IR
5087 struct peer *peer;
5088 int ret;
718e3744 5089
28c6e247
IR
5090 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5091 if (!peer)
d62a17ae 5092 return CMD_WARNING_CONFIG_FAILED;
718e3744 5093
28c6e247
IR
5094 ret = peer_local_as_unset(peer);
5095 return bgp_vty_return(vty, ret);
718e3744 5096}
5097
718e3744 5098
3f9c7369
DS
5099DEFUN (neighbor_solo,
5100 neighbor_solo_cmd,
9ccf14f7 5101 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
5102 NEIGHBOR_STR
5103 NEIGHBOR_ADDR_STR2
5104 "Solo peer - part of its own update group\n")
5105{
d62a17ae 5106 int idx_peer = 1;
5107 struct peer *peer;
5108 int ret;
3f9c7369 5109
d62a17ae 5110 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5111 if (!peer)
5112 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 5113
d62a17ae 5114 ret = update_group_adjust_soloness(peer, 1);
5115 return bgp_vty_return(vty, ret);
3f9c7369
DS
5116}
5117
5118DEFUN (no_neighbor_solo,
5119 no_neighbor_solo_cmd,
9ccf14f7 5120 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
5121 NO_STR
5122 NEIGHBOR_STR
5123 NEIGHBOR_ADDR_STR2
5124 "Solo peer - part of its own update group\n")
5125{
d62a17ae 5126 int idx_peer = 2;
5127 struct peer *peer;
5128 int ret;
3f9c7369 5129
d62a17ae 5130 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5131 if (!peer)
5132 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 5133
d62a17ae 5134 ret = update_group_adjust_soloness(peer, 0);
5135 return bgp_vty_return(vty, ret);
3f9c7369
DS
5136}
5137
28c6e247
IR
5138DEFUN (neighbor_password,
5139 neighbor_password_cmd,
5140 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
5141 NEIGHBOR_STR
5142 NEIGHBOR_ADDR_STR2
5143 "Set a password\n"
5144 "The password\n")
0df7c91f 5145{
d62a17ae 5146 int idx_peer = 1;
5147 int idx_line = 3;
28c6e247
IR
5148 struct peer *peer;
5149 int ret;
0df7c91f 5150
28c6e247
IR
5151 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5152 if (!peer)
d62a17ae 5153 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 5154
28c6e247
IR
5155 ret = peer_password_set(peer, argv[idx_line]->arg);
5156 return bgp_vty_return(vty, ret);
0df7c91f
PJ
5157}
5158
28c6e247
IR
5159DEFUN (no_neighbor_password,
5160 no_neighbor_password_cmd,
5161 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
5162 NO_STR
5163 NEIGHBOR_STR
5164 NEIGHBOR_ADDR_STR2
5165 "Set a password\n"
5166 "The password\n")
0df7c91f 5167{
d62a17ae 5168 int idx_peer = 2;
28c6e247
IR
5169 struct peer *peer;
5170 int ret;
0df7c91f 5171
28c6e247
IR
5172 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5173 if (!peer)
d62a17ae 5174 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 5175
28c6e247
IR
5176 ret = peer_password_unset(peer);
5177 return bgp_vty_return(vty, ret);
0df7c91f 5178}
6b0655a2 5179
28c6e247
IR
5180DEFUN (neighbor_activate,
5181 neighbor_activate_cmd,
5182 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5183 NEIGHBOR_STR
5184 NEIGHBOR_ADDR_STR2
5185 "Enable the Address Family for this Neighbor\n")
718e3744 5186{
d62a17ae 5187 int idx_peer = 1;
28c6e247
IR
5188 int ret;
5189 struct peer *peer;
56ceae84 5190
28c6e247
IR
5191 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5192 if (!peer)
d62a17ae 5193 return CMD_WARNING_CONFIG_FAILED;
718e3744 5194
28c6e247
IR
5195 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5196 return bgp_vty_return(vty, ret);
718e3744 5197}
5198
d62a17ae 5199ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
5200 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5201 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5202 "Enable the Address Family for this Neighbor\n")
596c17ba 5203
28c6e247
IR
5204DEFUN (no_neighbor_activate,
5205 no_neighbor_activate_cmd,
5206 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5207 NO_STR
5208 NEIGHBOR_STR
5209 NEIGHBOR_ADDR_STR2
5210 "Enable the Address Family for this Neighbor\n")
718e3744 5211{
d62a17ae 5212 int idx_peer = 2;
28c6e247
IR
5213 int ret;
5214 struct peer *peer;
f4b8ec07 5215
28c6e247
IR
5216 /* Lookup peer. */
5217 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5218 if (!peer)
d62a17ae 5219 return CMD_WARNING_CONFIG_FAILED;
718e3744 5220
28c6e247
IR
5221 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5222 return bgp_vty_return(vty, ret);
718e3744 5223}
6b0655a2 5224
d62a17ae 5225ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
5226 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5227 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5228 "Enable the Address Family for this Neighbor\n")
596c17ba 5229
28c6e247
IR
5230DEFUN (neighbor_set_peer_group,
5231 neighbor_set_peer_group_cmd,
5232 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5233 NEIGHBOR_STR
5234 NEIGHBOR_ADDR_STR2
5235 "Member of the peer-group\n"
5236 "Peer-group name\n")
718e3744 5237{
28c6e247 5238 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 5239 int idx_peer = 1;
5240 int idx_word = 3;
28c6e247
IR
5241 int ret;
5242 as_t as;
5243 union sockunion su;
5244 struct peer *peer;
5245 struct peer_group *group;
5246
5247 ret = str2sockunion(argv[idx_peer]->arg, &su);
5248 if (ret < 0) {
5249 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
5250 if (!peer) {
5251 vty_out(vty, "%% Malformed address or name: %s\n",
5252 argv[idx_peer]->arg);
5253 return CMD_WARNING_CONFIG_FAILED;
5254 }
5255 } else {
5256 if (peer_address_self_check(bgp, &su)) {
5257 vty_out(vty,
5258 "%% Can not configure the local system as neighbor\n");
5259 return CMD_WARNING_CONFIG_FAILED;
5260 }
2a059a54 5261
28c6e247
IR
5262 /* Disallow for dynamic neighbor. */
5263 peer = peer_lookup(bgp, &su);
5264 if (peer && peer_dynamic_neighbor(peer)) {
5265 vty_out(vty,
5266 "%% Operation not allowed on a dynamic neighbor\n");
5267 return CMD_WARNING_CONFIG_FAILED;
5268 }
5269 }
5270
5271 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5272 if (!group) {
5273 vty_out(vty, "%% Configure the peer-group first\n");
d62a17ae 5274 return CMD_WARNING_CONFIG_FAILED;
28c6e247 5275 }
d62a17ae 5276
28c6e247 5277 ret = peer_group_bind(bgp, &su, peer, group, &as);
2a059a54 5278
28c6e247 5279 return bgp_vty_return(vty, ret);
d62a17ae 5280}
5281
5282ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
d7b9898c 5283 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 5284 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5285 "Member of the peer-group\n"
5286 "Peer-group name\n")
596c17ba 5287
28c6e247
IR
5288DEFUN (no_neighbor_set_peer_group,
5289 no_neighbor_set_peer_group_cmd,
5290 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5291 NO_STR
5292 NEIGHBOR_STR
5293 NEIGHBOR_ADDR_STR2
5294 "Member of the peer-group\n"
5295 "Peer-group name\n")
718e3744 5296{
28c6e247 5297 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 5298 int idx_peer = 2;
28c6e247
IR
5299 int idx_word = 4;
5300 int ret;
5301 struct peer *peer;
5302 struct peer_group *group;
d62a17ae 5303
28c6e247
IR
5304 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
5305 if (!peer)
d62a17ae 5306 return CMD_WARNING_CONFIG_FAILED;
b3a3290e 5307
28c6e247
IR
5308 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5309 if (!group) {
5310 vty_out(vty, "%% Configure the peer-group first\n");
5311 return CMD_WARNING_CONFIG_FAILED;
5312 }
718e3744 5313
28c6e247
IR
5314 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
5315 bgp_zebra_terminate_radv(peer->bgp, peer);
5316
5317 peer_notify_unconfig(peer);
5318 ret = peer_delete(peer);
5319
5320 return bgp_vty_return(vty, ret);
718e3744 5321}
6b0655a2 5322
d62a17ae 5323ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
71cc0c88 5324 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 5325 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5326 "Member of the peer-group\n"
5327 "Peer-group name\n")
596c17ba 5328
718e3744 5329/* neighbor passive. */
28c6e247
IR
5330DEFUN (neighbor_passive,
5331 neighbor_passive_cmd,
5332 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5333 NEIGHBOR_STR
5334 NEIGHBOR_ADDR_STR2
5335 "Don't send open messages to this neighbor\n")
718e3744 5336{
d62a17ae 5337 int idx_peer = 1;
28c6e247 5338 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 5339}
5340
28c6e247
IR
5341DEFUN (no_neighbor_passive,
5342 no_neighbor_passive_cmd,
5343 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5344 NO_STR
5345 NEIGHBOR_STR
5346 NEIGHBOR_ADDR_STR2
5347 "Don't send open messages to this neighbor\n")
718e3744 5348{
d62a17ae 5349 int idx_peer = 2;
28c6e247 5350 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 5351}
6b0655a2 5352
718e3744 5353/* neighbor shutdown. */
28c6e247
IR
5354DEFUN (neighbor_shutdown_msg,
5355 neighbor_shutdown_msg_cmd,
5356 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5357 NEIGHBOR_STR
5358 NEIGHBOR_ADDR_STR2
5359 "Administratively shut down this neighbor\n"
5360 "Add a shutdown message (RFC 8203)\n"
5361 "Shutdown message\n")
718e3744 5362{
d62a17ae 5363 int idx_peer = 1;
73d70fa6 5364
d62a17ae 5365 if (argc >= 5) {
28c6e247
IR
5366 struct peer *peer =
5367 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
d62a17ae 5368 char *message;
73d70fa6 5369
28c6e247
IR
5370 if (!peer)
5371 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5372 message = argv_concat(argv, argc, 4);
28c6e247
IR
5373 peer_tx_shutdown_message_set(peer, message);
5374 XFREE(MTYPE_TMP, message);
d62a17ae 5375 }
73d70fa6 5376
28c6e247 5377 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 5378}
5379
1d80f243 5380ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
d62a17ae 5381 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5382 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5383 "Administratively shut down this neighbor\n")
73d70fa6 5384
28c6e247
IR
5385DEFUN (no_neighbor_shutdown_msg,
5386 no_neighbor_shutdown_msg_cmd,
5387 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5388 NO_STR
5389 NEIGHBOR_STR
5390 NEIGHBOR_ADDR_STR2
5391 "Administratively shut down this neighbor\n"
5392 "Remove a shutdown message (RFC 8203)\n"
5393 "Shutdown message\n")
718e3744 5394{
d62a17ae 5395 int idx_peer = 2;
73d70fa6 5396
28c6e247
IR
5397 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5398 PEER_FLAG_SHUTDOWN);
718e3744 5399}
6b0655a2 5400
1d80f243 5401ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
d62a17ae 5402 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5403 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5404 "Administratively shut down this neighbor\n")
73d70fa6 5405
8336c896
DA
5406DEFUN(neighbor_shutdown_rtt,
5407 neighbor_shutdown_rtt_cmd,
5408 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5409 NEIGHBOR_STR
5410 NEIGHBOR_ADDR_STR2
5411 "Administratively shut down this neighbor\n"
5412 "Shutdown if round-trip-time is higher than expected\n"
5413 "Round-trip-time in milliseconds\n"
5414 "Specify the number of keepalives before shutdown\n"
5415 "The number of keepalives with higher RTT to shutdown\n")
5416{
5417 int idx_peer = 1;
5418 int idx_rtt = 4;
5419 int idx_count = 0;
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 = strtol(argv[idx_rtt]->arg, NULL, 10);
5428
5429 if (argv_find(argv, argc, "count", &idx_count))
5430 peer->rtt_keepalive_conf =
5431 strtol(argv[idx_count + 1]->arg, NULL, 10);
5432
5433 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5434 PEER_FLAG_RTT_SHUTDOWN);
5435}
5436
5437DEFUN(no_neighbor_shutdown_rtt,
5438 no_neighbor_shutdown_rtt_cmd,
5439 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5440 NO_STR
5441 NEIGHBOR_STR
5442 NEIGHBOR_ADDR_STR2
5443 "Administratively shut down this neighbor\n"
5444 "Shutdown if round-trip-time is higher than expected\n"
5445 "Round-trip-time in milliseconds\n"
5446 "Specify the number of keepalives before shutdown\n"
5447 "The number of keepalives with higher RTT to shutdown\n")
5448{
5449 int idx_peer = 2;
5450 struct peer *peer;
5451
5452 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5453
5454 if (!peer)
5455 return CMD_WARNING_CONFIG_FAILED;
5456
5457 peer->rtt_expected = 0;
5458 peer->rtt_keepalive_conf = 1;
5459
5460 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5461 PEER_FLAG_RTT_SHUTDOWN);
5462}
5463
718e3744 5464/* neighbor capability dynamic. */
28c6e247
IR
5465DEFUN (neighbor_capability_dynamic,
5466 neighbor_capability_dynamic_cmd,
5467 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5468 NEIGHBOR_STR
5469 NEIGHBOR_ADDR_STR2
5470 "Advertise capability to the peer\n"
5471 "Advertise dynamic capability to this neighbor\n")
718e3744 5472{
d62a17ae 5473 int idx_peer = 1;
28c6e247
IR
5474 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5475 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 5476}
5477
28c6e247
IR
5478DEFUN (no_neighbor_capability_dynamic,
5479 no_neighbor_capability_dynamic_cmd,
5480 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5481 NO_STR
5482 NEIGHBOR_STR
5483 NEIGHBOR_ADDR_STR2
5484 "Advertise capability to the peer\n"
5485 "Advertise dynamic capability to this neighbor\n")
718e3744 5486{
d62a17ae 5487 int idx_peer = 2;
28c6e247
IR
5488 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5489 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 5490}
6b0655a2 5491
718e3744 5492/* neighbor dont-capability-negotiate */
5493DEFUN (neighbor_dont_capability_negotiate,
5494 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5495 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5496 NEIGHBOR_STR
5497 NEIGHBOR_ADDR_STR2
5498 "Do not perform capability negotiation\n")
5499{
d62a17ae 5500 int idx_peer = 1;
5501 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5502 PEER_FLAG_DONT_CAPABILITY);
718e3744 5503}
5504
5505DEFUN (no_neighbor_dont_capability_negotiate,
5506 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5507 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5508 NO_STR
5509 NEIGHBOR_STR
5510 NEIGHBOR_ADDR_STR2
5511 "Do not perform capability negotiation\n")
5512{
28c6e247
IR
5513 int idx_peer = 2;
5514 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5515 PEER_FLAG_DONT_CAPABILITY);
f4b8ec07
CS
5516}
5517
28c6e247
IR
5518/* neighbor capability extended next hop encoding */
5519DEFUN (neighbor_capability_enhe,
5520 neighbor_capability_enhe_cmd,
5521 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5522 NEIGHBOR_STR
5523 NEIGHBOR_ADDR_STR2
5524 "Advertise capability to the peer\n"
5525 "Advertise extended next-hop capability to the peer\n")
f4b8ec07 5526{
28c6e247 5527 int idx_peer = 1;
c4786405
DS
5528 struct peer *peer;
5529
5530 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5531 if (peer && peer->conf_if)
5532 return CMD_SUCCESS;
5533
28c6e247
IR
5534 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5535 PEER_FLAG_CAPABILITY_ENHE);
5536}
f4b8ec07 5537
28c6e247
IR
5538DEFUN (no_neighbor_capability_enhe,
5539 no_neighbor_capability_enhe_cmd,
5540 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5541 NO_STR
5542 NEIGHBOR_STR
5543 NEIGHBOR_ADDR_STR2
5544 "Advertise capability to the peer\n"
5545 "Advertise extended next-hop capability to the peer\n")
5546{
5547 int idx_peer = 2;
c4786405
DS
5548 struct peer *peer;
5549
5550 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5551 if (peer && peer->conf_if) {
5552 vty_out(vty,
5553 "Peer %s cannot have capability extended-nexthop turned off\n",
5554 argv[idx_peer]->arg);
5555 return CMD_WARNING_CONFIG_FAILED;
5556 }
5557
28c6e247
IR
5558 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5559 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
5560}
5561
d62a17ae 5562static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5563 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 5564 int set)
718e3744 5565{
d62a17ae 5566 int ret;
5567 struct peer *peer;
718e3744 5568
d62a17ae 5569 peer = peer_and_group_lookup_vty(vty, peer_str);
5570 if (!peer)
5571 return CMD_WARNING_CONFIG_FAILED;
718e3744 5572
d62a17ae 5573 if (set)
5574 ret = peer_af_flag_set(peer, afi, safi, flag);
5575 else
5576 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 5577
d62a17ae 5578 return bgp_vty_return(vty, ret);
718e3744 5579}
5580
d62a17ae 5581static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5582 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5583{
d62a17ae 5584 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 5585}
5586
d62a17ae 5587static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5588 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5589{
d62a17ae 5590 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 5591}
6b0655a2 5592
718e3744 5593/* neighbor capability orf prefix-list. */
5594DEFUN (neighbor_capability_orf_prefix,
5595 neighbor_capability_orf_prefix_cmd,
9ccf14f7 5596 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5597 NEIGHBOR_STR
5598 NEIGHBOR_ADDR_STR2
5599 "Advertise capability to the peer\n"
5600 "Advertise ORF capability to the peer\n"
5601 "Advertise prefixlist ORF capability to this neighbor\n"
5602 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5603 "Capability to RECEIVE the ORF from this neighbor\n"
5604 "Capability to SEND the ORF to this neighbor\n")
5605{
d62a17ae 5606 int idx_send_recv = 5;
db45f64d
DS
5607 char *peer_str = argv[1]->arg;
5608 struct peer *peer;
5609 afi_t afi = bgp_node_afi(vty);
5610 safi_t safi = bgp_node_safi(vty);
d62a17ae 5611
db45f64d
DS
5612 peer = peer_and_group_lookup_vty(vty, peer_str);
5613 if (!peer)
d62a17ae 5614 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5615
db45f64d
DS
5616 if (strmatch(argv[idx_send_recv]->text, "send"))
5617 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5618 PEER_FLAG_ORF_PREFIX_SM);
5619
5620 if (strmatch(argv[idx_send_recv]->text, "receive"))
5621 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5622 PEER_FLAG_ORF_PREFIX_RM);
5623
5624 if (strmatch(argv[idx_send_recv]->text, "both"))
5625 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5626 PEER_FLAG_ORF_PREFIX_SM)
5627 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5628 PEER_FLAG_ORF_PREFIX_RM);
5629
5630 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5631}
5632
5633ALIAS_HIDDEN(
5634 neighbor_capability_orf_prefix,
5635 neighbor_capability_orf_prefix_hidden_cmd,
5636 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5637 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5638 "Advertise capability to the peer\n"
5639 "Advertise ORF capability to the peer\n"
5640 "Advertise prefixlist ORF capability to this neighbor\n"
5641 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5642 "Capability to RECEIVE the ORF from this neighbor\n"
5643 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5644
718e3744 5645DEFUN (no_neighbor_capability_orf_prefix,
5646 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 5647 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5648 NO_STR
5649 NEIGHBOR_STR
5650 NEIGHBOR_ADDR_STR2
5651 "Advertise capability to the peer\n"
5652 "Advertise ORF capability to the peer\n"
5653 "Advertise prefixlist ORF capability to this neighbor\n"
5654 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5655 "Capability to RECEIVE the ORF from this neighbor\n"
5656 "Capability to SEND the ORF to this neighbor\n")
5657{
d62a17ae 5658 int idx_send_recv = 6;
db45f64d
DS
5659 char *peer_str = argv[2]->arg;
5660 struct peer *peer;
5661 afi_t afi = bgp_node_afi(vty);
5662 safi_t safi = bgp_node_safi(vty);
d62a17ae 5663
db45f64d
DS
5664 peer = peer_and_group_lookup_vty(vty, peer_str);
5665 if (!peer)
d62a17ae 5666 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5667
db45f64d
DS
5668 if (strmatch(argv[idx_send_recv]->text, "send"))
5669 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5670 PEER_FLAG_ORF_PREFIX_SM);
5671
5672 if (strmatch(argv[idx_send_recv]->text, "receive"))
5673 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5674 PEER_FLAG_ORF_PREFIX_RM);
5675
5676 if (strmatch(argv[idx_send_recv]->text, "both"))
5677 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5678 PEER_FLAG_ORF_PREFIX_SM)
5679 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5680 PEER_FLAG_ORF_PREFIX_RM);
5681
5682 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5683}
5684
5685ALIAS_HIDDEN(
5686 no_neighbor_capability_orf_prefix,
5687 no_neighbor_capability_orf_prefix_hidden_cmd,
5688 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5689 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5690 "Advertise capability to the peer\n"
5691 "Advertise ORF capability to the peer\n"
5692 "Advertise prefixlist ORF capability to this neighbor\n"
5693 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5694 "Capability to RECEIVE the ORF from this neighbor\n"
5695 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5696
718e3744 5697/* neighbor next-hop-self. */
28c6e247
IR
5698DEFUN (neighbor_nexthop_self,
5699 neighbor_nexthop_self_cmd,
5700 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5701 NEIGHBOR_STR
5702 NEIGHBOR_ADDR_STR2
5703 "Disable the next hop calculation for this neighbor\n")
718e3744 5704{
d62a17ae 5705 int idx_peer = 1;
28c6e247
IR
5706 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5707 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 5708}
9e7a53c1 5709
d62a17ae 5710ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5711 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5712 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5713 "Disable the next hop calculation for this neighbor\n")
596c17ba 5714
f4b8ec07 5715/* neighbor next-hop-self. */
28c6e247
IR
5716DEFUN (neighbor_nexthop_self_force,
5717 neighbor_nexthop_self_force_cmd,
5718 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5719 NEIGHBOR_STR
5720 NEIGHBOR_ADDR_STR2
5721 "Disable the next hop calculation for this neighbor\n"
5722 "Set the next hop to self for reflected routes\n")
f4b8ec07
CS
5723{
5724 int idx_peer = 1;
28c6e247
IR
5725 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5726 bgp_node_safi(vty),
5727 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 5728}
5729
d62a17ae 5730ALIAS_HIDDEN(neighbor_nexthop_self_force,
5731 neighbor_nexthop_self_force_hidden_cmd,
5732 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5733 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5734 "Disable the next hop calculation for this neighbor\n"
5735 "Set the next hop to self for reflected routes\n")
596c17ba 5736
1bc4e531
DA
5737ALIAS_HIDDEN(neighbor_nexthop_self_force,
5738 neighbor_nexthop_self_all_hidden_cmd,
5739 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5740 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5741 "Disable the next hop calculation for this neighbor\n"
5742 "Set the next hop to self for reflected routes\n")
5743
28c6e247
IR
5744DEFUN (no_neighbor_nexthop_self,
5745 no_neighbor_nexthop_self_cmd,
5746 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5747 NO_STR
5748 NEIGHBOR_STR
5749 NEIGHBOR_ADDR_STR2
5750 "Disable the next hop calculation for this neighbor\n")
718e3744 5751{
d62a17ae 5752 int idx_peer = 2;
28c6e247
IR
5753 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5754 bgp_node_afi(vty), bgp_node_safi(vty),
5755 PEER_FLAG_NEXTHOP_SELF);
718e3744 5756}
6b0655a2 5757
d62a17ae 5758ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5759 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5760 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5761 "Disable the next hop calculation for this neighbor\n")
596c17ba 5762
28c6e247
IR
5763DEFUN (no_neighbor_nexthop_self_force,
5764 no_neighbor_nexthop_self_force_cmd,
5765 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5766 NO_STR
5767 NEIGHBOR_STR
5768 NEIGHBOR_ADDR_STR2
5769 "Disable the next hop calculation for this neighbor\n"
5770 "Set the next hop to self for reflected routes\n")
88b8ed8d 5771{
d62a17ae 5772 int idx_peer = 2;
28c6e247
IR
5773 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5774 bgp_node_afi(vty), bgp_node_safi(vty),
5775 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 5776}
a538debe 5777
d62a17ae 5778ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5779 no_neighbor_nexthop_self_force_hidden_cmd,
5780 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5781 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5782 "Disable the next hop calculation for this neighbor\n"
5783 "Set the next hop to self for reflected routes\n")
596c17ba 5784
1bc4e531
DA
5785ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5786 no_neighbor_nexthop_self_all_hidden_cmd,
5787 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5788 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5789 "Disable the next hop calculation for this neighbor\n"
5790 "Set the next hop to self for reflected routes\n")
5791
c7122e14 5792/* neighbor as-override */
28c6e247
IR
5793DEFUN (neighbor_as_override,
5794 neighbor_as_override_cmd,
5795 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5796 NEIGHBOR_STR
5797 NEIGHBOR_ADDR_STR2
5798 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5799{
d62a17ae 5800 int idx_peer = 1;
28c6e247
IR
5801 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5802 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
5803}
5804
d62a17ae 5805ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5806 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5807 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5808 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5809
28c6e247
IR
5810DEFUN (no_neighbor_as_override,
5811 no_neighbor_as_override_cmd,
5812 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5813 NO_STR
5814 NEIGHBOR_STR
5815 NEIGHBOR_ADDR_STR2
5816 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5817{
d62a17ae 5818 int idx_peer = 2;
28c6e247
IR
5819 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5820 bgp_node_afi(vty), bgp_node_safi(vty),
5821 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
5822}
5823
d62a17ae 5824ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5825 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5826 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5827 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5828
718e3744 5829/* neighbor remove-private-AS. */
28c6e247
IR
5830DEFUN (neighbor_remove_private_as,
5831 neighbor_remove_private_as_cmd,
5832 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5833 NEIGHBOR_STR
5834 NEIGHBOR_ADDR_STR2
5835 "Remove private ASNs in outbound updates\n")
718e3744 5836{
d62a17ae 5837 int idx_peer = 1;
28c6e247
IR
5838 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5839 bgp_node_safi(vty),
5840 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 5841}
5842
d62a17ae 5843ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5844 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5845 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5846 "Remove private ASNs in outbound updates\n")
596c17ba 5847
28c6e247
IR
5848DEFUN (neighbor_remove_private_as_all,
5849 neighbor_remove_private_as_all_cmd,
5850 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5851 NEIGHBOR_STR
5852 NEIGHBOR_ADDR_STR2
5853 "Remove private ASNs in outbound updates\n"
5854 "Apply to all AS numbers\n")
5000f21c 5855{
d62a17ae 5856 int idx_peer = 1;
28c6e247
IR
5857 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5858 bgp_node_safi(vty),
5859 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
5860}
5861
d62a17ae 5862ALIAS_HIDDEN(neighbor_remove_private_as_all,
5863 neighbor_remove_private_as_all_hidden_cmd,
5864 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5865 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5866 "Remove private ASNs in outbound updates\n"
a0dfca37 5867 "Apply to all AS numbers\n")
596c17ba 5868
28c6e247
IR
5869DEFUN (neighbor_remove_private_as_replace_as,
5870 neighbor_remove_private_as_replace_as_cmd,
5871 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5872 NEIGHBOR_STR
5873 NEIGHBOR_ADDR_STR2
5874 "Remove private ASNs in outbound updates\n"
5875 "Replace private ASNs with our ASN in outbound updates\n")
5000f21c 5876{
d62a17ae 5877 int idx_peer = 1;
28c6e247
IR
5878 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5879 bgp_node_safi(vty),
5880 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
5881}
5882
d62a17ae 5883ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5884 neighbor_remove_private_as_replace_as_hidden_cmd,
5885 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5886 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5887 "Remove private ASNs in outbound updates\n"
5888 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5889
28c6e247
IR
5890DEFUN (neighbor_remove_private_as_all_replace_as,
5891 neighbor_remove_private_as_all_replace_as_cmd,
5892 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5893 NEIGHBOR_STR
5894 NEIGHBOR_ADDR_STR2
5895 "Remove private ASNs in outbound updates\n"
5896 "Apply to all AS numbers\n"
5897 "Replace private ASNs with our ASN in outbound updates\n")
5000f21c 5898{
d62a17ae 5899 int idx_peer = 1;
28c6e247
IR
5900 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5901 bgp_node_safi(vty),
5902 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
5903}
5904
d62a17ae 5905ALIAS_HIDDEN(
5906 neighbor_remove_private_as_all_replace_as,
5907 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5908 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5909 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5910 "Remove private ASNs in outbound updates\n"
5911 "Apply to all AS numbers\n"
5912 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5913
28c6e247
IR
5914DEFUN (no_neighbor_remove_private_as,
5915 no_neighbor_remove_private_as_cmd,
5916 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5917 NO_STR
5918 NEIGHBOR_STR
5919 NEIGHBOR_ADDR_STR2
5920 "Remove private ASNs in outbound updates\n")
718e3744 5921{
d62a17ae 5922 int idx_peer = 2;
28c6e247
IR
5923 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5924 bgp_node_afi(vty), bgp_node_safi(vty),
5925 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 5926}
6b0655a2 5927
d62a17ae 5928ALIAS_HIDDEN(no_neighbor_remove_private_as,
5929 no_neighbor_remove_private_as_hidden_cmd,
5930 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5931 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5932 "Remove private ASNs in outbound updates\n")
596c17ba 5933
28c6e247
IR
5934DEFUN (no_neighbor_remove_private_as_all,
5935 no_neighbor_remove_private_as_all_cmd,
5936 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5937 NO_STR
5938 NEIGHBOR_STR
5939 NEIGHBOR_ADDR_STR2
5940 "Remove private ASNs in outbound updates\n"
5941 "Apply to all AS numbers\n")
88b8ed8d 5942{
d62a17ae 5943 int idx_peer = 2;
28c6e247
IR
5944 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5945 bgp_node_afi(vty), bgp_node_safi(vty),
5946 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 5947}
5000f21c 5948
d62a17ae 5949ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
5950 no_neighbor_remove_private_as_all_hidden_cmd,
5951 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5952 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5953 "Remove private ASNs in outbound updates\n"
5954 "Apply to all AS numbers\n")
596c17ba 5955
28c6e247
IR
5956DEFUN (no_neighbor_remove_private_as_replace_as,
5957 no_neighbor_remove_private_as_replace_as_cmd,
5958 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5959 NO_STR
5960 NEIGHBOR_STR
5961 NEIGHBOR_ADDR_STR2
5962 "Remove private ASNs in outbound updates\n"
5963 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 5964{
d62a17ae 5965 int idx_peer = 2;
28c6e247
IR
5966 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5967 bgp_node_afi(vty), bgp_node_safi(vty),
5968 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 5969}
5000f21c 5970
d62a17ae 5971ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
5972 no_neighbor_remove_private_as_replace_as_hidden_cmd,
5973 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5974 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5975 "Remove private ASNs in outbound updates\n"
5976 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5977
28c6e247
IR
5978DEFUN (no_neighbor_remove_private_as_all_replace_as,
5979 no_neighbor_remove_private_as_all_replace_as_cmd,
5980 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5981 NO_STR
5982 NEIGHBOR_STR
5983 NEIGHBOR_ADDR_STR2
5984 "Remove private ASNs in outbound updates\n"
5985 "Apply to all AS numbers\n"
5986 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 5987{
d62a17ae 5988 int idx_peer = 2;
28c6e247
IR
5989 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5990 bgp_node_afi(vty), bgp_node_safi(vty),
5991 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 5992}
5000f21c 5993
d62a17ae 5994ALIAS_HIDDEN(
5995 no_neighbor_remove_private_as_all_replace_as,
5996 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
5997 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5998 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5999 "Remove private ASNs in outbound updates\n"
6000 "Apply to all AS numbers\n"
6001 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 6002
5000f21c 6003
718e3744 6004/* neighbor send-community. */
28c6e247
IR
6005DEFUN (neighbor_send_community,
6006 neighbor_send_community_cmd,
6007 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6008 NEIGHBOR_STR
6009 NEIGHBOR_ADDR_STR2
6010 "Send Community attribute to this neighbor\n")
718e3744 6011{
d62a17ae 6012 int idx_peer = 1;
27c05d4d 6013
f63d4054
IR
6014 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6015 bgp_node_safi(vty),
6016 PEER_FLAG_SEND_COMMUNITY);
718e3744 6017}
6018
d62a17ae 6019ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
6020 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6021 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6022 "Send Community attribute to this neighbor\n")
596c17ba 6023
28c6e247
IR
6024DEFUN (no_neighbor_send_community,
6025 no_neighbor_send_community_cmd,
6026 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6027 NO_STR
6028 NEIGHBOR_STR
6029 NEIGHBOR_ADDR_STR2
6030 "Send Community attribute to this neighbor\n")
718e3744 6031{
d62a17ae 6032 int idx_peer = 2;
27c05d4d 6033
f63d4054
IR
6034 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6035 bgp_node_afi(vty), bgp_node_safi(vty),
6036 PEER_FLAG_SEND_COMMUNITY);
718e3744 6037}
6b0655a2 6038
d62a17ae 6039ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
6040 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6041 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6042 "Send Community attribute to this neighbor\n")
596c17ba 6043
718e3744 6044/* neighbor send-community extended. */
28c6e247
IR
6045DEFUN (neighbor_send_community_type,
6046 neighbor_send_community_type_cmd,
6047 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6048 NEIGHBOR_STR
6049 NEIGHBOR_ADDR_STR2
6050 "Send Community attribute to this neighbor\n"
6051 "Send Standard and Extended Community attributes\n"
6052 "Send Standard, Large and Extended Community attributes\n"
6053 "Send Extended Community attributes\n"
6054 "Send Standard Community attributes\n"
6055 "Send Large Community attributes\n")
718e3744 6056{
27c05d4d 6057 const char *type = argv[argc - 1]->text;
db45f64d 6058 char *peer_str = argv[1]->arg;
28c6e247 6059 struct peer *peer;
db45f64d 6060 afi_t afi = bgp_node_afi(vty);
28c6e247 6061 safi_t safi = bgp_node_safi(vty);
f4b8ec07 6062
28c6e247
IR
6063 peer = peer_and_group_lookup_vty(vty, peer_str);
6064 if (!peer)
6065 return CMD_WARNING_CONFIG_FAILED;
f4b8ec07 6066
28c6e247
IR
6067 if (strmatch(type, "standard"))
6068 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6069 PEER_FLAG_SEND_COMMUNITY);
f4b8ec07 6070
28c6e247
IR
6071 if (strmatch(type, "extended"))
6072 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6073 PEER_FLAG_SEND_EXT_COMMUNITY);
f4b8ec07 6074
28c6e247
IR
6075 if (strmatch(type, "large"))
6076 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6077 PEER_FLAG_SEND_LARGE_COMMUNITY);
f4b8ec07 6078
28c6e247
IR
6079 if (strmatch(type, "both")) {
6080 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6081 PEER_FLAG_SEND_COMMUNITY)
6082 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6083 PEER_FLAG_SEND_EXT_COMMUNITY);
f4b8ec07 6084 }
28c6e247
IR
6085 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6086 PEER_FLAG_SEND_COMMUNITY)
6087 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6088 PEER_FLAG_SEND_EXT_COMMUNITY)
6089 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6090 PEER_FLAG_SEND_LARGE_COMMUNITY);
d62a17ae 6091}
6092
6093ALIAS_HIDDEN(
6094 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
6095 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6096 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6097 "Send Community attribute to this neighbor\n"
6098 "Send Standard and Extended Community attributes\n"
6099 "Send Standard, Large and Extended Community attributes\n"
6100 "Send Extended Community attributes\n"
6101 "Send Standard Community attributes\n"
6102 "Send Large Community attributes\n")
596c17ba 6103
28c6e247
IR
6104DEFUN (no_neighbor_send_community_type,
6105 no_neighbor_send_community_type_cmd,
6106 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6107 NO_STR
6108 NEIGHBOR_STR
6109 NEIGHBOR_ADDR_STR2
6110 "Send Community attribute to this neighbor\n"
6111 "Send Standard and Extended Community attributes\n"
6112 "Send Standard, Large and Extended Community attributes\n"
6113 "Send Extended Community attributes\n"
6114 "Send Standard Community attributes\n"
6115 "Send Large Community attributes\n")
718e3744 6116{
d62a17ae 6117 const char *type = argv[argc - 1]->text;
db45f64d 6118 char *peer_str = argv[2]->arg;
28c6e247 6119 struct peer *peer;
db45f64d
DS
6120 afi_t afi = bgp_node_afi(vty);
6121 safi_t safi = bgp_node_safi(vty);
6122
28c6e247
IR
6123 peer = peer_and_group_lookup_vty(vty, peer_str);
6124 if (!peer)
f4b8ec07
CS
6125 return CMD_WARNING_CONFIG_FAILED;
6126
28c6e247
IR
6127 if (strmatch(type, "standard"))
6128 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6129 PEER_FLAG_SEND_COMMUNITY);
f4b8ec07 6130
28c6e247
IR
6131 if (strmatch(type, "extended"))
6132 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6133 PEER_FLAG_SEND_EXT_COMMUNITY);
f4b8ec07 6134
28c6e247
IR
6135 if (strmatch(type, "large"))
6136 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6137 PEER_FLAG_SEND_LARGE_COMMUNITY);
f4b8ec07
CS
6138
6139 if (strmatch(type, "both")) {
db45f64d 6140
28c6e247
IR
6141 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6142 PEER_FLAG_SEND_COMMUNITY)
6143 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6144 PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d
PM
6145 }
6146
28c6e247
IR
6147 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6148 PEER_FLAG_SEND_COMMUNITY)
6149 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6150 PEER_FLAG_SEND_EXT_COMMUNITY)
6151 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6152 PEER_FLAG_SEND_LARGE_COMMUNITY);
d62a17ae 6153}
6154
6155ALIAS_HIDDEN(
6156 no_neighbor_send_community_type,
6157 no_neighbor_send_community_type_hidden_cmd,
6158 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6159 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6160 "Send Community attribute to this neighbor\n"
6161 "Send Standard and Extended Community attributes\n"
6162 "Send Standard, Large and Extended Community attributes\n"
6163 "Send Extended Community attributes\n"
6164 "Send Standard Community attributes\n"
6165 "Send Large Community attributes\n")
596c17ba 6166
718e3744 6167/* neighbor soft-reconfig. */
28c6e247
IR
6168DEFUN (neighbor_soft_reconfiguration,
6169 neighbor_soft_reconfiguration_cmd,
6170 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6171 NEIGHBOR_STR
6172 NEIGHBOR_ADDR_STR2
6173 "Per neighbor soft reconfiguration\n"
6174 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 6175{
d62a17ae 6176 int idx_peer = 1;
28c6e247
IR
6177 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6178 bgp_node_safi(vty),
6179 PEER_FLAG_SOFT_RECONFIG);
718e3744 6180}
6181
d62a17ae 6182ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6183 neighbor_soft_reconfiguration_hidden_cmd,
6184 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6185 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6186 "Per neighbor soft reconfiguration\n"
6187 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 6188
28c6e247
IR
6189DEFUN (no_neighbor_soft_reconfiguration,
6190 no_neighbor_soft_reconfiguration_cmd,
6191 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6192 NO_STR
6193 NEIGHBOR_STR
6194 NEIGHBOR_ADDR_STR2
6195 "Per neighbor soft reconfiguration\n"
6196 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 6197{
d62a17ae 6198 int idx_peer = 2;
28c6e247
IR
6199 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6200 bgp_node_afi(vty), bgp_node_safi(vty),
6201 PEER_FLAG_SOFT_RECONFIG);
718e3744 6202}
6b0655a2 6203
d62a17ae 6204ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6205 no_neighbor_soft_reconfiguration_hidden_cmd,
6206 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6207 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6208 "Per neighbor soft reconfiguration\n"
6209 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 6210
28c6e247
IR
6211DEFUN (neighbor_route_reflector_client,
6212 neighbor_route_reflector_client_cmd,
6213 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6214 NEIGHBOR_STR
6215 NEIGHBOR_ADDR_STR2
6216 "Configure a neighbor as Route Reflector client\n")
718e3744 6217{
d62a17ae 6218 int idx_peer = 1;
28c6e247 6219 struct peer *peer;
718e3744 6220
6221
28c6e247
IR
6222 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6223 if (!peer)
d62a17ae 6224 return CMD_WARNING_CONFIG_FAILED;
718e3744 6225
28c6e247
IR
6226 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6227 bgp_node_safi(vty),
6228 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 6229}
6230
d62a17ae 6231ALIAS_HIDDEN(neighbor_route_reflector_client,
6232 neighbor_route_reflector_client_hidden_cmd,
6233 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6234 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6235 "Configure a neighbor as Route Reflector client\n")
596c17ba 6236
28c6e247
IR
6237DEFUN (no_neighbor_route_reflector_client,
6238 no_neighbor_route_reflector_client_cmd,
6239 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6240 NO_STR
6241 NEIGHBOR_STR
6242 NEIGHBOR_ADDR_STR2
6243 "Configure a neighbor as Route Reflector client\n")
718e3744 6244{
d62a17ae 6245 int idx_peer = 2;
28c6e247
IR
6246 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6247 bgp_node_afi(vty), bgp_node_safi(vty),
6248 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 6249}
6b0655a2 6250
d62a17ae 6251ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6252 no_neighbor_route_reflector_client_hidden_cmd,
6253 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6254 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6255 "Configure a neighbor as Route Reflector client\n")
596c17ba 6256
70cd87ca
MK
6257/* optimal-route-reflection Root Routers configuration */
6258DEFPY (optimal_route_reflection,
6259 optimal_route_reflection_cmd,
6260 "[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]]]",
6261 NO_STR
6262 "Create ORR group and assign root router(s)\n"
6263 "ORR Group name\n"
6264 "Primary Root address\n"
6265 "Primary Root IPv6 address\n"
6266 "Secondary Root address\n"
6267 "Secondary Root IPv6 address\n"
6268 "Tertiary Root address\n"
6269 "Tertiary Root IPv6 address\n")
6270{
6271 if (!no && !primary) {
6272 vty_out(vty, "%% Specify Primary Root address\n");
6273 return CMD_WARNING_CONFIG_FAILED;
6274 }
6275 return bgp_afi_safi_orr_group_set_vty(
6276 vty, bgp_node_afi(vty), bgp_node_safi(vty), orr_group,
80f6ea8b 6277 primary_str, secondary_str, tertiary_str, !!no);
70cd87ca
MK
6278}
6279
6280/* neighbor optimal-route-reflection group*/
6281DEFPY (neighbor_optimal_route_reflection,
6282 neighbor_optimal_route_reflection_cmd,
6283 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor optimal-route-reflection WORD$orr_group",
6284 NO_STR
6285 NEIGHBOR_STR
6286 NEIGHBOR_ADDR_STR2
6287 "Apply ORR group configuration to the neighbor\n"
6288 "ORR group name\n")
6289{
6290 return peer_orr_group_set_vty(vty, neighbor, bgp_node_afi(vty),
80f6ea8b 6291 bgp_node_safi(vty), orr_group, !!no);
70cd87ca
MK
6292}
6293
718e3744 6294/* neighbor route-server-client. */
28c6e247
IR
6295DEFUN (neighbor_route_server_client,
6296 neighbor_route_server_client_cmd,
6297 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6298 NEIGHBOR_STR
6299 NEIGHBOR_ADDR_STR2
6300 "Configure a neighbor as Route Server client\n")
718e3744 6301{
d62a17ae 6302 int idx_peer = 1;
28c6e247 6303 struct peer *peer;
f4b8ec07 6304
28c6e247
IR
6305 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6306 if (!peer)
d62a17ae 6307 return CMD_WARNING_CONFIG_FAILED;
28c6e247
IR
6308 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6309 bgp_node_safi(vty),
6310 PEER_FLAG_RSERVER_CLIENT);
718e3744 6311}
6312
d62a17ae 6313ALIAS_HIDDEN(neighbor_route_server_client,
6314 neighbor_route_server_client_hidden_cmd,
6315 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6316 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6317 "Configure a neighbor as Route Server client\n")
596c17ba 6318
28c6e247
IR
6319DEFUN (no_neighbor_route_server_client,
6320 no_neighbor_route_server_client_cmd,
6321 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6322 NO_STR
6323 NEIGHBOR_STR
6324 NEIGHBOR_ADDR_STR2
6325 "Configure a neighbor as Route Server client\n")
fee0f4c6 6326{
d62a17ae 6327 int idx_peer = 2;
28c6e247
IR
6328 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6329 bgp_node_afi(vty), bgp_node_safi(vty),
6330 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 6331}
6b0655a2 6332
d62a17ae 6333ALIAS_HIDDEN(no_neighbor_route_server_client,
6334 no_neighbor_route_server_client_hidden_cmd,
6335 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6336 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6337 "Configure a neighbor as Route Server client\n")
596c17ba 6338
fee0f4c6 6339DEFUN (neighbor_nexthop_local_unchanged,
6340 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 6341 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 6342 NEIGHBOR_STR
6343 NEIGHBOR_ADDR_STR2
6344 "Configure treatment of outgoing link-local nexthop attribute\n"
6345 "Leave link-local nexthop unchanged for this peer\n")
6346{
d62a17ae 6347 int idx_peer = 1;
6348 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6349 bgp_node_safi(vty),
6350 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 6351}
6b0655a2 6352
fee0f4c6 6353DEFUN (no_neighbor_nexthop_local_unchanged,
6354 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 6355 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 6356 NO_STR
6357 NEIGHBOR_STR
6358 NEIGHBOR_ADDR_STR2
6359 "Configure treatment of outgoing link-local-nexthop attribute\n"
6360 "Leave link-local nexthop unchanged for this peer\n")
718e3744 6361{
d62a17ae 6362 int idx_peer = 2;
6363 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6364 bgp_node_afi(vty), bgp_node_safi(vty),
6365 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 6366}
6b0655a2 6367
28c6e247
IR
6368DEFUN (neighbor_attr_unchanged,
6369 neighbor_attr_unchanged_cmd,
6370 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6371 NEIGHBOR_STR
6372 NEIGHBOR_ADDR_STR2
6373 "BGP attribute is propagated unchanged to this neighbor\n"
6374 "As-path attribute\n"
6375 "Nexthop attribute\n"
6376 "Med attribute\n")
718e3744 6377{
d62a17ae 6378 int idx = 0;
8eeb0335 6379 char *peer_str = argv[1]->arg;
28c6e247 6380 struct peer *peer;
db45f64d
DS
6381 bool aspath = false;
6382 bool nexthop = false;
6383 bool med = false;
8eeb0335
DW
6384 afi_t afi = bgp_node_afi(vty);
6385 safi_t safi = bgp_node_safi(vty);
28c6e247 6386 int ret = 0;
f4b8ec07 6387
28c6e247
IR
6388 peer = peer_and_group_lookup_vty(vty, peer_str);
6389 if (!peer)
8eeb0335 6390 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6391
6392 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
6393 aspath = true;
6394
d62a17ae 6395 idx = 0;
6396 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6397 nexthop = true;
6398
d62a17ae 6399 idx = 0;
6400 if (argv_find(argv, argc, "med", &idx))
db45f64d 6401 med = true;
d62a17ae 6402
8eeb0335 6403 /* no flags means all of them! */
db45f64d 6404 if (!aspath && !nexthop && !med) {
28c6e247
IR
6405 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
6406 PEER_FLAG_AS_PATH_UNCHANGED);
6407 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6408 PEER_FLAG_NEXTHOP_UNCHANGED);
6409 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6410 PEER_FLAG_MED_UNCHANGED);
8eeb0335 6411 } else {
28c6e247
IR
6412 if (!aspath) {
6413 if (peer_af_flag_check(peer, afi, safi,
6414 PEER_FLAG_AS_PATH_UNCHANGED)) {
6415 ret |= peer_af_flag_unset_vty(
6416 vty, peer_str, afi, safi,
6417 PEER_FLAG_AS_PATH_UNCHANGED);
6418 }
6419 } else
6420 ret |= peer_af_flag_set_vty(
6421 vty, peer_str, afi, safi,
6422 PEER_FLAG_AS_PATH_UNCHANGED);
6423
6424 if (!nexthop) {
6425 if (peer_af_flag_check(peer, afi, safi,
6426 PEER_FLAG_NEXTHOP_UNCHANGED)) {
6427 ret |= peer_af_flag_unset_vty(
6428 vty, peer_str, afi, safi,
6429 PEER_FLAG_NEXTHOP_UNCHANGED);
6430 }
6431 } else
6432 ret |= peer_af_flag_set_vty(
6433 vty, peer_str, afi, safi,
6434 PEER_FLAG_NEXTHOP_UNCHANGED);
6435
6436 if (!med) {
6437 if (peer_af_flag_check(peer, afi, safi,
6438 PEER_FLAG_MED_UNCHANGED)) {
6439 ret |= peer_af_flag_unset_vty(
6440 vty, peer_str, afi, safi,
6441 PEER_FLAG_MED_UNCHANGED);
6442 }
6443 } else
6444 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6445 PEER_FLAG_MED_UNCHANGED);
d62a17ae 6446 }
6447
28c6e247 6448 return ret;
d62a17ae 6449}
6450
6451ALIAS_HIDDEN(
6452 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6453 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6454 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6455 "BGP attribute is propagated unchanged to this neighbor\n"
6456 "As-path attribute\n"
6457 "Nexthop attribute\n"
6458 "Med attribute\n")
596c17ba 6459
28c6e247
IR
6460DEFUN (no_neighbor_attr_unchanged,
6461 no_neighbor_attr_unchanged_cmd,
6462 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6463 NO_STR
6464 NEIGHBOR_STR
6465 NEIGHBOR_ADDR_STR2
6466 "BGP attribute is propagated unchanged to this neighbor\n"
6467 "As-path attribute\n"
6468 "Nexthop attribute\n"
6469 "Med attribute\n")
718e3744 6470{
d62a17ae 6471 int idx = 0;
db45f64d 6472 char *peer_str = argv[2]->arg;
28c6e247 6473 struct peer *peer;
db45f64d
DS
6474 bool aspath = false;
6475 bool nexthop = false;
6476 bool med = false;
6477 afi_t afi = bgp_node_afi(vty);
6478 safi_t safi = bgp_node_safi(vty);
28c6e247 6479 int ret = 0;
f4b8ec07 6480
28c6e247
IR
6481 peer = peer_and_group_lookup_vty(vty, peer_str);
6482 if (!peer)
db45f64d 6483 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6484
6485 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
6486 aspath = true;
6487
d62a17ae 6488 idx = 0;
6489 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6490 nexthop = true;
6491
d62a17ae 6492 idx = 0;
6493 if (argv_find(argv, argc, "med", &idx))
db45f64d 6494 med = true;
d62a17ae 6495
28c6e247
IR
6496 if (!aspath && !nexthop && !med) // no flags means all of them!
6497 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6498 PEER_FLAG_AS_PATH_UNCHANGED)
6499 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6500 PEER_FLAG_NEXTHOP_UNCHANGED)
6501 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6502 PEER_FLAG_MED_UNCHANGED);
db45f64d
DS
6503
6504 if (aspath)
28c6e247
IR
6505 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6506 PEER_FLAG_AS_PATH_UNCHANGED);
db45f64d
DS
6507
6508 if (nexthop)
28c6e247
IR
6509 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6510 PEER_FLAG_NEXTHOP_UNCHANGED);
d62a17ae 6511
db45f64d 6512 if (med)
28c6e247
IR
6513 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6514 PEER_FLAG_MED_UNCHANGED);
db45f64d 6515
28c6e247 6516 return ret;
d62a17ae 6517}
6518
6519ALIAS_HIDDEN(
6520 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6521 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6522 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6523 "BGP attribute is propagated unchanged to this neighbor\n"
6524 "As-path attribute\n"
6525 "Nexthop attribute\n"
6526 "Med attribute\n")
718e3744 6527
28c6e247
IR
6528/* EBGP multihop configuration. */
6529static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
6530 const char *ttl_str)
718e3744 6531{
28c6e247
IR
6532 struct peer *peer;
6533 unsigned int ttl;
718e3744 6534
28c6e247
IR
6535 peer = peer_and_group_lookup_vty(vty, ip_str);
6536 if (!peer)
d62a17ae 6537 return CMD_WARNING_CONFIG_FAILED;
718e3744 6538
28c6e247
IR
6539 if (peer->conf_if)
6540 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
6541
6542 if (!ttl_str)
6543 ttl = MAXTTL;
6544 else
6545 ttl = strtoul(ttl_str, NULL, 10);
718e3744 6546
28c6e247 6547 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 6548}
6549
28c6e247 6550static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 6551{
28c6e247 6552 struct peer *peer;
718e3744 6553
28c6e247
IR
6554 peer = peer_and_group_lookup_vty(vty, ip_str);
6555 if (!peer)
d62a17ae 6556 return CMD_WARNING_CONFIG_FAILED;
718e3744 6557
28c6e247 6558 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 6559}
6560
28c6e247
IR
6561/* neighbor ebgp-multihop. */
6562DEFUN (neighbor_ebgp_multihop,
6563 neighbor_ebgp_multihop_cmd,
6564 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6565 NEIGHBOR_STR
6566 NEIGHBOR_ADDR_STR2
6567 "Allow EBGP neighbors not on directly connected networks\n")
718e3744 6568{
28c6e247
IR
6569 int idx_peer = 1;
6570 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
6571}
f4b8ec07 6572
28c6e247
IR
6573DEFUN (neighbor_ebgp_multihop_ttl,
6574 neighbor_ebgp_multihop_ttl_cmd,
6575 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6576 NEIGHBOR_STR
6577 NEIGHBOR_ADDR_STR2
6578 "Allow EBGP neighbors not on directly connected networks\n"
6579 "maximum hop count\n")
6580{
6581 int idx_peer = 1;
6582 int idx_number = 3;
6583 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
6584 argv[idx_number]->arg);
6585}
f4b8ec07 6586
28c6e247
IR
6587DEFUN (no_neighbor_ebgp_multihop,
6588 no_neighbor_ebgp_multihop_cmd,
6589 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6590 NO_STR
6591 NEIGHBOR_STR
6592 NEIGHBOR_ADDR_STR2
6593 "Allow EBGP neighbors not on directly connected networks\n"
6594 "maximum hop count\n")
6595{
6596 int idx_peer = 2;
6597 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 6598}
6599
97a52c82
DA
6600DEFPY (neighbor_aigp,
6601 neighbor_aigp_cmd,
6602 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor aigp",
6603 NO_STR
6604 NEIGHBOR_STR
6605 NEIGHBOR_ADDR_STR2
6606 "Enable send and receive of the AIGP attribute per neighbor\n")
6607{
6608 struct peer *peer;
6609
6610 peer = peer_and_group_lookup_vty(vty, neighbor);
6611 if (!peer)
6612 return CMD_WARNING_CONFIG_FAILED;
6613
6614 if (no)
6615 return peer_flag_unset_vty(vty, neighbor, PEER_FLAG_AIGP);
6616 else
6617 return peer_flag_set_vty(vty, neighbor, PEER_FLAG_AIGP);
6618}
6619
d864dd9e
EB
6620static uint8_t get_role_by_name(const char *role_str)
6621{
6622 if (strncmp(role_str, "peer", 2) == 0)
6623 return ROLE_PEER;
6624 if (strncmp(role_str, "provider", 2) == 0)
6625 return ROLE_PROVIDER;
6626 if (strncmp(role_str, "customer", 2) == 0)
6627 return ROLE_CUSTOMER;
6628 if (strncmp(role_str, "rs-server", 4) == 0)
6629 return ROLE_RS_SERVER;
6630 if (strncmp(role_str, "rs-client", 4) == 0)
6631 return ROLE_RS_CLIENT;
8f2d6021 6632 return ROLE_UNDEFINED;
d864dd9e
EB
6633}
6634
6635static int peer_role_set_vty(struct vty *vty, const char *ip_str,
8f2d6021 6636 const char *role_str, bool strict_mode)
d864dd9e
EB
6637{
6638 struct peer *peer;
6639
7dddd1f7 6640 peer = peer_and_group_lookup_vty(vty, ip_str);
d864dd9e
EB
6641 if (!peer)
6642 return CMD_WARNING_CONFIG_FAILED;
6643 uint8_t role = get_role_by_name(role_str);
6644
8f2d6021 6645 if (role == ROLE_UNDEFINED)
d864dd9e
EB
6646 return bgp_vty_return(vty, BGP_ERR_INVALID_ROLE_NAME);
6647 return bgp_vty_return(vty, peer_role_set(peer, role, strict_mode));
6648}
6649
6650static int peer_role_unset_vty(struct vty *vty, const char *ip_str)
6651{
6652 struct peer *peer;
6653
7dddd1f7 6654 peer = peer_and_group_lookup_vty(vty, ip_str);
d864dd9e
EB
6655 if (!peer)
6656 return CMD_WARNING_CONFIG_FAILED;
6657 return bgp_vty_return(vty, peer_role_unset(peer));
6658}
6659
8f2d6021 6660DEFPY(neighbor_role,
d864dd9e
EB
6661 neighbor_role_cmd,
6662 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer>",
6663 NEIGHBOR_STR
6664 NEIGHBOR_ADDR_STR2
6665 "Set session role\n"
6666 ROLE_STR)
6667{
6668 int idx_peer = 1;
6669 int idx_role = 3;
6670
6671 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
8f2d6021 6672 false);
d864dd9e
EB
6673}
6674
8f2d6021 6675DEFPY(neighbor_role_strict,
d864dd9e
EB
6676 neighbor_role_strict_cmd,
6677 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> strict-mode",
6678 NEIGHBOR_STR
6679 NEIGHBOR_ADDR_STR2
6680 "Set session role\n"
6681 ROLE_STR
6682 "Use additional restriction on peer\n")
6683{
6684 int idx_peer = 1;
6685 int idx_role = 3;
6686
6687 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
8f2d6021 6688 true);
d864dd9e
EB
6689}
6690
8f2d6021 6691DEFPY(no_neighbor_role,
d864dd9e
EB
6692 no_neighbor_role_cmd,
6693 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> [strict-mode]",
6694 NO_STR
6695 NEIGHBOR_STR
6696 NEIGHBOR_ADDR_STR2
8f2d6021 6697 "Set session role\n"
d864dd9e 6698 ROLE_STR
8f2d6021 6699 "Use additional restriction on peer\n")
d864dd9e
EB
6700{
6701 int idx_peer = 2;
6702
6703 return peer_role_unset_vty(vty, argv[idx_peer]->arg);
6704}
6b0655a2 6705
6ffd2079 6706/* disable-connected-check */
28c6e247
IR
6707DEFUN (neighbor_disable_connected_check,
6708 neighbor_disable_connected_check_cmd,
6709 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6710 NEIGHBOR_STR
6711 NEIGHBOR_ADDR_STR2
6712 "one-hop away EBGP peer using loopback address\n"
6713 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6714{
d62a17ae 6715 int idx_peer = 1;
28c6e247
IR
6716 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6717 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 6718}
6719
28c6e247
IR
6720DEFUN (no_neighbor_disable_connected_check,
6721 no_neighbor_disable_connected_check_cmd,
6722 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6723 NO_STR
6724 NEIGHBOR_STR
6725 NEIGHBOR_ADDR_STR2
6726 "one-hop away EBGP peer using loopback address\n"
6727 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6728{
d62a17ae 6729 int idx_peer = 2;
28c6e247
IR
6730 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6731 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 6732}
6733
7ab294ea
DA
6734/* disable-link-bw-encoding-ieee */
6735DEFUN(neighbor_disable_link_bw_encoding_ieee,
6736 neighbor_disable_link_bw_encoding_ieee_cmd,
27aa23a4
DA
6737 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6738 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7ab294ea 6739 "Disable IEEE floating-point encoding for extended community bandwidth\n")
27aa23a4
DA
6740{
6741 int idx_peer = 1;
6742
6743 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6744 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6745}
6746
7ab294ea
DA
6747DEFUN(no_neighbor_disable_link_bw_encoding_ieee,
6748 no_neighbor_disable_link_bw_encoding_ieee_cmd,
27aa23a4
DA
6749 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6750 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7ab294ea 6751 "Disable IEEE floating-point encoding for extended community bandwidth\n")
27aa23a4
DA
6752{
6753 int idx_peer = 2;
6754
6755 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6756 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6757}
6758
d08c0c80
DA
6759/* extended-optional-parameters */
6760DEFUN(neighbor_extended_optional_parameters,
6761 neighbor_extended_optional_parameters_cmd,
6762 "neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6763 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6764 "Force the extended optional parameters format for OPEN messages\n")
6765{
6766 int idx_peer = 1;
6767
6768 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6769 PEER_FLAG_EXTENDED_OPT_PARAMS);
6770}
6771
6772DEFUN(no_neighbor_extended_optional_parameters,
6773 no_neighbor_extended_optional_parameters_cmd,
6774 "no neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6775 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6776 "Force the extended optional parameters format for OPEN messages\n")
6777{
6778 int idx_peer = 2;
6779
6780 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6781 PEER_FLAG_EXTENDED_OPT_PARAMS);
6782}
47cbc09b
PM
6783
6784/* enforce-first-as */
28c6e247
IR
6785DEFUN (neighbor_enforce_first_as,
6786 neighbor_enforce_first_as_cmd,
6787 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6788 NEIGHBOR_STR
6789 NEIGHBOR_ADDR_STR2
6790 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
6791{
6792 int idx_peer = 1;
f4b8ec07 6793
28c6e247
IR
6794 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6795 PEER_FLAG_ENFORCE_FIRST_AS);
47cbc09b
PM
6796}
6797
28c6e247
IR
6798DEFUN (no_neighbor_enforce_first_as,
6799 no_neighbor_enforce_first_as_cmd,
6800 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6801 NO_STR
6802 NEIGHBOR_STR
6803 NEIGHBOR_ADDR_STR2
6804 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
6805{
6806 int idx_peer = 2;
f4b8ec07 6807
28c6e247
IR
6808 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6809 PEER_FLAG_ENFORCE_FIRST_AS);
47cbc09b
PM
6810}
6811
6812
28c6e247
IR
6813DEFUN (neighbor_description,
6814 neighbor_description_cmd,
6815 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6816 NEIGHBOR_STR
6817 NEIGHBOR_ADDR_STR2
6818 "Neighbor specific description\n"
6819 "Up to 80 characters describing this neighbor\n")
718e3744 6820{
d62a17ae 6821 int idx_peer = 1;
6822 int idx_line = 3;
28c6e247 6823 struct peer *peer;
d62a17ae 6824 char *str;
718e3744 6825
28c6e247
IR
6826 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6827 if (!peer)
d62a17ae 6828 return CMD_WARNING_CONFIG_FAILED;
718e3744 6829
d62a17ae 6830 str = argv_concat(argv, argc, idx_line);
718e3744 6831
28c6e247 6832 peer_description_set(peer, str);
718e3744 6833
d62a17ae 6834 XFREE(MTYPE_TMP, str);
718e3744 6835
28c6e247 6836 return CMD_SUCCESS;
718e3744 6837}
6838
28c6e247
IR
6839DEFUN (no_neighbor_description,
6840 no_neighbor_description_cmd,
6841 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6842 NO_STR
6843 NEIGHBOR_STR
6844 NEIGHBOR_ADDR_STR2
6845 "Neighbor specific description\n")
718e3744 6846{
d62a17ae 6847 int idx_peer = 2;
28c6e247 6848 struct peer *peer;
f4b8ec07 6849
28c6e247
IR
6850 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6851 if (!peer)
d62a17ae 6852 return CMD_WARNING_CONFIG_FAILED;
718e3744 6853
28c6e247 6854 peer_description_unset(peer);
718e3744 6855
28c6e247 6856 return CMD_SUCCESS;
718e3744 6857}
6858
1d80f243 6859ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
a14810f4
PM
6860 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6861 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6862 "Neighbor specific description\n"
6863 "Up to 80 characters describing this neighbor\n")
6b0655a2 6864
28c6e247
IR
6865/* Neighbor update-source. */
6866static int peer_update_source_vty(struct vty *vty, const char *peer_str,
6867 const char *source_str)
6868{
6869 struct peer *peer;
6870 struct prefix p;
6871 union sockunion su;
6872
6873 peer = peer_and_group_lookup_vty(vty, peer_str);
6874 if (!peer)
6875 return CMD_WARNING_CONFIG_FAILED;
6876
6877 if (peer->conf_if)
6878 return CMD_WARNING;
6879
6880 if (source_str) {
6881 if (str2sockunion(source_str, &su) == 0)
6882 peer_update_source_addr_set(peer, &su);
6883 else {
6884 if (str2prefix(source_str, &p)) {
6885 vty_out(vty,
6886 "%% Invalid update-source, remove prefix length \n");
6887 return CMD_WARNING_CONFIG_FAILED;
6888 } else
6889 peer_update_source_if_set(peer, source_str);
6890 }
6891 } else
6892 peer_update_source_unset(peer);
6893
6894 return CMD_SUCCESS;
6895}
6896
d62a17ae 6897#define BGP_UPDATE_SOURCE_HELP_STR \
6898 "IPv4 address\n" \
6899 "IPv6 address\n" \
6900 "Interface name (requires zebra to be running)\n"
369688c0 6901
28c6e247
IR
6902DEFUN (neighbor_update_source,
6903 neighbor_update_source_cmd,
6904 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
6905 NEIGHBOR_STR
6906 NEIGHBOR_ADDR_STR2
6907 "Source of routing updates\n"
6908 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 6909{
d62a17ae 6910 int idx_peer = 1;
6911 int idx_peer_2 = 3;
28c6e247 6912 return peer_update_source_vty(vty, argv[idx_peer]->arg,
d62a17ae 6913 argv[idx_peer_2]->arg);
718e3744 6914}
6915
28c6e247
IR
6916DEFUN (no_neighbor_update_source,
6917 no_neighbor_update_source_cmd,
6918 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
6919 NO_STR
6920 NEIGHBOR_STR
6921 NEIGHBOR_ADDR_STR2
6922 "Source of routing updates\n"
6923 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 6924{
d62a17ae 6925 int idx_peer = 2;
28c6e247 6926 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 6927}
6b0655a2 6928
d62a17ae 6929static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
6930 afi_t afi, safi_t safi,
6931 const char *rmap, int set)
718e3744 6932{
d62a17ae 6933 int ret;
6934 struct peer *peer;
80912664 6935 struct route_map *route_map = NULL;
718e3744 6936
d62a17ae 6937 peer = peer_and_group_lookup_vty(vty, peer_str);
6938 if (!peer)
6939 return CMD_WARNING_CONFIG_FAILED;
718e3744 6940
1de27621 6941 if (set) {
80912664
DS
6942 if (rmap)
6943 route_map = route_map_lookup_warn_noexist(vty, rmap);
1de27621
DA
6944 ret = peer_default_originate_set(peer, afi, safi,
6945 rmap, route_map);
6946 } else
d62a17ae 6947 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 6948
d62a17ae 6949 return bgp_vty_return(vty, ret);
718e3744 6950}
6951
6952/* neighbor default-originate. */
6953DEFUN (neighbor_default_originate,
6954 neighbor_default_originate_cmd,
9ccf14f7 6955 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 6956 NEIGHBOR_STR
6957 NEIGHBOR_ADDR_STR2
6958 "Originate default route to this neighbor\n")
6959{
d62a17ae 6960 int idx_peer = 1;
6961 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6962 bgp_node_afi(vty),
6963 bgp_node_safi(vty), NULL, 1);
718e3744 6964}
6965
d62a17ae 6966ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
6967 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6968 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6969 "Originate default route to this neighbor\n")
596c17ba 6970
718e3744 6971DEFUN (neighbor_default_originate_rmap,
6972 neighbor_default_originate_rmap_cmd,
70dd370f 6973 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
718e3744 6974 NEIGHBOR_STR
6975 NEIGHBOR_ADDR_STR2
6976 "Originate default route to this neighbor\n"
6977 "Route-map to specify criteria to originate default\n"
6978 "route-map name\n")
6979{
d62a17ae 6980 int idx_peer = 1;
6981 int idx_word = 4;
6982 return peer_default_originate_set_vty(
6983 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6984 argv[idx_word]->arg, 1);
718e3744 6985}
6986
d62a17ae 6987ALIAS_HIDDEN(
6988 neighbor_default_originate_rmap,
6989 neighbor_default_originate_rmap_hidden_cmd,
70dd370f 6990 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
d62a17ae 6991 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6992 "Originate default route to this neighbor\n"
6993 "Route-map to specify criteria to originate default\n"
6994 "route-map name\n")
596c17ba 6995
718e3744 6996DEFUN (no_neighbor_default_originate,
6997 no_neighbor_default_originate_cmd,
70dd370f 6998 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
718e3744 6999 NO_STR
7000 NEIGHBOR_STR
7001 NEIGHBOR_ADDR_STR2
a636c635
DW
7002 "Originate default route to this neighbor\n"
7003 "Route-map to specify criteria to originate default\n"
7004 "route-map name\n")
718e3744 7005{
d62a17ae 7006 int idx_peer = 2;
7007 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7008 bgp_node_afi(vty),
7009 bgp_node_safi(vty), NULL, 0);
718e3744 7010}
7011
d62a17ae 7012ALIAS_HIDDEN(
7013 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
70dd370f 7014 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
d62a17ae 7015 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7016 "Originate default route to this neighbor\n"
7017 "Route-map to specify criteria to originate default\n"
7018 "route-map name\n")
596c17ba 7019
6b0655a2 7020
28c6e247
IR
7021/* Set neighbor's BGP port. */
7022static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
7023 const char *port_str)
718e3744 7024{
28c6e247
IR
7025 struct peer *peer;
7026 uint16_t port;
7027 struct servent *sp;
7028
a3aecc99 7029 peer = peer_and_group_lookup_vty(vty, ip_str);
28c6e247
IR
7030 if (!peer)
7031 return CMD_WARNING_CONFIG_FAILED;
7032
7033 if (!port_str) {
7034 sp = getservbyname("bgp", "tcp");
7035 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
7036 } else {
7037 port = strtoul(port_str, NULL, 10);
7038 }
718e3744 7039
28c6e247 7040 peer_port_set(peer, port);
718e3744 7041
28c6e247
IR
7042 return CMD_SUCCESS;
7043}
f4b8ec07 7044
28c6e247
IR
7045/* Set specified peer's BGP port. */
7046DEFUN (neighbor_port,
7047 neighbor_port_cmd,
a3aecc99 7048 "neighbor <A.B.C.D|X:X::X:X|WORD> port (0-65535)",
28c6e247 7049 NEIGHBOR_STR
a3aecc99 7050 NEIGHBOR_ADDR_STR2
28c6e247
IR
7051 "Neighbor's BGP port\n"
7052 "TCP port number\n")
7053{
7054 int idx_ip = 1;
7055 int idx_number = 3;
7056 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
7057 argv[idx_number]->arg);
f4b8ec07 7058}
6b0655a2 7059
28c6e247
IR
7060DEFUN (no_neighbor_port,
7061 no_neighbor_port_cmd,
a3aecc99 7062 "no neighbor <A.B.C.D|X:X::X:X|WORD> port [(0-65535)]",
28c6e247
IR
7063 NO_STR
7064 NEIGHBOR_STR
a3aecc99 7065 NEIGHBOR_ADDR_STR2
28c6e247
IR
7066 "Neighbor's BGP port\n"
7067 "TCP port number\n")
718e3744 7068{
f4b8ec07 7069 int idx_ip = 2;
28c6e247
IR
7070 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
7071}
7072
7073
7074/* neighbor weight. */
7075static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7076 safi_t safi, const char *weight_str)
7077{
7078 int ret;
7079 struct peer *peer;
7080 unsigned long weight;
718e3744 7081
28c6e247
IR
7082 peer = peer_and_group_lookup_vty(vty, ip_str);
7083 if (!peer)
7084 return CMD_WARNING_CONFIG_FAILED;
718e3744 7085
28c6e247 7086 weight = strtoul(weight_str, NULL, 10);
718e3744 7087
28c6e247
IR
7088 ret = peer_weight_set(peer, afi, safi, weight);
7089 return bgp_vty_return(vty, ret);
718e3744 7090}
7091
28c6e247
IR
7092static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7093 safi_t safi)
718e3744 7094{
28c6e247
IR
7095 int ret;
7096 struct peer *peer;
f4b8ec07 7097
28c6e247
IR
7098 peer = peer_and_group_lookup_vty(vty, ip_str);
7099 if (!peer)
d62a17ae 7100 return CMD_WARNING_CONFIG_FAILED;
718e3744 7101
28c6e247
IR
7102 ret = peer_weight_unset(peer, afi, safi);
7103 return bgp_vty_return(vty, ret);
7104}
f4b8ec07 7105
28c6e247
IR
7106DEFUN (neighbor_weight,
7107 neighbor_weight_cmd,
7108 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7109 NEIGHBOR_STR
7110 NEIGHBOR_ADDR_STR2
7111 "Set default weight for routes from this neighbor\n"
7112 "default weight\n")
7113{
7114 int idx_peer = 1;
7115 int idx_number = 3;
7116 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7117 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 7118}
7119
d62a17ae 7120ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
7121 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7122 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7123 "Set default weight for routes from this neighbor\n"
7124 "default weight\n")
596c17ba 7125
28c6e247
IR
7126DEFUN (no_neighbor_weight,
7127 no_neighbor_weight_cmd,
7128 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7129 NO_STR
7130 NEIGHBOR_STR
7131 NEIGHBOR_ADDR_STR2
7132 "Set default weight for routes from this neighbor\n"
7133 "default weight\n")
718e3744 7134{
d62a17ae 7135 int idx_peer = 2;
28c6e247
IR
7136 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
7137 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 7138}
7139
d62a17ae 7140ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
7141 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7142 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7143 "Set default weight for routes from this neighbor\n"
7144 "default weight\n")
596c17ba 7145
6b0655a2 7146
718e3744 7147/* Override capability negotiation. */
c36bc05f
IR
7148DEFUN (neighbor_override_capability,
7149 neighbor_override_capability_cmd,
7150 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7151 NEIGHBOR_STR
7152 NEIGHBOR_ADDR_STR2
7153 "Override capability negotiation result\n")
718e3744 7154{
d62a17ae 7155 int idx_peer = 1;
c36bc05f
IR
7156 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7157 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 7158}
7159
c36bc05f
IR
7160DEFUN (no_neighbor_override_capability,
7161 no_neighbor_override_capability_cmd,
7162 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7163 NO_STR
7164 NEIGHBOR_STR
7165 NEIGHBOR_ADDR_STR2
7166 "Override capability negotiation result\n")
718e3744 7167{
d62a17ae 7168 int idx_peer = 2;
c36bc05f
IR
7169 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7170 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 7171}
6b0655a2 7172
c36bc05f
IR
7173DEFUN (neighbor_strict_capability,
7174 neighbor_strict_capability_cmd,
7175 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7176 NEIGHBOR_STR
7177 NEIGHBOR_ADDR_STR2
7178 "Strict capability negotiation match\n")
718e3744 7179{
9fb964de
PM
7180 int idx_peer = 1;
7181
c36bc05f
IR
7182 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7183 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 7184}
7185
c36bc05f
IR
7186DEFUN (no_neighbor_strict_capability,
7187 no_neighbor_strict_capability_cmd,
7188 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7189 NO_STR
7190 NEIGHBOR_STR
7191 NEIGHBOR_ADDR_STR2
7192 "Strict capability negotiation match\n")
718e3744 7193{
9fb964de 7194 int idx_peer = 2;
8611c7f3 7195
c36bc05f
IR
7196 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7197 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 7198}
6b0655a2 7199
28c6e247
IR
7200static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
7201 const char *keep_str, const char *hold_str)
718e3744 7202{
28c6e247
IR
7203 int ret;
7204 struct peer *peer;
7205 uint32_t keepalive;
7206 uint32_t holdtime;
718e3744 7207
28c6e247
IR
7208 peer = peer_and_group_lookup_vty(vty, ip_str);
7209 if (!peer)
d62a17ae 7210 return CMD_WARNING_CONFIG_FAILED;
718e3744 7211
28c6e247
IR
7212 keepalive = strtoul(keep_str, NULL, 10);
7213 holdtime = strtoul(hold_str, NULL, 10);
718e3744 7214
28c6e247 7215 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 7216
28c6e247 7217 return bgp_vty_return(vty, ret);
718e3744 7218}
6b0655a2 7219
28c6e247 7220static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 7221{
28c6e247
IR
7222 int ret;
7223 struct peer *peer;
718e3744 7224
28c6e247
IR
7225 peer = peer_and_group_lookup_vty(vty, ip_str);
7226 if (!peer)
d62a17ae 7227 return CMD_WARNING_CONFIG_FAILED;
718e3744 7228
28c6e247 7229 ret = peer_timers_unset(peer);
718e3744 7230
28c6e247 7231 return bgp_vty_return(vty, ret);
718e3744 7232}
6b0655a2 7233
28c6e247
IR
7234DEFUN (neighbor_timers,
7235 neighbor_timers_cmd,
7236 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
7237 NEIGHBOR_STR
7238 NEIGHBOR_ADDR_STR2
7239 "BGP per neighbor timers\n"
7240 "Keepalive interval\n"
7241 "Holdtime\n")
718e3744 7242{
f4b8ec07 7243 int idx_peer = 1;
28c6e247
IR
7244 int idx_number = 3;
7245 int idx_number_2 = 4;
7246 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
7247 argv[idx_number]->arg,
7248 argv[idx_number_2]->arg);
7249}
7250
7251DEFUN (no_neighbor_timers,
7252 no_neighbor_timers_cmd,
7253 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
7254 NO_STR
7255 NEIGHBOR_STR
7256 NEIGHBOR_ADDR_STR2
7257 "BGP per neighbor timers\n"
7258 "Keepalive interval\n"
7259 "Holdtime\n")
7260{
7261 int idx_peer = 2;
7262 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
7263}
7264
7265
7266static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
7267 const char *time_str)
7268{
7269 int ret;
7270 struct peer *peer;
7271 uint32_t connect;
718e3744 7272
28c6e247
IR
7273 peer = peer_and_group_lookup_vty(vty, ip_str);
7274 if (!peer)
d62a17ae 7275 return CMD_WARNING_CONFIG_FAILED;
718e3744 7276
28c6e247
IR
7277 connect = strtoul(time_str, NULL, 10);
7278
7279 ret = peer_timers_connect_set(peer, connect);
718e3744 7280
28c6e247 7281 return bgp_vty_return(vty, ret);
718e3744 7282}
7283
28c6e247 7284static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 7285{
28c6e247
IR
7286 int ret;
7287 struct peer *peer;
718e3744 7288
28c6e247
IR
7289 peer = peer_and_group_lookup_vty(vty, ip_str);
7290 if (!peer)
d62a17ae 7291 return CMD_WARNING_CONFIG_FAILED;
718e3744 7292
28c6e247
IR
7293 ret = peer_timers_connect_unset(peer);
7294
7295 return bgp_vty_return(vty, ret);
7296}
7297
7298DEFUN (neighbor_timers_connect,
7299 neighbor_timers_connect_cmd,
7300 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7301 NEIGHBOR_STR
7302 NEIGHBOR_ADDR_STR2
7303 "BGP per neighbor timers\n"
7304 "BGP connect timer\n"
7305 "Connect timer\n")
7306{
7307 int idx_peer = 1;
7308 int idx_number = 4;
7309 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
7310 argv[idx_number]->arg);
7311}
718e3744 7312
28c6e247
IR
7313DEFUN (no_neighbor_timers_connect,
7314 no_neighbor_timers_connect_cmd,
7315 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7316 NO_STR
7317 NEIGHBOR_STR
7318 NEIGHBOR_ADDR_STR2
7319 "BGP per neighbor timers\n"
7320 "BGP connect timer\n"
7321 "Connect timer\n")
7322{
7323 int idx_peer = 2;
7324 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 7325}
7326
d43114f3
DS
7327DEFPY (neighbor_timers_delayopen,
7328 neighbor_timers_delayopen_cmd,
7329 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
7330 NEIGHBOR_STR
7331 NEIGHBOR_ADDR_STR2
7332 "BGP per neighbor timers\n"
7333 "RFC 4271 DelayOpenTimer\n"
7334 "DelayOpenTime timer interval\n")
7335{
7336 struct peer *peer;
7337
7338 peer = peer_and_group_lookup_vty(vty, neighbor);
7339 if (!peer)
7340 return CMD_WARNING_CONFIG_FAILED;
7341
7342 if (!interval) {
7343 if (peer_timers_delayopen_unset(peer))
7344 return CMD_WARNING_CONFIG_FAILED;
7345 } else {
7346 if (peer_timers_delayopen_set(peer, interval))
7347 return CMD_WARNING_CONFIG_FAILED;
7348 }
7349
7350 return CMD_SUCCESS;
7351}
7352
7353DEFPY (no_neighbor_timers_delayopen,
7354 no_neighbor_timers_delayopen_cmd,
7355 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7356 NO_STR
7357 NEIGHBOR_STR
7358 NEIGHBOR_ADDR_STR2
7359 "BGP per neighbor timers\n"
7360 "RFC 4271 DelayOpenTimer\n"
7361 "DelayOpenTime timer interval\n")
7362{
7363 struct peer *peer;
7364
7365 peer = peer_and_group_lookup_vty(vty, neighbor);
7366 if (!peer)
7367 return CMD_WARNING_CONFIG_FAILED;
7368
7369 if (peer_timers_delayopen_unset(peer))
7370 return CMD_WARNING_CONFIG_FAILED;
7371
7372 return CMD_SUCCESS;
7373}
7374
28c6e247
IR
7375static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
7376 const char *time_str, int set)
718e3744 7377{
28c6e247
IR
7378 int ret;
7379 struct peer *peer;
7380 uint32_t routeadv = 0;
718e3744 7381
28c6e247
IR
7382 peer = peer_and_group_lookup_vty(vty, ip_str);
7383 if (!peer)
d62a17ae 7384 return CMD_WARNING_CONFIG_FAILED;
718e3744 7385
28c6e247
IR
7386 if (time_str)
7387 routeadv = strtoul(time_str, NULL, 10);
7388
7389 if (set)
7390 ret = peer_advertise_interval_set(peer, routeadv);
7391 else
7392 ret = peer_advertise_interval_unset(peer);
718e3744 7393
28c6e247 7394 return bgp_vty_return(vty, ret);
718e3744 7395}
7396
28c6e247
IR
7397DEFUN (neighbor_advertise_interval,
7398 neighbor_advertise_interval_cmd,
7399 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7400 NEIGHBOR_STR
7401 NEIGHBOR_ADDR_STR2
7402 "Minimum interval between sending BGP routing updates\n"
7403 "time in seconds\n")
718e3744 7404{
28c6e247
IR
7405 int idx_peer = 1;
7406 int idx_number = 3;
7407 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
7408 argv[idx_number]->arg, 1);
7409}
f4b8ec07 7410
28c6e247
IR
7411DEFUN (no_neighbor_advertise_interval,
7412 no_neighbor_advertise_interval_cmd,
7413 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7414 NO_STR
7415 NEIGHBOR_STR
7416 NEIGHBOR_ADDR_STR2
7417 "Minimum interval between sending BGP routing updates\n"
7418 "time in seconds\n")
7419{
7420 int idx_peer = 2;
7421 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 7422}
7423
6b0655a2 7424
518f0eb1
DS
7425/* Time to wait before processing route-map updates */
7426DEFUN (bgp_set_route_map_delay_timer,
7427 bgp_set_route_map_delay_timer_cmd,
6147e2c6 7428 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
7429 SET_STR
7430 "BGP route-map delay timer\n"
7431 "Time in secs to wait before processing route-map changes\n"
f414725f 7432 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 7433{
d62a17ae 7434 int idx_number = 3;
d7c0a89a 7435 uint32_t rmap_delay_timer;
d62a17ae 7436
7437 if (argv[idx_number]->arg) {
7438 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7439 bm->rmap_update_timer = rmap_delay_timer;
7440
7441 /* if the dynamic update handling is being disabled, and a timer
7442 * is
7443 * running, stop the timer and act as if the timer has already
7444 * fired.
7445 */
7446 if (!rmap_delay_timer && bm->t_rmap_update) {
fa5806c3 7447 THREAD_OFF(bm->t_rmap_update);
d62a17ae 7448 thread_execute(bm->master, bgp_route_map_update_timer,
7449 NULL, 0);
7450 }
7451 return CMD_SUCCESS;
7452 } else {
7453 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7454 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 7455 }
518f0eb1
DS
7456}
7457
7458DEFUN (no_bgp_set_route_map_delay_timer,
7459 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 7460 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 7461 NO_STR
3a2d747c 7462 BGP_STR
518f0eb1 7463 "Default BGP route-map delay timer\n"
8334fd5a
DW
7464 "Reset to default time to wait for processing route-map changes\n"
7465 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 7466{
518f0eb1 7467
d62a17ae 7468 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 7469
d62a17ae 7470 return CMD_SUCCESS;
518f0eb1
DS
7471}
7472
28c6e247
IR
7473/* neighbor interface */
7474static int peer_interface_vty(struct vty *vty, const char *ip_str,
7475 const char *str)
718e3744 7476{
28c6e247 7477 struct peer *peer;
718e3744 7478
28c6e247
IR
7479 peer = peer_lookup_vty(vty, ip_str);
7480 if (!peer || peer->conf_if) {
7481 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
7482 return CMD_WARNING_CONFIG_FAILED;
7483 }
718e3744 7484
28c6e247
IR
7485 if (str)
7486 peer_interface_set(peer, str);
7487 else
7488 peer_interface_unset(peer);
718e3744 7489
28c6e247 7490 return CMD_SUCCESS;
718e3744 7491}
7492
28c6e247
IR
7493DEFUN (neighbor_interface,
7494 neighbor_interface_cmd,
7495 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7496 NEIGHBOR_STR
7497 NEIGHBOR_ADDR_STR
7498 "Interface\n"
7499 "Interface name\n")
718e3744 7500{
28c6e247
IR
7501 int idx_ip = 1;
7502 int idx_word = 3;
294d8425 7503
28c6e247
IR
7504 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
7505}
f4b8ec07 7506
28c6e247
IR
7507DEFUN (no_neighbor_interface,
7508 no_neighbor_interface_cmd,
294d8425 7509 "no neighbor <A.B.C.D|X:X::X:X> interface WORD",
28c6e247
IR
7510 NO_STR
7511 NEIGHBOR_STR
294d8425 7512 NEIGHBOR_ADDR_STR
28c6e247
IR
7513 "Interface\n"
7514 "Interface name\n")
7515{
7516 int idx_peer = 2;
294d8425 7517
28c6e247 7518 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 7519}
6b0655a2 7520
718e3744 7521DEFUN (neighbor_distribute_list,
7522 neighbor_distribute_list_cmd,
c60dec36 7523 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
718e3744 7524 NEIGHBOR_STR
7525 NEIGHBOR_ADDR_STR2
7526 "Filter updates to/from this neighbor\n"
718e3744 7527 "IP Access-list name\n"
7528 "Filter incoming updates\n"
7529 "Filter outgoing updates\n")
7530{
d62a17ae 7531 int idx_peer = 1;
7532 int idx_acl = 3;
7533 int direct, ret;
7534 struct peer *peer;
a8206004 7535
d62a17ae 7536 const char *pstr = argv[idx_peer]->arg;
7537 const char *acl = argv[idx_acl]->arg;
7538 const char *inout = argv[argc - 1]->text;
a8206004 7539
d62a17ae 7540 peer = peer_and_group_lookup_vty(vty, pstr);
7541 if (!peer)
7542 return CMD_WARNING_CONFIG_FAILED;
a8206004 7543
d62a17ae 7544 /* Check filter direction. */
7545 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7546 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7547 direct, acl);
a8206004 7548
d62a17ae 7549 return bgp_vty_return(vty, ret);
718e3744 7550}
7551
d62a17ae 7552ALIAS_HIDDEN(
7553 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
c60dec36 7554 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
d62a17ae 7555 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7556 "Filter updates to/from this neighbor\n"
d62a17ae 7557 "IP Access-list name\n"
7558 "Filter incoming updates\n"
7559 "Filter outgoing updates\n")
596c17ba 7560
718e3744 7561DEFUN (no_neighbor_distribute_list,
7562 no_neighbor_distribute_list_cmd,
c60dec36 7563 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
718e3744 7564 NO_STR
7565 NEIGHBOR_STR
7566 NEIGHBOR_ADDR_STR2
7567 "Filter updates to/from this neighbor\n"
718e3744 7568 "IP Access-list name\n"
7569 "Filter incoming updates\n"
7570 "Filter outgoing updates\n")
7571{
d62a17ae 7572 int idx_peer = 2;
7573 int direct, ret;
7574 struct peer *peer;
a8206004 7575
d62a17ae 7576 const char *pstr = argv[idx_peer]->arg;
7577 const char *inout = argv[argc - 1]->text;
a8206004 7578
d62a17ae 7579 peer = peer_and_group_lookup_vty(vty, pstr);
7580 if (!peer)
7581 return CMD_WARNING_CONFIG_FAILED;
a8206004 7582
d62a17ae 7583 /* Check filter direction. */
7584 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7585 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7586 direct);
a8206004 7587
d62a17ae 7588 return bgp_vty_return(vty, ret);
718e3744 7589}
6b0655a2 7590
d62a17ae 7591ALIAS_HIDDEN(
7592 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
c60dec36 7593 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
d62a17ae 7594 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7595 "Filter updates to/from this neighbor\n"
d62a17ae 7596 "IP Access-list name\n"
7597 "Filter incoming updates\n"
7598 "Filter outgoing updates\n")
596c17ba 7599
718e3744 7600/* Set prefix list to the peer. */
642ef664
IR
7601static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
7602 afi_t afi, safi_t safi,
7603 const char *name_str,
7604 const char *direct_str)
718e3744 7605{
642ef664
IR
7606 int ret;
7607 int direct = FILTER_IN;
7608 struct peer *peer;
718e3744 7609
642ef664
IR
7610 peer = peer_and_group_lookup_vty(vty, ip_str);
7611 if (!peer)
d62a17ae 7612 return CMD_WARNING_CONFIG_FAILED;
e52702f2 7613
642ef664
IR
7614 /* Check filter direction. */
7615 if (strncmp(direct_str, "i", 1) == 0)
7616 direct = FILTER_IN;
7617 else if (strncmp(direct_str, "o", 1) == 0)
7618 direct = FILTER_OUT;
718e3744 7619
642ef664 7620 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 7621
642ef664
IR
7622 return bgp_vty_return(vty, ret);
7623}
7624
7625static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
7626 afi_t afi, safi_t safi,
7627 const char *direct_str)
7628{
7629 int ret;
7630 struct peer *peer;
7631 int direct = FILTER_IN;
7632
7633 peer = peer_and_group_lookup_vty(vty, ip_str);
7634 if (!peer)
7635 return CMD_WARNING_CONFIG_FAILED;
7636
7637 /* Check filter direction. */
7638 if (strncmp(direct_str, "i", 1) == 0)
7639 direct = FILTER_IN;
7640 else if (strncmp(direct_str, "o", 1) == 0)
7641 direct = FILTER_OUT;
7642
7643 ret = peer_prefix_list_unset(peer, afi, safi, direct);
7644
7645 return bgp_vty_return(vty, ret);
7646}
7647
7648DEFUN (neighbor_prefix_list,
7649 neighbor_prefix_list_cmd,
7650 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7651 NEIGHBOR_STR
7652 NEIGHBOR_ADDR_STR2
7653 "Filter updates to/from this neighbor\n"
7654 "Name of a prefix list\n"
7655 "Filter incoming updates\n"
7656 "Filter outgoing updates\n")
7657{
7658 int idx_peer = 1;
7659 int idx_word = 3;
7660 int idx_in_out = 4;
7661 return peer_prefix_list_set_vty(
7662 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7663 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 7664}
7665
d62a17ae 7666ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7667 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7668 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7669 "Filter updates to/from this neighbor\n"
7670 "Name of a prefix list\n"
7671 "Filter incoming updates\n"
7672 "Filter outgoing updates\n")
596c17ba 7673
642ef664
IR
7674DEFUN (no_neighbor_prefix_list,
7675 no_neighbor_prefix_list_cmd,
7676 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7677 NO_STR
7678 NEIGHBOR_STR
7679 NEIGHBOR_ADDR_STR2
7680 "Filter updates to/from this neighbor\n"
7681 "Name of a prefix list\n"
7682 "Filter incoming updates\n"
7683 "Filter outgoing updates\n")
7684{
7685 int idx_peer = 2;
7686 int idx_in_out = 5;
7687 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7688 bgp_node_afi(vty), bgp_node_safi(vty),
7689 argv[idx_in_out]->arg);
7690}
7691
7692ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7693 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7694 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7695 "Filter updates to/from this neighbor\n"
7696 "Name of a prefix list\n"
7697 "Filter incoming updates\n"
7698 "Filter outgoing updates\n")
7699
d62a17ae 7700static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7701 safi_t safi, const char *name_str,
7702 const char *direct_str)
718e3744 7703{
d62a17ae 7704 int ret;
7705 struct peer *peer;
7706 int direct = FILTER_IN;
718e3744 7707
d62a17ae 7708 peer = peer_and_group_lookup_vty(vty, ip_str);
7709 if (!peer)
7710 return CMD_WARNING_CONFIG_FAILED;
718e3744 7711
d62a17ae 7712 /* Check filter direction. */
7713 if (strncmp(direct_str, "i", 1) == 0)
7714 direct = FILTER_IN;
7715 else if (strncmp(direct_str, "o", 1) == 0)
7716 direct = FILTER_OUT;
718e3744 7717
d62a17ae 7718 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 7719
d62a17ae 7720 return bgp_vty_return(vty, ret);
718e3744 7721}
7722
d62a17ae 7723static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7724 safi_t safi, const char *direct_str)
718e3744 7725{
d62a17ae 7726 int ret;
7727 struct peer *peer;
7728 int direct = FILTER_IN;
718e3744 7729
d62a17ae 7730 peer = peer_and_group_lookup_vty(vty, ip_str);
7731 if (!peer)
7732 return CMD_WARNING_CONFIG_FAILED;
718e3744 7733
d62a17ae 7734 /* Check filter direction. */
7735 if (strncmp(direct_str, "i", 1) == 0)
7736 direct = FILTER_IN;
7737 else if (strncmp(direct_str, "o", 1) == 0)
7738 direct = FILTER_OUT;
718e3744 7739
d62a17ae 7740 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 7741
d62a17ae 7742 return bgp_vty_return(vty, ret);
718e3744 7743}
7744
7745DEFUN (neighbor_filter_list,
7746 neighbor_filter_list_cmd,
de71d43e 7747 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
718e3744 7748 NEIGHBOR_STR
7749 NEIGHBOR_ADDR_STR2
7750 "Establish BGP filters\n"
7751 "AS path access-list name\n"
7752 "Filter incoming routes\n"
7753 "Filter outgoing routes\n")
7754{
d62a17ae 7755 int idx_peer = 1;
7756 int idx_word = 3;
7757 int idx_in_out = 4;
7758 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7759 bgp_node_safi(vty), argv[idx_word]->arg,
7760 argv[idx_in_out]->arg);
718e3744 7761}
7762
d62a17ae 7763ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
de71d43e 7764 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
d62a17ae 7765 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7766 "Establish BGP filters\n"
7767 "AS path access-list name\n"
7768 "Filter incoming routes\n"
7769 "Filter outgoing routes\n")
596c17ba 7770
718e3744 7771DEFUN (no_neighbor_filter_list,
7772 no_neighbor_filter_list_cmd,
de71d43e 7773 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
718e3744 7774 NO_STR
7775 NEIGHBOR_STR
7776 NEIGHBOR_ADDR_STR2
7777 "Establish BGP filters\n"
7778 "AS path access-list name\n"
7779 "Filter incoming routes\n"
7780 "Filter outgoing routes\n")
7781{
d62a17ae 7782 int idx_peer = 2;
7783 int idx_in_out = 5;
7784 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7785 bgp_node_afi(vty), bgp_node_safi(vty),
7786 argv[idx_in_out]->arg);
718e3744 7787}
6b0655a2 7788
d62a17ae 7789ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
de71d43e 7790 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
d62a17ae 7791 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7792 "Establish BGP filters\n"
7793 "AS path access-list name\n"
7794 "Filter incoming routes\n"
7795 "Filter outgoing routes\n")
596c17ba 7796
7f7940e6
MK
7797/* Set advertise-map to the peer. */
7798static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7799 afi_t afi, safi_t safi,
cf2ad4d8
MK
7800 const char *advertise_str,
7801 const char *condition_str, bool condition,
7802 bool set)
7f7940e6
MK
7803{
7804 int ret = CMD_WARNING_CONFIG_FAILED;
7805 struct peer *peer;
7806 struct route_map *advertise_map;
7807 struct route_map *condition_map;
7808
7809 peer = peer_and_group_lookup_vty(vty, ip_str);
7810 if (!peer)
7811 return ret;
7812
7813 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7814 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7815
cf2ad4d8
MK
7816 if (set)
7817 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7818 advertise_map, condition_str,
7819 condition_map, condition);
7820 else
7821 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7822 advertise_map, condition_str,
7823 condition_map, condition);
7f7940e6
MK
7824
7825 return bgp_vty_return(vty, ret);
7826}
7827
389e4f92
QY
7828DEFPY (bgp_condadv_period,
7829 bgp_condadv_period_cmd,
7830 "[no$no] bgp conditional-advertisement timer (5-240)$period",
7831 NO_STR
7832 BGP_STR
7833 "Conditional advertisement settings\n"
7834 "Set period to rescan BGP table to check if condition is met\n"
7835 "Period between BGP table scans, in seconds; default 60\n")
7836{
7837 VTY_DECLVAR_CONTEXT(bgp, bgp);
7838
7839 bgp->condition_check_period =
7840 no ? DEFAULT_CONDITIONAL_ROUTES_POLL_TIME : period;
7841
7842 return CMD_SUCCESS;
7843}
7844
cf2ad4d8 7845DEFPY (neighbor_advertise_map,
7f7940e6 7846 neighbor_advertise_map_cmd,
3ccddc25 7847 "[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 7848 NO_STR
7f7940e6
MK
7849 NEIGHBOR_STR
7850 NEIGHBOR_ADDR_STR2
7851 "Route-map to conditionally advertise routes\n"
7852 "Name of advertise map\n"
7853 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 7854 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 7855 "Name of the exist or non exist map\n")
7f7940e6 7856{
7f7940e6
MK
7857 bool condition = CONDITION_EXIST;
7858
52b84062 7859 if (!strcmp(exist, "non-exist-map"))
7f7940e6
MK
7860 condition = CONDITION_NON_EXIST;
7861
52b84062
MK
7862 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7863 bgp_node_safi(vty), advertise_str,
7864 condition_str, condition, !no);
7f7940e6
MK
7865}
7866
7867ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
3ccddc25 7868 "[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
7869 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7870 "Route-map to conditionally advertise routes\n"
7871 "Name of advertise map\n"
7872 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 7873 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 7874 "Name of the exist or non exist map\n")
7f7940e6 7875
718e3744 7876/* Set route-map to the peer. */
0ea8d871
IR
7877static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7878 afi_t afi, safi_t safi, const char *name_str,
7879 const char *direct_str)
718e3744 7880{
0ea8d871
IR
7881 int ret;
7882 struct peer *peer;
7883 int direct = RMAP_IN;
7884 struct route_map *route_map;
718e3744 7885
0ea8d871
IR
7886 peer = peer_and_group_lookup_vty(vty, ip_str);
7887 if (!peer)
d62a17ae 7888 return CMD_WARNING_CONFIG_FAILED;
718e3744 7889
0ea8d871
IR
7890 /* Check filter direction. */
7891 if (strncmp(direct_str, "in", 2) == 0)
7892 direct = RMAP_IN;
7893 else if (strncmp(direct_str, "o", 1) == 0)
7894 direct = RMAP_OUT;
718e3744 7895
0ea8d871
IR
7896 route_map = route_map_lookup_warn_noexist(vty, name_str);
7897 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
718e3744 7898
0ea8d871
IR
7899 return bgp_vty_return(vty, ret);
7900}
7901
7902static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7903 afi_t afi, safi_t safi,
7904 const char *direct_str)
7905{
7906 int ret;
7907 struct peer *peer;
7908 int direct = RMAP_IN;
7909
7910 peer = peer_and_group_lookup_vty(vty, ip_str);
7911 if (!peer)
7912 return CMD_WARNING_CONFIG_FAILED;
7913
7914 /* Check filter direction. */
7915 if (strncmp(direct_str, "in", 2) == 0)
7916 direct = RMAP_IN;
7917 else if (strncmp(direct_str, "o", 1) == 0)
7918 direct = RMAP_OUT;
7919
7920 ret = peer_route_map_unset(peer, afi, safi, direct);
7921
7922 return bgp_vty_return(vty, ret);
7923}
7924
7925DEFUN (neighbor_route_map,
7926 neighbor_route_map_cmd,
70dd370f 7927 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
0ea8d871
IR
7928 NEIGHBOR_STR
7929 NEIGHBOR_ADDR_STR2
7930 "Apply route map to neighbor\n"
7931 "Name of route map\n"
7932 "Apply map to incoming routes\n"
7933 "Apply map to outbound routes\n")
7934{
7935 int idx_peer = 1;
7936 int idx_word = 3;
7937 int idx_in_out = 4;
7938 return peer_route_map_set_vty(
7939 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7940 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 7941}
7942
d6d7ed37 7943ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
70dd370f 7944 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
d6d7ed37
IR
7945 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7946 "Apply route map to neighbor\n"
7947 "Name of route map\n"
7948 "Apply map to incoming routes\n"
7949 "Apply map to outbound routes\n")
7950
0ea8d871
IR
7951DEFUN (no_neighbor_route_map,
7952 no_neighbor_route_map_cmd,
70dd370f 7953 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
0ea8d871
IR
7954 NO_STR
7955 NEIGHBOR_STR
7956 NEIGHBOR_ADDR_STR2
7957 "Apply route map to neighbor\n"
7958 "Name of route map\n"
7959 "Apply map to incoming routes\n"
7960 "Apply map to outbound routes\n")
7961{
7962 int idx_peer = 2;
7963 int idx_in_out = 5;
7964 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
7965 bgp_node_afi(vty), bgp_node_safi(vty),
7966 argv[idx_in_out]->arg);
7967}
7968
7969ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
70dd370f 7970 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
d6d7ed37
IR
7971 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7972 "Apply route map to neighbor\n"
7973 "Name of route map\n"
7974 "Apply map to incoming routes\n"
7975 "Apply map to outbound routes\n")
7976
718e3744 7977/* Set unsuppress-map to the peer. */
d62a17ae 7978static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
7979 afi_t afi, safi_t safi,
7980 const char *name_str)
718e3744 7981{
d62a17ae 7982 int ret;
7983 struct peer *peer;
1de27621 7984 struct route_map *route_map;
718e3744 7985
d62a17ae 7986 peer = peer_and_group_lookup_vty(vty, ip_str);
7987 if (!peer)
7988 return CMD_WARNING_CONFIG_FAILED;
718e3744 7989
1de27621
DA
7990 route_map = route_map_lookup_warn_noexist(vty, name_str);
7991 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
718e3744 7992
d62a17ae 7993 return bgp_vty_return(vty, ret);
718e3744 7994}
7995
7996/* Unset route-map from the peer. */
d62a17ae 7997static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
7998 afi_t afi, safi_t safi)
718e3744 7999{
d62a17ae 8000 int ret;
8001 struct peer *peer;
718e3744 8002
d62a17ae 8003 peer = peer_and_group_lookup_vty(vty, ip_str);
8004 if (!peer)
8005 return CMD_WARNING_CONFIG_FAILED;
718e3744 8006
d62a17ae 8007 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 8008
d62a17ae 8009 return bgp_vty_return(vty, ret);
718e3744 8010}
8011
8012DEFUN (neighbor_unsuppress_map,
8013 neighbor_unsuppress_map_cmd,
9ccf14f7 8014 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 8015 NEIGHBOR_STR
8016 NEIGHBOR_ADDR_STR2
8017 "Route-map to selectively unsuppress suppressed routes\n"
8018 "Name of route map\n")
8019{
d62a17ae 8020 int idx_peer = 1;
8021 int idx_word = 3;
8022 return peer_unsuppress_map_set_vty(
8023 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8024 argv[idx_word]->arg);
718e3744 8025}
8026
d62a17ae 8027ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
8028 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8029 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8030 "Route-map to selectively unsuppress suppressed routes\n"
8031 "Name of route map\n")
596c17ba 8032
718e3744 8033DEFUN (no_neighbor_unsuppress_map,
8034 no_neighbor_unsuppress_map_cmd,
9ccf14f7 8035 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 8036 NO_STR
8037 NEIGHBOR_STR
8038 NEIGHBOR_ADDR_STR2
8039 "Route-map to selectively unsuppress suppressed routes\n"
8040 "Name of route map\n")
8041{
d62a17ae 8042 int idx_peer = 2;
8043 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
8044 bgp_node_afi(vty),
8045 bgp_node_safi(vty));
718e3744 8046}
6b0655a2 8047
d62a17ae 8048ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
8049 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8050 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8051 "Route-map to selectively unsuppress suppressed routes\n"
8052 "Name of route map\n")
596c17ba 8053
7e62b792
IR
8054static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
8055 afi_t afi, safi_t safi,
8056 const char *num_str,
8057 const char *threshold_str, int warning,
8058 const char *restart_str,
8059 const char *force_str)
8060{
8061 int ret;
8062 struct peer *peer;
8063 uint32_t max;
8064 uint8_t threshold;
8065 uint16_t restart;
8066
8067 peer = peer_and_group_lookup_vty(vty, ip_str);
8068 if (!peer)
8069 return CMD_WARNING_CONFIG_FAILED;
8070
8071 max = strtoul(num_str, NULL, 10);
8072 if (threshold_str)
8073 threshold = atoi(threshold_str);
8074 else
8075 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
8076
8077 if (restart_str)
8078 restart = atoi(restart_str);
8079 else
8080 restart = 0;
8081
8082 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
8083 restart, force_str ? true : false);
8084
8085 return bgp_vty_return(vty, ret);
8086}
8087
8088static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
8089 afi_t afi, safi_t safi)
8090{
8091 int ret;
8092 struct peer *peer;
8093
8094 peer = peer_and_group_lookup_vty(vty, ip_str);
8095 if (!peer)
8096 return CMD_WARNING_CONFIG_FAILED;
8097
8098 ret = peer_maximum_prefix_unset(peer, afi, safi);
8099
8100 return bgp_vty_return(vty, ret);
8101}
8102
fde246e8 8103/* Maximum number of prefix to be sent to the neighbor. */
1d80f243
IR
8104DEFUN(neighbor_maximum_prefix_out,
8105 neighbor_maximum_prefix_out_cmd,
8106 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
8107 NEIGHBOR_STR
8108 NEIGHBOR_ADDR_STR2
8109 "Maximum number of prefixes to be sent to this peer\n"
8110 "Maximum no. of prefix limit\n")
fde246e8 8111{
80444d30 8112 int ret;
fde246e8
DA
8113 int idx_peer = 1;
8114 int idx_number = 3;
7e62b792
IR
8115 struct peer *peer;
8116 uint32_t max;
fde246e8
DA
8117 afi_t afi = bgp_node_afi(vty);
8118 safi_t safi = bgp_node_safi(vty);
8119
7e62b792
IR
8120 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8121 if (!peer)
fde246e8
DA
8122 return CMD_WARNING_CONFIG_FAILED;
8123
7e62b792 8124 max = strtoul(argv[idx_number]->arg, NULL, 10);
fde246e8 8125
80444d30 8126 ret = peer_maximum_prefix_out_set(peer, afi, safi, max);
fde246e8 8127
80444d30 8128 return bgp_vty_return(vty, ret);
fde246e8
DA
8129}
8130
1d80f243
IR
8131DEFUN(no_neighbor_maximum_prefix_out,
8132 no_neighbor_maximum_prefix_out_cmd,
bc03c622 8133 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out [(1-4294967295)]",
1d80f243
IR
8134 NO_STR
8135 NEIGHBOR_STR
8136 NEIGHBOR_ADDR_STR2
bc03c622
LS
8137 "Maximum number of prefixes to be sent to this peer\n"
8138 "Maximum no. of prefix limit\n")
fde246e8 8139{
80444d30 8140 int ret;
fde246e8 8141 int idx_peer = 2;
7e62b792 8142 struct peer *peer;
fde246e8
DA
8143 afi_t afi = bgp_node_afi(vty);
8144 safi_t safi = bgp_node_safi(vty);
8145
7e62b792
IR
8146 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8147 if (!peer)
fde246e8
DA
8148 return CMD_WARNING_CONFIG_FAILED;
8149
80444d30 8150 ret = peer_maximum_prefix_out_unset(peer, afi, safi);
fde246e8 8151
80444d30 8152 return bgp_vty_return(vty, ret);
fde246e8
DA
8153}
8154
9cbd06e0
DA
8155/* Maximum number of prefix configuration. Prefix count is different
8156 for each peer configuration. So this configuration can be set for
718e3744 8157 each peer configuration. */
1d80f243
IR
8158DEFUN (neighbor_maximum_prefix,
8159 neighbor_maximum_prefix_cmd,
8160 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8161 NEIGHBOR_STR
8162 NEIGHBOR_ADDR_STR2
8163 "Maximum number of prefix accept from this peer\n"
8164 "maximum no. of prefix limit\n"
8165 "Force checking all received routes not only accepted\n")
718e3744 8166{
d62a17ae 8167 int idx_peer = 1;
8168 int idx_number = 3;
9cbd06e0 8169 int idx_force = 0;
7e62b792 8170 char *force = NULL;
9cbd06e0
DA
8171
8172 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 8173 force = argv[idx_force]->arg;
9cbd06e0 8174
7e62b792
IR
8175 return peer_maximum_prefix_set_vty(
8176 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8177 argv[idx_number]->arg, NULL, 0, NULL, force);
718e3744 8178}
8179
d62a17ae 8180ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 8181 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
d62a17ae 8182 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8183 "Maximum number of prefix accept from this peer\n"
9cbd06e0
DA
8184 "maximum no. of prefix limit\n"
8185 "Force checking all received routes not only accepted\n")
596c17ba 8186
1d80f243
IR
8187DEFUN (neighbor_maximum_prefix_threshold,
8188 neighbor_maximum_prefix_threshold_cmd,
8189 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8190 NEIGHBOR_STR
8191 NEIGHBOR_ADDR_STR2
8192 "Maximum number of prefix accept from this peer\n"
8193 "maximum no. of prefix limit\n"
8194 "Threshold value (%) at which to generate a warning msg\n"
8195 "Force checking all received routes not only accepted\n")
e0701b79 8196{
d62a17ae 8197 int idx_peer = 1;
8198 int idx_number = 3;
8199 int idx_number_2 = 4;
9cbd06e0 8200 int idx_force = 0;
7e62b792 8201 char *force = NULL;
9cbd06e0
DA
8202
8203 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 8204 force = argv[idx_force]->arg;
9cbd06e0 8205
7e62b792
IR
8206 return peer_maximum_prefix_set_vty(
8207 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8208 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
0a486e5f 8209}
e0701b79 8210
d62a17ae 8211ALIAS_HIDDEN(
8212 neighbor_maximum_prefix_threshold,
8213 neighbor_maximum_prefix_threshold_hidden_cmd,
9cbd06e0 8214 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
d62a17ae 8215 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8216 "Maximum number of prefix accept from this peer\n"
8217 "maximum no. of prefix limit\n"
9cbd06e0
DA
8218 "Threshold value (%) at which to generate a warning msg\n"
8219 "Force checking all received routes not only accepted\n")
596c17ba 8220
1d80f243
IR
8221DEFUN (neighbor_maximum_prefix_warning,
8222 neighbor_maximum_prefix_warning_cmd,
8223 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8224 NEIGHBOR_STR
8225 NEIGHBOR_ADDR_STR2
8226 "Maximum number of prefix accept from this peer\n"
8227 "maximum no. of prefix limit\n"
8228 "Only give warning message when limit is exceeded\n"
8229 "Force checking all received routes not only accepted\n")
718e3744 8230{
d62a17ae 8231 int idx_peer = 1;
8232 int idx_number = 3;
9cbd06e0 8233 int idx_force = 0;
7e62b792 8234 char *force = NULL;
9cbd06e0
DA
8235
8236 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 8237 force = argv[idx_force]->arg;
9cbd06e0 8238
7e62b792
IR
8239 return peer_maximum_prefix_set_vty(
8240 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8241 argv[idx_number]->arg, NULL, 1, NULL, force);
718e3744 8242}
8243
d62a17ae 8244ALIAS_HIDDEN(
8245 neighbor_maximum_prefix_warning,
8246 neighbor_maximum_prefix_warning_hidden_cmd,
9cbd06e0 8247 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
d62a17ae 8248 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8249 "Maximum number of prefix accept from this peer\n"
8250 "maximum no. of prefix limit\n"
9cbd06e0
DA
8251 "Only give warning message when limit is exceeded\n"
8252 "Force checking all received routes not only accepted\n")
596c17ba 8253
1d80f243
IR
8254DEFUN (neighbor_maximum_prefix_threshold_warning,
8255 neighbor_maximum_prefix_threshold_warning_cmd,
8256 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8257 NEIGHBOR_STR
8258 NEIGHBOR_ADDR_STR2
8259 "Maximum number of prefix accept from this peer\n"
8260 "maximum no. of prefix limit\n"
8261 "Threshold value (%) at which to generate a warning msg\n"
8262 "Only give warning message when limit is exceeded\n"
8263 "Force checking all received routes not only accepted\n")
e0701b79 8264{
d62a17ae 8265 int idx_peer = 1;
8266 int idx_number = 3;
8267 int idx_number_2 = 4;
9cbd06e0 8268 int idx_force = 0;
7e62b792 8269 char *force = NULL;
9cbd06e0
DA
8270
8271 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 8272 force = argv[idx_force]->arg;
9cbd06e0 8273
7e62b792
IR
8274 return peer_maximum_prefix_set_vty(
8275 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8276 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
0a486e5f 8277}
8278
d62a17ae 8279ALIAS_HIDDEN(
8280 neighbor_maximum_prefix_threshold_warning,
8281 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
9cbd06e0 8282 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
d62a17ae 8283 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8284 "Maximum number of prefix accept from this peer\n"
8285 "maximum no. of prefix limit\n"
8286 "Threshold value (%) at which to generate a warning msg\n"
9cbd06e0
DA
8287 "Only give warning message when limit is exceeded\n"
8288 "Force checking all received routes not only accepted\n")
596c17ba 8289
1d80f243
IR
8290DEFUN (neighbor_maximum_prefix_restart,
8291 neighbor_maximum_prefix_restart_cmd,
8292 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8293 NEIGHBOR_STR
8294 NEIGHBOR_ADDR_STR2
8295 "Maximum number of prefix accept from this peer\n"
8296 "maximum no. of prefix limit\n"
8297 "Restart bgp connection after limit is exceeded\n"
8298 "Restart interval in minutes\n"
8299 "Force checking all received routes not only accepted\n")
0a486e5f 8300{
d62a17ae 8301 int idx_peer = 1;
8302 int idx_number = 3;
8303 int idx_number_2 = 5;
9cbd06e0 8304 int idx_force = 0;
7e62b792 8305 char *force = NULL;
9cbd06e0
DA
8306
8307 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 8308 force = argv[idx_force]->arg;
9cbd06e0 8309
7e62b792
IR
8310 return peer_maximum_prefix_set_vty(
8311 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8312 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
0a486e5f 8313}
8314
d62a17ae 8315ALIAS_HIDDEN(
8316 neighbor_maximum_prefix_restart,
8317 neighbor_maximum_prefix_restart_hidden_cmd,
9cbd06e0 8318 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
d62a17ae 8319 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8320 "Maximum number of prefix accept from this peer\n"
8321 "maximum no. of prefix limit\n"
8322 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
8323 "Restart interval in minutes\n"
8324 "Force checking all received routes not only accepted\n")
596c17ba 8325
1d80f243
IR
8326DEFUN (neighbor_maximum_prefix_threshold_restart,
8327 neighbor_maximum_prefix_threshold_restart_cmd,
8328 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8329 NEIGHBOR_STR
8330 NEIGHBOR_ADDR_STR2
8331 "Maximum number of prefixes to accept from this peer\n"
8332 "maximum no. of prefix limit\n"
8333 "Threshold value (%) at which to generate a warning msg\n"
8334 "Restart bgp connection after limit is exceeded\n"
8335 "Restart interval in minutes\n"
8336 "Force checking all received routes not only accepted\n")
0a486e5f 8337{
d62a17ae 8338 int idx_peer = 1;
8339 int idx_number = 3;
8340 int idx_number_2 = 4;
8341 int idx_number_3 = 6;
9cbd06e0 8342 int idx_force = 0;
7e62b792 8343 char *force = NULL;
9cbd06e0
DA
8344
8345 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 8346 force = argv[idx_force]->arg;
9cbd06e0 8347
7e62b792
IR
8348 return peer_maximum_prefix_set_vty(
8349 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8350 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
8351 argv[idx_number_3]->arg, force);
d62a17ae 8352}
8353
8354ALIAS_HIDDEN(
8355 neighbor_maximum_prefix_threshold_restart,
8356 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
9cbd06e0 8357 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
d62a17ae 8358 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8359 "Maximum number of prefixes to accept from this peer\n"
8360 "maximum no. of prefix limit\n"
8361 "Threshold value (%) at which to generate a warning msg\n"
8362 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
8363 "Restart interval in minutes\n"
8364 "Force checking all received routes not only accepted\n")
596c17ba 8365
1d80f243
IR
8366DEFUN (no_neighbor_maximum_prefix,
8367 no_neighbor_maximum_prefix_cmd,
8368 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8369 NO_STR
8370 NEIGHBOR_STR
8371 NEIGHBOR_ADDR_STR2
8372 "Maximum number of prefixes to accept from this peer\n"
8373 "maximum no. of prefix limit\n"
8374 "Threshold value (%) at which to generate a warning msg\n"
8375 "Restart bgp connection after limit is exceeded\n"
8376 "Restart interval in minutes\n"
8377 "Only give warning message when limit is exceeded\n"
8378 "Force checking all received routes not only accepted\n")
718e3744 8379{
d62a17ae 8380 int idx_peer = 2;
7e62b792
IR
8381 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
8382 bgp_node_afi(vty),
8383 bgp_node_safi(vty));
718e3744 8384}
e52702f2 8385
d62a17ae 8386ALIAS_HIDDEN(
8387 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 8388 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
d62a17ae 8389 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8390 "Maximum number of prefixes to accept from this peer\n"
8391 "maximum no. of prefix limit\n"
8392 "Threshold value (%) at which to generate a warning msg\n"
8393 "Restart bgp connection after limit is exceeded\n"
8394 "Restart interval in minutes\n"
9cbd06e0
DA
8395 "Only give warning message when limit is exceeded\n"
8396 "Force checking all received routes not only accepted\n")
596c17ba 8397
46dbf9d0
DA
8398/* "neighbor accept-own" */
8399DEFPY (neighbor_accept_own,
8400 neighbor_accept_own_cmd,
8401 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor accept-own",
8402 NO_STR
8403 NEIGHBOR_STR
8404 NEIGHBOR_ADDR_STR2
8405 "Enable handling of self-originated VPN routes containing ACCEPT_OWN community\n")
8406{
8407 struct peer *peer;
8408 afi_t afi = bgp_node_afi(vty);
8409 safi_t safi = bgp_node_safi(vty);
8410 int ret;
8411
8412 peer = peer_and_group_lookup_vty(vty, neighbor);
8413 if (!peer)
8414 return CMD_WARNING_CONFIG_FAILED;
8415
8416 if (no)
8417 ret = peer_af_flag_unset(peer, afi, safi, PEER_FLAG_ACCEPT_OWN);
8418 else
8419 ret = peer_af_flag_set(peer, afi, safi, PEER_FLAG_ACCEPT_OWN);
8420
8421 return bgp_vty_return(vty, ret);
8422}
8423
01da2d26
DA
8424/* "neighbor soo" */
8425DEFPY (neighbor_soo,
8426 neighbor_soo_cmd,
8427 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo ASN:NN_OR_IP-ADDRESS:NN$soo",
8428 NEIGHBOR_STR
8429 NEIGHBOR_ADDR_STR2
8430 "Set the Site-of-Origin (SoO) extended community\n"
8431 "VPN extended community\n")
8432{
8433 struct peer *peer;
8434 afi_t afi = bgp_node_afi(vty);
8435 safi_t safi = bgp_node_safi(vty);
8436 struct ecommunity *ecomm_soo;
8437
8438 peer = peer_and_group_lookup_vty(vty, neighbor);
8439 if (!peer)
8440 return CMD_WARNING_CONFIG_FAILED;
8441
8442 ecomm_soo = ecommunity_str2com(soo, ECOMMUNITY_SITE_ORIGIN, 0);
8443 if (!ecomm_soo) {
8444 vty_out(vty, "%% Malformed SoO extended community\n");
8445 return CMD_WARNING;
8446 }
8447 ecommunity_str(ecomm_soo);
8448
8449 if (!ecommunity_match(peer->soo[afi][safi], ecomm_soo)) {
8450 ecommunity_free(&peer->soo[afi][safi]);
8451 peer->soo[afi][safi] = ecomm_soo;
8452 peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO);
8453 }
8454
8455 return bgp_vty_return(vty,
8456 peer_af_flag_set(peer, afi, safi, PEER_FLAG_SOO));
8457}
8458
8459DEFPY (no_neighbor_soo,
8460 no_neighbor_soo_cmd,
8461 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo [ASN:NN_OR_IP-ADDRESS:NN$soo]",
8462 NO_STR
8463 NEIGHBOR_STR
8464 NEIGHBOR_ADDR_STR2
8465 "Set the Site-of-Origin (SoO) extended community\n"
8466 "VPN extended community\n")
8467{
8468 struct peer *peer;
8469 afi_t afi = bgp_node_afi(vty);
8470 safi_t safi = bgp_node_safi(vty);
8471
8472 peer = peer_and_group_lookup_vty(vty, neighbor);
8473 if (!peer)
8474 return CMD_WARNING_CONFIG_FAILED;
8475
8476 ecommunity_free(&peer->soo[afi][safi]);
8477
8478 return bgp_vty_return(
8479 vty, peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO));
8480}
718e3744 8481
718e3744 8482/* "neighbor allowas-in" */
8483DEFUN (neighbor_allowas_in,
8484 neighbor_allowas_in_cmd,
fd8503f5 8485 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 8486 NEIGHBOR_STR
8487 NEIGHBOR_ADDR_STR2
31500417 8488 "Accept as-path with my AS present in it\n"
f79f7a7b 8489 "Number of occurrences of AS number\n"
fd8503f5 8490 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 8491{
d62a17ae 8492 int idx_peer = 1;
8493 int idx_number_origin = 3;
8494 int ret;
8495 int origin = 0;
8496 struct peer *peer;
8497 int allow_num = 0;
8498
8499 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8500 if (!peer)
8501 return CMD_WARNING_CONFIG_FAILED;
8502
8503 if (argc <= idx_number_origin)
8504 allow_num = 3;
8505 else {
8506 if (argv[idx_number_origin]->type == WORD_TKN)
8507 origin = 1;
8508 else
8509 allow_num = atoi(argv[idx_number_origin]->arg);
8510 }
8511
8512 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8513 allow_num, origin);
8514
8515 return bgp_vty_return(vty, ret);
8516}
8517
8518ALIAS_HIDDEN(
8519 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8520 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8521 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8522 "Accept as-path with my AS present in it\n"
f79f7a7b 8523 "Number of occurrences of AS number\n"
d62a17ae 8524 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 8525
718e3744 8526DEFUN (no_neighbor_allowas_in,
8527 no_neighbor_allowas_in_cmd,
fd8503f5 8528 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 8529 NO_STR
8530 NEIGHBOR_STR
8531 NEIGHBOR_ADDR_STR2
8334fd5a 8532 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8533 "Number of occurrences of AS number\n"
fd8503f5 8534 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 8535{
d62a17ae 8536 int idx_peer = 2;
8537 int ret;
8538 struct peer *peer;
718e3744 8539
d62a17ae 8540 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8541 if (!peer)
8542 return CMD_WARNING_CONFIG_FAILED;
718e3744 8543
d62a17ae 8544 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8545 bgp_node_safi(vty));
718e3744 8546
d62a17ae 8547 return bgp_vty_return(vty, ret);
718e3744 8548}
6b0655a2 8549
d62a17ae 8550ALIAS_HIDDEN(
8551 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8552 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8553 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8554 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8555 "Number of occurrences of AS number\n"
d62a17ae 8556 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 8557
28c6e247
IR
8558DEFUN (neighbor_ttl_security,
8559 neighbor_ttl_security_cmd,
8560 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8561 NEIGHBOR_STR
8562 NEIGHBOR_ADDR_STR2
8563 "BGP ttl-security parameters\n"
8564 "Specify the maximum number of hops to the BGP peer\n"
8565 "Number of hops to BGP peer\n")
fa411a21 8566{
d62a17ae 8567 int idx_peer = 1;
8568 int idx_number = 4;
28c6e247
IR
8569 struct peer *peer;
8570 int gtsm_hops;
d62a17ae 8571
28c6e247
IR
8572 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8573 if (!peer)
d62a17ae 8574 return CMD_WARNING_CONFIG_FAILED;
8575
28c6e247
IR
8576 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
8577
8578 /*
8579 * If 'neighbor swpX', then this is for directly connected peers,
8580 * we should not accept a ttl-security hops value greater than 1.
8581 */
8582 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
8583 vty_out(vty,
8584 "%s is directly connected peer, hops cannot exceed 1\n",
8585 argv[idx_peer]->arg);
8586 return CMD_WARNING_CONFIG_FAILED;
8587 }
7ebe625c 8588
28c6e247 8589 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
8590}
8591
1d80f243
IR
8592DEFUN (no_neighbor_ttl_security,
8593 no_neighbor_ttl_security_cmd,
8594 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8595 NO_STR
8596 NEIGHBOR_STR
8597 NEIGHBOR_ADDR_STR2
8598 "BGP ttl-security parameters\n"
8599 "Specify the maximum number of hops to the BGP peer\n"
8600 "Number of hops to BGP peer\n")
fa411a21 8601{
d62a17ae 8602 int idx_peer = 2;
28c6e247 8603 struct peer *peer;
fa411a21 8604
28c6e247
IR
8605 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8606 if (!peer)
d62a17ae 8607 return CMD_WARNING_CONFIG_FAILED;
fa411a21 8608
28c6e247 8609 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 8610}
6b0655a2 8611
7c0e4312
DA
8612/* disable-addpath-rx */
8613DEFUN(neighbor_disable_addpath_rx,
8614 neighbor_disable_addpath_rx_cmd,
8615 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8616 NEIGHBOR_STR
8617 NEIGHBOR_ADDR_STR2
8618 "Do not accept additional paths\n")
8619{
8620 char *peer_str = argv[1]->arg;
8621 struct peer *peer;
8622 afi_t afi = bgp_node_afi(vty);
8623 safi_t safi = bgp_node_safi(vty);
8624
8625 peer = peer_and_group_lookup_vty(vty, peer_str);
8626 if (!peer)
8627 return CMD_WARNING_CONFIG_FAILED;
8628
8629 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
8630 PEER_FLAG_DISABLE_ADDPATH_RX);
8631}
8632
8633DEFUN(no_neighbor_disable_addpath_rx,
8634 no_neighbor_disable_addpath_rx_cmd,
8635 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8636 NO_STR
8637 NEIGHBOR_STR
8638 NEIGHBOR_ADDR_STR2
8639 "Do not accept additional paths\n")
8640{
8641 char *peer_str = argv[2]->arg;
8642 struct peer *peer;
8643 afi_t afi = bgp_node_afi(vty);
8644 safi_t safi = bgp_node_safi(vty);
8645
8646 peer = peer_and_group_lookup_vty(vty, peer_str);
8647 if (!peer)
8648 return CMD_WARNING_CONFIG_FAILED;
8649
8650 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
8651 PEER_FLAG_DISABLE_ADDPATH_RX);
8652}
8653
adbac85e
DW
8654DEFUN (neighbor_addpath_tx_all_paths,
8655 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8656 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8657 NEIGHBOR_STR
8658 NEIGHBOR_ADDR_STR2
8659 "Use addpath to advertise all paths to a neighbor\n")
8660{
d62a17ae 8661 int idx_peer = 1;
8662 struct peer *peer;
adbac85e 8663
d62a17ae 8664 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8665 if (!peer)
8666 return CMD_WARNING_CONFIG_FAILED;
adbac85e 8667
dcc68b5e
MS
8668 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8669 BGP_ADDPATH_ALL);
8670 return CMD_SUCCESS;
adbac85e
DW
8671}
8672
d62a17ae 8673ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8674 neighbor_addpath_tx_all_paths_hidden_cmd,
8675 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8676 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8677 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8678
adbac85e
DW
8679DEFUN (no_neighbor_addpath_tx_all_paths,
8680 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8681 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8682 NO_STR
8683 NEIGHBOR_STR
8684 NEIGHBOR_ADDR_STR2
8685 "Use addpath to advertise all paths to a neighbor\n")
8686{
d62a17ae 8687 int idx_peer = 2;
dcc68b5e
MS
8688 struct peer *peer;
8689
8690 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8691 if (!peer)
8692 return CMD_WARNING_CONFIG_FAILED;
8693
8694 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8695 != BGP_ADDPATH_ALL) {
8696 vty_out(vty,
8697 "%% Peer not currently configured to transmit all paths.");
8698 return CMD_WARNING_CONFIG_FAILED;
8699 }
8700
8701 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8702 BGP_ADDPATH_NONE);
8703
8704 return CMD_SUCCESS;
adbac85e
DW
8705}
8706
d62a17ae 8707ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8708 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8709 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8710 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8711 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8712
06370dac
DW
8713DEFUN (neighbor_addpath_tx_bestpath_per_as,
8714 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8715 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8716 NEIGHBOR_STR
8717 NEIGHBOR_ADDR_STR2
8718 "Use addpath to advertise the bestpath per each neighboring AS\n")
8719{
d62a17ae 8720 int idx_peer = 1;
8721 struct peer *peer;
06370dac 8722
d62a17ae 8723 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8724 if (!peer)
8725 return CMD_WARNING_CONFIG_FAILED;
06370dac 8726
dcc68b5e
MS
8727 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8728 BGP_ADDPATH_BEST_PER_AS);
8729
8730 return CMD_SUCCESS;
06370dac
DW
8731}
8732
d62a17ae 8733ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8734 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8735 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8736 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8737 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8738
06370dac
DW
8739DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8740 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8741 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8742 NO_STR
8743 NEIGHBOR_STR
8744 NEIGHBOR_ADDR_STR2
8745 "Use addpath to advertise the bestpath per each neighboring AS\n")
8746{
d62a17ae 8747 int idx_peer = 2;
dcc68b5e
MS
8748 struct peer *peer;
8749
8750 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8751 if (!peer)
8752 return CMD_WARNING_CONFIG_FAILED;
8753
8754 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8755 != BGP_ADDPATH_BEST_PER_AS) {
8756 vty_out(vty,
8757 "%% Peer not currently configured to transmit all best path per as.");
8758 return CMD_WARNING_CONFIG_FAILED;
8759 }
8760
8761 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8762 BGP_ADDPATH_NONE);
8763
8764 return CMD_SUCCESS;
06370dac
DW
8765}
8766
d62a17ae 8767ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8768 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8769 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8770 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8771 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8772
2b31007c
RZ
8773DEFPY(
8774 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8775 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8776 NEIGHBOR_STR
8777 NEIGHBOR_ADDR_STR2
8778 "Detect AS loops before sending to neighbor\n")
8779{
8780 struct peer *peer;
8781
8782 peer = peer_and_group_lookup_vty(vty, neighbor);
8783 if (!peer)
8784 return CMD_WARNING_CONFIG_FAILED;
8785
8786 peer->as_path_loop_detection = true;
8787
8788 return CMD_SUCCESS;
8789}
8790
8791DEFPY(
8792 no_neighbor_aspath_loop_detection,
8793 no_neighbor_aspath_loop_detection_cmd,
8794 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8795 NO_STR
8796 NEIGHBOR_STR
8797 NEIGHBOR_ADDR_STR2
8798 "Detect AS loops before sending to neighbor\n")
8799{
8800 struct peer *peer;
8801
8802 peer = peer_and_group_lookup_vty(vty, neighbor);
8803 if (!peer)
8804 return CMD_WARNING_CONFIG_FAILED;
8805
8806 peer->as_path_loop_detection = false;
8807
8808 return CMD_SUCCESS;
8809}
8810
b9c7bc5a 8811static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
c6423c31 8812 struct ecommunity **list, bool is_rt6)
ddb5b488 8813{
b9c7bc5a
PZ
8814 struct ecommunity *ecom = NULL;
8815 struct ecommunity *ecomadd;
ddb5b488 8816
b9c7bc5a 8817 for (; argc; --argc, ++argv) {
9a659715
PG
8818 if (is_rt6)
8819 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8820 ECOMMUNITY_ROUTE_TARGET,
8821 0);
8822 else
8823 ecomadd = ecommunity_str2com(argv[0]->arg,
8824 ECOMMUNITY_ROUTE_TARGET,
8825 0);
b9c7bc5a
PZ
8826 if (!ecomadd) {
8827 vty_out(vty, "Malformed community-list value\n");
8828 if (ecom)
8829 ecommunity_free(&ecom);
8830 return CMD_WARNING_CONFIG_FAILED;
8831 }
ddb5b488 8832
b9c7bc5a
PZ
8833 if (ecom) {
8834 ecommunity_merge(ecom, ecomadd);
8835 ecommunity_free(&ecomadd);
8836 } else {
8837 ecom = ecomadd;
8838 }
8839 }
8840
8841 if (*list) {
8842 ecommunity_free(&*list);
ddb5b488 8843 }
b9c7bc5a
PZ
8844 *list = ecom;
8845
8846 return CMD_SUCCESS;
ddb5b488
PZ
8847}
8848
0ca70ba5
DS
8849/*
8850 * v2vimport is true if we are handling a `import vrf ...` command
8851 */
8852static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 8853{
0ca70ba5
DS
8854 afi_t afi;
8855
ddb5b488 8856 switch (vty->node) {
b9c7bc5a 8857 case BGP_IPV4_NODE:
0ca70ba5
DS
8858 afi = AFI_IP;
8859 break;
b9c7bc5a 8860 case BGP_IPV6_NODE:
0ca70ba5
DS
8861 afi = AFI_IP6;
8862 break;
ddb5b488
PZ
8863 default:
8864 vty_out(vty,
b9c7bc5a 8865 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 8866 return AFI_MAX;
ddb5b488 8867 }
69b07479 8868
0ca70ba5
DS
8869 if (!v2vimport) {
8870 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8871 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8872 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8873 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8874 vty_out(vty,
8875 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8876 return AFI_MAX;
8877 }
8878 } else {
8879 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8880 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8881 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8882 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8883 vty_out(vty,
8884 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
8885 return AFI_MAX;
8886 }
8887 }
8888 return afi;
ddb5b488
PZ
8889}
8890
585f1adc
IR
8891DEFPY (af_rd_vpn_export,
8892 af_rd_vpn_export_cmd,
8893 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
8894 NO_STR
8895 "Specify route distinguisher\n"
8896 "Between current address-family and vpn\n"
8897 "For routes leaked from current address-family to vpn\n"
8898 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
ddb5b488 8899{
585f1adc
IR
8900 VTY_DECLVAR_CONTEXT(bgp, bgp);
8901 struct prefix_rd prd;
8902 int ret;
ddb5b488 8903 afi_t afi;
b9c7bc5a 8904 int idx = 0;
585f1adc 8905 bool yes = true;
b9c7bc5a 8906
585f1adc
IR
8907 if (argv_find(argv, argc, "no", &idx))
8908 yes = false;
ddb5b488 8909
585f1adc
IR
8910 if (yes) {
8911 ret = str2prefix_rd(rd_str, &prd);
8912 if (!ret) {
8913 vty_out(vty, "%% Malformed rd\n");
8914 return CMD_WARNING_CONFIG_FAILED;
8915 }
8916 }
ddb5b488 8917
585f1adc
IR
8918 afi = vpn_policy_getafi(vty, bgp, false);
8919 if (afi == AFI_MAX)
8920 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8921
585f1adc
IR
8922 /*
8923 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8924 */
8925 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8926 bgp_get_default(), bgp);
ddb5b488 8927
585f1adc
IR
8928 if (yes) {
8929 bgp->vpn_policy[afi].tovpn_rd = prd;
8930 SET_FLAG(bgp->vpn_policy[afi].flags,
8931 BGP_VPN_POLICY_TOVPN_RD_SET);
8932 } else {
8933 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8934 BGP_VPN_POLICY_TOVPN_RD_SET);
8935 }
69b07479 8936
585f1adc
IR
8937 /* post-change: re-export vpn routes */
8938 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8939 bgp_get_default(), bgp);
8940
8941 return CMD_SUCCESS;
ddb5b488
PZ
8942}
8943
b9c7bc5a
PZ
8944ALIAS (af_rd_vpn_export,
8945 af_no_rd_vpn_export_cmd,
8946 "no rd vpn export",
ddb5b488 8947 NO_STR
b9c7bc5a
PZ
8948 "Specify route distinguisher\n"
8949 "Between current address-family and vpn\n"
8950 "For routes leaked from current address-family to vpn\n")
ddb5b488 8951
b9c7bc5a
PZ
8952DEFPY (af_label_vpn_export,
8953 af_label_vpn_export_cmd,
e70e9f8e 8954 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 8955 NO_STR
ddb5b488 8956 "label value for VRF\n"
b9c7bc5a
PZ
8957 "Between current address-family and vpn\n"
8958 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
8959 "Label Value <0-1048575>\n"
8960 "Automatically assign a label\n")
ddb5b488
PZ
8961{
8962 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 8963 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 8964 afi_t afi;
b9c7bc5a 8965 int idx = 0;
c6423c31 8966 bool yes = true;
b9c7bc5a
PZ
8967
8968 if (argv_find(argv, argc, "no", &idx))
c6423c31 8969 yes = false;
ddb5b488 8970
21a16cc2
PZ
8971 /* If "no ...", squash trailing parameter */
8972 if (!yes)
8973 label_auto = NULL;
8974
e70e9f8e
PZ
8975 if (yes) {
8976 if (!label_auto)
8977 label = label_val; /* parser should force unsigned */
8978 }
ddb5b488 8979
0ca70ba5 8980 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
8981 if (afi == AFI_MAX)
8982 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 8983
e70e9f8e 8984
69b07479
DS
8985 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8986 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
8987 /* no change */
8988 return CMD_SUCCESS;
e70e9f8e 8989
69b07479
DS
8990 /*
8991 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8992 */
8993 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8994 bgp_get_default(), bgp);
8995
8996 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8997 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
8998
8999 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
9000
9001 /*
9002 * label has previously been automatically
9003 * assigned by labelpool: release it
9004 *
9005 * NB if tovpn_label == MPLS_LABEL_NONE it
9006 * means the automatic assignment is in flight
9007 * and therefore the labelpool callback must
9008 * detect that the auto label is not needed.
9009 */
9010
9011 bgp_lp_release(LP_TYPE_VRF,
9012 &bgp->vpn_policy[afi],
9013 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 9014 }
69b07479
DS
9015 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9016 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9017 }
ddb5b488 9018
69b07479
DS
9019 bgp->vpn_policy[afi].tovpn_label = label;
9020 if (label_auto) {
9021 SET_FLAG(bgp->vpn_policy[afi].flags,
9022 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9023 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
9024 vpn_leak_label_callback);
ddb5b488
PZ
9025 }
9026
69b07479
DS
9027 /* post-change: re-export vpn routes */
9028 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9029 bgp_get_default(), bgp);
9030
0d020cd6 9031 hook_call(bgp_snmp_update_last_changed, bgp);
ddb5b488
PZ
9032 return CMD_SUCCESS;
9033}
9034
b72c9e14
HS
9035DEFPY (af_sid_vpn_export,
9036 af_sid_vpn_export_cmd,
46279a11 9037 "[no] sid vpn export <(1-1048575)$sid_idx|auto$sid_auto>",
b72c9e14
HS
9038 NO_STR
9039 "sid value for VRF\n"
9040 "Between current address-family and vpn\n"
9041 "For routes leaked from current address-family to vpn\n"
9042 "Sid allocation index\n"
9043 "Automatically assign a label\n")
9044{
9045 VTY_DECLVAR_CONTEXT(bgp, bgp);
9046 afi_t afi;
9047 int debug = 0;
9048 int idx = 0;
9049 bool yes = true;
9050
9051 if (argv_find(argv, argc, "no", &idx))
9052 yes = false;
9053 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
9054 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
9055
9056 afi = vpn_policy_getafi(vty, bgp, false);
9057 if (afi == AFI_MAX)
9058 return CMD_WARNING_CONFIG_FAILED;
9059
9060 if (!yes) {
9061 /* implement me */
4d4c404b 9062 vty_out(vty, "It's not implemented\n");
b72c9e14
HS
9063 return CMD_WARNING_CONFIG_FAILED;
9064 }
9065
527588aa
CS
9066 if (bgp->tovpn_sid_index != 0 ||
9067 CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)) {
9068 vty_out(vty,
9069 "per-vrf sid and per-af sid are mutually exclusive\n"
9070 "Failed: per-vrf sid is configured. Remove per-vrf sid before configuring per-af sid\n");
9071 return CMD_WARNING_CONFIG_FAILED;
9072 }
9073
b72c9e14
HS
9074 /* skip when it's already configured */
9075 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9076 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9077 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
9078 return CMD_SUCCESS;
9079
7de4c885
HS
9080 /*
9081 * mode change between sid_idx and sid_auto isn't supported.
9082 * user must negate sid vpn export when they want to change the mode
9083 */
b72c9e14
HS
9084 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9085 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9086 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
9087 vty_out(vty, "it's already configured as %s.\n",
9088 sid_auto ? "auto-mode" : "idx-mode");
9089 return CMD_WARNING_CONFIG_FAILED;
9090 }
9091
9092 /* pre-change */
9093 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9094 bgp_get_default(), bgp);
9095
9096 if (sid_auto) {
9097 /* SID allocation auto-mode */
9098 if (debug)
9099 zlog_debug("%s: auto sid alloc.", __func__);
9100 SET_FLAG(bgp->vpn_policy[afi].flags,
9101 BGP_VPN_POLICY_TOVPN_SID_AUTO);
9102 } else {
9103 /* SID allocation index-mode */
9104 if (debug)
9105 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
9106 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
9107 }
9108
9109 /* post-change */
9110 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9111 bgp_get_default(), bgp);
9112 return CMD_SUCCESS;
9113}
9114
527588aa
CS
9115DEFPY (bgp_sid_vpn_export,
9116 bgp_sid_vpn_export_cmd,
346bbb39 9117 "[no] sid vpn per-vrf export <(1-1048575)$sid_idx|auto$sid_auto>",
527588aa
CS
9118 NO_STR
9119 "sid value for VRF\n"
9120 "Between current vrf and vpn\n"
9121 "sid per-VRF (both IPv4 and IPv6 address families)\n"
9122 "For routes leaked from current vrf to vpn\n"
9123 "Sid allocation index\n"
9124 "Automatically assign a label\n")
9125{
9126 VTY_DECLVAR_CONTEXT(bgp, bgp);
9127 int debug;
9128
9129 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
9130 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
9131
9132 if (no) {
e606d8ec
CS
9133 /* when per-VRF SID is not set, do nothing */
9134 if (bgp->tovpn_sid_index == 0 &&
9135 !CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO))
9136 return CMD_SUCCESS;
9137
9138 sid_idx = 0;
9139 sid_auto = false;
9140 bgp->tovpn_sid_index = 0;
9141 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO);
527588aa
CS
9142 }
9143
9144 if (bgp->vpn_policy[AFI_IP].tovpn_sid_index != 0 ||
9145 CHECK_FLAG(bgp->vpn_policy[AFI_IP].flags,
9146 BGP_VPN_POLICY_TOVPN_SID_AUTO) ||
9147 bgp->vpn_policy[AFI_IP6].tovpn_sid_index != 0 ||
9148 CHECK_FLAG(bgp->vpn_policy[AFI_IP6].flags,
9149 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
9150 vty_out(vty,
9151 "per-vrf sid and per-af sid are mutually exclusive\n"
9152 "Failed: per-af sid is configured. Remove per-af sid before configuring per-vrf sid\n");
9153 return CMD_WARNING_CONFIG_FAILED;
9154 }
9155
9156 /* skip when it's already configured */
9157 if ((sid_idx != 0 && bgp->tovpn_sid_index != 0) ||
9158 (sid_auto && CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)))
9159 return CMD_SUCCESS;
9160
9161 /*
9162 * mode change between sid_idx and sid_auto isn't supported.
9163 * user must negate sid vpn export when they want to change the mode
9164 */
9165 if ((sid_auto && bgp->tovpn_sid_index != 0) ||
9166 (sid_idx != 0 &&
9167 CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO))) {
9168 vty_out(vty, "it's already configured as %s.\n",
9169 sid_auto ? "auto-mode" : "idx-mode");
9170 return CMD_WARNING_CONFIG_FAILED;
9171 }
9172
9173 /* pre-change */
9174 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP, bgp_get_default(),
9175 bgp);
9176 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP6, bgp_get_default(),
9177 bgp);
9178
9179 if (sid_auto) {
9180 /* SID allocation auto-mode */
9181 if (debug)
9182 zlog_debug("%s: auto per-vrf sid alloc.", __func__);
9183 SET_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO);
e606d8ec 9184 } else if (sid_idx != 0) {
527588aa
CS
9185 /* SID allocation index-mode */
9186 if (debug)
9187 zlog_debug("%s: idx %ld per-vrf sid alloc.", __func__,
9188 sid_idx);
9189 bgp->tovpn_sid_index = sid_idx;
9190 }
9191
9192 /* post-change */
9193 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP, bgp_get_default(),
9194 bgp);
9195 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP6,
9196 bgp_get_default(), bgp);
9197
9198 return CMD_SUCCESS;
9199}
9200
b9c7bc5a
PZ
9201ALIAS (af_label_vpn_export,
9202 af_no_label_vpn_export_cmd,
9203 "no label vpn export",
9204 NO_STR
9205 "label value for VRF\n"
9206 "Between current address-family and vpn\n"
9207 "For routes leaked from current address-family to vpn\n")
ddb5b488 9208
e606d8ec
CS
9209ALIAS (bgp_sid_vpn_export,
9210 no_bgp_sid_vpn_export_cmd,
9211 "no$no sid vpn per-vrf export",
9212 NO_STR
9213 "sid value for VRF\n"
9214 "Between current vrf and vpn\n"
9215 "sid per-VRF (both IPv4 and IPv6 address families)\n"
9216 "For routes leaked from current vrf to vpn\n")
9217
585f1adc 9218DEFPY (af_nexthop_vpn_export,
b9c7bc5a 9219 af_nexthop_vpn_export_cmd,
8c85ca28 9220 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
b9c7bc5a 9221 NO_STR
ddb5b488 9222 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
9223 "Between current address-family and vpn\n"
9224 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
9225 "IPv4 prefix\n"
9226 "IPv6 prefix\n")
9227{
585f1adc 9228 VTY_DECLVAR_CONTEXT(bgp, bgp);
ddb5b488 9229 afi_t afi;
ddb5b488
PZ
9230 struct prefix p;
9231
8c85ca28
QY
9232 if (!no) {
9233 if (!nexthop_su) {
9234 vty_out(vty, "%% Nexthop required\n");
9235 return CMD_WARNING_CONFIG_FAILED;
9236 }
8c85ca28 9237 if (!sockunion2hostprefix(nexthop_su, &p))
b9c7bc5a
PZ
9238 return CMD_WARNING_CONFIG_FAILED;
9239 }
ddb5b488 9240
585f1adc
IR
9241 afi = vpn_policy_getafi(vty, bgp, false);
9242 if (afi == AFI_MAX)
9243 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9244
585f1adc
IR
9245 /*
9246 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9247 */
9248 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9249 bgp_get_default(), bgp);
ddb5b488 9250
585f1adc
IR
9251 if (!no) {
9252 bgp->vpn_policy[afi].tovpn_nexthop = p;
9253 SET_FLAG(bgp->vpn_policy[afi].flags,
9254 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9255 } else {
9256 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9257 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9258 }
69b07479 9259
585f1adc
IR
9260 /* post-change: re-export vpn routes */
9261 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9262 bgp_get_default(), bgp);
37a87b8f 9263
585f1adc 9264 return CMD_SUCCESS;
ddb5b488
PZ
9265}
9266
b9c7bc5a 9267static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 9268{
b9c7bc5a
PZ
9269 if (!strcmp(dstr, "import")) {
9270 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9271 } else if (!strcmp(dstr, "export")) {
9272 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9273 } else if (!strcmp(dstr, "both")) {
9274 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9275 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9276 } else {
9277 vty_out(vty, "%% direction parse error\n");
9278 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9279 }
ddb5b488
PZ
9280 return CMD_SUCCESS;
9281}
9282
b9c7bc5a
PZ
9283DEFPY (af_rt_vpn_imexport,
9284 af_rt_vpn_imexport_cmd,
9285 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9286 NO_STR
9287 "Specify route target list\n"
ddb5b488 9288 "Specify route target list\n"
b9c7bc5a
PZ
9289 "Between current address-family and vpn\n"
9290 "For routes leaked from vpn to current address-family: match any\n"
9291 "For routes leaked from current address-family to vpn: set\n"
9292 "both import: match any and export: set\n"
ddb5b488
PZ
9293 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9294{
9295 VTY_DECLVAR_CONTEXT(bgp, bgp);
9296 int ret;
9297 struct ecommunity *ecom = NULL;
9298 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9c2fd3fe 9299 enum vpn_policy_direction dir;
ddb5b488
PZ
9300 afi_t afi;
9301 int idx = 0;
c6423c31 9302 bool yes = true;
ddb5b488 9303
b9c7bc5a 9304 if (argv_find(argv, argc, "no", &idx))
c6423c31 9305 yes = false;
b9c7bc5a 9306
0ca70ba5 9307 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9308 if (afi == AFI_MAX)
9309 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9310
b9c7bc5a 9311 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
9312 if (ret != CMD_SUCCESS)
9313 return ret;
9314
b9c7bc5a
PZ
9315 if (yes) {
9316 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9317 vty_out(vty, "%% Missing RTLIST\n");
9318 return CMD_WARNING_CONFIG_FAILED;
9319 }
c6423c31 9320 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
b9c7bc5a
PZ
9321 if (ret != CMD_SUCCESS) {
9322 return ret;
9323 }
ddb5b488
PZ
9324 }
9325
69b07479
DS
9326 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9327 if (!dodir[dir])
ddb5b488 9328 continue;
ddb5b488 9329
69b07479 9330 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 9331
69b07479
DS
9332 if (yes) {
9333 if (bgp->vpn_policy[afi].rtlist[dir])
9334 ecommunity_free(
9335 &bgp->vpn_policy[afi].rtlist[dir]);
9336 bgp->vpn_policy[afi].rtlist[dir] =
9337 ecommunity_dup(ecom);
9338 } else {
9339 if (bgp->vpn_policy[afi].rtlist[dir])
9340 ecommunity_free(
9341 &bgp->vpn_policy[afi].rtlist[dir]);
9342 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 9343 }
69b07479
DS
9344
9345 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 9346 }
69b07479 9347
d555f3e9
PZ
9348 if (ecom)
9349 ecommunity_free(&ecom);
ddb5b488
PZ
9350
9351 return CMD_SUCCESS;
9352}
9353
b9c7bc5a
PZ
9354ALIAS (af_rt_vpn_imexport,
9355 af_no_rt_vpn_imexport_cmd,
9356 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
9357 NO_STR
9358 "Specify route target list\n"
b9c7bc5a
PZ
9359 "Specify route target list\n"
9360 "Between current address-family and vpn\n"
9361 "For routes leaked from vpn to current address-family\n"
9362 "For routes leaked from current address-family to vpn\n"
9363 "both import and export\n")
9364
585f1adc 9365DEFPY (af_route_map_vpn_imexport,
b9c7bc5a
PZ
9366 af_route_map_vpn_imexport_cmd,
9367/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9368 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9369 NO_STR
ddb5b488 9370 "Specify route map\n"
b9c7bc5a
PZ
9371 "Between current address-family and vpn\n"
9372 "For routes leaked from vpn to current address-family\n"
9373 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
9374 "name of route-map\n")
9375{
585f1adc
IR
9376 VTY_DECLVAR_CONTEXT(bgp, bgp);
9377 int ret;
9378 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9c2fd3fe 9379 enum vpn_policy_direction dir;
ddb5b488 9380 afi_t afi;
ddb5b488 9381 int idx = 0;
585f1adc 9382 bool yes = true;
ddb5b488 9383
585f1adc
IR
9384 if (argv_find(argv, argc, "no", &idx))
9385 yes = false;
ddb5b488 9386
585f1adc
IR
9387 afi = vpn_policy_getafi(vty, bgp, false);
9388 if (afi == AFI_MAX)
9389 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9390
585f1adc
IR
9391 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9392 if (ret != CMD_SUCCESS)
9393 return ret;
ddb5b488 9394
585f1adc
IR
9395 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9396 if (!dodir[dir])
9397 continue;
69b07479 9398
585f1adc
IR
9399 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9400
9401 if (yes) {
9402 if (bgp->vpn_policy[afi].rmap_name[dir])
9403 XFREE(MTYPE_ROUTE_MAP_NAME,
9404 bgp->vpn_policy[afi].rmap_name[dir]);
9405 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
9406 MTYPE_ROUTE_MAP_NAME, rmap_str);
9407 bgp->vpn_policy[afi].rmap[dir] =
9408 route_map_lookup_warn_noexist(vty, rmap_str);
9409 if (!bgp->vpn_policy[afi].rmap[dir])
9410 return CMD_SUCCESS;
9411 } else {
9412 if (bgp->vpn_policy[afi].rmap_name[dir])
9413 XFREE(MTYPE_ROUTE_MAP_NAME,
9414 bgp->vpn_policy[afi].rmap_name[dir]);
9415 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9416 bgp->vpn_policy[afi].rmap[dir] = NULL;
9417 }
9418
9419 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9420 }
ddb5b488 9421
585f1adc 9422 return CMD_SUCCESS;
ddb5b488
PZ
9423}
9424
b9c7bc5a
PZ
9425ALIAS (af_route_map_vpn_imexport,
9426 af_no_route_map_vpn_imexport_cmd,
9427 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
9428 NO_STR
9429 "Specify route map\n"
b9c7bc5a
PZ
9430 "Between current address-family and vpn\n"
9431 "For routes leaked from vpn to current address-family\n"
9432 "For routes leaked from current address-family to vpn\n")
9433
bb4f6190 9434DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
ae6a6fb4 9435 "import vrf route-map RMAP$rmap_str",
bb4f6190
DS
9436 "Import routes from another VRF\n"
9437 "Vrf routes being filtered\n"
9438 "Specify route map\n"
9439 "name of route-map\n")
9440{
9441 VTY_DECLVAR_CONTEXT(bgp, bgp);
9c2fd3fe 9442 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
bb4f6190 9443 afi_t afi;
bb4f6190
DS
9444 struct bgp *bgp_default;
9445
0ca70ba5 9446 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
9447 if (afi == AFI_MAX)
9448 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
9449
9450 bgp_default = bgp_get_default();
9451 if (!bgp_default) {
9452 int32_t ret;
9453 as_t as = bgp->as;
9454
9455 /* Auto-create assuming the same AS */
5d5393b9
DL
9456 ret = bgp_get_vty(&bgp_default, &as, NULL,
9457 BGP_INSTANCE_TYPE_DEFAULT);
bb4f6190
DS
9458
9459 if (ret) {
9460 vty_out(vty,
9461 "VRF default is not configured as a bgp instance\n");
9462 return CMD_WARNING;
9463 }
9464 }
9465
69b07479 9466 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 9467
ae6a6fb4
DS
9468 if (bgp->vpn_policy[afi].rmap_name[dir])
9469 XFREE(MTYPE_ROUTE_MAP_NAME,
9470 bgp->vpn_policy[afi].rmap_name[dir]);
9471 bgp->vpn_policy[afi].rmap_name[dir] =
9472 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9473 bgp->vpn_policy[afi].rmap[dir] =
9474 route_map_lookup_warn_noexist(vty, rmap_str);
9475 if (!bgp->vpn_policy[afi].rmap[dir])
9476 return CMD_SUCCESS;
9477
9478 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9479 BGP_CONFIG_VRF_TO_VRF_IMPORT);
bb4f6190 9480
69b07479
DS
9481 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9482
bb4f6190
DS
9483 return CMD_SUCCESS;
9484}
9485
ae6a6fb4
DS
9486DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9487 "no import vrf route-map [RMAP$rmap_str]",
bb4f6190
DS
9488 NO_STR
9489 "Import routes from another VRF\n"
9490 "Vrf routes being filtered\n"
ae6a6fb4
DS
9491 "Specify route map\n"
9492 "name of route-map\n")
9493{
9494 VTY_DECLVAR_CONTEXT(bgp, bgp);
9c2fd3fe 9495 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
ae6a6fb4
DS
9496 afi_t afi;
9497
9498 afi = vpn_policy_getafi(vty, bgp, true);
9499 if (afi == AFI_MAX)
9500 return CMD_WARNING_CONFIG_FAILED;
9501
9502 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9503
9504 if (bgp->vpn_policy[afi].rmap_name[dir])
9505 XFREE(MTYPE_ROUTE_MAP_NAME,
9506 bgp->vpn_policy[afi].rmap_name[dir]);
9507 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9508 bgp->vpn_policy[afi].rmap[dir] = NULL;
9509
9510 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9511 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9512 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9513
9514 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9515
9516 return CMD_SUCCESS;
9517}
bb4f6190 9518
585f1adc
IR
9519DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
9520 "[no] import vrf VIEWVRFNAME$import_name",
9521 NO_STR
9522 "Import routes from another VRF\n"
9523 "VRF to import from\n"
9524 "The name of the VRF\n")
12a844a5 9525{
585f1adc
IR
9526 VTY_DECLVAR_CONTEXT(bgp, bgp);
9527 struct listnode *node;
9528 struct bgp *vrf_bgp, *bgp_default;
9529 int32_t ret = 0;
9530 as_t as = bgp->as;
9531 bool remove = false;
9532 int32_t idx = 0;
9533 char *vname;
9534 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
12a844a5
DS
9535 safi_t safi;
9536 afi_t afi;
9537
867f0cca 9538 if (import_name == NULL) {
9539 vty_out(vty, "%% Missing import name\n");
9540 return CMD_WARNING;
9541 }
9542
ae6a6fb4
DS
9543 if (strcmp(import_name, "route-map") == 0) {
9544 vty_out(vty, "%% Must include route-map name\n");
9545 return CMD_WARNING;
9546 }
9547
585f1adc
IR
9548 if (argv_find(argv, argc, "no", &idx))
9549 remove = true;
9550
9551 afi = vpn_policy_getafi(vty, bgp, true);
9552 if (afi == AFI_MAX)
9553 return CMD_WARNING_CONFIG_FAILED;
9554
12a844a5
DS
9555 safi = bgp_node_safi(vty);
9556
585f1adc
IR
9557 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
9558 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
9559 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
9560 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
9561 remove ? "unimport" : "import", import_name);
9562 return CMD_WARNING;
9563 }
25679caa 9564
585f1adc
IR
9565 bgp_default = bgp_get_default();
9566 if (!bgp_default) {
9567 /* Auto-create assuming the same AS */
9568 ret = bgp_get_vty(&bgp_default, &as, NULL,
9569 BGP_INSTANCE_TYPE_DEFAULT);
12a844a5 9570
585f1adc
IR
9571 if (ret) {
9572 vty_out(vty,
9573 "VRF default is not configured as a bgp instance\n");
9574 return CMD_WARNING;
9575 }
9576 }
12a844a5 9577
585f1adc
IR
9578 vrf_bgp = bgp_lookup_by_name(import_name);
9579 if (!vrf_bgp) {
9580 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
9581 vrf_bgp = bgp_default;
9582 else
9583 /* Auto-create assuming the same AS */
9584 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
9585
9586 if (ret) {
9587 vty_out(vty,
9588 "VRF %s is not configured as a bgp instance\n",
9589 import_name);
9590 return CMD_WARNING;
9591 }
9592 }
9593
9594 if (remove) {
9595 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
9596 } else {
9597 /* Already importing from "import_vrf"? */
9598 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
9599 vname)) {
9600 if (strcmp(vname, import_name) == 0)
9601 return CMD_WARNING;
9602 }
9603
9604 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
9605 }
9606
9607 return CMD_SUCCESS;
12a844a5
DS
9608}
9609
b9c7bc5a 9610/* This command is valid only in a bgp vrf instance or the default instance */
585f1adc 9611DEFPY (bgp_imexport_vpn,
b9c7bc5a
PZ
9612 bgp_imexport_vpn_cmd,
9613 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
9614 NO_STR
9615 "Import routes to this address-family\n"
9616 "Export routes from this address-family\n"
9617 "to/from default instance VPN RIB\n")
ddb5b488 9618{
585f1adc
IR
9619 VTY_DECLVAR_CONTEXT(bgp, bgp);
9620 int previous_state;
37a87b8f 9621 afi_t afi;
585f1adc
IR
9622 safi_t safi;
9623 int idx = 0;
9624 bool yes = true;
9625 int flag;
9c2fd3fe 9626 enum vpn_policy_direction dir;
585f1adc
IR
9627
9628 if (argv_find(argv, argc, "no", &idx))
9629 yes = false;
9630
9631 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
9632 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
9633
9634 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
9635 return CMD_WARNING_CONFIG_FAILED;
9636 }
ddb5b488 9637
b9c7bc5a
PZ
9638 afi = bgp_node_afi(vty);
9639 safi = bgp_node_safi(vty);
585f1adc
IR
9640 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
9641 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
9642 return CMD_WARNING_CONFIG_FAILED;
9643 }
ddb5b488 9644
b9c7bc5a 9645 if (!strcmp(direction_str, "import")) {
585f1adc
IR
9646 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
9647 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b9c7bc5a 9648 } else if (!strcmp(direction_str, "export")) {
585f1adc
IR
9649 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
9650 dir = BGP_VPN_POLICY_DIR_TOVPN;
b9c7bc5a
PZ
9651 } else {
9652 vty_out(vty, "%% unknown direction %s\n", direction_str);
9653 return CMD_WARNING_CONFIG_FAILED;
9654 }
9655
585f1adc 9656 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488 9657
585f1adc
IR
9658 if (yes) {
9659 SET_FLAG(bgp->af_flags[afi][safi], flag);
9660 if (!previous_state) {
9661 /* trigger export current vrf */
9662 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9663 }
9664 } else {
9665 if (previous_state) {
9666 /* trigger un-export current vrf */
9667 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9668 }
9669 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
9670 }
37a87b8f 9671
1ca2fd11
IR
9672 hook_call(bgp_snmp_init_stats, bgp);
9673
585f1adc 9674 return CMD_SUCCESS;
ddb5b488
PZ
9675}
9676
301ad80a
PG
9677DEFPY (af_routetarget_import,
9678 af_routetarget_import_cmd,
9a659715 9679 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
301ad80a
PG
9680 NO_STR
9681 "Specify route target list\n"
9682 "Specify route target list\n"
9a659715
PG
9683 "Specify route target list\n"
9684 "Specify route target list\n"
301ad80a
PG
9685 "Flow-spec redirect type route target\n"
9686 "Import routes to this address-family\n"
9a659715 9687 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
301ad80a
PG
9688{
9689 VTY_DECLVAR_CONTEXT(bgp, bgp);
9690 int ret;
9691 struct ecommunity *ecom = NULL;
301ad80a 9692 afi_t afi;
9a659715 9693 int idx = 0, idx_unused = 0;
c6423c31
PG
9694 bool yes = true;
9695 bool rt6 = false;
301ad80a
PG
9696
9697 if (argv_find(argv, argc, "no", &idx))
c6423c31 9698 yes = false;
301ad80a 9699
9a659715
PG
9700 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9701 argv_find(argv, argc, "route-target6", &idx_unused))
c6423c31 9702 rt6 = true;
301ad80a 9703
0ca70ba5 9704 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9705 if (afi == AFI_MAX)
9706 return CMD_WARNING_CONFIG_FAILED;
9707
9a659715
PG
9708 if (rt6 && afi != AFI_IP6)
9709 return CMD_WARNING_CONFIG_FAILED;
9710
301ad80a
PG
9711 if (yes) {
9712 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9713 vty_out(vty, "%% Missing RTLIST\n");
9714 return CMD_WARNING_CONFIG_FAILED;
9715 }
9a659715 9716 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
301ad80a
PG
9717 if (ret != CMD_SUCCESS)
9718 return ret;
9719 }
69b07479
DS
9720
9721 if (yes) {
9722 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9723 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9724 .import_redirect_rtlist);
69b07479
DS
9725 bgp->vpn_policy[afi].import_redirect_rtlist =
9726 ecommunity_dup(ecom);
9727 } else {
9728 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9729 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9730 .import_redirect_rtlist);
69b07479 9731 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 9732 }
69b07479 9733
301ad80a
PG
9734 if (ecom)
9735 ecommunity_free(&ecom);
9736
9737 return CMD_SUCCESS;
9738}
9739
505e5056 9740DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 9741 address_family_ipv4_safi_cmd,
9742 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9743 "Enter Address Family command mode\n"
00e6edb9 9744 BGP_AF_STR
7c40bf39 9745 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 9746{
f51bae9c 9747
d62a17ae 9748 if (argc == 3) {
585f1adc
IR
9749 VTY_DECLVAR_CONTEXT(bgp, bgp);
9750 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9751 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
a4d82a8a 9752 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9753 && safi != SAFI_EVPN) {
31947174
MK
9754 vty_out(vty,
9755 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9756 return CMD_WARNING_CONFIG_FAILED;
9757 }
585f1adc
IR
9758 vty->node = bgp_node_type(AFI_IP, safi);
9759 } else
9760 vty->node = BGP_IPV4_NODE;
718e3744 9761
d62a17ae 9762 return CMD_SUCCESS;
718e3744 9763}
9764
505e5056 9765DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 9766 address_family_ipv6_safi_cmd,
9767 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9768 "Enter Address Family command mode\n"
00e6edb9 9769 BGP_AF_STR
7c40bf39 9770 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 9771{
d62a17ae 9772 if (argc == 3) {
585f1adc
IR
9773 VTY_DECLVAR_CONTEXT(bgp, bgp);
9774 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9775 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
a4d82a8a 9776 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9777 && safi != SAFI_EVPN) {
31947174
MK
9778 vty_out(vty,
9779 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9780 return CMD_WARNING_CONFIG_FAILED;
9781 }
585f1adc
IR
9782 vty->node = bgp_node_type(AFI_IP6, safi);
9783 } else
9784 vty->node = BGP_IPV6_NODE;
25ffbdc1 9785
d62a17ae 9786 return CMD_SUCCESS;
25ffbdc1 9787}
718e3744 9788
d6902373 9789#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 9790DEFUN_NOSH (address_family_vpnv4,
718e3744 9791 address_family_vpnv4_cmd,
8334fd5a 9792 "address-family vpnv4 [unicast]",
718e3744 9793 "Enter Address Family command mode\n"
00e6edb9
DA
9794 BGP_AF_STR
9795 BGP_AF_MODIFIER_STR)
718e3744 9796{
d62a17ae 9797 vty->node = BGP_VPNV4_NODE;
9798 return CMD_SUCCESS;
718e3744 9799}
9800
505e5056 9801DEFUN_NOSH (address_family_vpnv6,
8ecd3266 9802 address_family_vpnv6_cmd,
8334fd5a 9803 "address-family vpnv6 [unicast]",
8ecd3266 9804 "Enter Address Family command mode\n"
00e6edb9
DA
9805 BGP_AF_STR
9806 BGP_AF_MODIFIER_STR)
8ecd3266 9807{
d62a17ae 9808 vty->node = BGP_VPNV6_NODE;
9809 return CMD_SUCCESS;
8ecd3266 9810}
64e4a6c5 9811#endif /* KEEP_OLD_VPN_COMMANDS */
d6902373 9812
505e5056 9813DEFUN_NOSH (address_family_evpn,
4e0b7b6d 9814 address_family_evpn_cmd,
7111c1a0 9815 "address-family l2vpn evpn",
4e0b7b6d 9816 "Enter Address Family command mode\n"
00e6edb9
DA
9817 BGP_AF_STR
9818 BGP_AF_MODIFIER_STR)
4e0b7b6d 9819{
2131d5cf 9820 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 9821 vty->node = BGP_EVPN_NODE;
9822 return CMD_SUCCESS;
4e0b7b6d
PG
9823}
9824
bfaab44d
HS
9825DEFUN_NOSH (bgp_segment_routing_srv6,
9826 bgp_segment_routing_srv6_cmd,
9827 "segment-routing srv6",
9828 "Segment-Routing configuration\n"
9829 "Segment-Routing SRv6 configuration\n")
9830{
9831 VTY_DECLVAR_CONTEXT(bgp, bgp);
92a9e6f2 9832 bgp->srv6_enabled = true;
bfaab44d
HS
9833 vty->node = BGP_SRV6_NODE;
9834 return CMD_SUCCESS;
9835}
9836
0249b8b6
HS
9837DEFUN (no_bgp_segment_routing_srv6,
9838 no_bgp_segment_routing_srv6_cmd,
9839 "no segment-routing srv6",
9840 NO_STR
9841 "Segment-Routing configuration\n"
9842 "Segment-Routing SRv6 configuration\n")
9843{
9844 VTY_DECLVAR_CONTEXT(bgp, bgp);
9845
9846 if (strlen(bgp->srv6_locator_name) > 0)
9847 if (bgp_srv6_locator_unset(bgp) < 0)
9848 return CMD_WARNING_CONFIG_FAILED;
9849
9850 bgp->srv6_enabled = false;
9851 return CMD_SUCCESS;
9852}
9853
a0281b2e
HS
9854DEFPY (bgp_srv6_locator,
9855 bgp_srv6_locator_cmd,
9856 "locator NAME$name",
9857 "Specify SRv6 locator\n"
9858 "Specify SRv6 locator\n")
9859{
9860 VTY_DECLVAR_CONTEXT(bgp, bgp);
7de4c885 9861 int ret;
a0281b2e
HS
9862
9863 if (strlen(bgp->srv6_locator_name) > 0
9864 && strcmp(name, bgp->srv6_locator_name) != 0) {
9865 vty_out(vty, "srv6 locator is already configured\n");
9866 return CMD_WARNING_CONFIG_FAILED;
7de4c885
HS
9867 }
9868
9869 snprintf(bgp->srv6_locator_name,
9870 sizeof(bgp->srv6_locator_name), "%s", name);
a0281b2e 9871
7de4c885 9872 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
a0281b2e
HS
9873 if (ret < 0)
9874 return CMD_WARNING_CONFIG_FAILED;
9875
9876 return CMD_SUCCESS;
9877}
9878
0249b8b6
HS
9879DEFPY (no_bgp_srv6_locator,
9880 no_bgp_srv6_locator_cmd,
9881 "no locator NAME$name",
9882 NO_STR
9883 "Specify SRv6 locator\n"
9884 "Specify SRv6 locator\n")
9885{
9886 VTY_DECLVAR_CONTEXT(bgp, bgp);
9887
9888 /* when locator isn't configured, do nothing */
9889 if (strlen(bgp->srv6_locator_name) < 1)
9890 return CMD_SUCCESS;
9891
9892 /* name validation */
9893 if (strcmp(name, bgp->srv6_locator_name) != 0) {
9894 vty_out(vty, "%% No srv6 locator is configured\n");
9895 return CMD_WARNING_CONFIG_FAILED;
9896 }
9897
9898 /* unset locator */
9899 if (bgp_srv6_locator_unset(bgp) < 0)
9900 return CMD_WARNING_CONFIG_FAILED;
9901
9902 return CMD_SUCCESS;
9903}
9904
ea372e81
HS
9905DEFPY (show_bgp_srv6,
9906 show_bgp_srv6_cmd,
9907 "show bgp segment-routing srv6",
9908 SHOW_STR
9909 BGP_STR
9910 "BGP Segment Routing\n"
9911 "BGP Segment Routing SRv6\n")
9912{
9913 struct bgp *bgp;
9914 struct listnode *node;
1c21a234 9915 struct srv6_locator_chunk *chunk;
ea372e81 9916 struct bgp_srv6_function *func;
ea372e81
HS
9917
9918 bgp = bgp_get_default();
96db4340 9919 if (!bgp)
ea372e81
HS
9920 return CMD_SUCCESS;
9921
9922 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
9923 vty_out(vty, "locator_chunks:\n");
dccef127 9924 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk)) {
511211bf 9925 vty_out(vty, "- %pFX\n", &chunk->prefix);
dccef127
CS
9926 vty_out(vty, " block-length: %d\n", chunk->block_bits_length);
9927 vty_out(vty, " node-length: %d\n", chunk->node_bits_length);
9928 vty_out(vty, " func-length: %d\n",
9929 chunk->function_bits_length);
9930 vty_out(vty, " arg-length: %d\n", chunk->argument_bits_length);
9931 }
ea372e81
HS
9932
9933 vty_out(vty, "functions:\n");
9934 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
07380148 9935 vty_out(vty, "- sid: %pI6\n", &func->sid);
ea372e81
HS
9936 vty_out(vty, " locator: %s\n", func->locator_name);
9937 }
9938
9939 vty_out(vty, "bgps:\n");
9940 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
9941 vty_out(vty, "- name: %s\n",
9942 bgp->name ? bgp->name : "default");
9943
1830895a
CS
9944 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %pI6\n",
9945 bgp->vpn_policy[AFI_IP].tovpn_sid);
9946 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %pI6\n",
9947 bgp->vpn_policy[AFI_IP6].tovpn_sid);
9f5d4430 9948 vty_out(vty, " per-vrf tovpn_sid: %pI6\n", bgp->tovpn_sid);
ea372e81
HS
9949 }
9950
9951 return CMD_SUCCESS;
9952}
9953
505e5056 9954DEFUN_NOSH (exit_address_family,
718e3744 9955 exit_address_family_cmd,
9956 "exit-address-family",
9957 "Exit from Address Family configuration mode\n")
9958{
d62a17ae 9959 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9960 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9961 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9962 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
9963 || vty->node == BGP_EVPN_NODE
9964 || vty->node == BGP_FLOWSPECV4_NODE
9965 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 9966 vty->node = BGP_NODE;
9967 return CMD_SUCCESS;
718e3744 9968}
6b0655a2 9969
8ad7271d 9970/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 9971static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9972 const char *ip_str, afi_t afi, safi_t safi,
9973 struct prefix_rd *prd)
9974{
9975 int ret;
9976 struct prefix match;
9bcb3eef
DS
9977 struct bgp_dest *dest;
9978 struct bgp_dest *rm;
d62a17ae 9979 struct bgp *bgp;
9980 struct bgp_table *table;
9981 struct bgp_table *rib;
9982
9983 /* BGP structure lookup. */
9984 if (view_name) {
9985 bgp = bgp_lookup_by_name(view_name);
9986 if (bgp == NULL) {
9987 vty_out(vty, "%% Can't find BGP instance %s\n",
9988 view_name);
9989 return CMD_WARNING;
9990 }
9991 } else {
9992 bgp = bgp_get_default();
9993 if (bgp == NULL) {
9994 vty_out(vty, "%% No BGP process is configured\n");
9995 return CMD_WARNING;
9996 }
9997 }
9998
9999 /* Check IP address argument. */
10000 ret = str2prefix(ip_str, &match);
10001 if (!ret) {
10002 vty_out(vty, "%% address is malformed\n");
10003 return CMD_WARNING;
10004 }
10005
10006 match.family = afi2family(afi);
10007 rib = bgp->rib[afi][safi];
10008
10009 if (safi == SAFI_MPLS_VPN) {
9bcb3eef
DS
10010 for (dest = bgp_table_top(rib); dest;
10011 dest = bgp_route_next(dest)) {
10012 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 10013
9bcb3eef 10014 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
d62a17ae 10015 continue;
10016
9bcb3eef 10017 table = bgp_dest_get_bgp_table_info(dest);
b54892e0
DS
10018 if (table == NULL)
10019 continue;
10020
4953391b
DA
10021 rm = bgp_node_match(table, &match);
10022 if (rm != NULL) {
b54892e0 10023 const struct prefix *rm_p =
9bcb3eef 10024 bgp_dest_get_prefix(rm);
b54892e0
DS
10025
10026 if (rm_p->prefixlen == match.prefixlen) {
10027 SET_FLAG(rm->flags,
10028 BGP_NODE_USER_CLEAR);
10029 bgp_process(bgp, rm, afi, safi);
d62a17ae 10030 }
9bcb3eef 10031 bgp_dest_unlock_node(rm);
d62a17ae 10032 }
10033 }
10034 } else {
4953391b
DA
10035 dest = bgp_node_match(rib, &match);
10036 if (dest != NULL) {
9bcb3eef 10037 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 10038
9bcb3eef
DS
10039 if (dest_p->prefixlen == match.prefixlen) {
10040 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
10041 bgp_process(bgp, dest, afi, safi);
d62a17ae 10042 }
9bcb3eef 10043 bgp_dest_unlock_node(dest);
d62a17ae 10044 }
10045 }
10046
10047 return CMD_SUCCESS;
8ad7271d
DS
10048}
10049
b09b5ae0 10050/* one clear bgp command to rule them all */
718e3744 10051DEFUN (clear_ip_bgp_all,
10052 clear_ip_bgp_all_cmd,
3cb14f26 10053 "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 10054 CLEAR_STR
10055 IP_STR
10056 BGP_STR
838758ac 10057 BGP_INSTANCE_HELP_STR
510afcd6 10058 BGP_AFI_HELP_STR
00e6edb9 10059 BGP_AF_STR
510afcd6 10060 BGP_SAFI_WITH_LABEL_HELP_STR
00e6edb9 10061 BGP_AF_MODIFIER_STR
b09b5ae0 10062 "Clear all peers\n"
453c92f6 10063 "BGP IPv4 neighbor to clear\n"
a80beece 10064 "BGP IPv6 neighbor to clear\n"
838758ac 10065 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
10066 "Clear peers with the AS number\n"
10067 "Clear all external peers\n"
718e3744 10068 "Clear all members of peer-group\n"
b09b5ae0 10069 "BGP peer-group name\n"
b09b5ae0
DW
10070 BGP_SOFT_STR
10071 BGP_SOFT_IN_STR
b09b5ae0
DW
10072 BGP_SOFT_OUT_STR
10073 BGP_SOFT_IN_STR
10074 "Push out prefix-list ORF and do inbound soft reconfig\n"
3cb14f26
DS
10075 BGP_SOFT_OUT_STR
10076 "Reset message statistics\n")
718e3744 10077{
d62a17ae 10078 char *vrf = NULL;
10079
dc912615
DS
10080 afi_t afi = AFI_UNSPEC;
10081 safi_t safi = SAFI_UNSPEC;
d62a17ae 10082 enum clear_sort clr_sort = clear_peer;
10083 enum bgp_clear_type clr_type;
10084 char *clr_arg = NULL;
10085
10086 int idx = 0;
10087
10088 /* clear [ip] bgp */
10089 if (argv_find(argv, argc, "ip", &idx))
10090 afi = AFI_IP;
10091
9a8bdf1c
PG
10092 /* [<vrf> VIEWVRFNAME] */
10093 if (argv_find(argv, argc, "vrf", &idx)) {
10094 vrf = argv[idx + 1]->arg;
10095 idx += 2;
10096 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10097 vrf = NULL;
10098 } else if (argv_find(argv, argc, "view", &idx)) {
10099 /* [<view> VIEWVRFNAME] */
d62a17ae 10100 vrf = argv[idx + 1]->arg;
10101 idx += 2;
10102 }
d62a17ae 10103 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
10104 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
10105 argv_find_and_parse_safi(argv, argc, &idx, &safi);
10106
d7b9898c 10107 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
d62a17ae 10108 if (argv_find(argv, argc, "*", &idx)) {
10109 clr_sort = clear_all;
10110 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
10111 clr_sort = clear_peer;
10112 clr_arg = argv[idx]->arg;
10113 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
10114 clr_sort = clear_peer;
10115 clr_arg = argv[idx]->arg;
10116 } else if (argv_find(argv, argc, "peer-group", &idx)) {
10117 clr_sort = clear_group;
10118 idx++;
10119 clr_arg = argv[idx]->arg;
d7b9898c 10120 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
d62a17ae 10121 clr_sort = clear_peer;
10122 clr_arg = argv[idx]->arg;
8fa7d444
DS
10123 } else if (argv_find(argv, argc, "WORD", &idx)) {
10124 clr_sort = clear_peer;
10125 clr_arg = argv[idx]->arg;
d62a17ae 10126 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
10127 clr_sort = clear_as;
10128 clr_arg = argv[idx]->arg;
10129 } else if (argv_find(argv, argc, "external", &idx)) {
10130 clr_sort = clear_external;
10131 }
10132
3cb14f26 10133 /* [<soft [<in|out>]|in [prefix-filter]|out|message-stats>] */
d62a17ae 10134 if (argv_find(argv, argc, "soft", &idx)) {
10135 if (argv_find(argv, argc, "in", &idx)
10136 || argv_find(argv, argc, "out", &idx))
10137 clr_type = strmatch(argv[idx]->text, "in")
10138 ? BGP_CLEAR_SOFT_IN
10139 : BGP_CLEAR_SOFT_OUT;
10140 else
10141 clr_type = BGP_CLEAR_SOFT_BOTH;
10142 } else if (argv_find(argv, argc, "in", &idx)) {
10143 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
10144 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
10145 : BGP_CLEAR_SOFT_IN;
10146 } else if (argv_find(argv, argc, "out", &idx)) {
10147 clr_type = BGP_CLEAR_SOFT_OUT;
3cb14f26
DS
10148 } else if (argv_find(argv, argc, "message-stats", &idx)) {
10149 clr_type = BGP_CLEAR_MESSAGE_STATS;
d62a17ae 10150 } else
10151 clr_type = BGP_CLEAR_SOFT_NONE;
10152
1ca2fd11 10153 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 10154}
01080f7c 10155
8ad7271d
DS
10156DEFUN (clear_ip_bgp_prefix,
10157 clear_ip_bgp_prefix_cmd,
18c57037 10158 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
10159 CLEAR_STR
10160 IP_STR
10161 BGP_STR
838758ac 10162 BGP_INSTANCE_HELP_STR
8ad7271d 10163 "Clear bestpath and re-advertise\n"
0c7b1b01 10164 "IPv4 prefix\n")
8ad7271d 10165{
d62a17ae 10166 char *vrf = NULL;
10167 char *prefix = NULL;
8ad7271d 10168
d62a17ae 10169 int idx = 0;
01080f7c 10170
d62a17ae 10171 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
10172 if (argv_find(argv, argc, "vrf", &idx)) {
10173 vrf = argv[idx + 1]->arg;
10174 idx += 2;
10175 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10176 vrf = NULL;
10177 } else if (argv_find(argv, argc, "view", &idx)) {
10178 /* [<view> VIEWVRFNAME] */
10179 vrf = argv[idx + 1]->arg;
10180 idx += 2;
10181 }
0c7b1b01 10182
d62a17ae 10183 prefix = argv[argc - 1]->arg;
8ad7271d 10184
d62a17ae 10185 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 10186}
8ad7271d 10187
b09b5ae0
DW
10188DEFUN (clear_bgp_ipv6_safi_prefix,
10189 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 10190 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 10191 CLEAR_STR
3a2d747c 10192 IP_STR
718e3744 10193 BGP_STR
00e6edb9 10194 BGP_AF_STR
46f296b4 10195 BGP_SAFI_HELP_STR
b09b5ae0 10196 "Clear bestpath and re-advertise\n"
0c7b1b01 10197 "IPv6 prefix\n")
718e3744 10198{
9b475e76
PG
10199 int idx_safi = 0;
10200 int idx_ipv6_prefix = 0;
10201 safi_t safi = SAFI_UNICAST;
10202 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10203 argv[idx_ipv6_prefix]->arg : NULL;
10204
10205 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 10206 return bgp_clear_prefix(
9b475e76
PG
10207 vty, NULL, prefix, AFI_IP6,
10208 safi, NULL);
838758ac 10209}
01080f7c 10210
b09b5ae0
DW
10211DEFUN (clear_bgp_instance_ipv6_safi_prefix,
10212 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 10213 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 10214 CLEAR_STR
3a2d747c 10215 IP_STR
718e3744 10216 BGP_STR
838758ac 10217 BGP_INSTANCE_HELP_STR
00e6edb9 10218 BGP_AF_STR
46f296b4 10219 BGP_SAFI_HELP_STR
b09b5ae0 10220 "Clear bestpath and re-advertise\n"
0c7b1b01 10221 "IPv6 prefix\n")
718e3744 10222{
9b475e76 10223 int idx_safi = 0;
9a8bdf1c 10224 int idx_vrfview = 0;
9b475e76
PG
10225 int idx_ipv6_prefix = 0;
10226 safi_t safi = SAFI_UNICAST;
10227 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10228 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 10229 char *vrfview = NULL;
9b475e76 10230
9a8bdf1c
PG
10231 /* [<view|vrf> VIEWVRFNAME] */
10232 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
10233 vrfview = argv[idx_vrfview + 1]->arg;
10234 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
10235 vrfview = NULL;
10236 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
10237 /* [<view> VIEWVRFNAME] */
10238 vrfview = argv[idx_vrfview + 1]->arg;
10239 }
9b475e76
PG
10240 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10241
d62a17ae 10242 return bgp_clear_prefix(
9b475e76
PG
10243 vty, vrfview, prefix,
10244 AFI_IP6, safi, NULL);
718e3744 10245}
10246
b09b5ae0
DW
10247DEFUN (show_bgp_views,
10248 show_bgp_views_cmd,
d6e3c605 10249 "show [ip] bgp views",
b09b5ae0 10250 SHOW_STR
d6e3c605 10251 IP_STR
01080f7c 10252 BGP_STR
b09b5ae0 10253 "Show the defined BGP views\n")
01080f7c 10254{
d62a17ae 10255 struct list *inst = bm->bgp;
10256 struct listnode *node;
10257 struct bgp *bgp;
01080f7c 10258
d62a17ae 10259 vty_out(vty, "Defined BGP views:\n");
10260 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10261 /* Skip VRFs. */
10262 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
10263 continue;
10264 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
10265 bgp->as);
10266 }
e52702f2 10267
d62a17ae 10268 return CMD_SUCCESS;
e0081f70
ML
10269}
10270
4acd6bc9
SPG
10271static inline void calc_peers_cfgd_estbd(struct bgp *bgp, int *peers_cfgd,
10272 int *peers_estbd)
10273{
10274 struct peer *peer;
10275 struct listnode *node;
10276
10277 *peers_cfgd = *peers_estbd = 0;
10278 for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer)) {
10279 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10280 continue;
10281 (*peers_cfgd)++;
10282 if (peer_established(peer))
10283 (*peers_estbd)++;
10284 }
10285}
10286
10287static void print_bgp_vrfs(struct bgp *bgp, struct vty *vty, json_object *json,
10288 const char *type)
10289{
10290 int peers_cfg, peers_estb;
10291
10292 calc_peers_cfgd_estbd(bgp, &peers_cfg, &peers_estb);
10293
10294 if (json) {
10295 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10296 ? -1
10297 : (int64_t)bgp->vrf_id;
10298 json_object_string_add(json, "type", type);
10299 json_object_int_add(json, "vrfId", vrf_id_ui);
10300 json_object_string_addf(json, "routerId", "%pI4",
10301 &bgp->router_id);
10302 json_object_int_add(json, "numConfiguredPeers", peers_cfg);
10303 json_object_int_add(json, "numEstablishedPeers", peers_estb);
10304 json_object_int_add(json, "l3vni", bgp->l3vni);
10305 json_object_string_addf(json, "rmac", "%pEA", &bgp->rmac);
10306 json_object_string_add(
10307 json, "interface",
10308 ifindex2ifname(bgp->l3vni_svi_ifindex, bgp->vrf_id));
10309 }
10310}
10311
10312static int show_bgp_vrfs_detail_common(struct vty *vty, struct bgp *bgp,
10313 json_object *json, const char *name,
10314 const char *type, bool use_vrf)
10315{
10316 int peers_cfg, peers_estb;
10317
10318 calc_peers_cfgd_estbd(bgp, &peers_cfg, &peers_estb);
10319
10320 if (use_vrf) {
10321 if (json) {
10322 print_bgp_vrfs(bgp, vty, json, type);
10323 } else {
10324 vty_out(vty, "BGP instance %s VRF id %d\n",
10325 bgp->name_pretty,
10326 bgp->vrf_id == VRF_UNKNOWN ? -1
10327 : (int)bgp->vrf_id);
10328 vty_out(vty, "Router Id %pI4\n", &bgp->router_id);
10329 vty_out(vty,
10330 "Num Configured Peers %d, Established %d\n",
10331 peers_cfg, peers_estb);
10332 if (bgp->l3vni) {
10333 vty_out(vty,
10334 "L3VNI %u, L3VNI-SVI %s, Router MAC %pEA\n",
10335 bgp->l3vni,
10336 ifindex2ifname(bgp->l3vni_svi_ifindex,
10337 bgp->vrf_id),
10338 &bgp->rmac);
10339 }
10340 }
10341 } else {
10342 if (json) {
10343 print_bgp_vrfs(bgp, vty, json, type);
10344 } else {
10345 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
10346 type,
10347 bgp->vrf_id == VRF_UNKNOWN ? -1
10348 : (int)bgp->vrf_id,
10349 &bgp->router_id, peers_cfg, peers_estb, name);
10350 vty_out(vty, "%11s %-16u %-21pEA %-20s\n", " ",
10351 bgp->l3vni, &bgp->rmac,
10352 ifindex2ifname(bgp->l3vni_svi_ifindex,
10353 bgp->vrf_id));
10354 }
10355 }
10356
10357 return CMD_SUCCESS;
10358}
10359
10360DEFPY (show_bgp_vrfs,
8386ac43 10361 show_bgp_vrfs_cmd,
4acd6bc9 10362 "show [ip] bgp vrfs [<VRFNAME$vrf_name>] [json]",
8386ac43 10363 SHOW_STR
d6e3c605 10364 IP_STR
8386ac43 10365 BGP_STR
10366 "Show BGP VRFs\n"
4acd6bc9 10367 "Specific VRF name\n"
9973d184 10368 JSON_STR)
8386ac43 10369{
d62a17ae 10370 struct list *inst = bm->bgp;
10371 struct listnode *node;
10372 struct bgp *bgp;
9f049418 10373 bool uj = use_json(argc, argv);
d62a17ae 10374 json_object *json = NULL;
10375 json_object *json_vrfs = NULL;
4acd6bc9 10376 json_object *json_vrf = NULL;
d62a17ae 10377 int count = 0;
4acd6bc9
SPG
10378 const char *name = vrf_name;
10379 const char *type;
d62a17ae 10380
4acd6bc9 10381 if (uj)
d62a17ae 10382 json = json_object_new_object();
4acd6bc9
SPG
10383
10384 if (name) {
10385 if (strmatch(name, VRF_DEFAULT_NAME)) {
10386 bgp = bgp_get_default();
10387 type = "DFLT";
10388 } else {
10389 bgp = bgp_lookup_by_name(name);
10390 type = "VRF";
10391 }
10392 if (!bgp) {
10393 if (uj)
10394 vty_json(vty, json);
10395 else
10396 vty_out(vty,
10397 "%% Specified BGP instance not found\n");
10398
10399 return CMD_WARNING;
10400 }
10401 }
10402
10403 if (vrf_name) {
10404 if (uj)
10405 json_vrf = json_object_new_object();
10406
10407 show_bgp_vrfs_detail_common(vty, bgp, json_vrf, name, type,
10408 true);
10409
10410 if (uj) {
10411 json_object_object_add(json, name, json_vrf);
10412 vty_json(vty, json);
10413 }
10414
10415 return CMD_SUCCESS;
d62a17ae 10416 }
10417
4acd6bc9
SPG
10418 if (uj)
10419 json_vrfs = json_object_new_object();
10420
d62a17ae 10421 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
4acd6bc9 10422 const char *name;
d62a17ae 10423
10424 /* Skip Views. */
10425 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
10426 continue;
10427
10428 count++;
efb4077a 10429 if (!uj && count == 1) {
fe1dc5a3 10430 vty_out(vty,
efb4077a 10431 "%4s %-5s %-16s %9s %10s %-37s\n",
3c0e7aa4 10432 "Type", "Id", "routerId", "#PeersCfg",
efb4077a
CS
10433 "#PeersEstb", "Name");
10434 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
10435 "L3-VNI", "RouterMAC", "Interface");
10436 }
d62a17ae 10437 if (uj)
10438 json_vrf = json_object_new_object();
10439
d62a17ae 10440 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
5742e42b 10441 name = VRF_DEFAULT_NAME;
d62a17ae 10442 type = "DFLT";
10443 } else {
10444 name = bgp->name;
10445 type = "VRF";
10446 }
10447
4acd6bc9
SPG
10448 show_bgp_vrfs_detail_common(vty, bgp, json_vrf, name, type,
10449 false);
a8bf7d9c 10450
4acd6bc9 10451 if (uj)
d62a17ae 10452 json_object_object_add(json_vrfs, name, json_vrf);
d62a17ae 10453 }
10454
10455 if (uj) {
10456 json_object_object_add(json, "vrfs", json_vrfs);
d62a17ae 10457 json_object_int_add(json, "totalVrfs", count);
75eeda93 10458 vty_json(vty, json);
d62a17ae 10459 } else {
10460 if (count)
10461 vty_out(vty,
10462 "\nTotal number of VRFs (including default): %d\n",
10463 count);
10464 }
10465
10466 return CMD_SUCCESS;
8386ac43 10467}
10468
48ecf8f5
DS
10469DEFUN (show_bgp_mac_hash,
10470 show_bgp_mac_hash_cmd,
10471 "show bgp mac hash",
10472 SHOW_STR
10473 BGP_STR
10474 "Mac Address\n"
10475 "Mac Address database\n")
10476{
10477 bgp_mac_dump_table(vty);
10478
10479 return CMD_SUCCESS;
10480}
acf71666 10481
e3b78da8 10482static void show_tip_entry(struct hash_bucket *bucket, void *args)
acf71666 10483{
0291c246 10484 struct vty *vty = (struct vty *)args;
e3b78da8 10485 struct tip_addr *tip = (struct tip_addr *)bucket->data;
acf71666 10486
23d0a753 10487 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
acf71666
MK
10488}
10489
10490static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10491{
10492 vty_out(vty, "self nexthop database:\n");
af97a18b 10493 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
10494
10495 vty_out(vty, "Tunnel-ip database:\n");
10496 hash_iterate(bgp->tip_hash,
e3b78da8 10497 (void (*)(struct hash_bucket *, void *))show_tip_entry,
acf71666
MK
10498 vty);
10499}
10500
15c81ca4
DS
10501DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10502 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10503 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
10504 "martian next-hops\n"
10505 "martian next-hop database\n")
acf71666 10506{
0291c246 10507 struct bgp *bgp = NULL;
15c81ca4 10508 int idx = 0;
9a8bdf1c
PG
10509 char *name = NULL;
10510
10511 /* [<vrf> VIEWVRFNAME] */
10512 if (argv_find(argv, argc, "vrf", &idx)) {
10513 name = argv[idx + 1]->arg;
10514 if (name && strmatch(name, VRF_DEFAULT_NAME))
10515 name = NULL;
10516 } else if (argv_find(argv, argc, "view", &idx))
10517 /* [<view> VIEWVRFNAME] */
10518 name = argv[idx + 1]->arg;
10519 if (name)
10520 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
10521 else
10522 bgp = bgp_get_default();
acf71666 10523
acf71666
MK
10524 if (!bgp) {
10525 vty_out(vty, "%% No BGP process is configured\n");
10526 return CMD_WARNING;
10527 }
10528 bgp_show_martian_nexthops(vty, bgp);
10529
10530 return CMD_SUCCESS;
10531}
10532
f412b39a 10533DEFUN (show_bgp_memory,
4bf6a362 10534 show_bgp_memory_cmd,
7fa12b13 10535 "show [ip] bgp memory",
4bf6a362 10536 SHOW_STR
3a2d747c 10537 IP_STR
4bf6a362
PJ
10538 BGP_STR
10539 "Global BGP memory statistics\n")
10540{
d62a17ae 10541 char memstrbuf[MTYPE_MEMSTR_LEN];
10542 unsigned long count;
10543
10544 /* RIB related usage stats */
10545 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10546 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10547 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9bcb3eef 10548 count * sizeof(struct bgp_dest)));
d62a17ae 10549
10550 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10551 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10552 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 10553 count * sizeof(struct bgp_path_info)));
d62a17ae 10554 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10555 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10556 count,
4b7e6066
DS
10557 mtype_memstr(
10558 memstrbuf, sizeof(memstrbuf),
10559 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 10560
10561 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10562 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10563 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10564 count * sizeof(struct bgp_static)));
10565
10566 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10567 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10568 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10569 count * sizeof(struct bpacket)));
10570
10571 /* Adj-In/Out */
10572 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10573 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10574 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10575 count * sizeof(struct bgp_adj_in)));
10576 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10577 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10578 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10579 count * sizeof(struct bgp_adj_out)));
10580
10581 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10582 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10583 count,
10584 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10585 count * sizeof(struct bgp_nexthop_cache)));
10586
10587 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10588 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10589 count,
10590 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10591 count * sizeof(struct bgp_damp_info)));
10592
10593 /* Attributes */
10594 count = attr_count();
10595 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10596 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10597 count * sizeof(struct attr)));
10598
10599 if ((count = attr_unknown_count()))
10600 vty_out(vty, "%ld unknown attributes\n", count);
10601
10602 /* AS_PATH attributes */
10603 count = aspath_count();
10604 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10605 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10606 count * sizeof(struct aspath)));
10607
10608 count = mtype_stats_alloc(MTYPE_AS_SEG);
10609 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10610 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10611 count * sizeof(struct assegment)));
10612
10613 /* Other attributes */
10614 if ((count = community_count()))
10615 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
10616 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10617 count * sizeof(struct community)));
d62a17ae 10618 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
145f7619
DA
10619 vty_out(vty,
10620 "%ld BGP ext-community entries, using %s of memory\n",
10621 count,
10622 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10623 count * sizeof(struct ecommunity)));
d62a17ae 10624 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10625 vty_out(vty,
10626 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
10627 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10628 count * sizeof(struct lcommunity)));
d62a17ae 10629
10630 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10631 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10632 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10633 count * sizeof(struct cluster_list)));
10634
10635 /* Peer related usage */
10636 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10637 vty_out(vty, "%ld peers, using %s of memory\n", count,
10638 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10639 count * sizeof(struct peer)));
10640
10641 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10642 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10643 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10644 count * sizeof(struct peer_group)));
10645
10646 /* Other */
d62a17ae 10647 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10648 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
10649 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10650 count * sizeof(regex_t)));
d62a17ae 10651 return CMD_SUCCESS;
4bf6a362 10652}
fee0f4c6 10653
57a9c8a8
DS
10654static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10655{
10656 json_object *bestpath = json_object_new_object();
10657
892fedb6 10658 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
57a9c8a8
DS
10659 json_object_string_add(bestpath, "asPath", "ignore");
10660
892fedb6 10661 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
57a9c8a8
DS
10662 json_object_string_add(bestpath, "asPath", "confed");
10663
892fedb6
DA
10664 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10665 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
a4d82a8a 10666 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
10667 "as-set");
10668 else
a4d82a8a 10669 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
10670 "true");
10671 } else
a4d82a8a 10672 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8 10673
ee88563a
JM
10674 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
10675 json_object_boolean_true_add(bestpath, "peerTypeRelax");
10676
892fedb6 10677 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
57a9c8a8 10678 json_object_string_add(bestpath, "compareRouterId", "true");
892fedb6
DA
10679 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10680 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10681 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
a4d82a8a 10682 json_object_string_add(bestpath, "med", "confed");
892fedb6 10683 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
57a9c8a8
DS
10684 json_object_string_add(bestpath, "med",
10685 "missing-as-worst");
10686 else
10687 json_object_string_add(bestpath, "med", "true");
10688 }
10689
10690 json_object_object_add(json, "bestPath", bestpath);
10691}
10692
3577f1c5
DD
10693/* Print the error code/subcode for why the peer is down */
10694static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10695 json_object *json_peer, bool use_json)
10696{
10697 const char *code_str;
10698 const char *subcode_str;
10699
10700 if (use_json) {
10701 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10702 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10703 char errorcodesubcode_hexstr[5];
10704 char errorcodesubcode_str[256];
10705
10706 code_str = bgp_notify_code_str(peer->notify.code);
10707 subcode_str = bgp_notify_subcode_str(
10708 peer->notify.code,
10709 peer->notify.subcode);
10710
772270f3
QY
10711 snprintf(errorcodesubcode_hexstr,
10712 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10713 peer->notify.code, peer->notify.subcode);
3577f1c5
DD
10714 json_object_string_add(json_peer,
10715 "lastErrorCodeSubcode",
10716 errorcodesubcode_hexstr);
10717 snprintf(errorcodesubcode_str, 255, "%s%s",
10718 code_str, subcode_str);
10719 json_object_string_add(json_peer,
10720 "lastNotificationReason",
10721 errorcodesubcode_str);
eea685b6
DA
10722 json_object_boolean_add(json_peer,
10723 "lastNotificationHardReset",
10724 peer->notify.hard_reset);
3577f1c5
DD
10725 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10726 && peer->notify.code == BGP_NOTIFY_CEASE
10727 && (peer->notify.subcode
10728 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10729 || peer->notify.subcode
10730 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10731 && peer->notify.length) {
10732 char msgbuf[1024];
10733 const char *msg_str;
10734
10735 msg_str = bgp_notify_admin_message(
10736 msgbuf, sizeof(msgbuf),
10737 (uint8_t *)peer->notify.data,
10738 peer->notify.length);
10739 if (msg_str)
10740 json_object_string_add(
10741 json_peer,
10742 "lastShutdownDescription",
10743 msg_str);
10744 }
10745
c258527b 10746 }
3577f1c5
DD
10747 json_object_string_add(json_peer, "lastResetDueTo",
10748 peer_down_str[(int)peer->last_reset]);
05912a17
DD
10749 json_object_int_add(json_peer, "lastResetCode",
10750 peer->last_reset);
3577f1c5
DD
10751 } else {
10752 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10753 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10754 code_str = bgp_notify_code_str(peer->notify.code);
10755 subcode_str =
10756 bgp_notify_subcode_str(peer->notify.code,
10757 peer->notify.subcode);
eea685b6 10758 vty_out(vty, " Notification %s (%s%s%s)\n",
3577f1c5 10759 peer->last_reset == PEER_DOWN_NOTIFY_SEND
eea685b6
DA
10760 ? "sent"
10761 : "received",
10762 code_str, subcode_str,
10763 peer->notify.hard_reset
10764 ? bgp_notify_subcode_str(
10765 BGP_NOTIFY_CEASE,
10766 BGP_NOTIFY_CEASE_HARD_RESET)
10767 : "");
3577f1c5 10768 } else {
e91c24c8 10769 vty_out(vty, " %s\n",
3577f1c5
DD
10770 peer_down_str[(int)peer->last_reset]);
10771 }
10772 }
10773}
10774
10775static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10776 safi_t safi)
10777{
feb17238 10778 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
3577f1c5
DD
10779}
10780
10781static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10782 struct peer *peer, json_object *json_peer,
10783 int max_neighbor_width, bool use_json)
10784{
10785 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10786 int len;
10787
10788 if (use_json) {
10789 if (peer_dynamic_neighbor(peer))
10790 json_object_boolean_true_add(json_peer,
10791 "dynamicPeer");
10792 if (peer->hostname)
10793 json_object_string_add(json_peer, "hostname",
10794 peer->hostname);
10795
10796 if (peer->domainname)
10797 json_object_string_add(json_peer, "domainname",
10798 peer->domainname);
10799 json_object_int_add(json_peer, "connectionsEstablished",
10800 peer->established);
10801 json_object_int_add(json_peer, "connectionsDropped",
10802 peer->dropped);
10803 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10804 use_json, json_peer);
feb17238 10805 if (peer_established(peer))
3577f1c5
DD
10806 json_object_string_add(json_peer, "lastResetDueTo",
10807 "AFI/SAFI Not Negotiated");
10808 else
10809 bgp_show_peer_reset(NULL, peer, json_peer, true);
10810 } else {
10811 dn_flag[1] = '\0';
10812 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10813 if (peer->hostname
892fedb6 10814 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
3577f1c5
DD
10815 len = vty_out(vty, "%s%s(%s)", dn_flag,
10816 peer->hostname, peer->host);
10817 else
10818 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10819
10820 /* pad the neighbor column with spaces */
10821 if (len < max_neighbor_width)
10822 vty_out(vty, "%*s", max_neighbor_width - len,
10823 " ");
e91c24c8 10824 vty_out(vty, "%7d %7d %9s", peer->established,
3577f1c5
DD
10825 peer->dropped,
10826 peer_uptime(peer->uptime, timebuf,
10827 BGP_UPTIME_LEN, 0, NULL));
feb17238 10828 if (peer_established(peer))
3577f1c5
DD
10829 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10830 else
10831 bgp_show_peer_reset(vty, peer, NULL,
10832 false);
10833 }
10834}
c258527b 10835
565e9ddd 10836/* Strip peer's description to the given size. */
cb75bb31
DA
10837static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10838{
10839 static char stripped[BUFSIZ];
64541ffa
FD
10840 uint32_t i = 0;
10841 uint32_t last_space = 0;
cb75bb31 10842
64541ffa
FD
10843 while (i < size) {
10844 if (*(desc + i) == 0) {
10845 stripped[i] = '\0';
10846 return stripped;
10847 }
10848 if (i != 0 && *(desc + i) == ' ' && last_space != i - 1)
10849 last_space = i;
10850 stripped[i] = *(desc + i);
10851 i++;
10852 }
10853
10854 if (last_space > size)
10855 stripped[size + 1] = '\0';
10856 else
10857 stripped[last_space] = '\0';
cb75bb31
DA
10858
10859 return stripped;
10860}
3577f1c5 10861
8c1d4cd5
LS
10862/* Determine whether var peer should be filtered out of the summary. */
10863static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
10864 struct peer *fpeer, int as_type,
10865 as_t as)
10866{
10867
10868 /* filter neighbor XXXX */
10869 if (fpeer && fpeer != peer)
10870 return true;
10871
10872 /* filter remote-as (internal|external) */
10873 if (as_type != AS_UNSPECIFIED) {
10874 if (peer->as_type == AS_SPECIFIED) {
10875 if (as_type == AS_INTERNAL) {
10876 if (peer->as != peer->local_as)
10877 return true;
10878 } else if (peer->as == peer->local_as)
10879 return true;
10880 } else if (as_type != peer->as_type)
10881 return true;
10882 } else if (as && as != peer->as) /* filter remote-as XXX */
10883 return true;
10884
10885 return false;
10886}
10887
565e9ddd
DA
10888/* Show BGP peer's summary information.
10889 *
10890 * Peer's description is stripped according to if `wide` option is given
10891 * or not.
10892 *
10893 * When adding new columns to `show bgp summary` output, please make
10894 * sure `Desc` is the lastest column to show because it can contain
10895 * whitespaces and the whole output will be tricky.
10896 */
d62a17ae 10897static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
8c1d4cd5 10898 struct peer *fpeer, int as_type, as_t as,
96c81f66 10899 uint16_t show_flags)
d62a17ae 10900{
10901 struct peer *peer;
10902 struct listnode *node, *nnode;
10903 unsigned int count = 0, dn_count = 0;
10904 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10905 char neighbor_buf[VTY_BUFSIZ];
10906 int neighbor_col_default_width = 16;
3577f1c5 10907 int len, failed_count = 0;
ce1944f0 10908 unsigned int filtered_count = 0;
d62a17ae 10909 int max_neighbor_width = 0;
10910 int pfx_rcd_safi;
3c13337d 10911 json_object *json = NULL;
d62a17ae 10912 json_object *json_peer = NULL;
10913 json_object *json_peers = NULL;
50e05855 10914 struct peer_af *paf;
d3ada366 10915 struct bgp_filter *filter;
85eeb029
DA
10916 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10917 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10918 bool show_established =
10919 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10920 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
96c81f66 10921 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
d62a17ae 10922
10923 /* labeled-unicast routes are installed in the unicast table so in order
10924 * to
10925 * display the correct PfxRcd value we must look at SAFI_UNICAST
10926 */
3577f1c5 10927
d62a17ae 10928 if (safi == SAFI_LABELED_UNICAST)
10929 pfx_rcd_safi = SAFI_UNICAST;
10930 else
10931 pfx_rcd_safi = safi;
10932
10933 if (use_json) {
3c13337d 10934 json = json_object_new_object();
d62a17ae 10935 json_peers = json_object_new_object();
3577f1c5 10936 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8c1d4cd5
LS
10937 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10938 as_type, as)) {
ce1944f0 10939 filtered_count++;
8c1d4cd5
LS
10940 count++;
10941 continue;
10942 }
10943
3577f1c5
DD
10944 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10945 continue;
10946
10947 if (peer->afc[afi][safi]) {
10948 /* See if we have at least a single failed peer */
10949 if (bgp_has_peer_failed(peer, afi, safi))
10950 failed_count++;
10951 count++;
10952 }
10953 if (peer_dynamic_neighbor(peer))
10954 dn_count++;
10955 }
c258527b 10956
d62a17ae 10957 } else {
10958 /* Loop over all neighbors that will be displayed to determine
10959 * how many
10960 * characters are needed for the Neighbor column
10961 */
10962 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8c1d4cd5
LS
10963 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10964 as_type, as)) {
ce1944f0 10965 filtered_count++;
8c1d4cd5
LS
10966 count++;
10967 continue;
10968 }
10969
d62a17ae 10970 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10971 continue;
10972
10973 if (peer->afc[afi][safi]) {
10974 memset(dn_flag, '\0', sizeof(dn_flag));
10975 if (peer_dynamic_neighbor(peer))
10976 dn_flag[0] = '*';
10977
10978 if (peer->hostname
892fedb6
DA
10979 && CHECK_FLAG(bgp->flags,
10980 BGP_FLAG_SHOW_HOSTNAME))
772270f3
QY
10981 snprintf(neighbor_buf,
10982 sizeof(neighbor_buf),
10983 "%s%s(%s) ", dn_flag,
10984 peer->hostname, peer->host);
d62a17ae 10985 else
772270f3
QY
10986 snprintf(neighbor_buf,
10987 sizeof(neighbor_buf), "%s%s ",
10988 dn_flag, peer->host);
d62a17ae 10989
10990 len = strlen(neighbor_buf);
10991
10992 if (len > max_neighbor_width)
10993 max_neighbor_width = len;
c258527b 10994
3577f1c5
DD
10995 /* See if we have at least a single failed peer */
10996 if (bgp_has_peer_failed(peer, afi, safi))
10997 failed_count++;
10998 count++;
d62a17ae 10999 }
11000 }
f933309e 11001
d62a17ae 11002 /* Originally we displayed the Neighbor column as 16
11003 * characters wide so make that the default
11004 */
11005 if (max_neighbor_width < neighbor_col_default_width)
11006 max_neighbor_width = neighbor_col_default_width;
11007 }
f933309e 11008
3577f1c5
DD
11009 if (show_failed && !failed_count) {
11010 if (use_json) {
11011 json_object_int_add(json, "failedPeersCount", 0);
11012 json_object_int_add(json, "dynamicPeers", dn_count);
c258527b 11013 json_object_int_add(json, "totalPeers", count);
3577f1c5 11014
75eeda93 11015 vty_json(vty, json);
3577f1c5
DD
11016 } else {
11017 vty_out(vty, "%% No failed BGP neighbors found\n");
3577f1c5
DD
11018 }
11019 return CMD_SUCCESS;
11020 }
c258527b 11021
3577f1c5 11022 count = 0; /* Reset the value as its used again */
ce1944f0 11023 filtered_count = 0;
800867d8 11024 dn_count = 0;
d62a17ae 11025 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
11026 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11027 continue;
11028
ea47320b
DL
11029 if (!peer->afc[afi][safi])
11030 continue;
d62a17ae 11031
ea47320b
DL
11032 if (!count) {
11033 unsigned long ents;
11034 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 11035 int64_t vrf_id_ui;
d62a17ae 11036
a4d82a8a
PZ
11037 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
11038 ? -1
11039 : (int64_t)bgp->vrf_id;
ea47320b
DL
11040
11041 /* Usage summary and header */
11042 if (use_json) {
c949c771
DA
11043 json_object_string_addf(json, "routerId",
11044 "%pI4",
11045 &bgp->router_id);
60466a63
QY
11046 json_object_int_add(json, "as", bgp->as);
11047 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
11048 json_object_string_add(
11049 json, "vrfName",
11050 (bgp->inst_type
11051 == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11052 ? VRF_DEFAULT_NAME
ea47320b
DL
11053 : bgp->name);
11054 } else {
11055 vty_out(vty,
23d0a753
DA
11056 "BGP router identifier %pI4, local AS number %u vrf-id %d",
11057 &bgp->router_id, bgp->as,
a4d82a8a
PZ
11058 bgp->vrf_id == VRF_UNKNOWN
11059 ? -1
11060 : (int)bgp->vrf_id);
ea47320b
DL
11061 vty_out(vty, "\n");
11062 }
d62a17ae 11063
ea47320b 11064 if (bgp_update_delay_configured(bgp)) {
d62a17ae 11065 if (use_json) {
ea47320b 11066 json_object_int_add(
60466a63 11067 json, "updateDelayLimit",
ea47320b 11068 bgp->v_update_delay);
d62a17ae 11069
ea47320b
DL
11070 if (bgp->v_update_delay
11071 != bgp->v_establish_wait)
d62a17ae 11072 json_object_int_add(
11073 json,
ea47320b
DL
11074 "updateDelayEstablishWait",
11075 bgp->v_establish_wait);
d62a17ae 11076
60466a63 11077 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
11078 json_object_string_add(
11079 json,
11080 "updateDelayFirstNeighbor",
11081 bgp->update_delay_begin_time);
11082 json_object_boolean_true_add(
11083 json,
11084 "updateDelayInProgress");
11085 } else {
11086 if (bgp->update_delay_over) {
d62a17ae 11087 json_object_string_add(
11088 json,
11089 "updateDelayFirstNeighbor",
11090 bgp->update_delay_begin_time);
ea47320b 11091 json_object_string_add(
d62a17ae 11092 json,
ea47320b
DL
11093 "updateDelayBestpathResumed",
11094 bgp->update_delay_end_time);
11095 json_object_string_add(
d62a17ae 11096 json,
ea47320b
DL
11097 "updateDelayZebraUpdateResume",
11098 bgp->update_delay_zebra_resume_time);
11099 json_object_string_add(
11100 json,
11101 "updateDelayPeerUpdateResume",
11102 bgp->update_delay_peers_resume_time);
d62a17ae 11103 }
ea47320b
DL
11104 }
11105 } else {
11106 vty_out(vty,
11107 "Read-only mode update-delay limit: %d seconds\n",
11108 bgp->v_update_delay);
11109 if (bgp->v_update_delay
11110 != bgp->v_establish_wait)
d62a17ae 11111 vty_out(vty,
ea47320b
DL
11112 " Establish wait: %d seconds\n",
11113 bgp->v_establish_wait);
d62a17ae 11114
60466a63 11115 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
11116 vty_out(vty,
11117 " First neighbor established: %s\n",
11118 bgp->update_delay_begin_time);
11119 vty_out(vty,
11120 " Delay in progress\n");
11121 } else {
11122 if (bgp->update_delay_over) {
d62a17ae 11123 vty_out(vty,
11124 " First neighbor established: %s\n",
11125 bgp->update_delay_begin_time);
11126 vty_out(vty,
ea47320b
DL
11127 " Best-paths resumed: %s\n",
11128 bgp->update_delay_end_time);
11129 vty_out(vty,
11130 " zebra update resumed: %s\n",
11131 bgp->update_delay_zebra_resume_time);
11132 vty_out(vty,
11133 " peers update resumed: %s\n",
11134 bgp->update_delay_peers_resume_time);
d62a17ae 11135 }
11136 }
11137 }
ea47320b 11138 }
d62a17ae 11139
ea47320b
DL
11140 if (use_json) {
11141 if (bgp_maxmed_onstartup_configured(bgp)
11142 && bgp->maxmed_active)
11143 json_object_boolean_true_add(
60466a63 11144 json, "maxMedOnStartup");
ea47320b
DL
11145 if (bgp->v_maxmed_admin)
11146 json_object_boolean_true_add(
60466a63 11147 json, "maxMedAdministrative");
d62a17ae 11148
ea47320b
DL
11149 json_object_int_add(
11150 json, "tableVersion",
60466a63 11151 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 11152
60466a63
QY
11153 ents = bgp_table_count(bgp->rib[afi][safi]);
11154 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
11155 json_object_int_add(
11156 json, "ribMemory",
9bcb3eef 11157 ents * sizeof(struct bgp_dest));
d62a17ae 11158
210ec2a0 11159 ents = bgp->af_peer_count[afi][safi];
60466a63
QY
11160 json_object_int_add(json, "peerCount", ents);
11161 json_object_int_add(json, "peerMemory",
11162 ents * sizeof(struct peer));
d62a17ae 11163
ea47320b
DL
11164 if ((ents = listcount(bgp->group))) {
11165 json_object_int_add(
60466a63 11166 json, "peerGroupCount", ents);
ea47320b
DL
11167 json_object_int_add(
11168 json, "peerGroupMemory",
996c9314
LB
11169 ents * sizeof(struct
11170 peer_group));
ea47320b 11171 }
d62a17ae 11172
ea47320b
DL
11173 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11174 BGP_CONFIG_DAMPENING))
11175 json_object_boolean_true_add(
60466a63 11176 json, "dampeningEnabled");
ea47320b 11177 } else {
96c81f66
LS
11178 if (!show_terse) {
11179 if (bgp_maxmed_onstartup_configured(bgp)
11180 && bgp->maxmed_active)
11181 vty_out(vty,
11182 "Max-med on-startup active\n");
11183 if (bgp->v_maxmed_admin)
11184 vty_out(vty,
11185 "Max-med administrative active\n");
d62a17ae 11186
96c81f66
LS
11187 vty_out(vty,
11188 "BGP table version %" PRIu64
11189 "\n",
11190 bgp_table_version(
11191 bgp->rib[afi][safi]));
ea47320b 11192
96c81f66
LS
11193 ents = bgp_table_count(
11194 bgp->rib[afi][safi]);
d62a17ae 11195 vty_out(vty,
96c81f66 11196 "RIB entries %ld, using %s of memory\n",
d62a17ae 11197 ents,
11198 mtype_memstr(
11199 memstrbuf,
11200 sizeof(memstrbuf),
96c81f66
LS
11201 ents
11202 * sizeof(
11203 struct
11204 bgp_dest)));
d62a17ae 11205
96c81f66
LS
11206 /* Peer related usage */
11207 ents = bgp->af_peer_count[afi][safi];
11208 vty_out(vty,
11209 "Peers %ld, using %s of memory\n",
11210 ents,
11211 mtype_memstr(
11212 memstrbuf,
11213 sizeof(memstrbuf),
11214 ents
11215 * sizeof(
11216 struct
11217 peer)));
d62a17ae 11218
96c81f66
LS
11219 if ((ents = listcount(bgp->group)))
11220 vty_out(vty,
11221 "Peer groups %ld, using %s of memory\n",
11222 ents,
11223 mtype_memstr(
11224 memstrbuf,
11225 sizeof(memstrbuf),
11226 ents
11227 * sizeof(
11228 struct
11229 peer_group)));
11230
11231 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11232 BGP_CONFIG_DAMPENING))
11233 vty_out(vty,
11234 "Dampening enabled.\n");
11235 }
11236 if (show_failed) {
11237 vty_out(vty, "\n");
11238
11239 /* Subtract 8 here because 'Neighbor' is
11240 * 8 characters */
11241 vty_out(vty, "Neighbor");
11242 vty_out(vty, "%*s",
11243 max_neighbor_width - 8, " ");
85eeb029
DA
11244 vty_out(vty,
11245 BGP_SHOW_SUMMARY_HEADER_FAILED);
96c81f66 11246 }
d62a17ae 11247 }
ea47320b 11248 }
d62a17ae 11249
d55811cc 11250 paf = peer_af_find(peer, afi, safi);
d3ada366 11251 filter = &peer->filter[afi][safi];
db92d226 11252
ea47320b 11253 count++;
3577f1c5
DD
11254 /* Works for both failed & successful cases */
11255 if (peer_dynamic_neighbor(peer))
11256 dn_count++;
d62a17ae 11257
ea47320b 11258 if (use_json) {
3577f1c5 11259 json_peer = NULL;
8c1d4cd5 11260 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
ce1944f0
LS
11261 as_type, as)) {
11262 filtered_count++;
8c1d4cd5 11263 continue;
ce1944f0 11264 }
3577f1c5
DD
11265 if (show_failed &&
11266 bgp_has_peer_failed(peer, afi, safi)) {
11267 json_peer = json_object_new_object();
11268 bgp_show_failed_summary(vty, bgp, peer,
11269 json_peer, 0, use_json);
11270 } else if (!show_failed) {
10b49f14 11271 if (show_established
ce1944f0
LS
11272 && bgp_has_peer_failed(peer, afi, safi)) {
11273 filtered_count++;
10b49f14 11274 continue;
ce1944f0 11275 }
10b49f14 11276
3577f1c5
DD
11277 json_peer = json_object_new_object();
11278 if (peer_dynamic_neighbor(peer)) {
11279 json_object_boolean_true_add(json_peer,
11280 "dynamicPeer");
11281 }
d62a17ae 11282
3577f1c5
DD
11283 if (peer->hostname)
11284 json_object_string_add(json_peer, "hostname",
11285 peer->hostname);
11286
11287 if (peer->domainname)
11288 json_object_string_add(json_peer, "domainname",
11289 peer->domainname);
11290
11291 json_object_int_add(json_peer, "remoteAs", peer->as);
c854765f
DA
11292 json_object_int_add(
11293 json_peer, "localAs",
11294 peer->change_local_as
11295 ? peer->change_local_as
11296 : peer->local_as);
3577f1c5
DD
11297 json_object_int_add(json_peer, "version", 4);
11298 json_object_int_add(json_peer, "msgRcvd",
11299 PEER_TOTAL_RX(peer));
11300 json_object_int_add(json_peer, "msgSent",
11301 PEER_TOTAL_TX(peer));
11302
43aa5965
QY
11303 atomic_size_t outq_count, inq_count;
11304 outq_count = atomic_load_explicit(
11305 &peer->obuf->count,
11306 memory_order_relaxed);
11307 inq_count = atomic_load_explicit(
11308 &peer->ibuf->count,
11309 memory_order_relaxed);
11310
3577f1c5
DD
11311 json_object_int_add(json_peer, "tableVersion",
11312 peer->version[afi][safi]);
11313 json_object_int_add(json_peer, "outq",
43aa5965
QY
11314 outq_count);
11315 json_object_int_add(json_peer, "inq",
11316 inq_count);
3577f1c5
DD
11317 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
11318 use_json, json_peer);
11319
3577f1c5
DD
11320 json_object_int_add(json_peer, "pfxRcd",
11321 peer->pcount[afi][pfx_rcd_safi]);
11322
3577f1c5 11323 if (paf && PAF_SUBGRP(paf))
a616dd1f
DA
11324 json_object_int_add(
11325 json_peer, "pfxSnt",
11326 (PAF_SUBGRP(paf))->scount);
11327 else
11328 json_object_int_add(json_peer, "pfxSnt",
11329 0);
0e1f8ab5
DA
11330
11331 /* BGP FSM state */
cb9196e7 11332 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
736b68f3
DS
11333 || CHECK_FLAG(peer->bgp->flags,
11334 BGP_FLAG_SHUTDOWN))
0e1f8ab5
DA
11335 json_object_string_add(json_peer,
11336 "state",
3577f1c5
DD
11337 "Idle (Admin)");
11338 else if (peer->afc_recv[afi][safi])
11339 json_object_string_add(
0e1f8ab5
DA
11340 json_peer, "state",
11341 lookup_msg(bgp_status_msg,
11342 peer->status, NULL));
11343 else if (CHECK_FLAG(
11344 peer->sflags,
11345 PEER_STATUS_PREFIX_OVERFLOW))
11346 json_object_string_add(json_peer,
11347 "state",
3577f1c5
DD
11348 "Idle (PfxCt)");
11349 else
11350 json_object_string_add(
0e1f8ab5
DA
11351 json_peer, "state",
11352 lookup_msg(bgp_status_msg,
11353 peer->status, NULL));
11354
11355 /* BGP peer state */
11356 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11357 || CHECK_FLAG(peer->bgp->flags,
11358 BGP_FLAG_SHUTDOWN))
11359 json_object_string_add(json_peer,
11360 "peerState",
11361 "Admin");
11362 else if (CHECK_FLAG(
11363 peer->sflags,
11364 PEER_STATUS_PREFIX_OVERFLOW))
11365 json_object_string_add(json_peer,
11366 "peerState",
11367 "PfxCt");
11368 else if (CHECK_FLAG(peer->flags,
11369 PEER_FLAG_PASSIVE))
11370 json_object_string_add(json_peer,
11371 "peerState",
11372 "Passive");
11373 else if (CHECK_FLAG(peer->sflags,
11374 PEER_STATUS_NSF_WAIT))
11375 json_object_string_add(json_peer,
11376 "peerState",
11377 "NSF passive");
11378 else if (CHECK_FLAG(
11379 peer->bgp->flags,
11380 BGP_FLAG_EBGP_REQUIRES_POLICY)
11381 && (!bgp_inbound_policy_exists(peer,
11382 filter)
11383 || !bgp_outbound_policy_exists(
11384 peer, filter)))
11385 json_object_string_add(json_peer,
11386 "peerState",
11387 "Policy");
11388 else
11389 json_object_string_add(
11390 json_peer, "peerState", "OK");
11391
200116db
DD
11392 json_object_int_add(json_peer, "connectionsEstablished",
11393 peer->established);
11394 json_object_int_add(json_peer, "connectionsDropped",
11395 peer->dropped);
aa72bd7e
PG
11396 if (peer->desc)
11397 json_object_string_add(
11398 json_peer, "desc", peer->desc);
b4e9dcba 11399 }
3577f1c5
DD
11400 /* Avoid creating empty peer dicts in JSON */
11401 if (json_peer == NULL)
11402 continue;
ea47320b
DL
11403
11404 if (peer->conf_if)
60466a63 11405 json_object_string_add(json_peer, "idType",
ea47320b
DL
11406 "interface");
11407 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
11408 json_object_string_add(json_peer, "idType",
11409 "ipv4");
ea47320b 11410 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
11411 json_object_string_add(json_peer, "idType",
11412 "ipv6");
ea47320b
DL
11413 json_object_object_add(json_peers, peer->host,
11414 json_peer);
11415 } else {
8c1d4cd5 11416 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
ce1944f0
LS
11417 as_type, as)) {
11418 filtered_count++;
8c1d4cd5 11419 continue;
ce1944f0 11420 }
3577f1c5
DD
11421 if (show_failed &&
11422 bgp_has_peer_failed(peer, afi, safi)) {
11423 bgp_show_failed_summary(vty, bgp, peer, NULL,
11424 max_neighbor_width,
11425 use_json);
11426 } else if (!show_failed) {
10b49f14 11427 if (show_established
ce1944f0
LS
11428 && bgp_has_peer_failed(peer, afi, safi)) {
11429 filtered_count++;
10b49f14 11430 continue;
ce1944f0 11431 }
96c81f66
LS
11432
11433 if ((count - filtered_count) == 1) {
11434 /* display headline before the first
11435 * neighbor line */
11436 vty_out(vty, "\n");
11437
11438 /* Subtract 8 here because 'Neighbor' is
11439 * 8 characters */
11440 vty_out(vty, "Neighbor");
11441 vty_out(vty, "%*s",
11442 max_neighbor_width - 8, " ");
11443 vty_out(vty,
11444 show_wide
11445 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
11446 : BGP_SHOW_SUMMARY_HEADER_ALL);
11447 }
11448
3577f1c5
DD
11449 memset(dn_flag, '\0', sizeof(dn_flag));
11450 if (peer_dynamic_neighbor(peer)) {
11451 dn_flag[0] = '*';
11452 }
d62a17ae 11453
3577f1c5 11454 if (peer->hostname
892fedb6
DA
11455 && CHECK_FLAG(bgp->flags,
11456 BGP_FLAG_SHOW_HOSTNAME))
3577f1c5 11457 len = vty_out(vty, "%s%s(%s)", dn_flag,
892fedb6
DA
11458 peer->hostname,
11459 peer->host);
d62a17ae 11460 else
3577f1c5
DD
11461 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11462
11463 /* pad the neighbor column with spaces */
11464 if (len < max_neighbor_width)
11465 vty_out(vty, "%*s", max_neighbor_width - len,
11466 " ");
11467
43aa5965
QY
11468 atomic_size_t outq_count, inq_count;
11469 outq_count = atomic_load_explicit(
11470 &peer->obuf->count,
11471 memory_order_relaxed);
11472 inq_count = atomic_load_explicit(
11473 &peer->ibuf->count,
11474 memory_order_relaxed);
11475
85eeb029
DA
11476 if (show_wide)
11477 vty_out(vty,
11478 "4 %10u %10u %9u %9u %8" PRIu64
11479 " %4zu %4zu %8s",
11480 peer->as,
11481 peer->change_local_as
11482 ? peer->change_local_as
11483 : peer->local_as,
11484 PEER_TOTAL_RX(peer),
11485 PEER_TOTAL_TX(peer),
11486 peer->version[afi][safi],
11487 inq_count, outq_count,
11488 peer_uptime(peer->uptime,
11489 timebuf,
11490 BGP_UPTIME_LEN, 0,
11491 NULL));
11492 else
11493 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
11494 " %4zu %4zu %8s",
11495 peer->as, PEER_TOTAL_RX(peer),
11496 PEER_TOTAL_TX(peer),
11497 peer->version[afi][safi],
11498 inq_count, outq_count,
11499 peer_uptime(peer->uptime,
11500 timebuf,
11501 BGP_UPTIME_LEN, 0,
11502 NULL));
3577f1c5 11503
feb17238 11504 if (peer_established(peer)) {
d3ada366
DA
11505 if (peer->afc_recv[afi][safi]) {
11506 if (CHECK_FLAG(
11507 bgp->flags,
11508 BGP_FLAG_EBGP_REQUIRES_POLICY)
11509 && !bgp_inbound_policy_exists(
11510 peer, filter))
11511 vty_out(vty, " %12s",
11512 "(Policy)");
11513 else
11514 vty_out(vty,
6cde4b45 11515 " %12u",
d3ada366
DA
11516 peer->pcount
11517 [afi]
11518 [pfx_rcd_safi]);
11519 } else {
749d0f27 11520 vty_out(vty, " NoNeg");
d3ada366 11521 }
db92d226 11522
d3ada366
DA
11523 if (paf && PAF_SUBGRP(paf)) {
11524 if (CHECK_FLAG(
11525 bgp->flags,
11526 BGP_FLAG_EBGP_REQUIRES_POLICY)
11527 && !bgp_outbound_policy_exists(
11528 peer, filter))
11529 vty_out(vty, " %8s",
11530 "(Policy)");
11531 else
11532 vty_out(vty,
6cde4b45 11533 " %8u",
d3ada366
DA
11534 (PAF_SUBGRP(
11535 paf))
11536 ->scount);
749d0f27
DA
11537 } else {
11538 vty_out(vty, " NoNeg");
d3ada366 11539 }
db92d226 11540 } else {
736b68f3
DS
11541 if (CHECK_FLAG(peer->flags,
11542 PEER_FLAG_SHUTDOWN)
11543 || CHECK_FLAG(peer->bgp->flags,
11544 BGP_FLAG_SHUTDOWN))
3577f1c5
DD
11545 vty_out(vty, " Idle (Admin)");
11546 else if (CHECK_FLAG(
11547 peer->sflags,
11548 PEER_STATUS_PREFIX_OVERFLOW))
11549 vty_out(vty, " Idle (PfxCt)");
11550 else
11551 vty_out(vty, " %12s",
11552 lookup_msg(bgp_status_msg,
11553 peer->status, NULL));
db92d226 11554
6cde4b45 11555 vty_out(vty, " %8u", 0);
3577f1c5 11556 }
565e9ddd
DA
11557 /* Make sure `Desc` column is the lastest in
11558 * the output.
11559 */
aa72bd7e 11560 if (peer->desc)
cb75bb31
DA
11561 vty_out(vty, " %s",
11562 bgp_peer_description_stripped(
85eeb029
DA
11563 peer->desc,
11564 show_wide ? 64 : 20));
aa72bd7e
PG
11565 else
11566 vty_out(vty, " N/A");
3577f1c5 11567 vty_out(vty, "\n");
d62a17ae 11568 }
3577f1c5 11569
d62a17ae 11570 }
11571 }
f933309e 11572
d62a17ae 11573 if (use_json) {
11574 json_object_object_add(json, "peers", json_peers);
3577f1c5 11575 json_object_int_add(json, "failedPeers", failed_count);
ce1944f0
LS
11576 json_object_int_add(json, "displayedPeers",
11577 count - filtered_count);
d62a17ae 11578 json_object_int_add(json, "totalPeers", count);
11579 json_object_int_add(json, "dynamicPeers", dn_count);
11580
3577f1c5
DD
11581 if (!show_failed)
11582 bgp_show_bestpath_json(bgp, json);
57a9c8a8 11583
75eeda93 11584 vty_json(vty, json);
d62a17ae 11585 } else {
ce1944f0 11586 if (count) {
96c81f66
LS
11587 if (filtered_count == count)
11588 vty_out(vty, "\n%% No matching neighbor\n");
11589 else {
11590 if (show_failed)
11591 vty_out(vty, "\nDisplayed neighbors %d",
11592 failed_count);
11593 else if (as_type != AS_UNSPECIFIED || as
11594 || fpeer || show_established)
ce1944f0
LS
11595 vty_out(vty, "\nDisplayed neighbors %d",
11596 count - filtered_count);
96c81f66
LS
11597
11598 vty_out(vty, "\nTotal number of neighbors %d\n",
11599 count);
ce1944f0 11600 }
ce1944f0 11601 } else {
d6ceaca3 11602 vty_out(vty, "No %s neighbor is configured\n",
5cb5f4d0 11603 get_afi_safi_str(afi, safi, false));
d62a17ae 11604 }
b05a1c8b 11605
d6ceaca3 11606 if (dn_count) {
d62a17ae 11607 vty_out(vty, "* - dynamic neighbor\n");
11608 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11609 dn_count, bgp->dynamic_neighbors_limit);
11610 }
11611 }
1ff9a340 11612
d62a17ae 11613 return CMD_SUCCESS;
718e3744 11614}
11615
d62a17ae 11616static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8c1d4cd5 11617 int safi, struct peer *fpeer, int as_type,
96c81f66 11618 as_t as, uint16_t show_flags)
d62a17ae 11619{
11620 int is_first = 1;
11621 int afi_wildcard = (afi == AFI_MAX);
11622 int safi_wildcard = (safi == SAFI_MAX);
11623 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 11624 bool nbr_output = false;
85eeb029 11625 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 11626
11627 if (use_json && is_wildcard)
11628 vty_out(vty, "{\n");
11629 if (afi_wildcard)
11630 afi = 1; /* AFI_IP */
11631 while (afi < AFI_MAX) {
11632 if (safi_wildcard)
11633 safi = 1; /* SAFI_UNICAST */
11634 while (safi < SAFI_MAX) {
318cac96 11635 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 11636 nbr_output = true;
f86897b9 11637
d62a17ae 11638 if (is_wildcard) {
11639 /*
11640 * So limit output to those afi/safi
11641 * pairs that
11642 * actualy have something interesting in
11643 * them
11644 */
11645 if (use_json) {
d62a17ae 11646 if (!is_first)
11647 vty_out(vty, ",\n");
11648 else
11649 is_first = 0;
11650
11651 vty_out(vty, "\"%s\":",
5cb5f4d0
DD
11652 get_afi_safi_str(afi,
11653 safi,
11654 true));
d62a17ae 11655 } else {
6cac2fcc
LS
11656 vty_out(vty,
11657 "\n%s Summary (%s):\n",
5cb5f4d0
DD
11658 get_afi_safi_str(afi,
11659 safi,
6cac2fcc
LS
11660 false),
11661 bgp->name_pretty);
d62a17ae 11662 }
11663 }
8c1d4cd5
LS
11664 bgp_show_summary(vty, bgp, afi, safi, fpeer,
11665 as_type, as, show_flags);
d62a17ae 11666 }
11667 safi++;
d62a17ae 11668 if (!safi_wildcard)
11669 safi = SAFI_MAX;
11670 }
11671 afi++;
ee851c8c 11672 if (!afi_wildcard)
d62a17ae 11673 afi = AFI_MAX;
11674 }
11675
11676 if (use_json && is_wildcard)
11677 vty_out(vty, "}\n");
ca61fd25
DS
11678 else if (!nbr_output) {
11679 if (use_json)
11680 vty_out(vty, "{}\n");
11681 else
6cac2fcc
LS
11682 vty_out(vty, "%% No BGP neighbors found in %s\n",
11683 bgp->name_pretty);
ca61fd25 11684 }
d62a17ae 11685}
11686
11687static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8c1d4cd5
LS
11688 safi_t safi,
11689 const char *neighbor,
11690 int as_type, as_t as,
96c81f66 11691 uint16_t show_flags)
d62a17ae 11692{
11693 struct listnode *node, *nnode;
11694 struct bgp *bgp;
8c1d4cd5 11695 struct peer *fpeer = NULL;
d62a17ae 11696 int is_first = 1;
9f049418 11697 bool nbr_output = false;
85eeb029 11698 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 11699
11700 if (use_json)
11701 vty_out(vty, "{\n");
11702
11703 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 11704 nbr_output = true;
d62a17ae 11705 if (use_json) {
d62a17ae 11706 if (!is_first)
11707 vty_out(vty, ",\n");
11708 else
11709 is_first = 0;
11710
11711 vty_out(vty, "\"%s\":",
11712 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11713 ? VRF_DEFAULT_NAME
d62a17ae 11714 : bgp->name);
d62a17ae 11715 }
8c1d4cd5
LS
11716 if (neighbor) {
11717 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11718 use_json);
11719 if (!fpeer)
11720 continue;
11721 }
11722 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11723 as, show_flags);
d62a17ae 11724 }
11725
11726 if (use_json)
11727 vty_out(vty, "}\n");
9f049418
DS
11728 else if (!nbr_output)
11729 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 11730}
11731
11732int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8c1d4cd5 11733 safi_t safi, const char *neighbor, int as_type,
96c81f66 11734 as_t as, uint16_t show_flags)
d62a17ae 11735{
11736 struct bgp *bgp;
85eeb029 11737 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
8c1d4cd5 11738 struct peer *fpeer = NULL;
d62a17ae 11739
11740 if (name) {
11741 if (strmatch(name, "all")) {
85eeb029 11742 bgp_show_all_instances_summary_vty(vty, afi, safi,
8c1d4cd5
LS
11743 neighbor, as_type,
11744 as, show_flags);
d62a17ae 11745 return CMD_SUCCESS;
11746 } else {
11747 bgp = bgp_lookup_by_name(name);
11748
11749 if (!bgp) {
11750 if (use_json)
11751 vty_out(vty, "{}\n");
11752 else
11753 vty_out(vty,
ca61fd25 11754 "%% BGP instance not found\n");
d62a17ae 11755 return CMD_WARNING;
11756 }
11757
8c1d4cd5
LS
11758 if (neighbor) {
11759 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11760 use_json);
11761 if (!fpeer)
11762 return CMD_WARNING;
11763 }
11764 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
11765 as_type, as, show_flags);
d62a17ae 11766 return CMD_SUCCESS;
11767 }
11768 }
11769
11770 bgp = bgp_get_default();
11771
8c1d4cd5
LS
11772 if (bgp) {
11773 if (neighbor) {
11774 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11775 use_json);
11776 if (!fpeer)
11777 return CMD_WARNING;
11778 }
11779 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11780 as, show_flags);
11781 } else {
ca61fd25
DS
11782 if (use_json)
11783 vty_out(vty, "{}\n");
11784 else
11785 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
11786 return CMD_WARNING;
11787 }
d62a17ae 11788
11789 return CMD_SUCCESS;
4fb25c53
DW
11790}
11791
716b2d8a 11792/* `show [ip] bgp summary' commands. */
8c1d4cd5
LS
11793DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
11794 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
11795 " [" BGP_SAFI_WITH_LABEL_CMD_STR
96c81f66 11796 "]] [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
11797 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11798 BGP_SAFI_WITH_LABEL_HELP_STR
11799 "Display the entries for all address families\n"
11800 "Summary of BGP neighbor status\n"
11801 "Show only sessions in Established state\n"
11802 "Show only sessions not in Established state\n"
11803 "Show only the specified neighbor session\n"
11804 "Neighbor to display information about\n"
11805 "Neighbor to display information about\n"
11806 "Neighbor on BGP configured interface\n"
11807 "Show only the specified remote AS sessions\n"
11808 "AS number\n"
11809 "Internal (iBGP) AS sessions\n"
11810 "External (eBGP) AS sessions\n"
96c81f66 11811 "Shorten the information on BGP instances\n"
8c1d4cd5 11812 "Increase table width for longer output\n" JSON_STR)
718e3744 11813{
d62a17ae 11814 char *vrf = NULL;
11815 afi_t afi = AFI_MAX;
11816 safi_t safi = SAFI_MAX;
8c1d4cd5
LS
11817 as_t as = 0; /* 0 means AS filter not set */
11818 int as_type = AS_UNSPECIFIED;
96c81f66 11819 uint16_t show_flags = 0;
d62a17ae 11820
11821 int idx = 0;
11822
11823 /* show [ip] bgp */
96f3485c 11824 if (!all && argv_find(argv, argc, "ip", &idx))
d62a17ae 11825 afi = AFI_IP;
9a8bdf1c
PG
11826 /* [<vrf> VIEWVRFNAME] */
11827 if (argv_find(argv, argc, "vrf", &idx)) {
11828 vrf = argv[idx + 1]->arg;
11829 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11830 vrf = NULL;
11831 } else if (argv_find(argv, argc, "view", &idx))
11832 /* [<view> VIEWVRFNAME] */
11833 vrf = argv[idx + 1]->arg;
d62a17ae 11834 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11835 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11836 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11837 }
11838
3577f1c5 11839 if (argv_find(argv, argc, "failed", &idx))
85eeb029
DA
11840 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11841
10b49f14 11842 if (argv_find(argv, argc, "established", &idx))
85eeb029
DA
11843 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11844
8c1d4cd5
LS
11845 if (argv_find(argv, argc, "remote-as", &idx)) {
11846 if (argv[idx + 1]->arg[0] == 'i')
11847 as_type = AS_INTERNAL;
11848 else if (argv[idx + 1]->arg[0] == 'e')
11849 as_type = AS_EXTERNAL;
11850 else
11851 as = (as_t)atoi(argv[idx + 1]->arg);
11852 }
11853
96c81f66
LS
11854 if (argv_find(argv, argc, "terse", &idx))
11855 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11856
85eeb029
DA
11857 if (argv_find(argv, argc, "wide", &idx))
11858 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11859
11860 if (argv_find(argv, argc, "json", &idx))
11861 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
3577f1c5 11862
8c1d4cd5
LS
11863 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
11864 show_flags);
d62a17ae 11865}
11866
5cb5f4d0 11867const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
d62a17ae 11868{
5cb5f4d0
DD
11869 if (for_json)
11870 return get_afi_safi_json_str(afi, safi);
d62a17ae 11871 else
5cb5f4d0 11872 return get_afi_safi_vty_str(afi, safi);
27162734
LB
11873}
11874
d62a17ae 11875
11876static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11877 afi_t afi, safi_t safi,
d7c0a89a
QY
11878 uint16_t adv_smcap, uint16_t adv_rmcap,
11879 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 11880 bool use_json, json_object *json_pref)
d62a17ae 11881{
11882 /* Send-Mode */
11883 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11884 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11885 if (use_json) {
11886 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11887 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11888 json_object_string_add(json_pref, "sendMode",
11889 "advertisedAndReceived");
11890 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11891 json_object_string_add(json_pref, "sendMode",
11892 "advertised");
11893 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11894 json_object_string_add(json_pref, "sendMode",
11895 "received");
11896 } else {
11897 vty_out(vty, " Send-mode: ");
11898 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11899 vty_out(vty, "advertised");
11900 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11901 vty_out(vty, "%sreceived",
11902 CHECK_FLAG(p->af_cap[afi][safi],
11903 adv_smcap)
11904 ? ", "
11905 : "");
11906 vty_out(vty, "\n");
11907 }
11908 }
11909
11910 /* Receive-Mode */
11911 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11912 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11913 if (use_json) {
11914 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11915 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11916 json_object_string_add(json_pref, "recvMode",
11917 "advertisedAndReceived");
11918 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11919 json_object_string_add(json_pref, "recvMode",
11920 "advertised");
11921 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11922 json_object_string_add(json_pref, "recvMode",
11923 "received");
11924 } else {
11925 vty_out(vty, " Receive-mode: ");
11926 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11927 vty_out(vty, "advertised");
11928 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11929 vty_out(vty, "%sreceived",
11930 CHECK_FLAG(p->af_cap[afi][safi],
11931 adv_rmcap)
11932 ? ", "
11933 : "");
11934 vty_out(vty, "\n");
11935 }
11936 }
11937}
11938
eea685b6
DA
11939static void bgp_show_neighnor_graceful_restart_flags(struct vty *vty,
11940 struct peer *p,
eea685b6 11941 json_object *json)
2986cac2 11942{
eea685b6
DA
11943 bool rbit = false;
11944 bool nbit = false;
2986cac2 11945
13909c4f
DS
11946 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11947 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
feb17238 11948 && (peer_established(p))) {
eea685b6
DA
11949 rbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_R_BIT_RCV);
11950 nbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_N_BIT_RCV);
2986cac2 11951 }
11952
403e64f8 11953 if (json) {
eea685b6
DA
11954 json_object_boolean_add(json, "rBit", rbit);
11955 json_object_boolean_add(json, "nBit", nbit);
2986cac2 11956 } else {
eea685b6
DA
11957 vty_out(vty, "\n R bit: %s", rbit ? "True" : "False");
11958 vty_out(vty, "\n N bit: %s\n", nbit ? "True" : "False");
2986cac2 11959 }
11960}
11961
13909c4f
DS
11962static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11963 struct peer *peer,
13909c4f 11964 json_object *json)
2986cac2 11965{
2bb5d39b 11966 const char *mode = "NotApplicable";
2986cac2 11967
403e64f8 11968 if (!json)
a53ca37b 11969 vty_out(vty, "\n Remote GR Mode: ");
2986cac2 11970
13909c4f 11971 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
feb17238 11972 && (peer_established(peer))) {
2986cac2 11973
13909c4f
DS
11974 if ((peer->nsf_af_count == 0)
11975 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11976
2986cac2 11977 mode = "Disable";
11978
13909c4f
DS
11979 } else if (peer->nsf_af_count == 0
11980 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11981
2986cac2 11982 mode = "Helper";
11983
13909c4f
DS
11984 } else if (peer->nsf_af_count != 0
11985 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11986
2986cac2 11987 mode = "Restart";
2986cac2 11988 }
11989 }
11990
403e64f8 11991 if (json)
13909c4f 11992 json_object_string_add(json, "remoteGrMode", mode);
403e64f8 11993 else
2986cac2 11994 vty_out(vty, mode, "\n");
11995}
11996
13909c4f
DS
11997static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11998 struct peer *p,
13909c4f 11999 json_object *json)
2986cac2 12000{
12001 const char *mode = "Invalid";
12002
403e64f8 12003 if (!json)
a53ca37b 12004 vty_out(vty, " Local GR Mode: ");
2986cac2 12005
12006 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
12007 mode = "Helper";
12008 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
12009 mode = "Restart";
12010 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
12011 mode = "Disable";
2ba1fe69 12012 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
2986cac2 12013 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
12014 mode = "Helper*";
12015 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
12016 mode = "Restart*";
12017 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
12018 mode = "Disable*";
12019 else
12020 mode = "Invalid*";
2ba1fe69 12021 }
2986cac2 12022
403e64f8 12023 if (json)
13909c4f 12024 json_object_string_add(json, "localGrMode", mode);
403e64f8 12025 else
2986cac2 12026 vty_out(vty, mode, "\n");
2986cac2 12027}
12028
13909c4f 12029static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
403e64f8 12030 struct vty *vty, struct peer *peer, json_object *json)
2986cac2 12031{
2ba1fe69 12032 afi_t afi;
12033 safi_t safi;
2986cac2 12034 json_object *json_afi_safi = NULL;
12035 json_object *json_timer = NULL;
12036 json_object *json_endofrib_status = NULL;
9e3b51a7 12037 bool eor_flag = false;
2986cac2 12038
df8d723c
DA
12039 FOREACH_AFI_SAFI_NSF (afi, safi) {
12040 if (!peer->afc[afi][safi])
12041 continue;
2986cac2 12042
df8d723c
DA
12043 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) ||
12044 !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
12045 continue;
9e3b51a7 12046
403e64f8 12047 if (json) {
df8d723c
DA
12048 json_afi_safi = json_object_new_object();
12049 json_endofrib_status = json_object_new_object();
12050 json_timer = json_object_new_object();
12051 }
2986cac2 12052
df8d723c
DA
12053 if (peer->eor_stime[afi][safi] >= peer->pkt_stime[afi][safi])
12054 eor_flag = true;
12055 else
12056 eor_flag = false;
2986cac2 12057
403e64f8 12058 if (!json) {
df8d723c
DA
12059 vty_out(vty, " %s:\n",
12060 get_afi_safi_str(afi, safi, false));
2986cac2 12061
df8d723c
DA
12062 vty_out(vty, " F bit: ");
12063 }
2986cac2 12064
df8d723c
DA
12065 if (peer->nsf[afi][safi] &&
12066 CHECK_FLAG(peer->af_cap[afi][safi],
12067 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
2986cac2 12068
403e64f8 12069 if (json) {
df8d723c
DA
12070 json_object_boolean_true_add(json_afi_safi,
12071 "fBit");
12072 } else
12073 vty_out(vty, "True\n");
12074 } else {
403e64f8 12075 if (json)
df8d723c
DA
12076 json_object_boolean_false_add(json_afi_safi,
12077 "fBit");
12078 else
12079 vty_out(vty, "False\n");
12080 }
2986cac2 12081
403e64f8 12082 if (!json)
df8d723c 12083 vty_out(vty, " End-of-RIB sent: ");
2986cac2 12084
df8d723c
DA
12085 if (CHECK_FLAG(peer->af_sflags[afi][safi],
12086 PEER_STATUS_EOR_SEND)) {
403e64f8 12087 if (json) {
df8d723c
DA
12088 json_object_boolean_true_add(
12089 json_endofrib_status, "endOfRibSend");
9e3b51a7 12090
df8d723c
DA
12091 PRINT_EOR_JSON(eor_flag);
12092 } else {
12093 vty_out(vty, "Yes\n");
12094 vty_out(vty,
12095 " End-of-RIB sent after update: ");
2986cac2 12096
df8d723c
DA
12097 PRINT_EOR(eor_flag);
12098 }
12099 } else {
403e64f8 12100 if (json) {
df8d723c
DA
12101 json_object_boolean_false_add(
12102 json_endofrib_status, "endOfRibSend");
12103 json_object_boolean_false_add(
12104 json_endofrib_status,
12105 "endOfRibSentAfterUpdate");
13909c4f 12106 } else {
df8d723c
DA
12107 vty_out(vty, "No\n");
12108 vty_out(vty,
12109 " End-of-RIB sent after update: ");
12110 vty_out(vty, "No\n");
13909c4f 12111 }
df8d723c 12112 }
2986cac2 12113
403e64f8 12114 if (!json)
df8d723c 12115 vty_out(vty, " End-of-RIB received: ");
a53ca37b 12116
df8d723c
DA
12117 if (CHECK_FLAG(peer->af_sflags[afi][safi],
12118 PEER_STATUS_EOR_RECEIVED)) {
403e64f8 12119 if (json)
df8d723c
DA
12120 json_object_boolean_true_add(
12121 json_endofrib_status, "endOfRibRecv");
12122 else
12123 vty_out(vty, "Yes\n");
12124 } else {
403e64f8 12125 if (json)
df8d723c
DA
12126 json_object_boolean_false_add(
12127 json_endofrib_status, "endOfRibRecv");
12128 else
12129 vty_out(vty, "No\n");
12130 }
12131
403e64f8 12132 if (json) {
df8d723c
DA
12133 json_object_int_add(json_timer, "stalePathTimer",
12134 peer->bgp->stalepath_time);
12135
12136 if (peer->t_gr_stale != NULL) {
12137 json_object_int_add(json_timer,
12138 "stalePathTimerRemaining",
12139 thread_timer_remain_second(
12140 peer->t_gr_stale));
a53ca37b
DA
12141 }
12142
df8d723c
DA
12143 /* Display Configured Selection
12144 * Deferral only when when
12145 * Gr mode is enabled.
12146 */
12147 if (CHECK_FLAG(peer->flags,
12148 PEER_FLAG_GRACEFUL_RESTART)) {
13909c4f 12149 json_object_int_add(json_timer,
df8d723c 12150 "selectionDeferralTimer",
13909c4f 12151 peer->bgp->stalepath_time);
df8d723c 12152 }
2986cac2 12153
df8d723c
DA
12154 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
12155 NULL) {
2986cac2 12156
df8d723c
DA
12157 json_object_int_add(
12158 json_timer,
12159 "selectionDeferralTimerRemaining",
12160 thread_timer_remain_second(
12161 peer->bgp->gr_info[afi][safi]
12162 .t_select_deferral));
12163 }
12164 } else {
12165 vty_out(vty, " Timers:\n");
12166 vty_out(vty,
12167 " Configured Stale Path Time(sec): %u\n",
12168 peer->bgp->stalepath_time);
2986cac2 12169
df8d723c 12170 if (peer->t_gr_stale != NULL)
13909c4f 12171 vty_out(vty,
df8d723c
DA
12172 " Stale Path Remaining(sec): %ld\n",
12173 thread_timer_remain_second(
12174 peer->t_gr_stale));
12175 /* Display Configured Selection
12176 * Deferral only when when
12177 * Gr mode is enabled.
12178 */
12179 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
12180 vty_out(vty,
12181 " Configured Selection Deferral Time(sec): %u\n",
12182 peer->bgp->select_defer_time);
2986cac2 12183
df8d723c
DA
12184 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
12185 NULL)
12186 vty_out(vty,
12187 " Selection Deferral Time Remaining(sec): %ld\n",
12188 thread_timer_remain_second(
12189 peer->bgp->gr_info[afi][safi]
12190 .t_select_deferral));
12191 }
403e64f8 12192 if (json) {
df8d723c
DA
12193 json_object_object_add(json_afi_safi, "endOfRibStatus",
12194 json_endofrib_status);
12195 json_object_object_add(json_afi_safi, "timers",
12196 json_timer);
12197 json_object_object_add(
12198 json, get_afi_safi_str(afi, safi, true),
12199 json_afi_safi);
2986cac2 12200 }
12201 }
12202}
12203
36235319
QY
12204static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
12205 struct peer *p,
36235319 12206 json_object *json)
2986cac2 12207{
403e64f8 12208 if (json) {
2986cac2 12209 json_object *json_timer = NULL;
12210
12211 json_timer = json_object_new_object();
12212
13909c4f
DS
12213 json_object_int_add(json_timer, "configuredRestartTimer",
12214 p->bgp->restart_time);
2986cac2 12215
13909c4f
DS
12216 json_object_int_add(json_timer, "receivedRestartTimer",
12217 p->v_gr_restart);
2986cac2 12218
13909c4f
DS
12219 if (p->t_gr_restart != NULL)
12220 json_object_int_add(
12221 json_timer, "restartTimerRemaining",
12222 thread_timer_remain_second(p->t_gr_restart));
2986cac2 12223
12224 json_object_object_add(json, "timers", json_timer);
12225 } else {
12226
a53ca37b
DA
12227 vty_out(vty, " Timers:\n");
12228 vty_out(vty, " Configured Restart Time(sec): %u\n",
13909c4f 12229 p->bgp->restart_time);
2986cac2 12230
a53ca37b 12231 vty_out(vty, " Received Restart Time(sec): %u\n",
13909c4f
DS
12232 p->v_gr_restart);
12233 if (p->t_gr_restart != NULL)
a53ca37b 12234 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
13909c4f 12235 thread_timer_remain_second(p->t_gr_restart));
36235319 12236 if (p->t_gr_restart != NULL) {
a53ca37b 12237 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
36235319
QY
12238 thread_timer_remain_second(p->t_gr_restart));
12239 }
2986cac2 12240 }
12241}
12242
12243static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
403e64f8 12244 json_object *json)
2986cac2 12245{
2986cac2 12246 char dn_flag[2] = {0};
2b7165e7
QY
12247 /* '*' + v6 address of neighbor */
12248 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
2986cac2 12249
2986cac2 12250 if (!p->conf_if && peer_dynamic_neighbor(p))
12251 dn_flag[0] = '*';
12252
12253 if (p->conf_if) {
403e64f8 12254 if (json)
47e12884
DA
12255 json_object_string_addf(json, "neighborAddr", "%pSU",
12256 &p->su);
2986cac2 12257 else
47e12884
DA
12258 vty_out(vty, "BGP neighbor on %s: %pSU\n", p->conf_if,
12259 &p->su);
2986cac2 12260 } else {
772270f3
QY
12261 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
12262 p->host);
2986cac2 12263
403e64f8 12264 if (json)
36235319
QY
12265 json_object_string_add(json, "neighborAddr",
12266 neighborAddr);
2986cac2 12267 else
36235319 12268 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
2986cac2 12269 }
12270
12271 /* more gr info in new format */
403e64f8 12272 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, json);
2986cac2 12273}
12274
d62a17ae 12275static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 12276 safi_t safi, bool use_json,
d62a17ae 12277 json_object *json_neigh)
12278{
0291c246
MK
12279 struct bgp_filter *filter;
12280 struct peer_af *paf;
12281 char orf_pfx_name[BUFSIZ];
12282 int orf_pfx_count;
12283 json_object *json_af = NULL;
12284 json_object *json_prefA = NULL;
12285 json_object *json_prefB = NULL;
12286 json_object *json_addr = NULL;
fa36596c 12287 json_object *json_advmap = NULL;
d62a17ae 12288
12289 if (use_json) {
12290 json_addr = json_object_new_object();
12291 json_af = json_object_new_object();
12292 filter = &p->filter[afi][safi];
12293
12294 if (peer_group_active(p))
12295 json_object_string_add(json_addr, "peerGroupMember",
12296 p->group->name);
12297
12298 paf = peer_af_find(p, afi, safi);
12299 if (paf && PAF_SUBGRP(paf)) {
12300 json_object_int_add(json_addr, "updateGroupId",
12301 PAF_UPDGRP(paf)->id);
12302 json_object_int_add(json_addr, "subGroupId",
12303 PAF_SUBGRP(paf)->id);
12304 json_object_int_add(json_addr, "packetQueueLength",
12305 bpacket_queue_virtual_length(paf));
12306 }
12307
12308 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12309 || CHECK_FLAG(p->af_cap[afi][safi],
12310 PEER_CAP_ORF_PREFIX_SM_RCV)
12311 || CHECK_FLAG(p->af_cap[afi][safi],
12312 PEER_CAP_ORF_PREFIX_RM_ADV)
12313 || CHECK_FLAG(p->af_cap[afi][safi],
12314 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12315 json_object_int_add(json_af, "orfType",
12316 ORF_TYPE_PREFIX);
12317 json_prefA = json_object_new_object();
12318 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
12319 PEER_CAP_ORF_PREFIX_SM_ADV,
12320 PEER_CAP_ORF_PREFIX_RM_ADV,
12321 PEER_CAP_ORF_PREFIX_SM_RCV,
12322 PEER_CAP_ORF_PREFIX_RM_RCV,
12323 use_json, json_prefA);
12324 json_object_object_add(json_af, "orfPrefixList",
12325 json_prefA);
12326 }
12327
12328 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12329 || CHECK_FLAG(p->af_cap[afi][safi],
12330 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12331 || CHECK_FLAG(p->af_cap[afi][safi],
12332 PEER_CAP_ORF_PREFIX_RM_ADV)
12333 || CHECK_FLAG(p->af_cap[afi][safi],
12334 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12335 json_object_int_add(json_af, "orfOldType",
12336 ORF_TYPE_PREFIX_OLD);
12337 json_prefB = json_object_new_object();
12338 bgp_show_peer_afi_orf_cap(
12339 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12340 PEER_CAP_ORF_PREFIX_RM_ADV,
12341 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12342 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
12343 json_prefB);
12344 json_object_object_add(json_af, "orfOldPrefixList",
12345 json_prefB);
12346 }
12347
12348 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12349 || CHECK_FLAG(p->af_cap[afi][safi],
12350 PEER_CAP_ORF_PREFIX_SM_RCV)
12351 || CHECK_FLAG(p->af_cap[afi][safi],
12352 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12353 || CHECK_FLAG(p->af_cap[afi][safi],
12354 PEER_CAP_ORF_PREFIX_RM_ADV)
12355 || CHECK_FLAG(p->af_cap[afi][safi],
12356 PEER_CAP_ORF_PREFIX_RM_RCV)
12357 || CHECK_FLAG(p->af_cap[afi][safi],
12358 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12359 json_object_object_add(json_addr, "afDependentCap",
12360 json_af);
12361 else
12362 json_object_free(json_af);
12363
772270f3
QY
12364 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12365 p->host, afi, safi);
d62a17ae 12366 orf_pfx_count = prefix_bgp_show_prefix_list(
12367 NULL, afi, orf_pfx_name, use_json);
12368
12369 if (CHECK_FLAG(p->af_sflags[afi][safi],
12370 PEER_STATUS_ORF_PREFIX_SEND)
12371 || orf_pfx_count) {
12372 if (CHECK_FLAG(p->af_sflags[afi][safi],
12373 PEER_STATUS_ORF_PREFIX_SEND))
12374 json_object_boolean_true_add(json_neigh,
12375 "orfSent");
12376 if (orf_pfx_count)
12377 json_object_int_add(json_addr, "orfRecvCounter",
12378 orf_pfx_count);
12379 }
12380 if (CHECK_FLAG(p->af_sflags[afi][safi],
12381 PEER_STATUS_ORF_WAIT_REFRESH))
12382 json_object_string_add(
12383 json_addr, "orfFirstUpdate",
12384 "deferredUntilORFOrRouteRefreshRecvd");
12385
12386 if (CHECK_FLAG(p->af_flags[afi][safi],
12387 PEER_FLAG_REFLECTOR_CLIENT))
12388 json_object_boolean_true_add(json_addr,
12389 "routeReflectorClient");
12390 if (CHECK_FLAG(p->af_flags[afi][safi],
12391 PEER_FLAG_RSERVER_CLIENT))
12392 json_object_boolean_true_add(json_addr,
12393 "routeServerClient");
12394 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12395 json_object_boolean_true_add(json_addr,
12396 "inboundSoftConfigPermit");
12397
12398 if (CHECK_FLAG(p->af_flags[afi][safi],
12399 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12400 json_object_boolean_true_add(
12401 json_addr,
12402 "privateAsNumsAllReplacedInUpdatesToNbr");
12403 else if (CHECK_FLAG(p->af_flags[afi][safi],
12404 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12405 json_object_boolean_true_add(
12406 json_addr,
12407 "privateAsNumsReplacedInUpdatesToNbr");
12408 else if (CHECK_FLAG(p->af_flags[afi][safi],
12409 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12410 json_object_boolean_true_add(
12411 json_addr,
12412 "privateAsNumsAllRemovedInUpdatesToNbr");
12413 else if (CHECK_FLAG(p->af_flags[afi][safi],
12414 PEER_FLAG_REMOVE_PRIVATE_AS))
12415 json_object_boolean_true_add(
12416 json_addr,
12417 "privateAsNumsRemovedInUpdatesToNbr");
12418
b2ac1d0d
MS
12419 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN)) {
12420 if (CHECK_FLAG(p->af_flags[afi][safi],
12421 PEER_FLAG_ALLOWAS_IN_ORIGIN))
12422 json_object_boolean_true_add(json_addr,
12423 "allowAsInOrigin");
12424 else
12425 json_object_int_add(json_addr, "allowAsInCount",
12426 p->allowas_in[afi][safi]);
12427 }
12428
dcc68b5e
MS
12429 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12430 json_object_boolean_true_add(
12431 json_addr,
12432 bgp_addpath_names(p->addpath_type[afi][safi])
12433 ->type_json_name);
d62a17ae 12434
12435 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12436 json_object_string_add(json_addr,
12437 "overrideASNsInOutboundUpdates",
12438 "ifAspathEqualRemoteAs");
12439
12440 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12441 || CHECK_FLAG(p->af_flags[afi][safi],
12442 PEER_FLAG_FORCE_NEXTHOP_SELF))
12443 json_object_boolean_true_add(json_addr,
12444 "routerAlwaysNextHop");
12445 if (CHECK_FLAG(p->af_flags[afi][safi],
12446 PEER_FLAG_AS_PATH_UNCHANGED))
12447 json_object_boolean_true_add(
12448 json_addr, "unchangedAsPathPropogatedToNbr");
12449 if (CHECK_FLAG(p->af_flags[afi][safi],
12450 PEER_FLAG_NEXTHOP_UNCHANGED))
12451 json_object_boolean_true_add(
12452 json_addr, "unchangedNextHopPropogatedToNbr");
12453 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12454 json_object_boolean_true_add(
12455 json_addr, "unchangedMedPropogatedToNbr");
12456 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12457 || CHECK_FLAG(p->af_flags[afi][safi],
12458 PEER_FLAG_SEND_EXT_COMMUNITY)) {
12459 if (CHECK_FLAG(p->af_flags[afi][safi],
12460 PEER_FLAG_SEND_COMMUNITY)
12461 && CHECK_FLAG(p->af_flags[afi][safi],
12462 PEER_FLAG_SEND_EXT_COMMUNITY))
12463 json_object_string_add(json_addr,
12464 "commAttriSentToNbr",
12465 "extendedAndStandard");
12466 else if (CHECK_FLAG(p->af_flags[afi][safi],
12467 PEER_FLAG_SEND_EXT_COMMUNITY))
12468 json_object_string_add(json_addr,
12469 "commAttriSentToNbr",
12470 "extended");
12471 else
12472 json_object_string_add(json_addr,
12473 "commAttriSentToNbr",
12474 "standard");
12475 }
12476 if (CHECK_FLAG(p->af_flags[afi][safi],
12477 PEER_FLAG_DEFAULT_ORIGINATE)) {
12478 if (p->default_rmap[afi][safi].name)
12479 json_object_string_add(
12480 json_addr, "defaultRouteMap",
12481 p->default_rmap[afi][safi].name);
12482
12483 if (paf && PAF_SUBGRP(paf)
12484 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12485 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12486 json_object_boolean_true_add(json_addr,
12487 "defaultSent");
12488 else
12489 json_object_boolean_true_add(json_addr,
12490 "defaultNotSent");
12491 }
12492
dff8f48d 12493 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 12494 if (is_evpn_enabled())
60466a63
QY
12495 json_object_boolean_true_add(
12496 json_addr, "advertiseAllVnis");
dff8f48d
MK
12497 }
12498
d62a17ae 12499 if (filter->plist[FILTER_IN].name
12500 || filter->dlist[FILTER_IN].name
12501 || filter->aslist[FILTER_IN].name
12502 || filter->map[RMAP_IN].name)
12503 json_object_boolean_true_add(json_addr,
12504 "inboundPathPolicyConfig");
12505 if (filter->plist[FILTER_OUT].name
12506 || filter->dlist[FILTER_OUT].name
12507 || filter->aslist[FILTER_OUT].name
12508 || filter->map[RMAP_OUT].name || filter->usmap.name)
12509 json_object_boolean_true_add(
12510 json_addr, "outboundPathPolicyConfig");
12511
12512 /* prefix-list */
12513 if (filter->plist[FILTER_IN].name)
12514 json_object_string_add(json_addr,
12515 "incomingUpdatePrefixFilterList",
12516 filter->plist[FILTER_IN].name);
12517 if (filter->plist[FILTER_OUT].name)
12518 json_object_string_add(json_addr,
12519 "outgoingUpdatePrefixFilterList",
12520 filter->plist[FILTER_OUT].name);
12521
12522 /* distribute-list */
12523 if (filter->dlist[FILTER_IN].name)
12524 json_object_string_add(
12525 json_addr, "incomingUpdateNetworkFilterList",
12526 filter->dlist[FILTER_IN].name);
12527 if (filter->dlist[FILTER_OUT].name)
12528 json_object_string_add(
12529 json_addr, "outgoingUpdateNetworkFilterList",
12530 filter->dlist[FILTER_OUT].name);
12531
12532 /* filter-list. */
12533 if (filter->aslist[FILTER_IN].name)
12534 json_object_string_add(json_addr,
12535 "incomingUpdateAsPathFilterList",
12536 filter->aslist[FILTER_IN].name);
12537 if (filter->aslist[FILTER_OUT].name)
12538 json_object_string_add(json_addr,
12539 "outgoingUpdateAsPathFilterList",
12540 filter->aslist[FILTER_OUT].name);
12541
12542 /* route-map. */
12543 if (filter->map[RMAP_IN].name)
12544 json_object_string_add(
12545 json_addr, "routeMapForIncomingAdvertisements",
12546 filter->map[RMAP_IN].name);
12547 if (filter->map[RMAP_OUT].name)
12548 json_object_string_add(
12549 json_addr, "routeMapForOutgoingAdvertisements",
12550 filter->map[RMAP_OUT].name);
12551
9dac9fc8 12552 /* ebgp-requires-policy (inbound) */
1d3fdccf 12553 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12554 && !bgp_inbound_policy_exists(p, filter))
12555 json_object_string_add(
12556 json_addr, "inboundEbgpRequiresPolicy",
12557 "Inbound updates discarded due to missing policy");
12558
12559 /* ebgp-requires-policy (outbound) */
1d3fdccf 12560 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12561 && (!bgp_outbound_policy_exists(p, filter)))
12562 json_object_string_add(
12563 json_addr, "outboundEbgpRequiresPolicy",
12564 "Outbound updates discarded due to missing policy");
12565
d62a17ae 12566 /* unsuppress-map */
12567 if (filter->usmap.name)
12568 json_object_string_add(json_addr,
12569 "selectiveUnsuppressRouteMap",
12570 filter->usmap.name);
12571
fa36596c
MK
12572 /* advertise-map */
12573 if (filter->advmap.aname) {
12574 json_advmap = json_object_new_object();
12575 json_object_string_add(json_advmap, "condition",
12576 filter->advmap.condition
12577 ? "EXIST"
12578 : "NON_EXIST");
12579 json_object_string_add(json_advmap, "conditionMap",
12580 filter->advmap.cname);
12581 json_object_string_add(json_advmap, "advertiseMap",
12582 filter->advmap.aname);
ecf2b628
QY
12583 json_object_string_add(
12584 json_advmap, "advertiseStatus",
12585 filter->advmap.update_type ==
12586 UPDATE_TYPE_ADVERTISE
12587 ? "Advertise"
12588 : "Withdraw");
fa36596c
MK
12589 json_object_object_add(json_addr, "advertiseMap",
12590 json_advmap);
12591 }
12592
d62a17ae 12593 /* Receive prefix count */
12594 json_object_int_add(json_addr, "acceptedPrefixCounter",
12595 p->pcount[afi][safi]);
50e05855
AD
12596 if (paf && PAF_SUBGRP(paf))
12597 json_object_int_add(json_addr, "sentPrefixCounter",
12598 (PAF_SUBGRP(paf))->scount);
d62a17ae 12599
fde246e8
DA
12600 /* Maximum prefix */
12601 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12602 json_object_int_add(json_addr, "prefixOutAllowedMax",
12603 p->pmax_out[afi][safi]);
12604
d62a17ae 12605 /* Maximum prefix */
12606 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12607 json_object_int_add(json_addr, "prefixAllowedMax",
12608 p->pmax[afi][safi]);
12609 if (CHECK_FLAG(p->af_flags[afi][safi],
12610 PEER_FLAG_MAX_PREFIX_WARNING))
12611 json_object_boolean_true_add(
12612 json_addr, "prefixAllowedMaxWarning");
12613 json_object_int_add(json_addr,
12614 "prefixAllowedWarningThresh",
12615 p->pmax_threshold[afi][safi]);
12616 if (p->pmax_restart[afi][safi])
12617 json_object_int_add(
12618 json_addr,
12619 "prefixAllowedRestartIntervalMsecs",
12620 p->pmax_restart[afi][safi] * 60000);
12621 }
2986cac2 12622 json_object_object_add(json_neigh,
36235319 12623 get_afi_safi_str(afi, safi, true),
d62a17ae 12624 json_addr);
12625
12626 } else {
12627 filter = &p->filter[afi][safi];
12628
12629 vty_out(vty, " For address family: %s\n",
5cb5f4d0 12630 get_afi_safi_str(afi, safi, false));
d62a17ae 12631
12632 if (peer_group_active(p))
12633 vty_out(vty, " %s peer-group member\n",
12634 p->group->name);
12635
12636 paf = peer_af_find(p, afi, safi);
12637 if (paf && PAF_SUBGRP(paf)) {
6cde4b45 12638 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
d62a17ae 12639 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12640 vty_out(vty, " Packet Queue length %d\n",
12641 bpacket_queue_virtual_length(paf));
12642 } else {
12643 vty_out(vty, " Not part of any update group\n");
12644 }
12645 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12646 || CHECK_FLAG(p->af_cap[afi][safi],
12647 PEER_CAP_ORF_PREFIX_SM_RCV)
12648 || CHECK_FLAG(p->af_cap[afi][safi],
12649 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12650 || CHECK_FLAG(p->af_cap[afi][safi],
12651 PEER_CAP_ORF_PREFIX_RM_ADV)
12652 || CHECK_FLAG(p->af_cap[afi][safi],
12653 PEER_CAP_ORF_PREFIX_RM_RCV)
12654 || CHECK_FLAG(p->af_cap[afi][safi],
12655 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12656 vty_out(vty, " AF-dependant capabilities:\n");
12657
12658 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12659 || CHECK_FLAG(p->af_cap[afi][safi],
12660 PEER_CAP_ORF_PREFIX_SM_RCV)
12661 || CHECK_FLAG(p->af_cap[afi][safi],
12662 PEER_CAP_ORF_PREFIX_RM_ADV)
12663 || CHECK_FLAG(p->af_cap[afi][safi],
12664 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12665 vty_out(vty,
12666 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12667 ORF_TYPE_PREFIX);
12668 bgp_show_peer_afi_orf_cap(
12669 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12670 PEER_CAP_ORF_PREFIX_RM_ADV,
12671 PEER_CAP_ORF_PREFIX_SM_RCV,
12672 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12673 }
12674 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12675 || CHECK_FLAG(p->af_cap[afi][safi],
12676 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12677 || CHECK_FLAG(p->af_cap[afi][safi],
12678 PEER_CAP_ORF_PREFIX_RM_ADV)
12679 || CHECK_FLAG(p->af_cap[afi][safi],
12680 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12681 vty_out(vty,
12682 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12683 ORF_TYPE_PREFIX_OLD);
12684 bgp_show_peer_afi_orf_cap(
12685 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12686 PEER_CAP_ORF_PREFIX_RM_ADV,
12687 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12688 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12689 }
12690
772270f3
QY
12691 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12692 p->host, afi, safi);
d62a17ae 12693 orf_pfx_count = prefix_bgp_show_prefix_list(
12694 NULL, afi, orf_pfx_name, use_json);
12695
12696 if (CHECK_FLAG(p->af_sflags[afi][safi],
12697 PEER_STATUS_ORF_PREFIX_SEND)
12698 || orf_pfx_count) {
12699 vty_out(vty, " Outbound Route Filter (ORF):");
12700 if (CHECK_FLAG(p->af_sflags[afi][safi],
12701 PEER_STATUS_ORF_PREFIX_SEND))
12702 vty_out(vty, " sent;");
12703 if (orf_pfx_count)
12704 vty_out(vty, " received (%d entries)",
12705 orf_pfx_count);
12706 vty_out(vty, "\n");
12707 }
12708 if (CHECK_FLAG(p->af_sflags[afi][safi],
12709 PEER_STATUS_ORF_WAIT_REFRESH))
12710 vty_out(vty,
12711 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12712
12713 if (CHECK_FLAG(p->af_flags[afi][safi],
12714 PEER_FLAG_REFLECTOR_CLIENT))
12715 vty_out(vty, " Route-Reflector Client\n");
12716 if (CHECK_FLAG(p->af_flags[afi][safi],
12717 PEER_FLAG_RSERVER_CLIENT))
12718 vty_out(vty, " Route-Server Client\n");
70cd87ca
MK
12719
12720 if (peer_af_flag_check(p, afi, safi, PEER_FLAG_ORR_GROUP))
12721 vty_out(vty, " ORR group (configured) : %s\n",
12722 p->orr_group_name[afi][safi]);
12723
d62a17ae 12724 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12725 vty_out(vty,
12726 " Inbound soft reconfiguration allowed\n");
12727
12728 if (CHECK_FLAG(p->af_flags[afi][safi],
12729 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12730 vty_out(vty,
12731 " Private AS numbers (all) replaced in updates to this neighbor\n");
12732 else if (CHECK_FLAG(p->af_flags[afi][safi],
12733 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12734 vty_out(vty,
12735 " Private AS numbers replaced in updates to this neighbor\n");
12736 else if (CHECK_FLAG(p->af_flags[afi][safi],
12737 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12738 vty_out(vty,
12739 " Private AS numbers (all) removed in updates to this neighbor\n");
12740 else if (CHECK_FLAG(p->af_flags[afi][safi],
12741 PEER_FLAG_REMOVE_PRIVATE_AS))
12742 vty_out(vty,
12743 " Private AS numbers removed in updates to this neighbor\n");
12744
b2ac1d0d
MS
12745 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN)) {
12746 if (CHECK_FLAG(p->af_flags[afi][safi],
12747 PEER_FLAG_ALLOWAS_IN_ORIGIN))
12748 vty_out(vty,
12749 " Local AS allowed as path origin\n");
12750 else
12751 vty_out(vty,
12752 " Local AS allowed in path, %d occurrences\n",
12753 p->allowas_in[afi][safi]);
12754 }
12755
dcc68b5e
MS
12756 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12757 vty_out(vty, " %s\n",
12758 bgp_addpath_names(p->addpath_type[afi][safi])
12759 ->human_description);
d62a17ae 12760
12761 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12762 vty_out(vty,
12763 " Override ASNs in outbound updates if aspath equals remote-as\n");
12764
12765 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12766 || CHECK_FLAG(p->af_flags[afi][safi],
12767 PEER_FLAG_FORCE_NEXTHOP_SELF))
12768 vty_out(vty, " NEXT_HOP is always this router\n");
12769 if (CHECK_FLAG(p->af_flags[afi][safi],
12770 PEER_FLAG_AS_PATH_UNCHANGED))
12771 vty_out(vty,
12772 " AS_PATH is propagated unchanged to this neighbor\n");
12773 if (CHECK_FLAG(p->af_flags[afi][safi],
12774 PEER_FLAG_NEXTHOP_UNCHANGED))
12775 vty_out(vty,
12776 " NEXT_HOP is propagated unchanged to this neighbor\n");
12777 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12778 vty_out(vty,
12779 " MED is propagated unchanged to this neighbor\n");
12780 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12781 || CHECK_FLAG(p->af_flags[afi][safi],
12782 PEER_FLAG_SEND_EXT_COMMUNITY)
12783 || CHECK_FLAG(p->af_flags[afi][safi],
12784 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12785 vty_out(vty,
12786 " Community attribute sent to this neighbor");
12787 if (CHECK_FLAG(p->af_flags[afi][safi],
12788 PEER_FLAG_SEND_COMMUNITY)
12789 && CHECK_FLAG(p->af_flags[afi][safi],
12790 PEER_FLAG_SEND_EXT_COMMUNITY)
12791 && CHECK_FLAG(p->af_flags[afi][safi],
12792 PEER_FLAG_SEND_LARGE_COMMUNITY))
12793 vty_out(vty, "(all)\n");
12794 else if (CHECK_FLAG(p->af_flags[afi][safi],
12795 PEER_FLAG_SEND_LARGE_COMMUNITY))
12796 vty_out(vty, "(large)\n");
12797 else if (CHECK_FLAG(p->af_flags[afi][safi],
12798 PEER_FLAG_SEND_EXT_COMMUNITY))
12799 vty_out(vty, "(extended)\n");
12800 else
12801 vty_out(vty, "(standard)\n");
12802 }
12803 if (CHECK_FLAG(p->af_flags[afi][safi],
12804 PEER_FLAG_DEFAULT_ORIGINATE)) {
12805 vty_out(vty, " Default information originate,");
12806
12807 if (p->default_rmap[afi][safi].name)
12808 vty_out(vty, " default route-map %s%s,",
12809 p->default_rmap[afi][safi].map ? "*"
12810 : "",
12811 p->default_rmap[afi][safi].name);
12812 if (paf && PAF_SUBGRP(paf)
12813 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12814 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12815 vty_out(vty, " default sent\n");
12816 else
12817 vty_out(vty, " default not sent\n");
12818 }
12819
dff8f48d
MK
12820 /* advertise-vni-all */
12821 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 12822 if (is_evpn_enabled())
dff8f48d
MK
12823 vty_out(vty, " advertise-all-vni\n");
12824 }
12825
d62a17ae 12826 if (filter->plist[FILTER_IN].name
12827 || filter->dlist[FILTER_IN].name
12828 || filter->aslist[FILTER_IN].name
12829 || filter->map[RMAP_IN].name)
12830 vty_out(vty, " Inbound path policy configured\n");
12831 if (filter->plist[FILTER_OUT].name
12832 || filter->dlist[FILTER_OUT].name
12833 || filter->aslist[FILTER_OUT].name
12834 || filter->map[RMAP_OUT].name || filter->usmap.name)
12835 vty_out(vty, " Outbound path policy configured\n");
12836
12837 /* prefix-list */
12838 if (filter->plist[FILTER_IN].name)
12839 vty_out(vty,
12840 " Incoming update prefix filter list is %s%s\n",
12841 filter->plist[FILTER_IN].plist ? "*" : "",
12842 filter->plist[FILTER_IN].name);
12843 if (filter->plist[FILTER_OUT].name)
12844 vty_out(vty,
12845 " Outgoing update prefix filter list is %s%s\n",
12846 filter->plist[FILTER_OUT].plist ? "*" : "",
12847 filter->plist[FILTER_OUT].name);
12848
12849 /* distribute-list */
12850 if (filter->dlist[FILTER_IN].name)
12851 vty_out(vty,
12852 " Incoming update network filter list is %s%s\n",
12853 filter->dlist[FILTER_IN].alist ? "*" : "",
12854 filter->dlist[FILTER_IN].name);
12855 if (filter->dlist[FILTER_OUT].name)
12856 vty_out(vty,
12857 " Outgoing update network filter list is %s%s\n",
12858 filter->dlist[FILTER_OUT].alist ? "*" : "",
12859 filter->dlist[FILTER_OUT].name);
12860
12861 /* filter-list. */
12862 if (filter->aslist[FILTER_IN].name)
12863 vty_out(vty,
12864 " Incoming update AS path filter list is %s%s\n",
12865 filter->aslist[FILTER_IN].aslist ? "*" : "",
12866 filter->aslist[FILTER_IN].name);
12867 if (filter->aslist[FILTER_OUT].name)
12868 vty_out(vty,
12869 " Outgoing update AS path filter list is %s%s\n",
12870 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12871 filter->aslist[FILTER_OUT].name);
12872
12873 /* route-map. */
12874 if (filter->map[RMAP_IN].name)
12875 vty_out(vty,
12876 " Route map for incoming advertisements is %s%s\n",
12877 filter->map[RMAP_IN].map ? "*" : "",
12878 filter->map[RMAP_IN].name);
12879 if (filter->map[RMAP_OUT].name)
12880 vty_out(vty,
12881 " Route map for outgoing advertisements is %s%s\n",
12882 filter->map[RMAP_OUT].map ? "*" : "",
12883 filter->map[RMAP_OUT].name);
12884
9dac9fc8 12885 /* ebgp-requires-policy (inbound) */
1d3fdccf 12886 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12887 && !bgp_inbound_policy_exists(p, filter))
12888 vty_out(vty,
12889 " Inbound updates discarded due to missing policy\n");
12890
12891 /* ebgp-requires-policy (outbound) */
1d3fdccf 12892 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12893 && !bgp_outbound_policy_exists(p, filter))
12894 vty_out(vty,
12895 " Outbound updates discarded due to missing policy\n");
12896
d62a17ae 12897 /* unsuppress-map */
12898 if (filter->usmap.name)
12899 vty_out(vty,
12900 " Route map for selective unsuppress is %s%s\n",
12901 filter->usmap.map ? "*" : "",
12902 filter->usmap.name);
12903
7f7940e6
MK
12904 /* advertise-map */
12905 if (filter->advmap.aname && filter->advmap.cname)
12906 vty_out(vty,
12907 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12908 filter->advmap.condition ? "EXIST"
12909 : "NON_EXIST",
12910 filter->advmap.cmap ? "*" : "",
12911 filter->advmap.cname,
12912 filter->advmap.amap ? "*" : "",
12913 filter->advmap.aname,
ecf2b628
QY
12914 filter->advmap.update_type ==
12915 UPDATE_TYPE_ADVERTISE
c385f82a
MK
12916 ? "Advertise"
12917 : "Withdraw");
7f7940e6 12918
d62a17ae 12919 /* Receive prefix count */
6cde4b45 12920 vty_out(vty, " %u accepted prefixes\n",
a0a87037 12921 p->pcount[afi][safi]);
d62a17ae 12922
fde246e8
DA
12923 /* maximum-prefix-out */
12924 if (CHECK_FLAG(p->af_flags[afi][safi],
12925 PEER_FLAG_MAX_PREFIX_OUT))
12926 vty_out(vty,
6cde4b45 12927 " Maximum allowed prefixes sent %u\n",
fde246e8
DA
12928 p->pmax_out[afi][safi]);
12929
d62a17ae 12930 /* Maximum prefix */
12931 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
a0a87037 12932 vty_out(vty,
6cde4b45 12933 " Maximum prefixes allowed %u%s\n",
d62a17ae 12934 p->pmax[afi][safi],
12935 CHECK_FLAG(p->af_flags[afi][safi],
12936 PEER_FLAG_MAX_PREFIX_WARNING)
12937 ? " (warning-only)"
12938 : "");
12939 vty_out(vty, " Threshold for warning message %d%%",
12940 p->pmax_threshold[afi][safi]);
12941 if (p->pmax_restart[afi][safi])
12942 vty_out(vty, ", restart interval %d min",
12943 p->pmax_restart[afi][safi]);
12944 vty_out(vty, "\n");
12945 }
12946
12947 vty_out(vty, "\n");
12948 }
12949}
12950
9f049418 12951static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 12952 json_object *json)
718e3744 12953{
d62a17ae 12954 struct bgp *bgp;
d62a17ae 12955 char timebuf[BGP_UPTIME_LEN];
12956 char dn_flag[2];
d62a17ae 12957 afi_t afi;
12958 safi_t safi;
d7c0a89a
QY
12959 uint16_t i;
12960 uint8_t *msg;
d62a17ae 12961 json_object *json_neigh = NULL;
12962 time_t epoch_tbuf;
4ab46701 12963 uint32_t sync_tcp_mss;
718e3744 12964
d62a17ae 12965 bgp = p->bgp;
12966
12967 if (use_json)
12968 json_neigh = json_object_new_object();
12969
12970 memset(dn_flag, '\0', sizeof(dn_flag));
12971 if (!p->conf_if && peer_dynamic_neighbor(p))
12972 dn_flag[0] = '*';
12973
12974 if (!use_json) {
12975 if (p->conf_if) /* Configured interface name. */
47e12884
DA
12976 vty_out(vty, "BGP neighbor on %s: %pSU, ", p->conf_if,
12977 &p->su);
d62a17ae 12978 else /* Configured IP address. */
12979 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12980 p->host);
12981 }
12982
12983 if (use_json) {
12984 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12985 json_object_string_add(json_neigh, "bgpNeighborAddr",
12986 "none");
12987 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
47e12884
DA
12988 json_object_string_addf(json_neigh, "bgpNeighborAddr",
12989 "%pSU", &p->su);
d62a17ae 12990
12991 json_object_int_add(json_neigh, "remoteAs", p->as);
12992
12993 if (p->change_local_as)
12994 json_object_int_add(json_neigh, "localAs",
12995 p->change_local_as);
12996 else
12997 json_object_int_add(json_neigh, "localAs", p->local_as);
12998
12999 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
13000 json_object_boolean_true_add(json_neigh,
13001 "localAsNoPrepend");
13002
13003 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
13004 json_object_boolean_true_add(json_neigh,
13005 "localAsReplaceAs");
13006 } else {
13007 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
13008 || (p->as_type == AS_INTERNAL))
13009 vty_out(vty, "remote AS %u, ", p->as);
13010 else
13011 vty_out(vty, "remote AS Unspecified, ");
13012 vty_out(vty, "local AS %u%s%s, ",
13013 p->change_local_as ? p->change_local_as : p->local_as,
13014 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
13015 ? " no-prepend"
13016 : "",
13017 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
13018 ? " replace-as"
13019 : "");
13020 }
faa16034
DS
13021 /* peer type internal or confed-internal */
13022 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
d62a17ae 13023 if (use_json) {
13024 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13025 json_object_boolean_true_add(
13026 json_neigh, "nbrConfedInternalLink");
13027 else
13028 json_object_boolean_true_add(json_neigh,
13029 "nbrInternalLink");
13030 } else {
13031 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13032 vty_out(vty, "confed-internal link\n");
13033 else
13034 vty_out(vty, "internal link\n");
13035 }
faa16034
DS
13036 /* peer type external or confed-external */
13037 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
d62a17ae 13038 if (use_json) {
13039 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13040 json_object_boolean_true_add(
13041 json_neigh, "nbrConfedExternalLink");
13042 else
13043 json_object_boolean_true_add(json_neigh,
13044 "nbrExternalLink");
13045 } else {
13046 if (bgp_confederation_peers_check(bgp, p->as))
13047 vty_out(vty, "confed-external link\n");
13048 else
13049 vty_out(vty, "external link\n");
13050 }
faa16034
DS
13051 } else {
13052 if (use_json)
13053 json_object_boolean_true_add(json_neigh,
13054 "nbrUnspecifiedLink");
13055 else
13056 vty_out(vty, "unspecified link\n");
d62a17ae 13057 }
13058
d864dd9e
EB
13059 /* Roles */
13060 if (use_json) {
13061 json_object_string_add(json_neigh, "localRole",
8f2d6021
EB
13062 bgp_get_name_by_role(p->local_role));
13063 json_object_string_add(json_neigh, "remoteRole",
13064 bgp_get_name_by_role(p->remote_role));
d864dd9e
EB
13065 } else {
13066 vty_out(vty, " Local Role: %s\n",
8f2d6021
EB
13067 bgp_get_name_by_role(p->local_role));
13068 vty_out(vty, " Remote Role: %s\n",
13069 bgp_get_name_by_role(p->remote_role));
d864dd9e
EB
13070 }
13071
13072
d62a17ae 13073 /* Description. */
13074 if (p->desc) {
13075 if (use_json)
13076 json_object_string_add(json_neigh, "nbrDesc", p->desc);
13077 else
13078 vty_out(vty, " Description: %s\n", p->desc);
13079 }
13080
13081 if (p->hostname) {
13082 if (use_json) {
432e7e46
KQ
13083 json_object_string_add(json_neigh, "hostname",
13084 p->hostname);
d62a17ae 13085
13086 if (p->domainname)
13087 json_object_string_add(json_neigh, "domainname",
13088 p->domainname);
13089 } else {
13090 if (p->domainname && (p->domainname[0] != '\0'))
13091 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
13092 p->domainname);
13093 else
13094 vty_out(vty, "Hostname: %s\n", p->hostname);
13095 }
432e7e46
KQ
13096 } else {
13097 if (use_json)
13098 json_object_string_add(json_neigh, "hostname",
13099 "Unknown");
d62a17ae 13100 }
13101
13102 /* Peer-group */
13103 if (p->group) {
13104 if (use_json) {
13105 json_object_string_add(json_neigh, "peerGroup",
13106 p->group->name);
13107
13108 if (dn_flag[0]) {
13109 struct prefix prefix, *range = NULL;
13110
0154d8ce
DS
13111 if (sockunion2hostprefix(&(p->su), &prefix))
13112 range = peer_group_lookup_dynamic_neighbor_range(
13113 p->group, &prefix);
d62a17ae 13114
13115 if (range) {
67d7e256 13116 json_object_string_addf(
d62a17ae 13117 json_neigh,
67d7e256
DA
13118 "peerSubnetRangeGroup", "%pFX",
13119 range);
d62a17ae 13120 }
13121 }
13122 } else {
13123 vty_out(vty,
13124 " Member of peer-group %s for session parameters\n",
13125 p->group->name);
13126
13127 if (dn_flag[0]) {
13128 struct prefix prefix, *range = NULL;
13129
0154d8ce
DS
13130 if (sockunion2hostprefix(&(p->su), &prefix))
13131 range = peer_group_lookup_dynamic_neighbor_range(
13132 p->group, &prefix);
d62a17ae 13133
13134 if (range) {
d62a17ae 13135 vty_out(vty,
1b78780b
DL
13136 " Belongs to the subnet range group: %pFX\n",
13137 range);
d62a17ae 13138 }
13139 }
13140 }
13141 }
13142
13143 if (use_json) {
13144 /* Administrative shutdown. */
cb9196e7
DS
13145 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13146 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 13147 json_object_boolean_true_add(json_neigh,
13148 "adminShutDown");
13149
13150 /* BGP Version. */
13151 json_object_int_add(json_neigh, "bgpVersion", 4);
c949c771
DA
13152 json_object_string_addf(json_neigh, "remoteRouterId", "%pI4",
13153 &p->remote_id);
13154 json_object_string_addf(json_neigh, "localRouterId", "%pI4",
13155 &bgp->router_id);
d62a17ae 13156
13157 /* Confederation */
13158 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13159 && bgp_confederation_peers_check(bgp, p->as))
13160 json_object_boolean_true_add(json_neigh,
13161 "nbrCommonAdmin");
13162
13163 /* Status. */
13164 json_object_string_add(
13165 json_neigh, "bgpState",
13166 lookup_msg(bgp_status_msg, p->status, NULL));
13167
feb17238 13168 if (peer_established(p)) {
d62a17ae 13169 time_t uptime;
d62a17ae 13170
083ec940 13171 uptime = monotime(NULL);
d62a17ae 13172 uptime -= p->uptime;
d62a17ae 13173 epoch_tbuf = time(NULL) - uptime;
13174
d3c7efed
DS
13175 json_object_int_add(json_neigh, "bgpTimerUpMsec",
13176 uptime * 1000);
d62a17ae 13177 json_object_string_add(json_neigh, "bgpTimerUpString",
13178 peer_uptime(p->uptime, timebuf,
13179 BGP_UPTIME_LEN, 0,
13180 NULL));
13181 json_object_int_add(json_neigh,
13182 "bgpTimerUpEstablishedEpoch",
13183 epoch_tbuf);
13184 }
13185
13186 else if (p->status == Active) {
13187 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13188 json_object_string_add(json_neigh, "bgpStateIs",
13189 "passive");
13190 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13191 json_object_string_add(json_neigh, "bgpStateIs",
13192 "passiveNSF");
13193 }
13194
13195 /* read timer */
13196 time_t uptime;
a2700b50 13197 struct tm tm;
d62a17ae 13198
083ec940 13199 uptime = monotime(NULL);
d62a17ae 13200 uptime -= p->readtime;
a2700b50
MS
13201 gmtime_r(&uptime, &tm);
13202
d62a17ae 13203 json_object_int_add(json_neigh, "bgpTimerLastRead",
a2700b50
MS
13204 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13205 + (tm.tm_hour * 3600000));
d62a17ae 13206
083ec940 13207 uptime = monotime(NULL);
d62a17ae 13208 uptime -= p->last_write;
a2700b50
MS
13209 gmtime_r(&uptime, &tm);
13210
d62a17ae 13211 json_object_int_add(json_neigh, "bgpTimerLastWrite",
a2700b50
MS
13212 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13213 + (tm.tm_hour * 3600000));
d62a17ae 13214
083ec940 13215 uptime = monotime(NULL);
d62a17ae 13216 uptime -= p->update_time;
a2700b50
MS
13217 gmtime_r(&uptime, &tm);
13218
d62a17ae 13219 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
a2700b50
MS
13220 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13221 + (tm.tm_hour * 3600000));
d62a17ae 13222
13223 /* Configured timer values. */
9b1b9623
TA
13224 json_object_int_add(json_neigh,
13225 "bgpTimerConfiguredHoldTimeMsecs",
e93d5c29
TA
13226 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13227 ? p->holdtime * 1000
13228 : bgp->default_holdtime * 1000);
13229 json_object_int_add(json_neigh,
13230 "bgpTimerConfiguredKeepAliveIntervalMsecs",
13231 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13232 ? p->keepalive * 1000
13233 : bgp->default_keepalive * 1000);
d62a17ae 13234 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
13235 p->v_holdtime * 1000);
13236 json_object_int_add(json_neigh,
13237 "bgpTimerKeepAliveIntervalMsecs",
13238 p->v_keepalive * 1000);
d43114f3
DS
13239 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
13240 json_object_int_add(json_neigh,
13241 "bgpTimerDelayOpenTimeMsecs",
13242 p->v_delayopen * 1000);
13243 }
13244
4ab46701
AR
13245 /* Configured and Synced tcp-mss value for peer */
13246 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13247 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13248 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
13249 p->tcp_mss);
13250 json_object_int_add(json_neigh, "bgpTcpMssSynced",
13251 sync_tcp_mss);
13252 }
13253
d08c0c80
DA
13254 /* Extended Optional Parameters Length for BGP OPEN Message */
13255 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
13256 json_object_boolean_true_add(
13257 json_neigh, "extendedOptionalParametersLength");
13258 else
13259 json_object_boolean_false_add(
13260 json_neigh, "extendedOptionalParametersLength");
6e37924b
DA
13261
13262 /* Conditional advertisements */
13263 json_object_int_add(
13264 json_neigh,
13265 "bgpTimerConfiguredConditionalAdvertisementsSec",
13266 bgp->condition_check_period);
13267 if (thread_is_scheduled(bgp->t_condition_check))
13268 json_object_int_add(
13269 json_neigh,
13270 "bgpTimerUntilConditionalAdvertisementsSec",
13271 thread_timer_remain_second(
13272 bgp->t_condition_check));
d62a17ae 13273 } else {
13274 /* Administrative shutdown. */
cb9196e7
DS
13275 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13276 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 13277 vty_out(vty, " Administratively shut down\n");
13278
13279 /* BGP Version. */
13280 vty_out(vty, " BGP version 4");
07380148
DA
13281 vty_out(vty, ", remote router ID %pI4", &p->remote_id);
13282 vty_out(vty, ", local router ID %pI4\n", &bgp->router_id);
d62a17ae 13283
13284 /* Confederation */
13285 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13286 && bgp_confederation_peers_check(bgp, p->as))
13287 vty_out(vty,
13288 " Neighbor under common administration\n");
13289
13290 /* Status. */
13291 vty_out(vty, " BGP state = %s",
13292 lookup_msg(bgp_status_msg, p->status, NULL));
13293
feb17238 13294 if (peer_established(p))
d62a17ae 13295 vty_out(vty, ", up for %8s",
13296 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
13297 0, NULL));
13298
13299 else if (p->status == Active) {
13300 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13301 vty_out(vty, " (passive)");
13302 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13303 vty_out(vty, " (NSF passive)");
13304 }
13305 vty_out(vty, "\n");
13306
13307 /* read timer */
13308 vty_out(vty, " Last read %s",
13309 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
13310 NULL));
13311 vty_out(vty, ", Last write %s\n",
13312 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
13313 NULL));
13314
13315 /* Configured timer values. */
13316 vty_out(vty,
e93d5c29 13317 " Hold time is %d seconds, keepalive interval is %d seconds\n",
d62a17ae 13318 p->v_holdtime, p->v_keepalive);
e93d5c29
TA
13319 vty_out(vty, " Configured hold time is %d seconds",
13320 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13321 ? p->holdtime
13322 : bgp->default_holdtime);
9b1b9623 13323 vty_out(vty, ", keepalive interval is %d seconds\n",
e93d5c29
TA
13324 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13325 ? p->keepalive
13326 : bgp->default_keepalive);
d43114f3
DS
13327 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
13328 vty_out(vty,
13329 " Configured DelayOpenTime is %d seconds\n",
13330 p->delayopen);
4ab46701
AR
13331
13332 /* Configured and synced tcp-mss value for peer */
13333 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13334 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13335 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
13336 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
13337 }
d08c0c80
DA
13338
13339 /* Extended Optional Parameters Length for BGP OPEN Message */
13340 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
13341 vty_out(vty,
13342 " Extended Optional Parameters Length is enabled\n");
6e37924b
DA
13343
13344 /* Conditional advertisements */
13345 vty_out(vty,
13346 " Configured conditional advertisements interval is %d seconds\n",
13347 bgp->condition_check_period);
13348 if (thread_is_scheduled(bgp->t_condition_check))
13349 vty_out(vty,
13350 " Time until conditional advertisements begin is %lu seconds\n",
13351 thread_timer_remain_second(
13352 bgp->t_condition_check));
d62a17ae 13353 }
13354 /* Capability. */
10711563
DA
13355 if (peer_established(p) &&
13356 (p->cap || peer_afc_advertised(p) || peer_afc_received(p))) {
13357 if (use_json) {
13358 json_object *json_cap = NULL;
d62a17ae 13359
10711563 13360 json_cap = json_object_new_object();
d62a17ae 13361
10711563
DA
13362 /* AS4 */
13363 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13364 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13365 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV) &&
13366 CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
ef56aee4 13367 json_object_string_add(
10711563 13368 json_cap, "4byteAs",
ef56aee4 13369 "advertisedAndReceived");
10711563
DA
13370 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13371 json_object_string_add(json_cap,
13372 "4byteAs",
13373 "advertised");
13374 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13375 json_object_string_add(json_cap,
13376 "4byteAs",
13377 "received");
13378 }
ef56aee4 13379
10711563
DA
13380 /* Extended Message Support */
13381 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV) &&
13382 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV))
13383 json_object_string_add(json_cap,
13384 "extendedMessage",
13385 "advertisedAndReceived");
13386 else if (CHECK_FLAG(p->cap,
13387 PEER_CAP_EXTENDED_MESSAGE_ADV))
13388 json_object_string_add(json_cap,
13389 "extendedMessage",
13390 "advertised");
13391 else if (CHECK_FLAG(p->cap,
13392 PEER_CAP_EXTENDED_MESSAGE_RCV))
13393 json_object_string_add(json_cap,
13394 "extendedMessage",
13395 "received");
ef56aee4 13396
10711563
DA
13397 /* AddPath */
13398 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13399 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13400 json_object *json_add = NULL;
13401 const char *print_store;
d62a17ae 13402
10711563 13403 json_add = json_object_new_object();
d62a17ae 13404
10711563
DA
13405 FOREACH_AFI_SAFI (afi, safi) {
13406 json_object *json_sub = NULL;
13407 json_sub = json_object_new_object();
13408 print_store = get_afi_safi_str(
13409 afi, safi, true);
d62a17ae 13410
10711563
DA
13411 if (CHECK_FLAG(
13412 p->af_cap[afi][safi],
13413 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13414 CHECK_FLAG(
13415 p->af_cap[afi][safi],
13416 PEER_CAP_ADDPATH_AF_TX_RCV)) {
05c7a1cc
QY
13417 if (CHECK_FLAG(
13418 p->af_cap[afi]
13419 [safi],
10711563
DA
13420 PEER_CAP_ADDPATH_AF_TX_ADV) &&
13421 CHECK_FLAG(
05c7a1cc
QY
13422 p->af_cap[afi]
13423 [safi],
10711563
DA
13424 PEER_CAP_ADDPATH_AF_TX_RCV))
13425 json_object_boolean_true_add(
13426 json_sub,
13427 "txAdvertisedAndReceived");
13428 else if (
13429 CHECK_FLAG(
13430 p->af_cap[afi]
13431 [safi],
13432 PEER_CAP_ADDPATH_AF_TX_ADV))
13433 json_object_boolean_true_add(
13434 json_sub,
13435 "txAdvertised");
13436 else if (
13437 CHECK_FLAG(
13438 p->af_cap[afi]
13439 [safi],
13440 PEER_CAP_ADDPATH_AF_TX_RCV))
13441 json_object_boolean_true_add(
13442 json_sub,
13443 "txReceived");
13444 }
d62a17ae 13445
10711563
DA
13446 if (CHECK_FLAG(
13447 p->af_cap[afi][safi],
13448 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13449 CHECK_FLAG(
13450 p->af_cap[afi][safi],
13451 PEER_CAP_ADDPATH_AF_RX_RCV)) {
05c7a1cc
QY
13452 if (CHECK_FLAG(
13453 p->af_cap[afi]
13454 [safi],
10711563
DA
13455 PEER_CAP_ADDPATH_AF_RX_ADV) &&
13456 CHECK_FLAG(
13457 p->af_cap[afi]
13458 [safi],
13459 PEER_CAP_ADDPATH_AF_RX_RCV))
13460 json_object_boolean_true_add(
13461 json_sub,
13462 "rxAdvertisedAndReceived");
13463 else if (
13464 CHECK_FLAG(
13465 p->af_cap[afi]
13466 [safi],
13467 PEER_CAP_ADDPATH_AF_RX_ADV))
13468 json_object_boolean_true_add(
13469 json_sub,
13470 "rxAdvertised");
13471 else if (
13472 CHECK_FLAG(
13473 p->af_cap[afi]
13474 [safi],
13475 PEER_CAP_ADDPATH_AF_RX_RCV))
13476 json_object_boolean_true_add(
13477 json_sub,
13478 "rxReceived");
05c7a1cc
QY
13479 }
13480
10711563
DA
13481 if (CHECK_FLAG(
13482 p->af_cap[afi][safi],
13483 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13484 CHECK_FLAG(
13485 p->af_cap[afi][safi],
13486 PEER_CAP_ADDPATH_AF_TX_RCV) ||
13487 CHECK_FLAG(
13488 p->af_cap[afi][safi],
13489 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13490 CHECK_FLAG(
13491 p->af_cap[afi][safi],
13492 PEER_CAP_ADDPATH_AF_RX_RCV))
13493 json_object_object_add(
13494 json_add, print_store,
13495 json_sub);
13496 else
13497 json_object_free(json_sub);
d62a17ae 13498 }
13499
10711563
DA
13500 json_object_object_add(json_cap, "addPath",
13501 json_add);
13502 }
d62a17ae 13503
10711563
DA
13504 /* Dynamic */
13505 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13506 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13507 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV) &&
13508 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13509 json_object_string_add(
13510 json_cap, "dynamic",
13511 "advertisedAndReceived");
13512 else if (CHECK_FLAG(p->cap,
13513 PEER_CAP_DYNAMIC_ADV))
13514 json_object_string_add(json_cap,
13515 "dynamic",
13516 "advertised");
13517 else if (CHECK_FLAG(p->cap,
13518 PEER_CAP_DYNAMIC_RCV))
13519 json_object_string_add(json_cap,
13520 "dynamic",
13521 "received");
13522 }
d62a17ae 13523
d864dd9e
EB
13524 /* Role */
13525 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13526 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13527 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV) &&
13528 CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13529 json_object_string_add(
13530 json_cap, "role",
13531 "advertisedAndReceived");
13532 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13533 json_object_string_add(json_cap, "role",
13534 "advertised");
13535 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13536 json_object_string_add(json_cap, "role",
13537 "received");
13538 }
13539
10711563
DA
13540 /* Extended nexthop */
13541 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13542 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13543 json_object *json_nxt = NULL;
13544 const char *print_store;
d62a17ae 13545
d62a17ae 13546
10711563
DA
13547 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV) &&
13548 CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13549 json_object_string_add(
13550 json_cap, "extendedNexthop",
13551 "advertisedAndReceived");
13552 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13553 json_object_string_add(
13554 json_cap, "extendedNexthop",
13555 "advertised");
13556 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13557 json_object_string_add(
13558 json_cap, "extendedNexthop",
13559 "received");
d62a17ae 13560
10711563
DA
13561 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13562 json_nxt = json_object_new_object();
d62a17ae 13563
10711563
DA
13564 for (safi = SAFI_UNICAST;
13565 safi < SAFI_MAX; safi++) {
13566 if (CHECK_FLAG(
13567 p->af_cap[AFI_IP]
13568 [safi],
13569 PEER_CAP_ENHE_AF_RCV)) {
13570 print_store =
13571 get_afi_safi_str(
d62a17ae 13572 AFI_IP,
10711563
DA
13573 safi,
13574 true);
13575 json_object_string_add(
13576 json_nxt,
13577 print_store,
13578 "recieved"); /* misspelled for compatibility */
d62a17ae 13579 }
d62a17ae 13580 }
10711563
DA
13581 json_object_object_add(
13582 json_cap,
13583 "extendedNexthopFamililesByPeer",
13584 json_nxt);
d62a17ae 13585 }
10711563 13586 }
d62a17ae 13587
10711563
DA
13588 /* Long-lived Graceful Restart */
13589 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13590 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13591 json_object *json_llgr = NULL;
13592 const char *afi_safi_str;
8606be87 13593
10711563
DA
13594 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV) &&
13595 CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13596 json_object_string_add(
13597 json_cap,
13598 "longLivedGracefulRestart",
13599 "advertisedAndReceived");
13600 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13601 json_object_string_add(
13602 json_cap,
13603 "longLivedGracefulRestart",
13604 "advertised");
13605 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13606 json_object_string_add(
13607 json_cap,
13608 "longLivedGracefulRestart",
13609 "received");
8606be87 13610
10711563
DA
13611 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13612 json_llgr = json_object_new_object();
8606be87 13613
10711563
DA
13614 FOREACH_AFI_SAFI (afi, safi) {
13615 if (CHECK_FLAG(
13616 p->af_cap[afi]
13617 [safi],
13618 PEER_CAP_ENHE_AF_RCV)) {
13619 afi_safi_str =
13620 get_afi_safi_str(
8606be87
DA
13621 afi,
13622 safi,
13623 true);
10711563
DA
13624 json_object_string_add(
13625 json_llgr,
13626 afi_safi_str,
13627 "received");
8606be87 13628 }
8606be87 13629 }
10711563
DA
13630 json_object_object_add(
13631 json_cap,
13632 "longLivedGracefulRestartByPeer",
13633 json_llgr);
8606be87 13634 }
10711563 13635 }
8606be87 13636
10711563
DA
13637 /* Route Refresh */
13638 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13639 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13640 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13641 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) &&
13642 (CHECK_FLAG(p->cap,
13643 PEER_CAP_REFRESH_NEW_RCV) ||
13644 CHECK_FLAG(p->cap,
13645 PEER_CAP_REFRESH_OLD_RCV))) {
13646 if (CHECK_FLAG(
13647 p->cap,
13648 PEER_CAP_REFRESH_OLD_RCV) &&
13649 CHECK_FLAG(
13650 p->cap,
13651 PEER_CAP_REFRESH_NEW_RCV))
13652 json_object_string_add(
13653 json_cap,
13654 "routeRefresh",
13655 "advertisedAndReceivedOldNew");
13656 else {
d62a17ae 13657 if (CHECK_FLAG(
13658 p->cap,
10711563 13659 PEER_CAP_REFRESH_OLD_RCV))
d62a17ae 13660 json_object_string_add(
13661 json_cap,
13662 "routeRefresh",
10711563
DA
13663 "advertisedAndReceivedOld");
13664 else
13665 json_object_string_add(
13666 json_cap,
13667 "routeRefresh",
13668 "advertisedAndReceivedNew");
d62a17ae 13669 }
10711563
DA
13670 } else if (CHECK_FLAG(p->cap,
13671 PEER_CAP_REFRESH_ADV))
13672 json_object_string_add(json_cap,
13673 "routeRefresh",
13674 "advertised");
13675 else if (CHECK_FLAG(p->cap,
13676 PEER_CAP_REFRESH_NEW_RCV) ||
13677 CHECK_FLAG(p->cap,
13678 PEER_CAP_REFRESH_OLD_RCV))
13679 json_object_string_add(json_cap,
13680 "routeRefresh",
13681 "received");
13682 }
d62a17ae 13683
10711563
DA
13684 /* Enhanced Route Refresh */
13685 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13686 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13687 if (CHECK_FLAG(p->cap,
13688 PEER_CAP_ENHANCED_RR_ADV) &&
13689 CHECK_FLAG(p->cap,
13690 PEER_CAP_ENHANCED_RR_RCV))
d77114b7 13691 json_object_string_add(
10711563
DA
13692 json_cap,
13693 "enhancedRouteRefresh",
13694 "advertisedAndReceived");
13695 else if (CHECK_FLAG(p->cap,
13696 PEER_CAP_ENHANCED_RR_ADV))
d77114b7 13697 json_object_string_add(
10711563
DA
13698 json_cap,
13699 "enhancedRouteRefresh",
13700 "advertised");
13701 else if (CHECK_FLAG(p->cap,
9af52ccf 13702 PEER_CAP_ENHANCED_RR_RCV))
10711563
DA
13703 json_object_string_add(
13704 json_cap,
13705 "enhancedRouteRefresh",
13706 "received");
13707 }
d77114b7 13708
10711563
DA
13709 /* Multiprotocol Extensions */
13710 json_object *json_multi = NULL;
d77114b7 13711
10711563 13712 json_multi = json_object_new_object();
d77114b7 13713
10711563
DA
13714 FOREACH_AFI_SAFI (afi, safi) {
13715 if (p->afc_adv[afi][safi] ||
13716 p->afc_recv[afi][safi]) {
13717 json_object *json_exten = NULL;
13718 json_exten = json_object_new_object();
13719
13720 if (p->afc_adv[afi][safi] &&
13721 p->afc_recv[afi][safi])
13722 json_object_boolean_true_add(
13723 json_exten,
9af52ccf 13724 "advertisedAndReceived");
10711563
DA
13725 else if (p->afc_adv[afi][safi])
13726 json_object_boolean_true_add(
13727 json_exten,
9af52ccf 13728 "advertised");
10711563
DA
13729 else if (p->afc_recv[afi][safi])
13730 json_object_boolean_true_add(
13731 json_exten, "received");
9af52ccf 13732
10711563
DA
13733 json_object_object_add(
13734 json_multi,
13735 get_afi_safi_str(afi, safi,
13736 true),
13737 json_exten);
13738 }
13739 }
13740 json_object_object_add(json_cap,
13741 "multiprotocolExtensions",
13742 json_multi);
d62a17ae 13743
10711563
DA
13744 /* Hostname capabilities */
13745 json_object *json_hname = NULL;
d62a17ae 13746
10711563 13747 json_hname = json_object_new_object();
d62a17ae 13748
10711563
DA
13749 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13750 json_object_string_add(
13751 json_hname, "advHostName",
13752 bgp->peer_self->hostname
13753 ? bgp->peer_self->hostname
13754 : "n/a");
13755 json_object_string_add(
13756 json_hname, "advDomainName",
13757 bgp->peer_self->domainname
13758 ? bgp->peer_self->domainname
13759 : "n/a");
13760 }
d77114b7 13761
d77114b7 13762
10711563
DA
13763 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13764 json_object_string_add(
13765 json_hname, "rcvHostName",
13766 p->hostname ? p->hostname : "n/a");
13767 json_object_string_add(
13768 json_hname, "rcvDomainName",
13769 p->domainname ? p->domainname : "n/a");
13770 }
d77114b7 13771
10711563
DA
13772 json_object_object_add(json_cap, "hostName",
13773 json_hname);
d77114b7 13774
17be83bf 13775 /* Graceful Restart */
10711563
DA
13776 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13777 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13778 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) &&
13779 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
d77114b7 13780 json_object_string_add(
10711563
DA
13781 json_cap, "gracefulRestart",
13782 "advertisedAndReceived");
13783 else if (CHECK_FLAG(p->cap,
13784 PEER_CAP_RESTART_ADV))
d77114b7 13785 json_object_string_add(
10711563
DA
13786 json_cap,
13787 "gracefulRestartCapability",
13788 "advertised");
13789 else if (CHECK_FLAG(p->cap,
13790 PEER_CAP_RESTART_RCV))
13791 json_object_string_add(
13792 json_cap,
13793 "gracefulRestartCapability",
13794 "received");
d77114b7 13795
10711563
DA
13796 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13797 int restart_af_count = 0;
13798 json_object *json_restart = NULL;
13799 json_restart = json_object_new_object();
d62a17ae 13800
10711563
DA
13801 json_object_int_add(
13802 json_cap,
13803 "gracefulRestartRemoteTimerMsecs",
13804 p->v_gr_restart * 1000);
d62a17ae 13805
10711563 13806 FOREACH_AFI_SAFI (afi, safi) {
05c7a1cc
QY
13807 if (CHECK_FLAG(
13808 p->af_cap[afi]
13809 [safi],
10711563
DA
13810 PEER_CAP_RESTART_AF_RCV)) {
13811 json_object *json_sub =
13812 NULL;
13813 json_sub =
13814 json_object_new_object();
d62a17ae 13815
05c7a1cc
QY
13816 if (CHECK_FLAG(
13817 p->af_cap
13818 [afi]
13819 [safi],
10711563
DA
13820 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13821 json_object_boolean_true_add(
13822 json_sub,
13823 "preserved");
13824 restart_af_count++;
d62a17ae 13825 json_object_object_add(
10711563
DA
13826 json_restart,
13827 get_afi_safi_str(
13828 afi,
13829 safi,
13830 true),
13831 json_sub);
d62a17ae 13832 }
d62a17ae 13833 }
10711563
DA
13834 if (!restart_af_count) {
13835 json_object_string_add(
13836 json_cap,
13837 "addressFamiliesByPeer",
13838 "none");
13839 json_object_free(json_restart);
13840 } else
13841 json_object_object_add(
13842 json_cap,
13843 "addressFamiliesByPeer",
13844 json_restart);
d62a17ae 13845 }
10711563
DA
13846 }
13847 json_object_object_add(
13848 json_neigh, "neighborCapabilities", json_cap);
13849 } else {
13850 vty_out(vty, " Neighbor capabilities:\n");
13851
13852 /* AS4 */
13853 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13854 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13855 vty_out(vty, " 4 Byte AS:");
13856 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13857 vty_out(vty, " advertised");
13858 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13859 vty_out(vty, " %sreceived",
13860 CHECK_FLAG(p->cap,
13861 PEER_CAP_AS4_ADV)
13862 ? "and "
13863 : "");
13864 vty_out(vty, "\n");
13865 }
d62a17ae 13866
10711563
DA
13867 /* Extended Message Support */
13868 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV) ||
13869 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13870 vty_out(vty, " Extended Message:");
ef56aee4 13871 if (CHECK_FLAG(p->cap,
10711563
DA
13872 PEER_CAP_EXTENDED_MESSAGE_ADV))
13873 vty_out(vty, " advertised");
13874 if (CHECK_FLAG(p->cap,
13875 PEER_CAP_EXTENDED_MESSAGE_RCV))
13876 vty_out(vty, " %sreceived",
13877 CHECK_FLAG(
13878 p->cap,
13879 PEER_CAP_EXTENDED_MESSAGE_ADV)
13880 ? "and "
13881 : "");
13882 vty_out(vty, "\n");
13883 }
d62a17ae 13884
10711563
DA
13885 /* AddPath */
13886 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13887 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13888 vty_out(vty, " AddPath:\n");
d62a17ae 13889
10711563 13890 FOREACH_AFI_SAFI (afi, safi) {
ef56aee4 13891 if (CHECK_FLAG(
10711563
DA
13892 p->af_cap[afi][safi],
13893 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13894 CHECK_FLAG(
13895 p->af_cap[afi][safi],
13896 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13897 vty_out(vty, " %s: TX ",
13898 get_afi_safi_str(
13899 afi, safi,
13900 false));
ef56aee4 13901
10711563
DA
13902 if (CHECK_FLAG(
13903 p->af_cap[afi]
13904 [safi],
13905 PEER_CAP_ADDPATH_AF_TX_ADV))
13906 vty_out(vty,
13907 "advertised");
d62a17ae 13908
05c7a1cc
QY
13909 if (CHECK_FLAG(
13910 p->af_cap[afi]
13911 [safi],
10711563 13912 PEER_CAP_ADDPATH_AF_TX_RCV))
05c7a1cc 13913 vty_out(vty,
10711563
DA
13914 "%sreceived",
13915 CHECK_FLAG(
13916 p->af_cap
13917 [afi]
13918 [safi],
13919 PEER_CAP_ADDPATH_AF_TX_ADV)
13920 ? " and "
13921 : "");
05c7a1cc 13922
10711563
DA
13923 vty_out(vty, "\n");
13924 }
d62a17ae 13925
9af52ccf 13926 if (CHECK_FLAG(
10711563
DA
13927 p->af_cap[afi][safi],
13928 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13929 CHECK_FLAG(
13930 p->af_cap[afi][safi],
13931 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13932 vty_out(vty, " %s: RX ",
5cb5f4d0 13933 get_afi_safi_str(
10711563
DA
13934 afi, safi,
13935 false));
d62a17ae 13936
05c7a1cc
QY
13937 if (CHECK_FLAG(
13938 p->af_cap[afi]
13939 [safi],
10711563 13940 PEER_CAP_ADDPATH_AF_RX_ADV))
05c7a1cc 13941 vty_out(vty,
10711563 13942 "advertised");
d62a17ae 13943
10711563
DA
13944 if (CHECK_FLAG(
13945 p->af_cap[afi]
13946 [safi],
13947 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc 13948 vty_out(vty,
10711563
DA
13949 "%sreceived",
13950 CHECK_FLAG(
13951 p->af_cap
13952 [afi]
13953 [safi],
13954 PEER_CAP_ADDPATH_AF_RX_ADV)
13955 ? " and "
05c7a1cc 13956 : "");
d62a17ae 13957
05c7a1cc 13958 vty_out(vty, "\n");
05c7a1cc 13959 }
d62a17ae 13960 }
10711563 13961 }
d62a17ae 13962
10711563
DA
13963 /* Dynamic */
13964 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13965 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13966 vty_out(vty, " Dynamic:");
13967 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV))
13968 vty_out(vty, " advertised");
13969 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13970 vty_out(vty, " %sreceived",
13971 CHECK_FLAG(p->cap,
13972 PEER_CAP_DYNAMIC_ADV)
13973 ? "and "
13974 : "");
13975 vty_out(vty, "\n");
13976 }
d62a17ae 13977
d864dd9e
EB
13978 /* Role */
13979 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13980 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13981 vty_out(vty, " Role:");
13982 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13983 vty_out(vty, " advertised");
13984 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13985 vty_out(vty, " %sreceived",
13986 CHECK_FLAG(p->cap,
13987 PEER_CAP_ROLE_ADV)
13988 ? "and "
13989 : "");
13990 vty_out(vty, "\n");
13991 }
13992
10711563
DA
13993 /* Extended nexthop */
13994 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13995 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13996 vty_out(vty, " Extended nexthop:");
13997 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13998 vty_out(vty, " advertised");
13999 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
14000 vty_out(vty, " %sreceived",
14001 CHECK_FLAG(p->cap,
14002 PEER_CAP_ENHE_ADV)
14003 ? "and "
14004 : "");
14005 vty_out(vty, "\n");
d62a17ae 14006
10711563 14007 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
57f7feb6 14008 vty_out(vty,
10711563
DA
14009 " Address families by peer:\n ");
14010 for (safi = SAFI_UNICAST;
14011 safi < SAFI_MAX; safi++)
14012 if (CHECK_FLAG(
14013 p->af_cap[AFI_IP]
14014 [safi],
14015 PEER_CAP_ENHE_AF_RCV))
14016 vty_out(vty,
14017 " %s\n",
14018 get_afi_safi_str(
14019 AFI_IP,
14020 safi,
14021 false));
d62a17ae 14022 }
10711563 14023 }
d62a17ae 14024
10711563
DA
14025 /* Long-lived Graceful Restart */
14026 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
14027 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
14028 vty_out(vty,
14029 " Long-lived Graceful Restart:");
14030 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
14031 vty_out(vty, " advertised");
14032 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
14033 vty_out(vty, " %sreceived",
14034 CHECK_FLAG(p->cap,
14035 PEER_CAP_LLGR_ADV)
14036 ? "and "
14037 : "");
14038 vty_out(vty, "\n");
8606be87 14039
10711563 14040 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
57f7feb6 14041 vty_out(vty,
10711563
DA
14042 " Address families by peer:\n");
14043 FOREACH_AFI_SAFI (afi, safi)
14044 if (CHECK_FLAG(
14045 p->af_cap[afi]
14046 [safi],
14047 PEER_CAP_LLGR_AF_RCV))
14048 vty_out(vty,
14049 " %s\n",
14050 get_afi_safi_str(
14051 afi,
14052 safi,
14053 false));
8606be87 14054 }
10711563 14055 }
8606be87 14056
10711563
DA
14057 /* Route Refresh */
14058 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
14059 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
14060 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
14061 vty_out(vty, " Route refresh:");
14062 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV))
14063 vty_out(vty, " advertised");
14064 if (CHECK_FLAG(p->cap,
14065 PEER_CAP_REFRESH_NEW_RCV) ||
14066 CHECK_FLAG(p->cap,
14067 PEER_CAP_REFRESH_OLD_RCV))
14068 vty_out(vty, " %sreceived(%s)",
14069 CHECK_FLAG(p->cap,
14070 PEER_CAP_REFRESH_ADV)
14071 ? "and "
14072 : "",
14073 (CHECK_FLAG(
14074 p->cap,
14075 PEER_CAP_REFRESH_OLD_RCV) &&
14076 CHECK_FLAG(
14077 p->cap,
14078 PEER_CAP_REFRESH_NEW_RCV))
14079 ? "old & new"
14080 : CHECK_FLAG(
14081 p->cap,
14082 PEER_CAP_REFRESH_OLD_RCV)
14083 ? "old"
14084 : "new");
d62a17ae 14085
d77114b7 14086 vty_out(vty, "\n");
10711563 14087 }
d62a17ae 14088
10711563
DA
14089 /* Enhanced Route Refresh */
14090 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
14091 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
14092 vty_out(vty, " Enhanced Route Refresh:");
14093 if (CHECK_FLAG(p->cap,
14094 PEER_CAP_ENHANCED_RR_ADV))
14095 vty_out(vty, " advertised");
14096 if (CHECK_FLAG(p->cap,
14097 PEER_CAP_ENHANCED_RR_RCV))
14098 vty_out(vty, " %sreceived",
14099 CHECK_FLAG(p->cap,
14100 PEER_CAP_REFRESH_ADV)
14101 ? "and "
14102 : "");
14103 vty_out(vty, "\n");
14104 }
14105
14106 /* Multiprotocol Extensions */
14107 FOREACH_AFI_SAFI (afi, safi)
14108 if (p->afc_adv[afi][safi] ||
14109 p->afc_recv[afi][safi]) {
14110 vty_out(vty, " Address Family %s:",
14111 get_afi_safi_str(afi, safi,
14112 false));
14113 if (p->afc_adv[afi][safi])
9af52ccf 14114 vty_out(vty, " advertised");
10711563 14115 if (p->afc_recv[afi][safi])
9af52ccf 14116 vty_out(vty, " %sreceived",
10711563 14117 p->afc_adv[afi][safi]
9af52ccf
DA
14118 ? "and "
14119 : "");
14120 vty_out(vty, "\n");
14121 }
14122
10711563
DA
14123 /* Hostname capability */
14124 vty_out(vty, " Hostname Capability:");
d62a17ae 14125
10711563
DA
14126 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
14127 vty_out(vty,
14128 " advertised (name: %s,domain name: %s)",
14129 bgp->peer_self->hostname
14130 ? bgp->peer_self->hostname
14131 : "n/a",
14132 bgp->peer_self->domainname
14133 ? bgp->peer_self->domainname
14134 : "n/a");
14135 } else {
14136 vty_out(vty, " not advertised");
14137 }
d77114b7 14138
10711563
DA
14139 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
14140 vty_out(vty,
14141 " received (name: %s,domain name: %s)",
14142 p->hostname ? p->hostname : "n/a",
14143 p->domainname ? p->domainname : "n/a");
14144 } else {
14145 vty_out(vty, " not received");
d62a17ae 14146 }
d62a17ae 14147
10711563 14148 vty_out(vty, "\n");
d77114b7 14149
10711563
DA
14150 /* Graceful Restart */
14151 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
14152 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
14153 vty_out(vty,
14154 " Graceful Restart Capability:");
14155 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV))
14156 vty_out(vty, " advertised");
14157 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
14158 vty_out(vty, " %sreceived",
14159 CHECK_FLAG(p->cap,
14160 PEER_CAP_RESTART_ADV)
14161 ? "and "
14162 : "");
d77114b7
MK
14163 vty_out(vty, "\n");
14164
10711563
DA
14165 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14166 int restart_af_count = 0;
d62a17ae 14167
10711563
DA
14168 vty_out(vty,
14169 " Remote Restart timer is %d seconds\n",
14170 p->v_gr_restart);
14171 vty_out(vty,
14172 " Address families by peer:\n ");
d62a17ae 14173
10711563
DA
14174 FOREACH_AFI_SAFI (afi, safi)
14175 if (CHECK_FLAG(
14176 p->af_cap[afi]
14177 [safi],
14178 PEER_CAP_RESTART_AF_RCV)) {
14179 vty_out(vty, "%s%s(%s)",
14180 restart_af_count
14181 ? ", "
14182 : "",
14183 get_afi_safi_str(
14184 afi,
14185 safi,
14186 false),
14187 CHECK_FLAG(
14188 p->af_cap
14189 [afi]
14190 [safi],
14191 PEER_CAP_RESTART_AF_PRESERVE_RCV)
14192 ? "preserved"
14193 : "not preserved");
14194 restart_af_count++;
14195 }
14196 if (!restart_af_count)
14197 vty_out(vty, "none");
14198 vty_out(vty, "\n");
14199 }
17be83bf 14200 } /* Graceful Restart */
d62a17ae 14201 }
14202 }
14203
14204 /* graceful restart information */
10711563
DA
14205 json_object *json_grace = NULL;
14206 json_object *json_grace_send = NULL;
14207 json_object *json_grace_recv = NULL;
14208 int eor_send_af_count = 0;
14209 int eor_receive_af_count = 0;
d62a17ae 14210
10711563
DA
14211 if (use_json) {
14212 json_grace = json_object_new_object();
14213 json_grace_send = json_object_new_object();
14214 json_grace_recv = json_object_new_object();
14215
14216 if ((peer_established(p)) &&
14217 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14218 FOREACH_AFI_SAFI (afi, safi) {
14219 if (CHECK_FLAG(p->af_sflags[afi][safi],
14220 PEER_STATUS_EOR_SEND)) {
14221 json_object_boolean_true_add(
14222 json_grace_send,
14223 get_afi_safi_str(afi, safi,
14224 true));
14225 eor_send_af_count++;
d62a17ae 14226 }
10711563
DA
14227 }
14228 FOREACH_AFI_SAFI (afi, safi) {
14229 if (CHECK_FLAG(p->af_sflags[afi][safi],
14230 PEER_STATUS_EOR_RECEIVED)) {
14231 json_object_boolean_true_add(
14232 json_grace_recv,
14233 get_afi_safi_str(afi, safi,
14234 true));
14235 eor_receive_af_count++;
d62a17ae 14236 }
14237 }
10711563
DA
14238 }
14239 json_object_object_add(json_grace, "endOfRibSend",
14240 json_grace_send);
14241 json_object_object_add(json_grace, "endOfRibRecv",
14242 json_grace_recv);
d62a17ae 14243
d62a17ae 14244
10711563
DA
14245 if (p->t_gr_restart)
14246 json_object_int_add(
14247 json_grace, "gracefulRestartTimerMsecs",
14248 thread_timer_remain_second(p->t_gr_restart) *
14249 1000);
2986cac2 14250
10711563
DA
14251 if (p->t_gr_stale)
14252 json_object_int_add(
14253 json_grace, "gracefulStalepathTimerMsecs",
14254 thread_timer_remain_second(p->t_gr_stale) *
14255 1000);
14256 /* more gr info in new format */
403e64f8 14257 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, json_grace);
10711563
DA
14258 json_object_object_add(json_neigh, "gracefulRestartInfo",
14259 json_grace);
14260 } else {
14261 vty_out(vty, " Graceful restart information:\n");
14262 if ((peer_established(p)) &&
14263 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14264
14265 vty_out(vty, " End-of-RIB send: ");
14266 FOREACH_AFI_SAFI (afi, safi) {
14267 if (CHECK_FLAG(p->af_sflags[afi][safi],
14268 PEER_STATUS_EOR_SEND)) {
14269 vty_out(vty, "%s%s",
14270 eor_send_af_count ? ", " : "",
14271 get_afi_safi_str(afi, safi,
14272 false));
14273 eor_send_af_count++;
d62a17ae 14274 }
10711563
DA
14275 }
14276 vty_out(vty, "\n");
14277 vty_out(vty, " End-of-RIB received: ");
14278 FOREACH_AFI_SAFI (afi, safi) {
14279 if (CHECK_FLAG(p->af_sflags[afi][safi],
14280 PEER_STATUS_EOR_RECEIVED)) {
14281 vty_out(vty, "%s%s",
14282 eor_receive_af_count ? ", "
14283 : "",
14284 get_afi_safi_str(afi, safi,
14285 false));
14286 eor_receive_af_count++;
d62a17ae 14287 }
d62a17ae 14288 }
10711563
DA
14289 vty_out(vty, "\n");
14290 }
d62a17ae 14291
10711563
DA
14292 if (p->t_gr_restart)
14293 vty_out(vty,
14294 " The remaining time of restart timer is %ld\n",
14295 thread_timer_remain_second(p->t_gr_restart));
d62a17ae 14296
10711563
DA
14297 if (p->t_gr_stale)
14298 vty_out(vty,
14299 " The remaining time of stalepath timer is %ld\n",
14300 thread_timer_remain_second(p->t_gr_stale));
2986cac2 14301
10711563 14302 /* more gr info in new format */
403e64f8 14303 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, NULL);
10711563 14304 }
2986cac2 14305
d62a17ae 14306 if (use_json) {
14307 json_object *json_stat = NULL;
14308 json_stat = json_object_new_object();
14309 /* Packet counts. */
43aa5965
QY
14310
14311 atomic_size_t outq_count, inq_count;
14312 outq_count = atomic_load_explicit(&p->obuf->count,
14313 memory_order_relaxed);
14314 inq_count = atomic_load_explicit(&p->ibuf->count,
14315 memory_order_relaxed);
14316
14317 json_object_int_add(json_stat, "depthInq",
14318 (unsigned long)inq_count);
d62a17ae 14319 json_object_int_add(json_stat, "depthOutq",
43aa5965 14320 (unsigned long)outq_count);
0112e9e0
QY
14321 json_object_int_add(json_stat, "opensSent",
14322 atomic_load_explicit(&p->open_out,
14323 memory_order_relaxed));
14324 json_object_int_add(json_stat, "opensRecv",
14325 atomic_load_explicit(&p->open_in,
14326 memory_order_relaxed));
d62a17ae 14327 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
14328 atomic_load_explicit(&p->notify_out,
14329 memory_order_relaxed));
d62a17ae 14330 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
14331 atomic_load_explicit(&p->notify_in,
14332 memory_order_relaxed));
14333 json_object_int_add(json_stat, "updatesSent",
14334 atomic_load_explicit(&p->update_out,
14335 memory_order_relaxed));
14336 json_object_int_add(json_stat, "updatesRecv",
14337 atomic_load_explicit(&p->update_in,
14338 memory_order_relaxed));
d62a17ae 14339 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
14340 atomic_load_explicit(&p->keepalive_out,
14341 memory_order_relaxed));
d62a17ae 14342 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
14343 atomic_load_explicit(&p->keepalive_in,
14344 memory_order_relaxed));
d62a17ae 14345 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
14346 atomic_load_explicit(&p->refresh_out,
14347 memory_order_relaxed));
d62a17ae 14348 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
14349 atomic_load_explicit(&p->refresh_in,
14350 memory_order_relaxed));
d62a17ae 14351 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
14352 atomic_load_explicit(&p->dynamic_cap_out,
14353 memory_order_relaxed));
d62a17ae 14354 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
14355 atomic_load_explicit(&p->dynamic_cap_in,
14356 memory_order_relaxed));
14357 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
14358 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 14359 json_object_object_add(json_neigh, "messageStats", json_stat);
14360 } else {
cb93e0a2
IS
14361 atomic_size_t outq_count, inq_count, open_out, open_in,
14362 notify_out, notify_in, update_out, update_in,
14363 keepalive_out, keepalive_in, refresh_out, refresh_in,
14364 dynamic_cap_out, dynamic_cap_in;
43aa5965
QY
14365 outq_count = atomic_load_explicit(&p->obuf->count,
14366 memory_order_relaxed);
14367 inq_count = atomic_load_explicit(&p->ibuf->count,
14368 memory_order_relaxed);
cb93e0a2
IS
14369 open_out = atomic_load_explicit(&p->open_out,
14370 memory_order_relaxed);
14371 open_in =
14372 atomic_load_explicit(&p->open_in, memory_order_relaxed);
14373 notify_out = atomic_load_explicit(&p->notify_out,
14374 memory_order_relaxed);
14375 notify_in = atomic_load_explicit(&p->notify_in,
14376 memory_order_relaxed);
14377 update_out = atomic_load_explicit(&p->update_out,
14378 memory_order_relaxed);
14379 update_in = atomic_load_explicit(&p->update_in,
14380 memory_order_relaxed);
14381 keepalive_out = atomic_load_explicit(&p->keepalive_out,
14382 memory_order_relaxed);
14383 keepalive_in = atomic_load_explicit(&p->keepalive_in,
14384 memory_order_relaxed);
14385 refresh_out = atomic_load_explicit(&p->refresh_out,
14386 memory_order_relaxed);
14387 refresh_in = atomic_load_explicit(&p->refresh_in,
14388 memory_order_relaxed);
14389 dynamic_cap_out = atomic_load_explicit(&p->dynamic_cap_out,
14390 memory_order_relaxed);
14391 dynamic_cap_in = atomic_load_explicit(&p->dynamic_cap_in,
14392 memory_order_relaxed);
43aa5965 14393
d62a17ae 14394 /* Packet counts. */
14395 vty_out(vty, " Message statistics:\n");
43aa5965
QY
14396 vty_out(vty, " Inq depth is %zu\n", inq_count);
14397 vty_out(vty, " Outq depth is %zu\n", outq_count);
d62a17ae 14398 vty_out(vty, " Sent Rcvd\n");
cb93e0a2
IS
14399 vty_out(vty, " Opens: %10zu %10zu\n", open_out,
14400 open_in);
14401 vty_out(vty, " Notifications: %10zu %10zu\n", notify_out,
14402 notify_in);
14403 vty_out(vty, " Updates: %10zu %10zu\n", update_out,
14404 update_in);
14405 vty_out(vty, " Keepalives: %10zu %10zu\n", keepalive_out,
14406 keepalive_in);
14407 vty_out(vty, " Route Refresh: %10zu %10zu\n", refresh_out,
14408 refresh_in);
14409 vty_out(vty, " Capability: %10zu %10zu\n",
14410 dynamic_cap_out, dynamic_cap_in);
14411 vty_out(vty, " Total: %10u %10u\n",
14412 (uint32_t)PEER_TOTAL_TX(p), (uint32_t)PEER_TOTAL_RX(p));
d62a17ae 14413 }
14414
14415 if (use_json) {
14416 /* advertisement-interval */
14417 json_object_int_add(json_neigh,
14418 "minBtwnAdvertisementRunsTimerMsecs",
14419 p->v_routeadv * 1000);
14420
14421 /* Update-source. */
14422 if (p->update_if || p->update_source) {
14423 if (p->update_if)
14424 json_object_string_add(json_neigh,
14425 "updateSource",
14426 p->update_if);
14427 else if (p->update_source)
47e12884
DA
14428 json_object_string_addf(json_neigh,
14429 "updateSource", "%pSU",
14430 p->update_source);
d62a17ae 14431 }
14432 } else {
14433 /* advertisement-interval */
14434 vty_out(vty,
14435 " Minimum time between advertisement runs is %d seconds\n",
14436 p->v_routeadv);
14437
14438 /* Update-source. */
14439 if (p->update_if || p->update_source) {
14440 vty_out(vty, " Update source is ");
14441 if (p->update_if)
14442 vty_out(vty, "%s", p->update_if);
14443 else if (p->update_source)
47e12884 14444 vty_out(vty, "%pSU", p->update_source);
d62a17ae 14445 vty_out(vty, "\n");
14446 }
14447
14448 vty_out(vty, "\n");
14449 }
14450
14451 /* Address Family Information */
14452 json_object *json_hold = NULL;
14453
14454 if (use_json)
14455 json_hold = json_object_new_object();
14456
05c7a1cc
QY
14457 FOREACH_AFI_SAFI (afi, safi)
14458 if (p->afc[afi][safi])
14459 bgp_show_peer_afi(vty, p, afi, safi, use_json,
14460 json_hold);
d62a17ae 14461
14462 if (use_json) {
14463 json_object_object_add(json_neigh, "addressFamilyInfo",
14464 json_hold);
14465 json_object_int_add(json_neigh, "connectionsEstablished",
14466 p->established);
14467 json_object_int_add(json_neigh, "connectionsDropped",
14468 p->dropped);
14469 } else
14470 vty_out(vty, " Connections established %d; dropped %d\n",
14471 p->established, p->dropped);
14472
14473 if (!p->last_reset) {
14474 if (use_json)
14475 json_object_string_add(json_neigh, "lastReset",
14476 "never");
14477 else
14478 vty_out(vty, " Last reset never\n");
14479 } else {
14480 if (use_json) {
14481 time_t uptime;
a2700b50 14482 struct tm tm;
d62a17ae 14483
083ec940 14484 uptime = monotime(NULL);
d62a17ae 14485 uptime -= p->resettime;
a2700b50
MS
14486 gmtime_r(&uptime, &tm);
14487
d62a17ae 14488 json_object_int_add(json_neigh, "lastResetTimerMsecs",
a2700b50
MS
14489 (tm.tm_sec * 1000)
14490 + (tm.tm_min * 60000)
14491 + (tm.tm_hour * 3600000));
3577f1c5 14492 bgp_show_peer_reset(NULL, p, json_neigh, true);
d62a17ae 14493 } else {
14494 vty_out(vty, " Last reset %s, ",
14495 peer_uptime(p->resettime, timebuf,
14496 BGP_UPTIME_LEN, 0, NULL));
14497
3577f1c5 14498 bgp_show_peer_reset(vty, p, NULL, false);
d62a17ae 14499 if (p->last_reset_cause_size) {
14500 msg = p->last_reset_cause;
14501 vty_out(vty,
14502 " Message received that caused BGP to send a NOTIFICATION:\n ");
14503 for (i = 1; i <= p->last_reset_cause_size;
14504 i++) {
14505 vty_out(vty, "%02X", *msg++);
14506
14507 if (i != p->last_reset_cause_size) {
14508 if (i % 16 == 0) {
14509 vty_out(vty, "\n ");
14510 } else if (i % 4 == 0) {
14511 vty_out(vty, " ");
14512 }
14513 }
14514 }
14515 vty_out(vty, "\n");
14516 }
14517 }
14518 }
14519
14520 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
14521 if (use_json)
14522 json_object_boolean_true_add(json_neigh,
14523 "prefixesConfigExceedMax");
14524 else
14525 vty_out(vty,
14526 " Peer had exceeded the max. no. of prefixes configured.\n");
14527
14528 if (p->t_pmax_restart) {
14529 if (use_json) {
14530 json_object_boolean_true_add(
14531 json_neigh, "reducePrefixNumFrom");
14532 json_object_int_add(json_neigh,
14533 "restartInTimerMsec",
14534 thread_timer_remain_second(
14535 p->t_pmax_restart)
14536 * 1000);
14537 } else
14538 vty_out(vty,
14539 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
14540 p->host, thread_timer_remain_second(
14541 p->t_pmax_restart));
d62a17ae 14542 } else {
14543 if (use_json)
14544 json_object_boolean_true_add(
14545 json_neigh,
14546 "reducePrefixNumAndClearIpBgp");
14547 else
14548 vty_out(vty,
14549 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
14550 p->host);
14551 }
14552 }
14553
14554 /* EBGP Multihop and GTSM */
14555 if (p->sort != BGP_PEER_IBGP) {
14556 if (use_json) {
e2521429 14557 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14558 json_object_int_add(json_neigh,
14559 "externalBgpNbrMaxHopsAway",
14560 p->gtsm_hops);
be8d1733 14561 else
d62a17ae 14562 json_object_int_add(json_neigh,
14563 "externalBgpNbrMaxHopsAway",
14564 p->ttl);
14565 } else {
e2521429 14566 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14567 vty_out(vty,
14568 " External BGP neighbor may be up to %d hops away.\n",
14569 p->gtsm_hops);
be8d1733 14570 else
d62a17ae 14571 vty_out(vty,
14572 " External BGP neighbor may be up to %d hops away.\n",
14573 p->ttl);
14574 }
14575 } else {
be8d1733
DA
14576 if (use_json) {
14577 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14578 json_object_int_add(json_neigh,
14579 "internalBgpNbrMaxHopsAway",
14580 p->gtsm_hops);
14581 else
be8d1733
DA
14582 json_object_int_add(json_neigh,
14583 "internalBgpNbrMaxHopsAway",
14584 p->ttl);
14585 } else {
14586 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14587 vty_out(vty,
14588 " Internal BGP neighbor may be up to %d hops away.\n",
14589 p->gtsm_hops);
be8d1733
DA
14590 else
14591 vty_out(vty,
14592 " Internal BGP neighbor may be up to %d hops away.\n",
14593 p->ttl);
d62a17ae 14594 }
14595 }
14596
14597 /* Local address. */
14598 if (p->su_local) {
14599 if (use_json) {
47e12884
DA
14600 json_object_string_addf(json_neigh, "hostLocal", "%pSU",
14601 p->su_local);
d62a17ae 14602 json_object_int_add(json_neigh, "portLocal",
14603 ntohs(p->su_local->sin.sin_port));
14604 } else
47e12884
DA
14605 vty_out(vty, "Local host: %pSU, Local port: %d\n",
14606 p->su_local, ntohs(p->su_local->sin.sin_port));
1e592331
DS
14607 } else {
14608 if (use_json) {
14609 json_object_string_add(json_neigh, "hostLocal",
14610 "Unknown");
14611 json_object_int_add(json_neigh, "portLocal", -1);
14612 }
d62a17ae 14613 }
14614
14615 /* Remote address. */
14616 if (p->su_remote) {
14617 if (use_json) {
47e12884
DA
14618 json_object_string_addf(json_neigh, "hostForeign",
14619 "%pSU", p->su_remote);
d62a17ae 14620 json_object_int_add(json_neigh, "portForeign",
14621 ntohs(p->su_remote->sin.sin_port));
14622 } else
47e12884
DA
14623 vty_out(vty, "Foreign host: %pSU, Foreign port: %d\n",
14624 p->su_remote,
d62a17ae 14625 ntohs(p->su_remote->sin.sin_port));
1e592331
DS
14626 } else {
14627 if (use_json) {
14628 json_object_string_add(json_neigh, "hostForeign",
14629 "Unknown");
14630 json_object_int_add(json_neigh, "portForeign", -1);
14631 }
d62a17ae 14632 }
14633
14634 /* Nexthop display. */
14635 if (p->su_local) {
14636 if (use_json) {
c949c771
DA
14637 json_object_string_addf(json_neigh, "nexthop", "%pI4",
14638 &p->nexthop.v4);
14639 json_object_string_addf(json_neigh, "nexthopGlobal",
14640 "%pI6", &p->nexthop.v6_global);
14641 json_object_string_addf(json_neigh, "nexthopLocal",
14642 "%pI6", &p->nexthop.v6_local);
d62a17ae 14643 if (p->shared_network)
14644 json_object_string_add(json_neigh,
14645 "bgpConnection",
14646 "sharedNetwork");
14647 else
14648 json_object_string_add(json_neigh,
14649 "bgpConnection",
14650 "nonSharedNetwork");
14651 } else {
07380148
DA
14652 vty_out(vty, "Nexthop: %pI4\n", &p->nexthop.v4);
14653 vty_out(vty, "Nexthop global: %pI6\n",
14654 &p->nexthop.v6_global);
14655 vty_out(vty, "Nexthop local: %pI6\n",
14656 &p->nexthop.v6_local);
d62a17ae 14657 vty_out(vty, "BGP connection: %s\n",
14658 p->shared_network ? "shared network"
14659 : "non shared network");
14660 }
432e7e46
KQ
14661 } else {
14662 if (use_json) {
14663 json_object_string_add(json_neigh, "nexthop",
14664 "Unknown");
14665 json_object_string_add(json_neigh, "nexthopGlobal",
14666 "Unknown");
14667 json_object_string_add(json_neigh, "nexthopLocal",
14668 "Unknown");
14669 json_object_string_add(json_neigh, "bgpConnection",
14670 "Unknown");
14671 }
d62a17ae 14672 }
14673
14674 /* Timer information. */
14675 if (use_json) {
14676 json_object_int_add(json_neigh, "connectRetryTimer",
14677 p->v_connect);
f41255a0 14678 if (peer_established(p)) {
d62a17ae 14679 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14680 p->rtt);
f41255a0
DA
14681 if (CHECK_FLAG(p->flags, PEER_FLAG_RTT_SHUTDOWN)) {
14682 json_object_int_add(json_neigh,
14683 "shutdownRttInMsecs",
14684 p->rtt_expected);
14685 json_object_int_add(json_neigh,
14686 "shutdownRttAfterCount",
14687 p->rtt_keepalive_rcv);
14688 }
14689 }
d62a17ae 14690 if (p->t_start)
14691 json_object_int_add(
14692 json_neigh, "nextStartTimerDueInMsecs",
14693 thread_timer_remain_second(p->t_start) * 1000);
14694 if (p->t_connect)
14695 json_object_int_add(
14696 json_neigh, "nextConnectTimerDueInMsecs",
14697 thread_timer_remain_second(p->t_connect)
14698 * 1000);
14699 if (p->t_routeadv) {
14700 json_object_int_add(json_neigh, "mraiInterval",
14701 p->v_routeadv);
14702 json_object_int_add(
14703 json_neigh, "mraiTimerExpireInMsecs",
14704 thread_timer_remain_second(p->t_routeadv)
14705 * 1000);
14706 }
14707 if (p->password)
14708 json_object_int_add(json_neigh, "authenticationEnabled",
14709 1);
14710
14711 if (p->t_read)
14712 json_object_string_add(json_neigh, "readThread", "on");
14713 else
14714 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
14715
14716 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 14717 json_object_string_add(json_neigh, "writeThread", "on");
14718 else
14719 json_object_string_add(json_neigh, "writeThread",
14720 "off");
14721 } else {
14722 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14723 p->v_connect);
f41255a0 14724 if (peer_established(p)) {
d62a17ae 14725 vty_out(vty, "Estimated round trip time: %d ms\n",
14726 p->rtt);
f41255a0
DA
14727 if (CHECK_FLAG(p->flags, PEER_FLAG_RTT_SHUTDOWN))
14728 vty_out(vty,
14729 "Shutdown when RTT > %dms, count > %u\n",
14730 p->rtt_expected, p->rtt_keepalive_rcv);
14731 }
d62a17ae 14732 if (p->t_start)
14733 vty_out(vty, "Next start timer due in %ld seconds\n",
14734 thread_timer_remain_second(p->t_start));
14735 if (p->t_connect)
14736 vty_out(vty, "Next connect timer due in %ld seconds\n",
14737 thread_timer_remain_second(p->t_connect));
14738 if (p->t_routeadv)
14739 vty_out(vty,
14740 "MRAI (interval %u) timer expires in %ld seconds\n",
14741 p->v_routeadv,
14742 thread_timer_remain_second(p->t_routeadv));
14743 if (p->password)
14744 vty_out(vty, "Peer Authentication Enabled\n");
14745
cac9e917 14746 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
49507a6f
QY
14747 p->t_read ? "on" : "off",
14748 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14749 ? "on"
cac9e917 14750 : "off", p->fd);
d62a17ae 14751 }
14752
14753 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14754 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14755 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14756
14757 if (!use_json)
14758 vty_out(vty, "\n");
14759
14760 /* BFD information. */
21bfce98
RZ
14761 if (p->bfd_config)
14762 bgp_bfd_show_info(vty, p, json_neigh);
d62a17ae 14763
14764 if (use_json) {
14765 if (p->conf_if) /* Configured interface name. */
14766 json_object_object_add(json, p->conf_if, json_neigh);
14767 else /* Configured IP address. */
14768 json_object_object_add(json, p->host, json_neigh);
14769 }
14770}
14771
36235319
QY
14772static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14773 enum show_type type,
14774 union sockunion *su,
14775 const char *conf_if, afi_t afi,
403e64f8 14776 json_object *json)
2986cac2 14777{
14778 struct listnode *node, *nnode;
14779 struct peer *peer;
5a59e9b2 14780 bool found = false;
2986cac2 14781 safi_t safi = SAFI_UNICAST;
14782 json_object *json_neighbor = NULL;
14783
14784 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14785
14786 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14787 continue;
14788
14789 if ((peer->afc[afi][safi]) == 0)
14790 continue;
14791
403e64f8
DA
14792 if (json)
14793 json_neighbor = json_object_new_object();
14794
2ba1fe69 14795 if (type == show_all) {
403e64f8 14796 bgp_show_peer_gr_status(vty, peer, json_neighbor);
2986cac2 14797
403e64f8 14798 if (json)
13909c4f
DS
14799 json_object_object_add(json, peer->host,
14800 json_neighbor);
2986cac2 14801
2ba1fe69 14802 } else if (type == show_peer) {
2986cac2 14803 if (conf_if) {
14804 if ((peer->conf_if
13909c4f
DS
14805 && !strcmp(peer->conf_if, conf_if))
14806 || (peer->hostname
2986cac2 14807 && !strcmp(peer->hostname, conf_if))) {
5a59e9b2 14808 found = true;
13909c4f 14809 bgp_show_peer_gr_status(vty, peer,
13909c4f 14810 json_neighbor);
2986cac2 14811 }
14812 } else {
14813 if (sockunion_same(&peer->su, su)) {
5a59e9b2 14814 found = true;
13909c4f 14815 bgp_show_peer_gr_status(vty, peer,
13909c4f 14816 json_neighbor);
2986cac2 14817 }
14818 }
5a59e9b2
DS
14819 if (json) {
14820 if (found)
14821 json_object_object_add(json, peer->host,
14822 json_neighbor);
14823 else
14824 json_object_free(json_neighbor);
14825 }
2986cac2 14826 }
14827
5a59e9b2 14828 if (found)
2986cac2 14829 break;
14830 }
14831
5a59e9b2 14832 if (type == show_peer && !found) {
403e64f8 14833 if (json)
13909c4f 14834 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
2986cac2 14835 else
14836 vty_out(vty, "%% No such neighbor\n");
14837 }
403e64f8
DA
14838
14839 if (!json)
2986cac2 14840 vty_out(vty, "\n");
2986cac2 14841
14842 return CMD_SUCCESS;
14843}
14844
d62a17ae 14845static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14846 enum show_type type, union sockunion *su,
9f049418 14847 const char *conf_if, bool use_json,
d62a17ae 14848 json_object *json)
14849{
14850 struct listnode *node, *nnode;
14851 struct peer *peer;
14852 int find = 0;
9f049418 14853 bool nbr_output = false;
d1927ebe
AS
14854 afi_t afi = AFI_MAX;
14855 safi_t safi = SAFI_MAX;
14856
14857 if (type == show_ipv4_peer || type == show_ipv4_all) {
14858 afi = AFI_IP;
14859 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14860 afi = AFI_IP6;
14861 }
d62a17ae 14862
14863 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14864 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14865 continue;
14866
14867 switch (type) {
14868 case show_all:
14869 bgp_show_peer(vty, peer, use_json, json);
9f049418 14870 nbr_output = true;
d62a17ae 14871 break;
14872 case show_peer:
14873 if (conf_if) {
14874 if ((peer->conf_if
14875 && !strcmp(peer->conf_if, conf_if))
14876 || (peer->hostname
14877 && !strcmp(peer->hostname, conf_if))) {
14878 find = 1;
14879 bgp_show_peer(vty, peer, use_json,
14880 json);
14881 }
14882 } else {
14883 if (sockunion_same(&peer->su, su)) {
14884 find = 1;
14885 bgp_show_peer(vty, peer, use_json,
14886 json);
14887 }
14888 }
14889 break;
d1927ebe
AS
14890 case show_ipv4_peer:
14891 case show_ipv6_peer:
14892 FOREACH_SAFI (safi) {
14893 if (peer->afc[afi][safi]) {
14894 if (conf_if) {
14895 if ((peer->conf_if
14896 && !strcmp(peer->conf_if, conf_if))
14897 || (peer->hostname
14898 && !strcmp(peer->hostname, conf_if))) {
14899 find = 1;
14900 bgp_show_peer(vty, peer, use_json,
14901 json);
14902 break;
14903 }
14904 } else {
14905 if (sockunion_same(&peer->su, su)) {
14906 find = 1;
14907 bgp_show_peer(vty, peer, use_json,
14908 json);
14909 break;
14910 }
14911 }
14912 }
14913 }
14914 break;
14915 case show_ipv4_all:
14916 case show_ipv6_all:
14917 FOREACH_SAFI (safi) {
14918 if (peer->afc[afi][safi]) {
14919 bgp_show_peer(vty, peer, use_json, json);
14920 nbr_output = true;
14921 break;
14922 }
14923 }
14924 break;
d62a17ae 14925 }
14926 }
14927
d1927ebe
AS
14928 if ((type == show_peer || type == show_ipv4_peer ||
14929 type == show_ipv6_peer) && !find) {
d62a17ae 14930 if (use_json)
14931 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14932 else
88b7d255 14933 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 14934 }
14935
d1927ebe
AS
14936 if (type != show_peer && type != show_ipv4_peer &&
14937 type != show_ipv6_peer && !nbr_output && !use_json)
94d4c685 14938 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 14939
d62a17ae 14940 if (use_json) {
996c9314
LB
14941 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14942 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 14943 } else {
14944 vty_out(vty, "\n");
14945 }
14946
14947 return CMD_SUCCESS;
14948}
14949
36235319
QY
14950static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14951 enum show_type type,
14952 const char *ip_str,
403e64f8 14953 afi_t afi, json_object *json)
2986cac2 14954{
14955
14956 int ret;
14957 struct bgp *bgp;
14958 union sockunion su;
2986cac2 14959
14960 bgp = bgp_get_default();
14961
13909c4f
DS
14962 if (!bgp)
14963 return;
2986cac2 14964
403e64f8
DA
14965 if (!json)
14966 bgp_show_global_graceful_restart_mode_vty(vty, bgp);
2986cac2 14967
13909c4f
DS
14968 if (ip_str) {
14969 ret = str2sockunion(ip_str, &su);
14970 if (ret < 0)
403e64f8
DA
14971 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL,
14972 ip_str, afi, json);
74a630b6
NT
14973 else
14974 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
403e64f8 14975 NULL, afi, json);
13909c4f
DS
14976 } else
14977 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
403e64f8 14978 afi, json);
2986cac2 14979}
14980
d62a17ae 14981static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
14982 enum show_type type,
14983 const char *ip_str,
9f049418 14984 bool use_json)
d62a17ae 14985{
0291c246
MK
14986 struct listnode *node, *nnode;
14987 struct bgp *bgp;
71aedaa3 14988 union sockunion su;
0291c246 14989 json_object *json = NULL;
71aedaa3 14990 int ret, is_first = 1;
9f049418 14991 bool nbr_output = false;
d62a17ae 14992
14993 if (use_json)
14994 vty_out(vty, "{\n");
14995
14996 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 14997 nbr_output = true;
d62a17ae 14998 if (use_json) {
14999 if (!(json = json_object_new_object())) {
af4c2728 15000 flog_err(
e50f7cfd 15001 EC_BGP_JSON_MEM_ERROR,
d62a17ae 15002 "Unable to allocate memory for JSON object");
15003 vty_out(vty,
15004 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
15005 return;
15006 }
15007
15008 json_object_int_add(json, "vrfId",
15009 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
15010 ? -1
15011 : (int64_t)bgp->vrf_id);
d62a17ae 15012 json_object_string_add(
15013 json, "vrfName",
15014 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 15015 ? VRF_DEFAULT_NAME
d62a17ae 15016 : bgp->name);
15017
15018 if (!is_first)
15019 vty_out(vty, ",\n");
15020 else
15021 is_first = 0;
15022
15023 vty_out(vty, "\"%s\":",
15024 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 15025 ? VRF_DEFAULT_NAME
d62a17ae 15026 : bgp->name);
15027 } else {
15028 vty_out(vty, "\nInstance %s:\n",
15029 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 15030 ? VRF_DEFAULT_NAME
d62a17ae 15031 : bgp->name);
15032 }
71aedaa3 15033
d1927ebe
AS
15034 if (type == show_peer || type == show_ipv4_peer ||
15035 type == show_ipv6_peer) {
71aedaa3
DS
15036 ret = str2sockunion(ip_str, &su);
15037 if (ret < 0)
15038 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
15039 use_json, json);
15040 else
15041 bgp_show_neighbor(vty, bgp, type, &su, NULL,
15042 use_json, json);
15043 } else {
d1927ebe 15044 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
71aedaa3
DS
15045 use_json, json);
15046 }
b77004d6 15047 json_object_free(json);
121067e9 15048 json = NULL;
d62a17ae 15049 }
15050
3e78a6ce 15051 if (use_json)
d62a17ae 15052 vty_out(vty, "}\n");
9f049418
DS
15053 else if (!nbr_output)
15054 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 15055}
15056
15057static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
15058 enum show_type type, const char *ip_str,
9f049418 15059 bool use_json)
d62a17ae 15060{
15061 int ret;
15062 struct bgp *bgp;
15063 union sockunion su;
15064 json_object *json = NULL;
15065
15066 if (name) {
15067 if (strmatch(name, "all")) {
71aedaa3
DS
15068 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
15069 use_json);
d62a17ae 15070 return CMD_SUCCESS;
15071 } else {
15072 bgp = bgp_lookup_by_name(name);
15073 if (!bgp) {
15074 if (use_json) {
15075 json = json_object_new_object();
75eeda93 15076 vty_json(vty, json);
d62a17ae 15077 } else
15078 vty_out(vty,
9f049418 15079 "%% BGP instance not found\n");
d62a17ae 15080
15081 return CMD_WARNING;
15082 }
15083 }
15084 } else {
15085 bgp = bgp_get_default();
15086 }
15087
15088 if (bgp) {
15089 json = json_object_new_object();
15090 if (ip_str) {
15091 ret = str2sockunion(ip_str, &su);
15092 if (ret < 0)
15093 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
15094 use_json, json);
15095 else
15096 bgp_show_neighbor(vty, bgp, type, &su, NULL,
15097 use_json, json);
15098 } else {
15099 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
15100 json);
15101 }
15102 json_object_free(json);
ca61fd25
DS
15103 } else {
15104 if (use_json)
15105 vty_out(vty, "{}\n");
15106 else
15107 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 15108 }
15109
15110 return CMD_SUCCESS;
4fb25c53
DW
15111}
15112
2986cac2 15113
15114
15115/* "show [ip] bgp neighbors graceful-restart" commands. */
dcab9012 15116DEFUN (show_ip_bgp_neighbors_graceful_restart,
2986cac2 15117 show_ip_bgp_neighbors_graceful_restart_cmd,
15118 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
15119 SHOW_STR
15120 BGP_STR
15121 IP_STR
15122 IPV6_STR
15123 NEIGHBOR_STR
15124 "Neighbor to display information about\n"
15125 "Neighbor to display information about\n"
15126 "Neighbor on BGP configured interface\n"
15127 GR_SHOW
15128 JSON_STR)
15129{
15130 char *sh_arg = NULL;
15131 enum show_type sh_type;
15132 int idx = 0;
15133 afi_t afi = AFI_MAX;
2986cac2 15134 bool uj = use_json(argc, argv);
15135
36235319 15136 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
2986cac2 15137 afi = AFI_MAX;
15138
15139 idx++;
15140
15141 if (argv_find(argv, argc, "A.B.C.D", &idx)
15142 || argv_find(argv, argc, "X:X::X:X", &idx)
15143 || argv_find(argv, argc, "WORD", &idx)) {
15144 sh_type = show_peer;
15145 sh_arg = argv[idx]->arg;
15146 } else
15147 sh_type = show_all;
15148
15149 if (!argv_find(argv, argc, "graceful-restart", &idx))
15150 return CMD_SUCCESS;
15151
15152
36235319
QY
15153 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
15154 afi, uj);
2986cac2 15155}
15156
716b2d8a 15157/* "show [ip] bgp neighbors" commands. */
718e3744 15158DEFUN (show_ip_bgp_neighbors,
15159 show_ip_bgp_neighbors_cmd,
24345e82 15160 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 15161 SHOW_STR
15162 IP_STR
15163 BGP_STR
f2a8972b 15164 BGP_INSTANCE_HELP_STR
00e6edb9
DA
15165 BGP_AF_STR
15166 BGP_AF_STR
718e3744 15167 "Detailed information on TCP and BGP neighbor connections\n"
15168 "Neighbor to display information about\n"
a80beece 15169 "Neighbor to display information about\n"
91d37724 15170 "Neighbor on BGP configured interface\n"
9973d184 15171 JSON_STR)
718e3744 15172{
d62a17ae 15173 char *vrf = NULL;
15174 char *sh_arg = NULL;
15175 enum show_type sh_type;
d1927ebe 15176 afi_t afi = AFI_MAX;
718e3744 15177
9f049418 15178 bool uj = use_json(argc, argv);
718e3744 15179
d62a17ae 15180 int idx = 0;
718e3744 15181
9a8bdf1c
PG
15182 /* [<vrf> VIEWVRFNAME] */
15183 if (argv_find(argv, argc, "vrf", &idx)) {
15184 vrf = argv[idx + 1]->arg;
15185 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15186 vrf = NULL;
15187 } else if (argv_find(argv, argc, "view", &idx))
15188 /* [<view> VIEWVRFNAME] */
d62a17ae 15189 vrf = argv[idx + 1]->arg;
718e3744 15190
d62a17ae 15191 idx++;
d1927ebe
AS
15192
15193 if (argv_find(argv, argc, "ipv4", &idx)) {
15194 sh_type = show_ipv4_all;
15195 afi = AFI_IP;
15196 } else if (argv_find(argv, argc, "ipv6", &idx)) {
15197 sh_type = show_ipv6_all;
15198 afi = AFI_IP6;
15199 } else {
15200 sh_type = show_all;
15201 }
15202
d62a17ae 15203 if (argv_find(argv, argc, "A.B.C.D", &idx)
15204 || argv_find(argv, argc, "X:X::X:X", &idx)
15205 || argv_find(argv, argc, "WORD", &idx)) {
15206 sh_type = show_peer;
15207 sh_arg = argv[idx]->arg;
d1927ebe
AS
15208 }
15209
15210 if (sh_type == show_peer && afi == AFI_IP) {
15211 sh_type = show_ipv4_peer;
15212 } else if (sh_type == show_peer && afi == AFI_IP6) {
15213 sh_type = show_ipv6_peer;
15214 }
856ca177 15215
d62a17ae 15216 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 15217}
15218
716b2d8a 15219/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 15220 paths' and `show ip mbgp paths'. Those functions results are the
15221 same.*/
f412b39a 15222DEFUN (show_ip_bgp_paths,
718e3744 15223 show_ip_bgp_paths_cmd,
46f296b4 15224 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 15225 SHOW_STR
15226 IP_STR
15227 BGP_STR
46f296b4 15228 BGP_SAFI_HELP_STR
718e3744 15229 "Path information\n")
15230{
d62a17ae 15231 vty_out(vty, "Address Refcnt Path\n");
15232 aspath_print_all_vty(vty);
15233 return CMD_SUCCESS;
718e3744 15234}
15235
718e3744 15236#include "hash.h"
15237
e3b78da8 15238static void community_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 15239 struct vty *vty)
718e3744 15240{
d62a17ae 15241 struct community *com;
718e3744 15242
e3b78da8 15243 com = (struct community *)bucket->data;
3f65c5b1 15244 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
c0945b78 15245 community_str(com, false, false));
718e3744 15246}
15247
15248/* Show BGP's community internal data. */
f412b39a 15249DEFUN (show_ip_bgp_community_info,
718e3744 15250 show_ip_bgp_community_info_cmd,
bec37ba5 15251 "show [ip] bgp community-info",
718e3744 15252 SHOW_STR
15253 IP_STR
15254 BGP_STR
15255 "List all bgp community information\n")
15256{
d62a17ae 15257 vty_out(vty, "Address Refcnt Community\n");
718e3744 15258
d62a17ae 15259 hash_iterate(community_hash(),
e3b78da8 15260 (void (*)(struct hash_bucket *,
d62a17ae 15261 void *))community_show_all_iterator,
15262 vty);
718e3744 15263
d62a17ae 15264 return CMD_SUCCESS;
718e3744 15265}
15266
e3b78da8 15267static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 15268 struct vty *vty)
57d187bc 15269{
d62a17ae 15270 struct lcommunity *lcom;
57d187bc 15271
e3b78da8 15272 lcom = (struct lcommunity *)bucket->data;
3f65c5b1 15273 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
c0945b78 15274 lcommunity_str(lcom, false, false));
57d187bc
JS
15275}
15276
15277/* Show BGP's community internal data. */
15278DEFUN (show_ip_bgp_lcommunity_info,
15279 show_ip_bgp_lcommunity_info_cmd,
15280 "show ip bgp large-community-info",
15281 SHOW_STR
15282 IP_STR
15283 BGP_STR
15284 "List all bgp large-community information\n")
15285{
d62a17ae 15286 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 15287
d62a17ae 15288 hash_iterate(lcommunity_hash(),
e3b78da8 15289 (void (*)(struct hash_bucket *,
d62a17ae 15290 void *))lcommunity_show_all_iterator,
15291 vty);
57d187bc 15292
d62a17ae 15293 return CMD_SUCCESS;
57d187bc 15294}
2986cac2 15295/* Graceful Restart */
15296
15297static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
403e64f8 15298 struct bgp *bgp)
2986cac2 15299{
57d187bc
JS
15300
15301
2986cac2 15302 vty_out(vty, "\n%s", SHOW_GR_HEADER);
15303
7318ae88 15304 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
2986cac2 15305
15306 switch (bgp_global_gr_mode) {
15307
15308 case GLOBAL_HELPER:
13909c4f 15309 vty_out(vty, "Global BGP GR Mode : Helper\n");
2986cac2 15310 break;
15311
15312 case GLOBAL_GR:
13909c4f 15313 vty_out(vty, "Global BGP GR Mode : Restart\n");
2986cac2 15314 break;
15315
15316 case GLOBAL_DISABLE:
13909c4f 15317 vty_out(vty, "Global BGP GR Mode : Disable\n");
2986cac2 15318 break;
15319
15320 case GLOBAL_INVALID:
2986cac2 15321 vty_out(vty,
2ba1fe69 15322 "Global BGP GR Mode Invalid\n");
2986cac2 15323 break;
15324 }
15325 vty_out(vty, "\n");
15326}
15327
36235319
QY
15328static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
15329 enum show_type type,
15330 const char *ip_str,
15331 afi_t afi, bool use_json)
2986cac2 15332{
403e64f8
DA
15333 json_object *json = NULL;
15334
15335 if (use_json)
15336 json = json_object_new_object();
15337
2986cac2 15338 if ((afi == AFI_MAX) && (ip_str == NULL)) {
15339 afi = AFI_IP;
15340
15341 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
15342
36235319 15343 bgp_show_neighbor_graceful_restart_vty(
403e64f8 15344 vty, type, ip_str, afi, json);
2986cac2 15345 afi++;
15346 }
15347 } else if (afi != AFI_MAX) {
36235319 15348 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
403e64f8 15349 json);
2986cac2 15350 } else {
403e64f8
DA
15351 if (json)
15352 json_object_free(json);
2986cac2 15353 return CMD_ERR_INCOMPLETE;
15354 }
15355
403e64f8
DA
15356 if (json)
15357 vty_json(vty, json);
15358
2986cac2 15359 return CMD_SUCCESS;
15360}
15361/* Graceful Restart */
15362
f412b39a 15363DEFUN (show_ip_bgp_attr_info,
718e3744 15364 show_ip_bgp_attr_info_cmd,
bec37ba5 15365 "show [ip] bgp attribute-info",
718e3744 15366 SHOW_STR
15367 IP_STR
15368 BGP_STR
15369 "List all bgp attribute information\n")
15370{
d62a17ae 15371 attr_show_all(vty);
15372 return CMD_SUCCESS;
718e3744 15373}
6b0655a2 15374
03915806
CS
15375static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
15376 afi_t afi, safi_t safi,
15377 bool use_json, json_object *json)
53089bec 15378{
15379 struct bgp *bgp;
15380 struct listnode *node;
15381 char *vname;
53089bec 15382 char *ecom_str;
9c2fd3fe 15383 enum vpn_policy_direction dir;
53089bec 15384
03915806 15385 if (json) {
b46dfd20
DS
15386 json_object *json_import_vrfs = NULL;
15387 json_object *json_export_vrfs = NULL;
15388
b46dfd20
DS
15389 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15390
53089bec 15391 if (!bgp) {
75eeda93 15392 vty_json(vty, json);
b46dfd20 15393
53089bec 15394 return CMD_WARNING;
15395 }
b46dfd20 15396
94d4c685
DS
15397 /* Provide context for the block */
15398 json_object_string_add(json, "vrf", name ? name : "default");
15399 json_object_string_add(json, "afiSafi",
5cb5f4d0 15400 get_afi_safi_str(afi, safi, true));
94d4c685 15401
b46dfd20
DS
15402 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15403 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
15404 json_object_string_add(json, "importFromVrfs", "none");
15405 json_object_string_add(json, "importRts", "none");
15406 } else {
6ce24e52
DS
15407 json_import_vrfs = json_object_new_array();
15408
b46dfd20
DS
15409 for (ALL_LIST_ELEMENTS_RO(
15410 bgp->vpn_policy[afi].import_vrf,
15411 node, vname))
15412 json_object_array_add(json_import_vrfs,
15413 json_object_new_string(vname));
15414
b20875ea
CS
15415 json_object_object_add(json, "importFromVrfs",
15416 json_import_vrfs);
b46dfd20 15417 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
15418 if (bgp->vpn_policy[afi].rtlist[dir]) {
15419 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15420 bgp->vpn_policy[afi].rtlist[dir],
15421 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
15422 json_object_string_add(json, "importRts",
15423 ecom_str);
15424 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15425 } else
15426 json_object_string_add(json, "importRts",
15427 "none");
b46dfd20
DS
15428 }
15429
15430 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15431 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
15432 json_object_string_add(json, "exportToVrfs", "none");
15433 json_object_string_add(json, "routeDistinguisher",
15434 "none");
15435 json_object_string_add(json, "exportRts", "none");
15436 } else {
6ce24e52
DS
15437 json_export_vrfs = json_object_new_array();
15438
b46dfd20
DS
15439 for (ALL_LIST_ELEMENTS_RO(
15440 bgp->vpn_policy[afi].export_vrf,
15441 node, vname))
15442 json_object_array_add(json_export_vrfs,
15443 json_object_new_string(vname));
15444 json_object_object_add(json, "exportToVrfs",
15445 json_export_vrfs);
c4f64ea9
DA
15446 json_object_string_addf(json, "routeDistinguisher",
15447 "%pRD",
15448 &bgp->vpn_policy[afi].tovpn_rd);
b46dfd20
DS
15449
15450 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
15451 if (bgp->vpn_policy[afi].rtlist[dir]) {
15452 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15453 bgp->vpn_policy[afi].rtlist[dir],
15454 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
15455 json_object_string_add(json, "exportRts",
15456 ecom_str);
15457 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15458 } else
15459 json_object_string_add(json, "exportRts",
15460 "none");
b46dfd20
DS
15461 }
15462
03915806 15463 if (use_json) {
75eeda93 15464 vty_json(vty, json);
03915806 15465 }
53089bec 15466 } else {
b46dfd20
DS
15467 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15468
53089bec 15469 if (!bgp) {
b46dfd20 15470 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 15471 return CMD_WARNING;
15472 }
53089bec 15473
b46dfd20
DS
15474 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15475 BGP_CONFIG_VRF_TO_VRF_IMPORT))
15476 vty_out(vty,
15477 "This VRF is not importing %s routes from any other VRF\n",
5cb5f4d0 15478 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15479 else {
15480 vty_out(vty,
15481 "This VRF is importing %s routes from the following VRFs:\n",
5cb5f4d0 15482 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15483
15484 for (ALL_LIST_ELEMENTS_RO(
15485 bgp->vpn_policy[afi].import_vrf,
15486 node, vname))
15487 vty_out(vty, " %s\n", vname);
15488
15489 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
15490 ecom_str = NULL;
15491 if (bgp->vpn_policy[afi].rtlist[dir]) {
15492 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15493 bgp->vpn_policy[afi].rtlist[dir],
15494 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea 15495 vty_out(vty, "Import RT(s): %s\n", ecom_str);
b46dfd20 15496
b20875ea
CS
15497 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15498 } else
15499 vty_out(vty, "Import RT(s):\n");
53089bec 15500 }
53089bec 15501
b46dfd20
DS
15502 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15503 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15504 vty_out(vty,
15505 "This VRF is not exporting %s routes to any other VRF\n",
5cb5f4d0 15506 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15507 else {
15508 vty_out(vty,
04c9077f 15509 "This VRF is exporting %s routes to the following VRFs:\n",
5cb5f4d0 15510 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15511
15512 for (ALL_LIST_ELEMENTS_RO(
15513 bgp->vpn_policy[afi].export_vrf,
15514 node, vname))
15515 vty_out(vty, " %s\n", vname);
15516
c4f64ea9
DA
15517 vty_out(vty, "RD: %pRD\n",
15518 &bgp->vpn_policy[afi].tovpn_rd);
b46dfd20
DS
15519
15520 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
15521 if (bgp->vpn_policy[afi].rtlist[dir]) {
15522 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15523 bgp->vpn_policy[afi].rtlist[dir],
15524 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
15525 vty_out(vty, "Export RT: %s\n", ecom_str);
15526 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15527 } else
15528 vty_out(vty, "Import RT(s):\n");
53089bec 15529 }
53089bec 15530 }
15531
15532 return CMD_SUCCESS;
15533}
15534
03915806
CS
15535static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
15536 safi_t safi, bool use_json)
15537{
15538 struct listnode *node, *nnode;
15539 struct bgp *bgp;
15540 char *vrf_name = NULL;
15541 json_object *json = NULL;
15542 json_object *json_vrf = NULL;
15543 json_object *json_vrfs = NULL;
15544
15545 if (use_json) {
15546 json = json_object_new_object();
15547 json_vrfs = json_object_new_object();
15548 }
15549
15550 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15551
15552 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
15553 vrf_name = bgp->name;
15554
15555 if (use_json) {
15556 json_vrf = json_object_new_object();
15557 } else {
15558 vty_out(vty, "\nInstance %s:\n",
15559 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15560 ? VRF_DEFAULT_NAME : bgp->name);
15561 }
15562 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
15563 if (use_json) {
15564 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15565 json_object_object_add(json_vrfs,
15566 VRF_DEFAULT_NAME, json_vrf);
15567 else
15568 json_object_object_add(json_vrfs, vrf_name,
15569 json_vrf);
15570 }
15571 }
15572
15573 if (use_json) {
15574 json_object_object_add(json, "vrfs", json_vrfs);
75eeda93 15575 vty_json(vty, json);
03915806
CS
15576 }
15577
15578 return CMD_SUCCESS;
15579}
15580
53089bec 15581/* "show [ip] bgp route-leak" command. */
15582DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
15583 show_ip_bgp_route_leak_cmd,
15584 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
15585 SHOW_STR
15586 IP_STR
15587 BGP_STR
15588 BGP_INSTANCE_HELP_STR
15589 BGP_AFI_HELP_STR
15590 BGP_SAFI_HELP_STR
15591 "Route leaking information\n"
15592 JSON_STR)
53089bec 15593{
15594 char *vrf = NULL;
15595 afi_t afi = AFI_MAX;
15596 safi_t safi = SAFI_MAX;
15597
9f049418 15598 bool uj = use_json(argc, argv);
53089bec 15599 int idx = 0;
03915806 15600 json_object *json = NULL;
53089bec 15601
15602 /* show [ip] bgp */
15603 if (argv_find(argv, argc, "ip", &idx)) {
15604 afi = AFI_IP;
15605 safi = SAFI_UNICAST;
15606 }
15607 /* [vrf VIEWVRFNAME] */
15608 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
15609 vty_out(vty,
15610 "%% This command is not applicable to BGP views\n");
53089bec 15611 return CMD_WARNING;
15612 }
15613
9a8bdf1c
PG
15614 if (argv_find(argv, argc, "vrf", &idx)) {
15615 vrf = argv[idx + 1]->arg;
15616 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15617 vrf = NULL;
15618 }
53089bec 15619 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
c48349e3 15620 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
53089bec 15621 argv_find_and_parse_safi(argv, argc, &idx, &safi);
53089bec 15622
15623 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
15624 vty_out(vty,
15625 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 15626 return CMD_WARNING;
15627 }
15628
03915806
CS
15629 if (vrf && strmatch(vrf, "all"))
15630 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15631
15632 if (uj)
15633 json = json_object_new_object();
15634
15635 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
53089bec 15636}
15637
d62a17ae 15638static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
fa5a9276 15639 safi_t safi, bool uj)
f186de26 15640{
d62a17ae 15641 struct listnode *node, *nnode;
15642 struct bgp *bgp;
f186de26 15643
d62a17ae 15644 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
fa5a9276
AR
15645 if (!uj)
15646 vty_out(vty, "\nInstance %s:\n",
15647 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15648 ? VRF_DEFAULT_NAME
15649 : bgp->name);
15650
15651 update_group_show(bgp, afi, safi, vty, 0, uj);
d62a17ae 15652 }
f186de26 15653}
15654
d62a17ae 15655static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
fa5a9276 15656 int safi, uint64_t subgrp_id, bool uj)
4fb25c53 15657{
d62a17ae 15658 struct bgp *bgp;
4fb25c53 15659
d62a17ae 15660 if (name) {
15661 if (strmatch(name, "all")) {
fa5a9276 15662 bgp_show_all_instances_updgrps_vty(vty, afi, safi, uj);
d62a17ae 15663 return CMD_SUCCESS;
15664 } else {
15665 bgp = bgp_lookup_by_name(name);
15666 }
15667 } else {
15668 bgp = bgp_get_default();
15669 }
4fb25c53 15670
d62a17ae 15671 if (bgp)
fa5a9276 15672 update_group_show(bgp, afi, safi, vty, subgrp_id, uj);
d62a17ae 15673 return CMD_SUCCESS;
4fb25c53
DW
15674}
15675
8fe8a7f6
DS
15676DEFUN (show_ip_bgp_updgrps,
15677 show_ip_bgp_updgrps_cmd,
fa5a9276 15678 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID] [json]",
8386ac43 15679 SHOW_STR
15680 IP_STR
15681 BGP_STR
15682 BGP_INSTANCE_HELP_STR
c9e571b4 15683 BGP_AFI_HELP_STR
9bedbb1e 15684 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956 15685 "Detailed info about dynamic update groups\n"
fa5a9276
AR
15686 "Specific subgroup to display detailed info for\n"
15687 JSON_STR)
8386ac43 15688{
d62a17ae 15689 char *vrf = NULL;
15690 afi_t afi = AFI_IP6;
15691 safi_t safi = SAFI_UNICAST;
15692 uint64_t subgrp_id = 0;
15693
15694 int idx = 0;
15695
fa5a9276
AR
15696 bool uj = use_json(argc, argv);
15697
d62a17ae 15698 /* show [ip] bgp */
15699 if (argv_find(argv, argc, "ip", &idx))
15700 afi = AFI_IP;
9a8bdf1c
PG
15701 /* [<vrf> VIEWVRFNAME] */
15702 if (argv_find(argv, argc, "vrf", &idx)) {
15703 vrf = argv[idx + 1]->arg;
15704 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15705 vrf = NULL;
15706 } else if (argv_find(argv, argc, "view", &idx))
15707 /* [<view> VIEWVRFNAME] */
15708 vrf = argv[idx + 1]->arg;
d62a17ae 15709 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15710 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15711 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15712 }
5bf15956 15713
d62a17ae 15714 /* get subgroup id, if provided */
15715 idx = argc - 1;
15716 if (argv[idx]->type == VARIABLE_TKN)
15717 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 15718
fa5a9276 15719 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id, uj));
8fe8a7f6
DS
15720}
15721
f186de26 15722DEFUN (show_bgp_instance_all_ipv6_updgrps,
15723 show_bgp_instance_all_ipv6_updgrps_cmd,
fa5a9276 15724 "show [ip] bgp <view|vrf> all update-groups [json]",
f186de26 15725 SHOW_STR
716b2d8a 15726 IP_STR
f186de26 15727 BGP_STR
15728 BGP_INSTANCE_ALL_HELP_STR
fa5a9276
AR
15729 "Detailed info about dynamic update groups\n"
15730 JSON_STR)
f186de26 15731{
fa5a9276
AR
15732 bool uj = use_json(argc, argv);
15733
15734 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST, uj);
d62a17ae 15735 return CMD_SUCCESS;
f186de26 15736}
15737
43d3f4fc
DS
15738DEFUN (show_bgp_l2vpn_evpn_updgrps,
15739 show_bgp_l2vpn_evpn_updgrps_cmd,
15740 "show [ip] bgp l2vpn evpn update-groups",
15741 SHOW_STR
15742 IP_STR
15743 BGP_STR
15744 "l2vpn address family\n"
15745 "evpn sub-address family\n"
15746 "Detailed info about dynamic update groups\n")
15747{
15748 char *vrf = NULL;
15749 uint64_t subgrp_id = 0;
15750
fa5a9276 15751 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id, 0);
43d3f4fc
DS
15752 return CMD_SUCCESS;
15753}
15754
5bf15956
DW
15755DEFUN (show_bgp_updgrps_stats,
15756 show_bgp_updgrps_stats_cmd,
716b2d8a 15757 "show [ip] bgp update-groups statistics",
3f9c7369 15758 SHOW_STR
716b2d8a 15759 IP_STR
3f9c7369 15760 BGP_STR
0c7b1b01 15761 "Detailed info about dynamic update groups\n"
3f9c7369
DS
15762 "Statistics\n")
15763{
d62a17ae 15764 struct bgp *bgp;
3f9c7369 15765
d62a17ae 15766 bgp = bgp_get_default();
15767 if (bgp)
15768 update_group_show_stats(bgp, vty);
3f9c7369 15769
d62a17ae 15770 return CMD_SUCCESS;
3f9c7369
DS
15771}
15772
8386ac43 15773DEFUN (show_bgp_instance_updgrps_stats,
15774 show_bgp_instance_updgrps_stats_cmd,
18c57037 15775 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 15776 SHOW_STR
716b2d8a 15777 IP_STR
8386ac43 15778 BGP_STR
15779 BGP_INSTANCE_HELP_STR
0c7b1b01 15780 "Detailed info about dynamic update groups\n"
8386ac43 15781 "Statistics\n")
15782{
d62a17ae 15783 int idx_word = 3;
15784 struct bgp *bgp;
8386ac43 15785
d62a17ae 15786 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15787 if (bgp)
15788 update_group_show_stats(bgp, vty);
8386ac43 15789
d62a17ae 15790 return CMD_SUCCESS;
8386ac43 15791}
15792
d62a17ae 15793static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15794 afi_t afi, safi_t safi,
15795 const char *what, uint64_t subgrp_id)
3f9c7369 15796{
d62a17ae 15797 struct bgp *bgp;
8386ac43 15798
d62a17ae 15799 if (name)
15800 bgp = bgp_lookup_by_name(name);
15801 else
15802 bgp = bgp_get_default();
8386ac43 15803
d62a17ae 15804 if (bgp) {
15805 if (!strcmp(what, "advertise-queue"))
15806 update_group_show_adj_queue(bgp, afi, safi, vty,
15807 subgrp_id);
15808 else if (!strcmp(what, "advertised-routes"))
15809 update_group_show_advertised(bgp, afi, safi, vty,
15810 subgrp_id);
15811 else if (!strcmp(what, "packet-queue"))
15812 update_group_show_packet_queue(bgp, afi, safi, vty,
15813 subgrp_id);
15814 }
3f9c7369
DS
15815}
15816
dc64bdec
QY
15817DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15818 show_ip_bgp_instance_updgrps_adj_s_cmd,
15819 "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",
15820 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15821 BGP_SAFI_HELP_STR
15822 "Detailed info about dynamic update groups\n"
15823 "Specific subgroup to display info for\n"
15824 "Advertisement queue\n"
15825 "Announced routes\n"
15826 "Packet queue\n")
3f9c7369 15827{
dc64bdec
QY
15828 uint64_t subgrp_id = 0;
15829 afi_t afiz;
15830 safi_t safiz;
15831 if (sgid)
15832 subgrp_id = strtoull(sgid, NULL, 10);
15833
15834 if (!ip && !afi)
15835 afiz = AFI_IP6;
15836 if (!ip && afi)
15837 afiz = bgp_vty_afi_from_str(afi);
15838 if (ip && !afi)
15839 afiz = AFI_IP;
15840 if (ip && afi) {
15841 afiz = bgp_vty_afi_from_str(afi);
15842 if (afiz != AFI_IP)
15843 vty_out(vty,
15844 "%% Cannot specify both 'ip' and 'ipv6'\n");
15845 return CMD_WARNING;
15846 }
d62a17ae 15847
dc64bdec 15848 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 15849
dc64bdec 15850 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 15851 return CMD_SUCCESS;
15852}
15853
6f4eacf3
DA
15854static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
15855 json_object *json)
d62a17ae 15856{
15857 struct listnode *node, *nnode;
15858 struct prefix *range;
15859 struct peer *conf;
15860 struct peer *peer;
d62a17ae 15861 afi_t afi;
15862 safi_t safi;
15863 const char *peer_status;
d62a17ae 15864 int lr_count;
15865 int dynamic;
6f4eacf3
DA
15866 bool af_cfgd;
15867 json_object *json_peer_group = NULL;
15868 json_object *json_peer_group_afc = NULL;
15869 json_object *json_peer_group_members = NULL;
15870 json_object *json_peer_group_dynamic = NULL;
15871 json_object *json_peer_group_dynamic_af = NULL;
15872 json_object *json_peer_group_ranges = NULL;
d62a17ae 15873
15874 conf = group->conf;
15875
6f4eacf3
DA
15876 if (json) {
15877 json_peer_group = json_object_new_object();
15878 json_peer_group_afc = json_object_new_array();
15879 }
15880
d62a17ae 15881 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
6f4eacf3
DA
15882 if (json)
15883 json_object_int_add(json_peer_group, "remoteAs",
15884 conf->as);
15885 else
15886 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15887 group->name, conf->as);
d62a17ae 15888 } else if (conf->as_type == AS_INTERNAL) {
6f4eacf3
DA
15889 if (json)
15890 json_object_int_add(json_peer_group, "remoteAs",
15891 group->bgp->as);
15892 else
15893 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15894 group->name, group->bgp->as);
d62a17ae 15895 } else {
6f4eacf3
DA
15896 if (!json)
15897 vty_out(vty, "\nBGP peer-group %s\n", group->name);
d62a17ae 15898 }
f14e6fdb 15899
6f4eacf3
DA
15900 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
15901 if (json)
15902 json_object_string_add(json_peer_group, "type",
15903 "internal");
15904 else
15905 vty_out(vty, " Peer-group type is internal\n");
15906 } else {
15907 if (json)
15908 json_object_string_add(json_peer_group, "type",
15909 "external");
15910 else
15911 vty_out(vty, " Peer-group type is external\n");
15912 }
d62a17ae 15913
15914 /* Display AFs configured. */
6f4eacf3
DA
15915 if (!json)
15916 vty_out(vty, " Configured address-families:");
15917
05c7a1cc
QY
15918 FOREACH_AFI_SAFI (afi, safi) {
15919 if (conf->afc[afi][safi]) {
6f4eacf3
DA
15920 af_cfgd = true;
15921 if (json)
15922 json_object_array_add(
15923 json_peer_group_afc,
15924 json_object_new_string(get_afi_safi_str(
15925 afi, safi, false)));
15926 else
15927 vty_out(vty, " %s;",
15928 get_afi_safi_str(afi, safi, false));
d62a17ae 15929 }
05c7a1cc 15930 }
6f4eacf3
DA
15931
15932 if (json) {
15933 json_object_object_add(json_peer_group,
15934 "addressFamiliesConfigured",
15935 json_peer_group_afc);
15936 } else {
15937 if (!af_cfgd)
15938 vty_out(vty, " none\n");
15939 else
15940 vty_out(vty, "\n");
15941 }
d62a17ae 15942
15943 /* Display listen ranges (for dynamic neighbors), if any */
15944 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
d62a17ae 15945 lr_count = listcount(group->listen_range[afi]);
15946 if (lr_count) {
6f4eacf3
DA
15947 if (json) {
15948 if (!json_peer_group_dynamic)
15949 json_peer_group_dynamic =
15950 json_object_new_object();
15951
15952 json_peer_group_dynamic_af =
15953 json_object_new_object();
15954 json_peer_group_ranges =
15955 json_object_new_array();
15956 json_object_int_add(json_peer_group_dynamic_af,
15957 "count", lr_count);
15958 } else {
15959 vty_out(vty, " %d %s listen range(s)\n",
15960 lr_count, afi2str(afi));
15961 }
d62a17ae 15962
15963 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
6f4eacf3
DA
15964 nnode, range)) {
15965 if (json) {
15966 char buf[BUFSIZ];
15967
15968 snprintfrr(buf, sizeof(buf), "%pFX",
15969 range);
15970
15971 json_object_array_add(
15972 json_peer_group_ranges,
15973 json_object_new_string(buf));
15974 } else {
15975 vty_out(vty, " %pFX\n", range);
15976 }
15977 }
15978
15979 if (json) {
15980 json_object_object_add(
15981 json_peer_group_dynamic_af, "ranges",
15982 json_peer_group_ranges);
15983
15984 json_object_object_add(
15985 json_peer_group_dynamic, afi2str(afi),
15986 json_peer_group_dynamic_af);
15987 }
d62a17ae 15988 }
15989 }
f14e6fdb 15990
6f4eacf3
DA
15991 if (json_peer_group_dynamic)
15992 json_object_object_add(json_peer_group, "dynamicRanges",
15993 json_peer_group_dynamic);
15994
d62a17ae 15995 /* Display group members and their status */
15996 if (listcount(group->peer)) {
6f4eacf3
DA
15997 if (json)
15998 json_peer_group_members = json_object_new_object();
15999 else
16000 vty_out(vty, " Peer-group members:\n");
d62a17ae 16001 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
cb9196e7
DS
16002 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
16003 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 16004 peer_status = "Idle (Admin)";
16005 else if (CHECK_FLAG(peer->sflags,
16006 PEER_STATUS_PREFIX_OVERFLOW))
16007 peer_status = "Idle (PfxCt)";
16008 else
16009 peer_status = lookup_msg(bgp_status_msg,
16010 peer->status, NULL);
16011
16012 dynamic = peer_dynamic_neighbor(peer);
6f4eacf3
DA
16013
16014 if (json) {
16015 json_object *json_peer_group_member =
16016 json_object_new_object();
16017
16018 json_object_string_add(json_peer_group_member,
16019 "status", peer_status);
16020
16021 if (dynamic)
16022 json_object_boolean_true_add(
16023 json_peer_group_member,
16024 "dynamic");
16025
16026 json_object_object_add(json_peer_group_members,
16027 peer->host,
16028 json_peer_group_member);
16029 } else {
16030 vty_out(vty, " %s %s %s \n", peer->host,
16031 dynamic ? "(dynamic)" : "",
16032 peer_status);
16033 }
d62a17ae 16034 }
6f4eacf3
DA
16035 if (json)
16036 json_object_object_add(json_peer_group, "members",
16037 json_peer_group_members);
d62a17ae 16038 }
f14e6fdb 16039
6f4eacf3
DA
16040 if (json)
16041 json_object_object_add(json, group->name, json_peer_group);
16042
d62a17ae 16043 return CMD_SUCCESS;
16044}
16045
ff9959b0 16046static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
6f4eacf3 16047 const char *group_name, bool uj)
d62a17ae 16048{
ff9959b0 16049 struct bgp *bgp;
d62a17ae 16050 struct listnode *node, *nnode;
16051 struct peer_group *group;
ff9959b0 16052 bool found = false;
6f4eacf3
DA
16053 json_object *json = NULL;
16054
16055 if (uj)
16056 json = json_object_new_object();
ff9959b0
QY
16057
16058 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
16059
16060 if (!bgp) {
c48349e3 16061 if (uj)
75eeda93 16062 vty_json(vty, json);
c48349e3 16063 else
6f4eacf3 16064 vty_out(vty, "%% BGP instance not found\n");
6f4eacf3 16065
ff9959b0
QY
16066 return CMD_WARNING;
16067 }
d62a17ae 16068
16069 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
16070 if (group_name) {
16071 if (strmatch(group->name, group_name)) {
6f4eacf3 16072 bgp_show_one_peer_group(vty, group, json);
ff9959b0
QY
16073 found = true;
16074 break;
d62a17ae 16075 }
ff9959b0 16076 } else {
6f4eacf3 16077 bgp_show_one_peer_group(vty, group, json);
d62a17ae 16078 }
f14e6fdb 16079 }
f14e6fdb 16080
6f4eacf3 16081 if (group_name && !found && !uj)
d62a17ae 16082 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 16083
c48349e3 16084 if (uj)
75eeda93 16085 vty_json(vty, json);
6f4eacf3 16086
d62a17ae 16087 return CMD_SUCCESS;
f14e6fdb
DS
16088}
16089
6f4eacf3
DA
16090DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
16091 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
16092 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
16093 "Detailed information on BGP peer groups\n"
16094 "Peer group name\n" JSON_STR)
f14e6fdb 16095{
d62a17ae 16096 char *vrf, *pg;
d62a17ae 16097 int idx = 0;
6f4eacf3 16098 bool uj = use_json(argc, argv);
f14e6fdb 16099
a4d82a8a
PZ
16100 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
16101 : NULL;
d62a17ae 16102 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 16103
6f4eacf3 16104 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
f14e6fdb 16105}
3f9c7369 16106
d6e3c605 16107
718e3744 16108/* Redistribute VTY commands. */
16109
585f1adc
IR
16110DEFUN (bgp_redistribute_ipv4,
16111 bgp_redistribute_ipv4_cmd,
16112 "redistribute " FRR_IP_REDIST_STR_BGPD,
16113 "Redistribute information from another routing protocol\n"
16114 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 16115{
585f1adc 16116 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16117 int idx_protocol = 1;
585f1adc 16118 int type;
37a87b8f 16119
585f1adc
IR
16120 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16121 if (type < 0) {
16122 vty_out(vty, "%% Invalid route type\n");
16123 return CMD_WARNING_CONFIG_FAILED;
16124 }
7f323236 16125
585f1adc
IR
16126 bgp_redist_add(bgp, AFI_IP, type, 0);
16127 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
718e3744 16128}
16129
d62a17ae 16130ALIAS_HIDDEN(
16131 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
16132 "redistribute " FRR_IP_REDIST_STR_BGPD,
16133 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 16134
585f1adc
IR
16135DEFUN (bgp_redistribute_ipv4_rmap,
16136 bgp_redistribute_ipv4_rmap_cmd,
70dd370f 16137 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
585f1adc
IR
16138 "Redistribute information from another routing protocol\n"
16139 FRR_IP_REDIST_HELP_STR_BGPD
16140 "Route map reference\n"
16141 "Pointer to route-map entries\n")
718e3744 16142{
585f1adc 16143 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16144 int idx_protocol = 1;
16145 int idx_word = 3;
585f1adc
IR
16146 int type;
16147 struct bgp_redist *red;
16148 bool changed;
16149 struct route_map *route_map = route_map_lookup_warn_noexist(
16150 vty, argv[idx_word]->arg);
16151
16152 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16153 if (type < 0) {
16154 vty_out(vty, "%% Invalid route type\n");
16155 return CMD_WARNING_CONFIG_FAILED;
16156 }
37a87b8f 16157
585f1adc
IR
16158 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16159 changed =
16160 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16161 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
718e3744 16162}
16163
d62a17ae 16164ALIAS_HIDDEN(
16165 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
70dd370f 16166 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
d62a17ae 16167 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16168 "Route map reference\n"
16169 "Pointer to route-map entries\n")
596c17ba 16170
585f1adc
IR
16171DEFUN (bgp_redistribute_ipv4_metric,
16172 bgp_redistribute_ipv4_metric_cmd,
16173 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
16174 "Redistribute information from another routing protocol\n"
16175 FRR_IP_REDIST_HELP_STR_BGPD
16176 "Metric for redistributed routes\n"
16177 "Default metric\n")
718e3744 16178{
585f1adc 16179 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16180 int idx_protocol = 1;
16181 int idx_number = 3;
585f1adc
IR
16182 int type;
16183 uint32_t metric;
16184 struct bgp_redist *red;
16185 bool changed;
16186
16187 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16188 if (type < 0) {
16189 vty_out(vty, "%% Invalid route type\n");
16190 return CMD_WARNING_CONFIG_FAILED;
16191 }
16192 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 16193
585f1adc
IR
16194 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16195 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16196 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 16197}
16198
16199ALIAS_HIDDEN(
16200 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
16201 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
16202 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16203 "Metric for redistributed routes\n"
16204 "Default metric\n")
596c17ba 16205
585f1adc
IR
16206DEFUN (bgp_redistribute_ipv4_rmap_metric,
16207 bgp_redistribute_ipv4_rmap_metric_cmd,
70dd370f 16208 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
585f1adc
IR
16209 "Redistribute information from another routing protocol\n"
16210 FRR_IP_REDIST_HELP_STR_BGPD
16211 "Route map reference\n"
16212 "Pointer to route-map entries\n"
16213 "Metric for redistributed routes\n"
16214 "Default metric\n")
718e3744 16215{
585f1adc 16216 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16217 int idx_protocol = 1;
16218 int idx_word = 3;
16219 int idx_number = 5;
585f1adc
IR
16220 int type;
16221 uint32_t metric;
16222 struct bgp_redist *red;
16223 bool changed;
16224 struct route_map *route_map =
16225 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16226
16227 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16228 if (type < 0) {
16229 vty_out(vty, "%% Invalid route type\n");
16230 return CMD_WARNING_CONFIG_FAILED;
16231 }
16232 metric = strtoul(argv[idx_number]->arg, NULL, 10);
d62a17ae 16233
585f1adc
IR
16234 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16235 changed =
16236 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16237 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16238 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 16239}
16240
16241ALIAS_HIDDEN(
16242 bgp_redistribute_ipv4_rmap_metric,
16243 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
16244 "redistribute " FRR_IP_REDIST_STR_BGPD
70dd370f 16245 " route-map RMAP_NAME metric (0-4294967295)",
d62a17ae 16246 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16247 "Route map reference\n"
16248 "Pointer to route-map entries\n"
16249 "Metric for redistributed routes\n"
16250 "Default metric\n")
596c17ba 16251
585f1adc
IR
16252DEFUN (bgp_redistribute_ipv4_metric_rmap,
16253 bgp_redistribute_ipv4_metric_rmap_cmd,
70dd370f 16254 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
585f1adc
IR
16255 "Redistribute information from another routing protocol\n"
16256 FRR_IP_REDIST_HELP_STR_BGPD
16257 "Metric for redistributed routes\n"
16258 "Default metric\n"
16259 "Route map reference\n"
16260 "Pointer to route-map entries\n")
718e3744 16261{
585f1adc 16262 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16263 int idx_protocol = 1;
37a87b8f 16264 int idx_number = 3;
585f1adc
IR
16265 int idx_word = 5;
16266 int type;
16267 uint32_t metric;
16268 struct bgp_redist *red;
16269 bool changed;
16270 struct route_map *route_map =
16271 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16272
16273 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16274 if (type < 0) {
16275 vty_out(vty, "%% Invalid route type\n");
16276 return CMD_WARNING_CONFIG_FAILED;
16277 }
16278 metric = strtoul(argv[idx_number]->arg, NULL, 10);
d62a17ae 16279
585f1adc
IR
16280 red = bgp_redist_add(bgp, AFI_IP, type, 0);
16281 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16282 changed |=
16283 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16284 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 16285}
16286
16287ALIAS_HIDDEN(
16288 bgp_redistribute_ipv4_metric_rmap,
16289 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
16290 "redistribute " FRR_IP_REDIST_STR_BGPD
70dd370f 16291 " metric (0-4294967295) route-map RMAP_NAME",
d62a17ae 16292 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16293 "Metric for redistributed routes\n"
16294 "Default metric\n"
16295 "Route map reference\n"
16296 "Pointer to route-map entries\n")
596c17ba 16297
585f1adc
IR
16298DEFUN (bgp_redistribute_ipv4_ospf,
16299 bgp_redistribute_ipv4_ospf_cmd,
16300 "redistribute <ospf|table> (1-65535)",
16301 "Redistribute information from another routing protocol\n"
16302 "Open Shortest Path First (OSPFv2)\n"
16303 "Non-main Kernel Routing Table\n"
16304 "Instance ID/Table ID\n")
7c8ff89e 16305{
585f1adc
IR
16306 VTY_DECLVAR_CONTEXT(bgp, bgp);
16307 int idx_ospf_table = 1;
d62a17ae 16308 int idx_number = 2;
585f1adc
IR
16309 unsigned short instance;
16310 unsigned short protocol;
7c8ff89e 16311
585f1adc 16312 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 16313
585f1adc
IR
16314 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16315 protocol = ZEBRA_ROUTE_OSPF;
16316 else
16317 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 16318
585f1adc
IR
16319 bgp_redist_add(bgp, AFI_IP, protocol, instance);
16320 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
7c8ff89e
DS
16321}
16322
d62a17ae 16323ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
16324 "redistribute <ospf|table> (1-65535)",
16325 "Redistribute information from another routing protocol\n"
16326 "Open Shortest Path First (OSPFv2)\n"
16327 "Non-main Kernel Routing Table\n"
16328 "Instance ID/Table ID\n")
596c17ba 16329
585f1adc
IR
16330DEFUN (bgp_redistribute_ipv4_ospf_rmap,
16331 bgp_redistribute_ipv4_ospf_rmap_cmd,
70dd370f 16332 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
585f1adc
IR
16333 "Redistribute information from another routing protocol\n"
16334 "Open Shortest Path First (OSPFv2)\n"
16335 "Non-main Kernel Routing Table\n"
16336 "Instance ID/Table ID\n"
16337 "Route map reference\n"
16338 "Pointer to route-map entries\n")
7c8ff89e 16339{
585f1adc
IR
16340 VTY_DECLVAR_CONTEXT(bgp, bgp);
16341 int idx_ospf_table = 1;
d62a17ae 16342 int idx_number = 2;
16343 int idx_word = 4;
585f1adc
IR
16344 struct bgp_redist *red;
16345 unsigned short instance;
16346 int protocol;
16347 bool changed;
16348 struct route_map *route_map =
16349 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16350
16351 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16352 protocol = ZEBRA_ROUTE_OSPF;
16353 else
16354 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 16355
585f1adc
IR
16356 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16357 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16358 changed =
16359 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16360 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 16361}
16362
16363ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
16364 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
70dd370f 16365 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
d62a17ae 16366 "Redistribute information from another routing protocol\n"
16367 "Open Shortest Path First (OSPFv2)\n"
16368 "Non-main Kernel Routing Table\n"
16369 "Instance ID/Table ID\n"
16370 "Route map reference\n"
16371 "Pointer to route-map entries\n")
596c17ba 16372
585f1adc
IR
16373DEFUN (bgp_redistribute_ipv4_ospf_metric,
16374 bgp_redistribute_ipv4_ospf_metric_cmd,
16375 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16376 "Redistribute information from another routing protocol\n"
16377 "Open Shortest Path First (OSPFv2)\n"
16378 "Non-main Kernel Routing Table\n"
16379 "Instance ID/Table ID\n"
16380 "Metric for redistributed routes\n"
16381 "Default metric\n")
7c8ff89e 16382{
585f1adc
IR
16383 VTY_DECLVAR_CONTEXT(bgp, bgp);
16384 int idx_ospf_table = 1;
d62a17ae 16385 int idx_number = 2;
16386 int idx_number_2 = 4;
585f1adc
IR
16387 uint32_t metric;
16388 struct bgp_redist *red;
16389 unsigned short instance;
16390 int protocol;
16391 bool changed;
16392
16393 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16394 protocol = ZEBRA_ROUTE_OSPF;
16395 else
16396 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 16397
585f1adc
IR
16398 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16399 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 16400
585f1adc
IR
16401 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16402 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16403 metric);
16404 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 16405}
16406
16407ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
16408 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
16409 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16410 "Redistribute information from another routing protocol\n"
16411 "Open Shortest Path First (OSPFv2)\n"
16412 "Non-main Kernel Routing Table\n"
16413 "Instance ID/Table ID\n"
16414 "Metric for redistributed routes\n"
16415 "Default metric\n")
596c17ba 16416
585f1adc
IR
16417DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
16418 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
70dd370f 16419 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
585f1adc
IR
16420 "Redistribute information from another routing protocol\n"
16421 "Open Shortest Path First (OSPFv2)\n"
16422 "Non-main Kernel Routing Table\n"
16423 "Instance ID/Table ID\n"
16424 "Route map reference\n"
16425 "Pointer to route-map entries\n"
16426 "Metric for redistributed routes\n"
16427 "Default metric\n")
7c8ff89e 16428{
585f1adc
IR
16429 VTY_DECLVAR_CONTEXT(bgp, bgp);
16430 int idx_ospf_table = 1;
d62a17ae 16431 int idx_number = 2;
16432 int idx_word = 4;
16433 int idx_number_2 = 6;
585f1adc
IR
16434 uint32_t metric;
16435 struct bgp_redist *red;
16436 unsigned short instance;
16437 int protocol;
16438 bool changed;
16439 struct route_map *route_map =
16440 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16441
16442 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16443 protocol = ZEBRA_ROUTE_OSPF;
16444 else
16445 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 16446
585f1adc
IR
16447 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16448 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 16449
585f1adc
IR
16450 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16451 changed =
16452 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16453 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16454 metric);
16455 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 16456}
16457
16458ALIAS_HIDDEN(
16459 bgp_redistribute_ipv4_ospf_rmap_metric,
16460 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
70dd370f 16461 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
d62a17ae 16462 "Redistribute information from another routing protocol\n"
16463 "Open Shortest Path First (OSPFv2)\n"
16464 "Non-main Kernel Routing Table\n"
16465 "Instance ID/Table ID\n"
16466 "Route map reference\n"
16467 "Pointer to route-map entries\n"
16468 "Metric for redistributed routes\n"
16469 "Default metric\n")
596c17ba 16470
585f1adc
IR
16471DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
16472 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
70dd370f 16473 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
585f1adc
IR
16474 "Redistribute information from another routing protocol\n"
16475 "Open Shortest Path First (OSPFv2)\n"
16476 "Non-main Kernel Routing Table\n"
16477 "Instance ID/Table ID\n"
16478 "Metric for redistributed routes\n"
16479 "Default metric\n"
16480 "Route map reference\n"
16481 "Pointer to route-map entries\n")
7c8ff89e 16482{
585f1adc
IR
16483 VTY_DECLVAR_CONTEXT(bgp, bgp);
16484 int idx_ospf_table = 1;
d62a17ae 16485 int idx_number = 2;
16486 int idx_number_2 = 4;
16487 int idx_word = 6;
585f1adc
IR
16488 uint32_t metric;
16489 struct bgp_redist *red;
16490 unsigned short instance;
16491 int protocol;
16492 bool changed;
16493 struct route_map *route_map =
16494 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16495
16496 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16497 protocol = ZEBRA_ROUTE_OSPF;
16498 else
16499 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 16500
585f1adc
IR
16501 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16502 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 16503
585f1adc
IR
16504 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16505 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16506 metric);
16507 changed |=
16508 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16509 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 16510}
16511
16512ALIAS_HIDDEN(
16513 bgp_redistribute_ipv4_ospf_metric_rmap,
16514 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
70dd370f 16515 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
d62a17ae 16516 "Redistribute information from another routing protocol\n"
16517 "Open Shortest Path First (OSPFv2)\n"
16518 "Non-main Kernel Routing Table\n"
16519 "Instance ID/Table ID\n"
16520 "Metric for redistributed routes\n"
16521 "Default metric\n"
16522 "Route map reference\n"
16523 "Pointer to route-map entries\n")
596c17ba 16524
585f1adc
IR
16525DEFUN (no_bgp_redistribute_ipv4_ospf,
16526 no_bgp_redistribute_ipv4_ospf_cmd,
70dd370f 16527 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
585f1adc
IR
16528 NO_STR
16529 "Redistribute information from another routing protocol\n"
16530 "Open Shortest Path First (OSPFv2)\n"
16531 "Non-main Kernel Routing Table\n"
16532 "Instance ID/Table ID\n"
16533 "Metric for redistributed routes\n"
16534 "Default metric\n"
16535 "Route map reference\n"
16536 "Pointer to route-map entries\n")
7c8ff89e 16537{
585f1adc
IR
16538 VTY_DECLVAR_CONTEXT(bgp, bgp);
16539 int idx_ospf_table = 2;
d62a17ae 16540 int idx_number = 3;
585f1adc
IR
16541 unsigned short instance;
16542 int protocol;
37a87b8f 16543
585f1adc
IR
16544 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16545 protocol = ZEBRA_ROUTE_OSPF;
16546 else
16547 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 16548
585f1adc
IR
16549 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16550 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
d62a17ae 16551}
16552
16553ALIAS_HIDDEN(
16554 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
70dd370f 16555 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
d62a17ae 16556 NO_STR
16557 "Redistribute information from another routing protocol\n"
16558 "Open Shortest Path First (OSPFv2)\n"
16559 "Non-main Kernel Routing Table\n"
16560 "Instance ID/Table ID\n"
16561 "Metric for redistributed routes\n"
16562 "Default metric\n"
16563 "Route map reference\n"
16564 "Pointer to route-map entries\n")
596c17ba 16565
585f1adc
IR
16566DEFUN (no_bgp_redistribute_ipv4,
16567 no_bgp_redistribute_ipv4_cmd,
70dd370f 16568 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
585f1adc
IR
16569 NO_STR
16570 "Redistribute information from another routing protocol\n"
16571 FRR_IP_REDIST_HELP_STR_BGPD
16572 "Metric for redistributed routes\n"
16573 "Default metric\n"
16574 "Route map reference\n"
16575 "Pointer to route-map entries\n")
718e3744 16576{
585f1adc 16577 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16578 int idx_protocol = 2;
585f1adc 16579 int type;
d62a17ae 16580
585f1adc
IR
16581 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16582 if (type < 0) {
16583 vty_out(vty, "%% Invalid route type\n");
16584 return CMD_WARNING_CONFIG_FAILED;
16585 }
16586 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
d62a17ae 16587}
16588
16589ALIAS_HIDDEN(
16590 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
16591 "no redistribute " FRR_IP_REDIST_STR_BGPD
70dd370f 16592 " [{metric (0-4294967295)|route-map RMAP_NAME}]",
d62a17ae 16593 NO_STR
16594 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16595 "Metric for redistributed routes\n"
16596 "Default metric\n"
16597 "Route map reference\n"
16598 "Pointer to route-map entries\n")
596c17ba 16599
585f1adc
IR
16600DEFUN (bgp_redistribute_ipv6,
16601 bgp_redistribute_ipv6_cmd,
16602 "redistribute " FRR_IP6_REDIST_STR_BGPD,
16603 "Redistribute information from another routing protocol\n"
16604 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 16605{
585f1adc 16606 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16607 int idx_protocol = 1;
585f1adc 16608 int type;
718e3744 16609
585f1adc
IR
16610 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16611 if (type < 0) {
16612 vty_out(vty, "%% Invalid route type\n");
16613 return CMD_WARNING_CONFIG_FAILED;
16614 }
718e3744 16615
585f1adc
IR
16616 bgp_redist_add(bgp, AFI_IP6, type, 0);
16617 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
718e3744 16618}
16619
585f1adc
IR
16620DEFUN (bgp_redistribute_ipv6_rmap,
16621 bgp_redistribute_ipv6_rmap_cmd,
70dd370f 16622 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME",
585f1adc
IR
16623 "Redistribute information from another routing protocol\n"
16624 FRR_IP6_REDIST_HELP_STR_BGPD
16625 "Route map reference\n"
16626 "Pointer to route-map entries\n")
718e3744 16627{
585f1adc 16628 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16629 int idx_protocol = 1;
16630 int idx_word = 3;
585f1adc
IR
16631 int type;
16632 struct bgp_redist *red;
16633 bool changed;
16634 struct route_map *route_map =
16635 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16636
16637 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16638 if (type < 0) {
16639 vty_out(vty, "%% Invalid route type\n");
16640 return CMD_WARNING_CONFIG_FAILED;
16641 }
37a87b8f 16642
585f1adc
IR
16643 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16644 changed =
16645 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16646 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 16647}
16648
585f1adc 16649DEFUN (bgp_redistribute_ipv6_metric,
718e3744 16650 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 16651 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 16652 "Redistribute information from another routing protocol\n"
ab0181ee 16653 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 16654 "Metric for redistributed routes\n"
16655 "Default metric\n")
16656{
585f1adc 16657 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16658 int idx_protocol = 1;
16659 int idx_number = 3;
585f1adc
IR
16660 int type;
16661 uint32_t metric;
16662 struct bgp_redist *red;
16663 bool changed;
16664
16665 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16666 if (type < 0) {
16667 vty_out(vty, "%% Invalid route type\n");
16668 return CMD_WARNING_CONFIG_FAILED;
16669 }
16670 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 16671
585f1adc
IR
16672 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16673 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
16674 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 16675}
16676
585f1adc
IR
16677DEFUN (bgp_redistribute_ipv6_rmap_metric,
16678 bgp_redistribute_ipv6_rmap_metric_cmd,
70dd370f 16679 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
585f1adc
IR
16680 "Redistribute information from another routing protocol\n"
16681 FRR_IP6_REDIST_HELP_STR_BGPD
16682 "Route map reference\n"
16683 "Pointer to route-map entries\n"
16684 "Metric for redistributed routes\n"
16685 "Default metric\n")
718e3744 16686{
585f1adc 16687 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16688 int idx_protocol = 1;
16689 int idx_word = 3;
16690 int idx_number = 5;
585f1adc
IR
16691 int type;
16692 uint32_t metric;
16693 struct bgp_redist *red;
16694 bool changed;
16695 struct route_map *route_map =
16696 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16697
16698 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16699 if (type < 0) {
16700 vty_out(vty, "%% Invalid route type\n");
16701 return CMD_WARNING_CONFIG_FAILED;
16702 }
16703 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 16704
585f1adc
IR
16705 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16706 changed =
16707 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16708 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
16709 metric);
16710 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 16711}
16712
585f1adc
IR
16713DEFUN (bgp_redistribute_ipv6_metric_rmap,
16714 bgp_redistribute_ipv6_metric_rmap_cmd,
70dd370f 16715 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
585f1adc
IR
16716 "Redistribute information from another routing protocol\n"
16717 FRR_IP6_REDIST_HELP_STR_BGPD
16718 "Metric for redistributed routes\n"
16719 "Default metric\n"
16720 "Route map reference\n"
16721 "Pointer to route-map entries\n")
718e3744 16722{
585f1adc 16723 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16724 int idx_protocol = 1;
37a87b8f 16725 int idx_number = 3;
585f1adc
IR
16726 int idx_word = 5;
16727 int type;
16728 uint32_t metric;
16729 struct bgp_redist *red;
16730 bool changed;
16731 struct route_map *route_map =
16732 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16733
16734 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16735 if (type < 0) {
16736 vty_out(vty, "%% Invalid route type\n");
16737 return CMD_WARNING_CONFIG_FAILED;
16738 }
16739 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 16740
585f1adc
IR
16741 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16742 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
16743 metric);
16744 changed |=
16745 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16746 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 16747}
16748
585f1adc
IR
16749DEFUN (no_bgp_redistribute_ipv6,
16750 no_bgp_redistribute_ipv6_cmd,
70dd370f 16751 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
585f1adc
IR
16752 NO_STR
16753 "Redistribute information from another routing protocol\n"
16754 FRR_IP6_REDIST_HELP_STR_BGPD
16755 "Metric for redistributed routes\n"
16756 "Default metric\n"
16757 "Route map reference\n"
16758 "Pointer to route-map entries\n")
718e3744 16759{
585f1adc 16760 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16761 int idx_protocol = 2;
585f1adc 16762 int type;
37a87b8f 16763
585f1adc
IR
16764 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16765 if (type < 0) {
16766 vty_out(vty, "%% Invalid route type\n");
16767 return CMD_WARNING_CONFIG_FAILED;
16768 }
718e3744 16769
585f1adc 16770 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
d62a17ae 16771}
16772
4ab46701
AR
16773/* Neighbor update tcp-mss. */
16774static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
16775 const char *tcp_mss_str)
16776{
16777 struct peer *peer;
16778 uint32_t tcp_mss_val = 0;
16779
16780 peer = peer_and_group_lookup_vty(vty, peer_str);
16781 if (!peer)
16782 return CMD_WARNING_CONFIG_FAILED;
16783
16784 if (tcp_mss_str) {
16785 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
16786 peer_tcp_mss_set(peer, tcp_mss_val);
16787 } else {
16788 peer_tcp_mss_unset(peer);
16789 }
16790
16791 return CMD_SUCCESS;
16792}
16793
16794DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
16795 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
16796 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16797 "TCP max segment size\n"
16798 "TCP MSS value\n")
16799{
16800 int peer_index = 1;
16801 int mss_index = 3;
16802
16803 vty_out(vty,
16804 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16805 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
16806 argv[mss_index]->arg);
16807}
16808
16809DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
16810 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
16811 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16812 "TCP max segment size\n"
16813 "TCP MSS value\n")
16814{
16815 int peer_index = 2;
16816
16817 vty_out(vty,
16818 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16819 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
16820}
16821
a486300b
PG
16822DEFPY(bgp_retain_route_target, bgp_retain_route_target_cmd,
16823 "[no$no] bgp retain route-target all",
16824 NO_STR BGP_STR
16825 "Retain BGP updates\n"
16826 "Retain BGP updates based on route-target values\n"
16827 "Retain all BGP updates\n")
16828{
16829 bool check;
16830 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
16831
16832 check = CHECK_FLAG(bgp->af_flags[bgp_node_afi(vty)][bgp_node_safi(vty)],
16833 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16834 if (check != !no) {
16835 if (!no)
16836 SET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16837 [bgp_node_safi(vty)],
16838 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16839 else
16840 UNSET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16841 [bgp_node_safi(vty)],
16842 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16843 /* trigger a flush to re-sync with ADJ-RIB-in */
16844 bgp_clear(vty, bgp, bgp_node_afi(vty), bgp_node_safi(vty),
16845 clear_all, BGP_CLEAR_SOFT_IN, NULL);
16846 }
16847 return CMD_SUCCESS;
16848}
16849
dd65f45e
DL
16850static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16851 afi_t afi, safi_t safi)
d62a17ae 16852{
16853 int i;
16854
16855 /* Unicast redistribution only. */
16856 if (safi != SAFI_UNICAST)
2b791107 16857 return;
d62a17ae 16858
16859 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16860 /* Redistribute BGP does not make sense. */
16861 if (i != ZEBRA_ROUTE_BGP) {
16862 struct list *red_list;
16863 struct listnode *node;
16864 struct bgp_redist *red;
16865
16866 red_list = bgp->redist[afi][i];
16867 if (!red_list)
16868 continue;
16869
16870 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 16871 /* "redistribute" configuration. */
16872 vty_out(vty, " redistribute %s",
16873 zebra_route_string(i));
16874 if (red->instance)
16875 vty_out(vty, " %d", red->instance);
16876 if (red->redist_metric_flag)
16877 vty_out(vty, " metric %u",
16878 red->redist_metric);
16879 if (red->rmap.name)
16880 vty_out(vty, " route-map %s",
16881 red->rmap.name);
16882 vty_out(vty, "\n");
16883 }
16884 }
16885 }
718e3744 16886}
6b0655a2 16887
dd65f45e
DL
16888/* peer-group helpers for config-write */
16889
83194f39 16890static bool peergroup_flag_check(struct peer *peer, uint64_t flag)
dd65f45e
DL
16891{
16892 if (!peer_group_active(peer)) {
16893 if (CHECK_FLAG(peer->flags_invert, flag))
16894 return !CHECK_FLAG(peer->flags, flag);
16895 else
16896 return !!CHECK_FLAG(peer->flags, flag);
16897 }
16898
16899 return !!CHECK_FLAG(peer->flags_override, flag);
16900}
16901
16902static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
da5e1a58 16903 uint64_t flag)
dd65f45e
DL
16904{
16905 if (!peer_group_active(peer)) {
16906 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16907 return !peer_af_flag_check(peer, afi, safi, flag);
16908 else
16909 return !!peer_af_flag_check(peer, afi, safi, flag);
16910 }
16911
16912 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16913}
16914
16915static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16916 uint8_t type, int direct)
16917{
16918 struct bgp_filter *filter;
16919
16920 if (peer_group_active(peer))
16921 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16922 type);
16923
16924 filter = &peer->filter[afi][safi];
16925 switch (type) {
16926 case PEER_FT_DISTRIBUTE_LIST:
16927 return !!(filter->dlist[direct].name);
16928 case PEER_FT_FILTER_LIST:
16929 return !!(filter->aslist[direct].name);
16930 case PEER_FT_PREFIX_LIST:
16931 return !!(filter->plist[direct].name);
16932 case PEER_FT_ROUTE_MAP:
16933 return !!(filter->map[direct].name);
16934 case PEER_FT_UNSUPPRESS_MAP:
16935 return !!(filter->usmap.name);
7f7940e6
MK
16936 case PEER_FT_ADVERTISE_MAP:
16937 return !!(filter->advmap.aname
16938 && ((filter->advmap.condition == direct)
16939 && filter->advmap.cname));
dd65f45e
DL
16940 default:
16941 return false;
16942 }
16943}
16944
16945/* Return true if the addpath type is set for peer and different from
16946 * peer-group.
16947 */
3dc339cd
DA
16948static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16949 safi_t safi)
dd65f45e
DL
16950{
16951 enum bgp_addpath_strat type, g_type;
16952
16953 type = peer->addpath_type[afi][safi];
16954
16955 if (type != BGP_ADDPATH_NONE) {
16956 if (peer_group_active(peer)) {
16957 g_type = peer->group->conf->addpath_type[afi][safi];
16958
16959 if (type != g_type)
3dc339cd 16960 return true;
dd65f45e 16961 else
3dc339cd 16962 return false;
dd65f45e
DL
16963 }
16964
3dc339cd 16965 return true;
dd65f45e
DL
16966 }
16967
3dc339cd 16968 return false;
dd65f45e
DL
16969}
16970
b9c7bc5a 16971/* This is part of the address-family block (unicast only) */
dd65f45e 16972static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
16973 afi_t afi)
16974{
b9c7bc5a 16975 int indent = 2;
53970de3 16976 uint32_t tovpn_sid_index = 0;
ddb5b488 16977
8a066a70 16978 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
ae6a6fb4
DS
16979 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16980 BGP_CONFIG_VRF_TO_VRF_IMPORT))
8a066a70
PG
16981 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16982 bgp->vpn_policy[afi]
bb4f6190 16983 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
16984 else
16985 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16986 bgp->vpn_policy[afi]
16987 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16988 }
12a844a5
DS
16989 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16990 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16991 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16992 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16993 return;
16994
e70e9f8e
PZ
16995 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16996 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16997
16998 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16999
17000 } else {
17001 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
17002 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
17003 bgp->vpn_policy[afi].tovpn_label);
17004 }
ddb5b488 17005 }
53970de3
RS
17006
17007 tovpn_sid_index = bgp->vpn_policy[afi].tovpn_sid_index;
17008 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17009 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
17010 vty_out(vty, "%*ssid vpn export %s\n", indent, "", "auto");
17011 } else if (tovpn_sid_index != 0) {
17012 vty_out(vty, "%*ssid vpn export %d\n", indent, "",
17013 tovpn_sid_index);
17014 }
17015
c4f64ea9
DA
17016 if (CHECK_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_RD_SET))
17017 vty_out(vty, "%*srd vpn export %pRD\n", indent, "",
17018 &bgp->vpn_policy[afi].tovpn_rd);
17019
ddb5b488
PZ
17020 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17021 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
17022
17023 char buf[PREFIX_STRLEN];
17024 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
17025 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
17026 sizeof(buf))) {
17027
b9c7bc5a
PZ
17028 vty_out(vty, "%*snexthop vpn export %s\n",
17029 indent, "", buf);
ddb5b488
PZ
17030 }
17031 }
17032 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
17033 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
17034 && ecommunity_cmp(
17035 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
17036 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
17037
17038 char *b = ecommunity_ecom2str(
17039 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
17040 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 17041 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
17042 XFREE(MTYPE_ECOMMUNITY_STR, b);
17043 } else {
17044 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
17045 char *b = ecommunity_ecom2str(
17046 bgp->vpn_policy[afi]
17047 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
17048 ECOMMUNITY_FORMAT_ROUTE_MAP,
17049 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 17050 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
17051 XFREE(MTYPE_ECOMMUNITY_STR, b);
17052 }
17053 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
17054 char *b = ecommunity_ecom2str(
17055 bgp->vpn_policy[afi]
17056 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
17057 ECOMMUNITY_FORMAT_ROUTE_MAP,
17058 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 17059 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
17060 XFREE(MTYPE_ECOMMUNITY_STR, b);
17061 }
17062 }
bb4f6190
DS
17063
17064 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 17065 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
17066 bgp->vpn_policy[afi]
17067 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 17068
301ad80a
PG
17069 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
17070 char *b = ecommunity_ecom2str(
17071 bgp->vpn_policy[afi]
17072 .import_redirect_rtlist,
17073 ECOMMUNITY_FORMAT_ROUTE_MAP,
17074 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 17075
9a659715
PG
17076 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
17077 != ECOMMUNITY_SIZE)
c6423c31 17078 vty_out(vty, "%*srt6 redirect import %s\n",
9a659715
PG
17079 indent, "", b);
17080 else
17081 vty_out(vty, "%*srt redirect import %s\n",
17082 indent, "", b);
301ad80a
PG
17083 XFREE(MTYPE_ECOMMUNITY_STR, b);
17084 }
ddb5b488
PZ
17085}
17086
dd65f45e
DL
17087static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
17088 afi_t afi, safi_t safi)
17089{
17090 struct bgp_filter *filter;
17091 char *addr;
17092
17093 addr = peer->host;
17094 filter = &peer->filter[afi][safi];
17095
17096 /* distribute-list. */
17097 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
17098 FILTER_IN))
17099 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
17100 filter->dlist[FILTER_IN].name);
17101
17102 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
17103 FILTER_OUT))
17104 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
17105 filter->dlist[FILTER_OUT].name);
17106
17107 /* prefix-list. */
17108 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
17109 FILTER_IN))
17110 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
17111 filter->plist[FILTER_IN].name);
17112
17113 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
17114 FILTER_OUT))
17115 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
17116 filter->plist[FILTER_OUT].name);
17117
17118 /* route-map. */
17119 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
17120 vty_out(vty, " neighbor %s route-map %s in\n", addr,
17121 filter->map[RMAP_IN].name);
17122
17123 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
17124 RMAP_OUT))
17125 vty_out(vty, " neighbor %s route-map %s out\n", addr,
17126 filter->map[RMAP_OUT].name);
17127
17128 /* unsuppress-map */
17129 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
17130 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
17131 filter->usmap.name);
17132
7f7940e6
MK
17133 /* advertise-map : always applied in OUT direction*/
17134 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
17135 CONDITION_NON_EXIST))
17136 vty_out(vty,
17137 " neighbor %s advertise-map %s non-exist-map %s\n",
17138 addr, filter->advmap.aname, filter->advmap.cname);
17139
17140 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
17141 CONDITION_EXIST))
17142 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
17143 addr, filter->advmap.aname, filter->advmap.cname);
17144
dd65f45e
DL
17145 /* filter-list. */
17146 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
17147 FILTER_IN))
17148 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
17149 filter->aslist[FILTER_IN].name);
17150
17151 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
17152 FILTER_OUT))
17153 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
17154 filter->aslist[FILTER_OUT].name);
17155}
17156
17157/* BGP peer configuration display function. */
17158static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
17159 struct peer *peer)
17160{
17161 struct peer *g_peer = NULL;
dd65f45e
DL
17162 char *addr;
17163 int if_pg_printed = false;
17164 int if_ras_printed = false;
17165
17166 /* Skip dynamic neighbors. */
17167 if (peer_dynamic_neighbor(peer))
17168 return;
17169
17170 if (peer->conf_if)
17171 addr = peer->conf_if;
17172 else
17173 addr = peer->host;
17174
17175 /************************************
17176 ****** Global to the neighbor ******
17177 ************************************/
17178 if (peer->conf_if) {
17179 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
17180 vty_out(vty, " neighbor %s interface v6only", addr);
17181 else
17182 vty_out(vty, " neighbor %s interface", addr);
17183
17184 if (peer_group_active(peer)) {
17185 vty_out(vty, " peer-group %s", peer->group->name);
17186 if_pg_printed = true;
17187 } else if (peer->as_type == AS_SPECIFIED) {
17188 vty_out(vty, " remote-as %u", peer->as);
17189 if_ras_printed = true;
17190 } else if (peer->as_type == AS_INTERNAL) {
17191 vty_out(vty, " remote-as internal");
17192 if_ras_printed = true;
17193 } else if (peer->as_type == AS_EXTERNAL) {
17194 vty_out(vty, " remote-as external");
17195 if_ras_printed = true;
17196 }
17197
17198 vty_out(vty, "\n");
17199 }
17200
17201 /* remote-as and peer-group */
17202 /* peer is a member of a peer-group */
17203 if (peer_group_active(peer)) {
17204 g_peer = peer->group->conf;
17205
17206 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
17207 if (peer->as_type == AS_SPECIFIED) {
17208 vty_out(vty, " neighbor %s remote-as %u\n",
17209 addr, peer->as);
17210 } else if (peer->as_type == AS_INTERNAL) {
17211 vty_out(vty,
17212 " neighbor %s remote-as internal\n",
17213 addr);
17214 } else if (peer->as_type == AS_EXTERNAL) {
17215 vty_out(vty,
17216 " neighbor %s remote-as external\n",
17217 addr);
17218 }
17219 }
17220
17221 /* For swpX peers we displayed the peer-group
17222 * via 'neighbor swpX interface peer-group PGNAME' */
17223 if (!if_pg_printed)
17224 vty_out(vty, " neighbor %s peer-group %s\n", addr,
17225 peer->group->name);
17226 }
17227
17228 /* peer is NOT a member of a peer-group */
17229 else {
17230 /* peer is a peer-group, declare the peer-group */
17231 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
17232 vty_out(vty, " neighbor %s peer-group\n", addr);
17233 }
17234
17235 if (!if_ras_printed) {
17236 if (peer->as_type == AS_SPECIFIED) {
17237 vty_out(vty, " neighbor %s remote-as %u\n",
17238 addr, peer->as);
17239 } else if (peer->as_type == AS_INTERNAL) {
17240 vty_out(vty,
17241 " neighbor %s remote-as internal\n",
17242 addr);
17243 } else if (peer->as_type == AS_EXTERNAL) {
17244 vty_out(vty,
17245 " neighbor %s remote-as external\n",
17246 addr);
17247 }
17248 }
17249 }
17250
17251 /* local-as */
17252 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
17253 vty_out(vty, " neighbor %s local-as %u", addr,
17254 peer->change_local_as);
17255 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
17256 vty_out(vty, " no-prepend");
17257 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
17258 vty_out(vty, " replace-as");
17259 vty_out(vty, "\n");
17260 }
17261
17262 /* description */
17263 if (peer->desc) {
17264 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
17265 }
17266
17267 /* shutdown */
17268 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
17269 if (peer->tx_shutdown_message)
17270 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
17271 peer->tx_shutdown_message);
17272 else
17273 vty_out(vty, " neighbor %s shutdown\n", addr);
17274 }
17275
8336c896
DA
17276 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
17277 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
17278 peer->rtt_expected, peer->rtt_keepalive_conf);
17279
dd65f45e 17280 /* bfd */
21bfce98
RZ
17281 if (peer->bfd_config)
17282 bgp_bfd_peer_config_write(vty, peer, addr);
dd65f45e
DL
17283
17284 /* password */
17285 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
17286 vty_out(vty, " neighbor %s password %s\n", addr,
17287 peer->password);
17288
17289 /* neighbor solo */
17290 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
17291 if (!peer_group_active(peer)) {
17292 vty_out(vty, " neighbor %s solo\n", addr);
17293 }
17294 }
17295
17296 /* BGP port */
17297 if (peer->port != BGP_PORT_DEFAULT) {
17298 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
17299 }
17300
17301 /* Local interface name */
17302 if (peer->ifname) {
17303 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
17304 }
17305
4ab46701
AR
17306 /* TCP max segment size */
17307 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
17308 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
17309
dd65f45e
DL
17310 /* passive */
17311 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
17312 vty_out(vty, " neighbor %s passive\n", addr);
17313
17314 /* ebgp-multihop */
17315 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
e2521429
DA
17316 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
17317 && peer->ttl == MAXTTL)) {
dd65f45e
DL
17318 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
17319 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
17320 peer->ttl);
17321 }
17322 }
17323
97a52c82
DA
17324 /* aigp */
17325 if (peergroup_flag_check(peer, PEER_FLAG_AIGP))
17326 vty_out(vty, " neighbor %s aigp\n", addr);
17327
4f770cf1
DA
17328 /* graceful-shutdown */
17329 if (peergroup_flag_check(peer, PEER_FLAG_GRACEFUL_SHUTDOWN))
17330 vty_out(vty, " neighbor %s graceful-shutdown\n", addr);
17331
d864dd9e 17332 /* role */
7dddd1f7
DA
17333 if (peergroup_flag_check(peer, PEER_FLAG_ROLE) &&
17334 peer->local_role != ROLE_UNDEFINED)
d864dd9e 17335 vty_out(vty, " neighbor %s local-role %s%s\n", addr,
8f2d6021 17336 bgp_get_name_by_role(peer->local_role),
7dddd1f7 17337 CHECK_FLAG(peer->flags, PEER_FLAG_ROLE_STRICT_MODE)
d864dd9e
EB
17338 ? " strict-mode"
17339 : "");
d864dd9e 17340
dd65f45e 17341 /* ttl-security hops */
e2521429 17342 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
dd65f45e
DL
17343 if (!peer_group_active(peer)
17344 || g_peer->gtsm_hops != peer->gtsm_hops) {
17345 vty_out(vty, " neighbor %s ttl-security hops %d\n",
17346 addr, peer->gtsm_hops);
17347 }
17348 }
17349
17350 /* disable-connected-check */
17351 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
17352 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
17353
27aa23a4
DA
17354 /* link-bw-encoding-ieee */
17355 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE))
17356 vty_out(vty, " neighbor %s disable-link-bw-encoding-ieee\n",
17357 addr);
17358
d08c0c80
DA
17359 /* extended-optional-parameters */
17360 if (peergroup_flag_check(peer, PEER_FLAG_EXTENDED_OPT_PARAMS))
17361 vty_out(vty, " neighbor %s extended-optional-parameters\n",
17362 addr);
17363
dd65f45e
DL
17364 /* enforce-first-as */
17365 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
17366 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
17367
17368 /* update-source */
17369 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
17370 if (peer->update_source)
47e12884
DA
17371 vty_out(vty, " neighbor %s update-source %pSU\n", addr,
17372 peer->update_source);
dd65f45e
DL
17373 else if (peer->update_if)
17374 vty_out(vty, " neighbor %s update-source %s\n", addr,
17375 peer->update_if);
17376 }
17377
17378 /* advertisement-interval */
17379 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
17380 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
17381 peer->routeadv);
17382
17383 /* timers */
17384 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
17385 vty_out(vty, " neighbor %s timers %u %u\n", addr,
17386 peer->keepalive, peer->holdtime);
17387
17388 /* timers connect */
17389 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
17390 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17391 peer->connect);
5d5393b9
DL
17392 /* need special-case handling for changed default values due to
17393 * config profile / version (because there is no "timers bgp connect"
17394 * command, we need to save this per-peer :/)
17395 */
17396 else if (!peer_group_active(peer) && !peer->connect &&
17397 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
17398 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17399 peer->bgp->default_connect_retry);
dd65f45e 17400
d43114f3
DS
17401 /* timers delayopen */
17402 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
17403 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17404 peer->delayopen);
17405 /* Save config even though flag is not set if default values have been
17406 * changed
17407 */
17408 else if (!peer_group_active(peer) && !peer->delayopen
17409 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
17410 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17411 peer->bgp->default_delayopen);
17412
dd65f45e
DL
17413 /* capability dynamic */
17414 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
17415 vty_out(vty, " neighbor %s capability dynamic\n", addr);
17416
17417 /* capability extended-nexthop */
17418 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
8e89adc1
DS
17419 if (CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE) &&
17420 !peer->conf_if)
843770f6
DA
17421 vty_out(vty,
17422 " no neighbor %s capability extended-nexthop\n",
17423 addr);
17424 else if (!peer->conf_if)
17425 vty_out(vty,
17426 " neighbor %s capability extended-nexthop\n",
17427 addr);
dd65f45e
DL
17428 }
17429
17430 /* dont-capability-negotiation */
17431 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
17432 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
17433
17434 /* override-capability */
17435 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
17436 vty_out(vty, " neighbor %s override-capability\n", addr);
17437
17438 /* strict-capability-match */
17439 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
17440 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
17441
17442 /* Sender side AS path loop detection. */
17443 if (peer->as_path_loop_detection)
17444 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
17445 addr);
cfd47646 17446
17447 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 17448 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
cfd47646 17449
17450 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 17451 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
cfd47646 17452 vty_out(vty,
17453 " neighbor %s graceful-restart-helper\n", addr);
13909c4f
DS
17454 } else if (CHECK_FLAG(
17455 peer->peer_gr_new_status_flag,
17456 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
cfd47646 17457 vty_out(vty,
17458 " neighbor %s graceful-restart\n", addr);
13909c4f
DS
17459 } else if (
17460 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
17461 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
17462 && !(CHECK_FLAG(
17463 peer->peer_gr_new_status_flag,
17464 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
17465 vty_out(vty, " neighbor %s graceful-restart-disable\n",
17466 addr);
cfd47646 17467 }
17468 }
dd65f45e
DL
17469}
17470
17471/* BGP peer configuration display function. */
17472static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
17473 struct peer *peer, afi_t afi, safi_t safi)
17474{
17475 struct peer *g_peer = NULL;
17476 char *addr;
17477 bool flag_scomm, flag_secomm, flag_slcomm;
17478
17479 /* Skip dynamic neighbors. */
17480 if (peer_dynamic_neighbor(peer))
17481 return;
17482
17483 if (peer->conf_if)
17484 addr = peer->conf_if;
17485 else
17486 addr = peer->host;
17487
17488 /************************************
17489 ****** Per AF to the neighbor ******
17490 ************************************/
17491 if (peer_group_active(peer)) {
17492 g_peer = peer->group->conf;
17493
17494 /* If the peer-group is active but peer is not, print a 'no
17495 * activate' */
17496 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
17497 vty_out(vty, " no neighbor %s activate\n", addr);
17498 }
17499
17500 /* If the peer-group is not active but peer is, print an
17501 'activate' */
17502 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
17503 vty_out(vty, " neighbor %s activate\n", addr);
17504 }
17505 } else {
17506 if (peer->afc[afi][safi]) {
38d11af5
TA
17507 if (safi == SAFI_ENCAP)
17508 vty_out(vty, " neighbor %s activate\n", addr);
17509 else if (!bgp->default_af[afi][safi])
dd65f45e
DL
17510 vty_out(vty, " neighbor %s activate\n", addr);
17511 } else {
38d11af5
TA
17512 if (bgp->default_af[afi][safi])
17513 vty_out(vty, " no neighbor %s activate\n",
17514 addr);
dd65f45e
DL
17515 }
17516 }
17517
17518 /* addpath TX knobs */
17519 if (peergroup_af_addpath_check(peer, afi, safi)) {
17520 switch (peer->addpath_type[afi][safi]) {
17521 case BGP_ADDPATH_ALL:
17522 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
17523 addr);
17524 break;
17525 case BGP_ADDPATH_BEST_PER_AS:
17526 vty_out(vty,
17527 " neighbor %s addpath-tx-bestpath-per-AS\n",
17528 addr);
17529 break;
17530 case BGP_ADDPATH_MAX:
17531 case BGP_ADDPATH_NONE:
17532 break;
17533 }
17534 }
17535
7c0e4312
DA
17536 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DISABLE_ADDPATH_RX))
17537 vty_out(vty, " neighbor %s disable-addpath-rx\n", addr);
17538
dd65f45e
DL
17539 /* ORF capability. */
17540 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
17541 || peergroup_af_flag_check(peer, afi, safi,
17542 PEER_FLAG_ORF_PREFIX_RM)) {
17543 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
17544
17545 if (peergroup_af_flag_check(peer, afi, safi,
17546 PEER_FLAG_ORF_PREFIX_SM)
17547 && peergroup_af_flag_check(peer, afi, safi,
17548 PEER_FLAG_ORF_PREFIX_RM))
17549 vty_out(vty, " both");
17550 else if (peergroup_af_flag_check(peer, afi, safi,
17551 PEER_FLAG_ORF_PREFIX_SM))
17552 vty_out(vty, " send");
17553 else
17554 vty_out(vty, " receive");
17555 vty_out(vty, "\n");
17556 }
17557
dd65f45e
DL
17558 /* Route reflector client. */
17559 if (peergroup_af_flag_check(peer, afi, safi,
17560 PEER_FLAG_REFLECTOR_CLIENT)) {
17561 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
17562 }
17563
17564 /* next-hop-self force */
17565 if (peergroup_af_flag_check(peer, afi, safi,
17566 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
17567 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
17568 }
17569
17570 /* next-hop-self */
17571 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
17572 vty_out(vty, " neighbor %s next-hop-self\n", addr);
17573 }
17574
17575 /* remove-private-AS */
17576 if (peergroup_af_flag_check(peer, afi, safi,
17577 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
17578 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
17579 addr);
17580 }
17581
17582 else if (peergroup_af_flag_check(peer, afi, safi,
17583 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
17584 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
17585 addr);
17586 }
17587
17588 else if (peergroup_af_flag_check(peer, afi, safi,
17589 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
17590 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
17591 }
17592
17593 else if (peergroup_af_flag_check(peer, afi, safi,
17594 PEER_FLAG_REMOVE_PRIVATE_AS)) {
17595 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
17596 }
17597
17598 /* as-override */
17599 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
17600 vty_out(vty, " neighbor %s as-override\n", addr);
17601 }
17602
17603 /* send-community print. */
17604 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
17605 PEER_FLAG_SEND_COMMUNITY);
17606 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
17607 PEER_FLAG_SEND_EXT_COMMUNITY);
17608 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
17609 PEER_FLAG_SEND_LARGE_COMMUNITY);
17610
17611 if (flag_scomm && flag_secomm && flag_slcomm) {
17612 vty_out(vty, " no neighbor %s send-community all\n", addr);
17613 } else {
17614 if (flag_scomm)
17615 vty_out(vty, " no neighbor %s send-community\n", addr);
17616 if (flag_secomm)
17617 vty_out(vty,
17618 " no neighbor %s send-community extended\n",
17619 addr);
17620
17621 if (flag_slcomm)
17622 vty_out(vty, " no neighbor %s send-community large\n",
17623 addr);
17624 }
17625
17626 /* Default information */
17627 if (peergroup_af_flag_check(peer, afi, safi,
17628 PEER_FLAG_DEFAULT_ORIGINATE)) {
17629 vty_out(vty, " neighbor %s default-originate", addr);
17630
17631 if (peer->default_rmap[afi][safi].name)
17632 vty_out(vty, " route-map %s",
17633 peer->default_rmap[afi][safi].name);
17634
17635 vty_out(vty, "\n");
17636 }
17637
17638 /* Soft reconfiguration inbound. */
17639 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
17640 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
17641 addr);
17642 }
17643
17644 /* maximum-prefix. */
17645 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
6cde4b45 17646 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
dd65f45e
DL
17647 peer->pmax[afi][safi]);
17648
17649 if (peer->pmax_threshold[afi][safi]
17650 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
17651 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
17652 if (peer_af_flag_check(peer, afi, safi,
17653 PEER_FLAG_MAX_PREFIX_WARNING))
17654 vty_out(vty, " warning-only");
17655 if (peer->pmax_restart[afi][safi])
17656 vty_out(vty, " restart %u",
17657 peer->pmax_restart[afi][safi]);
9cbd06e0
DA
17658 if (peer_af_flag_check(peer, afi, safi,
17659 PEER_FLAG_MAX_PREFIX_FORCE))
17660 vty_out(vty, " force");
dd65f45e
DL
17661
17662 vty_out(vty, "\n");
17663 }
17664
fde246e8
DA
17665 /* maximum-prefix-out */
17666 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
6cde4b45 17667 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
fde246e8
DA
17668 addr, peer->pmax_out[afi][safi]);
17669
dd65f45e
DL
17670 /* Route server client. */
17671 if (peergroup_af_flag_check(peer, afi, safi,
17672 PEER_FLAG_RSERVER_CLIENT)) {
17673 vty_out(vty, " neighbor %s route-server-client\n", addr);
17674 }
17675
17676 /* Nexthop-local unchanged. */
17677 if (peergroup_af_flag_check(peer, afi, safi,
17678 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
17679 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
17680 }
17681
17682 /* allowas-in <1-10> */
17683 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
17684 if (peer_af_flag_check(peer, afi, safi,
17685 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
17686 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
17687 } else if (peer->allowas_in[afi][safi] == 3) {
17688 vty_out(vty, " neighbor %s allowas-in\n", addr);
17689 } else {
17690 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
17691 peer->allowas_in[afi][safi]);
17692 }
17693 }
17694
46dbf9d0
DA
17695 /* accept-own */
17696 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ACCEPT_OWN))
17697 vty_out(vty, " neighbor %s accept-own\n", addr);
17698
01da2d26
DA
17699 /* soo */
17700 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOO)) {
17701 char *soo_str = ecommunity_ecom2str(
17702 peer->soo[afi][safi], ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
17703
17704 vty_out(vty, " neighbor %s soo %s\n", addr, soo_str);
17705 XFREE(MTYPE_ECOMMUNITY_STR, soo_str);
17706 }
17707
dd65f45e
DL
17708 /* weight */
17709 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
17710 vty_out(vty, " neighbor %s weight %lu\n", addr,
17711 peer->weight[afi][safi]);
17712
17713 /* Filter. */
17714 bgp_config_write_filter(vty, peer, afi, safi);
17715
17716 /* atribute-unchanged. */
17717 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
17718 || (safi != SAFI_EVPN
17719 && peer_af_flag_check(peer, afi, safi,
17720 PEER_FLAG_NEXTHOP_UNCHANGED))
17721 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
17722
17723 if (!peer_group_active(peer)
17724 || peergroup_af_flag_check(peer, afi, safi,
17725 PEER_FLAG_AS_PATH_UNCHANGED)
17726 || peergroup_af_flag_check(peer, afi, safi,
17727 PEER_FLAG_NEXTHOP_UNCHANGED)
17728 || peergroup_af_flag_check(peer, afi, safi,
17729 PEER_FLAG_MED_UNCHANGED)) {
17730
17731 vty_out(vty,
17732 " neighbor %s attribute-unchanged%s%s%s\n",
17733 addr,
17734 peer_af_flag_check(peer, afi, safi,
17735 PEER_FLAG_AS_PATH_UNCHANGED)
17736 ? " as-path"
17737 : "",
17738 peer_af_flag_check(peer, afi, safi,
17739 PEER_FLAG_NEXTHOP_UNCHANGED)
17740 ? " next-hop"
17741 : "",
17742 peer_af_flag_check(peer, afi, safi,
17743 PEER_FLAG_MED_UNCHANGED)
17744 ? " med"
17745 : "");
17746 }
17747 }
70cd87ca
MK
17748
17749 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_ORR_GROUP))
17750 vty_out(vty, " neighbor %s optimal-route-reflection %s\n",
5fcf01c9 17751 addr, peer->orr_group_name[afi][safi]);
dd65f45e
DL
17752}
17753
a486300b
PG
17754static void bgp_vpn_config_write(struct vty *vty, struct bgp *bgp, afi_t afi,
17755 safi_t safi)
17756{
17757 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
17758 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL))
17759 vty_out(vty, " no bgp retain route-target all\n");
17760}
17761
dd65f45e
DL
17762/* Address family based peer configuration display. */
17763static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
17764 safi_t safi)
17765{
17766 struct peer *peer;
17767 struct peer_group *group;
17768 struct listnode *node, *nnode;
17769
17770
17771 vty_frame(vty, " !\n address-family ");
17772 if (afi == AFI_IP) {
17773 if (safi == SAFI_UNICAST)
17774 vty_frame(vty, "ipv4 unicast");
17775 else if (safi == SAFI_LABELED_UNICAST)
17776 vty_frame(vty, "ipv4 labeled-unicast");
17777 else if (safi == SAFI_MULTICAST)
17778 vty_frame(vty, "ipv4 multicast");
17779 else if (safi == SAFI_MPLS_VPN)
17780 vty_frame(vty, "ipv4 vpn");
17781 else if (safi == SAFI_ENCAP)
17782 vty_frame(vty, "ipv4 encap");
17783 else if (safi == SAFI_FLOWSPEC)
17784 vty_frame(vty, "ipv4 flowspec");
17785 } else if (afi == AFI_IP6) {
17786 if (safi == SAFI_UNICAST)
17787 vty_frame(vty, "ipv6 unicast");
17788 else if (safi == SAFI_LABELED_UNICAST)
17789 vty_frame(vty, "ipv6 labeled-unicast");
17790 else if (safi == SAFI_MULTICAST)
17791 vty_frame(vty, "ipv6 multicast");
17792 else if (safi == SAFI_MPLS_VPN)
17793 vty_frame(vty, "ipv6 vpn");
17794 else if (safi == SAFI_ENCAP)
17795 vty_frame(vty, "ipv6 encap");
17796 else if (safi == SAFI_FLOWSPEC)
17797 vty_frame(vty, "ipv6 flowspec");
17798 } else if (afi == AFI_L2VPN) {
17799 if (safi == SAFI_EVPN)
17800 vty_frame(vty, "l2vpn evpn");
17801 }
17802 vty_frame(vty, "\n");
17803
17804 bgp_config_write_distance(vty, bgp, afi, safi);
17805
17806 bgp_config_write_network(vty, bgp, afi, safi);
17807
17808 bgp_config_write_redistribute(vty, bgp, afi, safi);
17809
8a4e7fe6
DA
17810 /* BGP flag dampening. */
17811 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
6c75f4b3 17812 bgp_config_write_damp(vty, afi, safi);
8a4e7fe6 17813
dd65f45e
DL
17814 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
17815 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
17816
17817 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dd65f45e
DL
17818 /* Do not display doppelganger peers */
17819 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17820 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
17821 }
17822
17823 bgp_config_write_maxpaths(vty, bgp, afi, safi);
17824 bgp_config_write_table_map(vty, bgp, afi, safi);
17825
17826 if (safi == SAFI_EVPN)
17827 bgp_config_write_evpn_info(vty, bgp, afi, safi);
17828
17829 if (safi == SAFI_FLOWSPEC)
17830 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
17831
a486300b
PG
17832 if (safi == SAFI_MPLS_VPN)
17833 bgp_vpn_config_write(vty, bgp, afi, safi);
17834
dd65f45e
DL
17835 if (safi == SAFI_UNICAST) {
17836 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
17837 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17838 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
17839
17840 vty_out(vty, " export vpn\n");
17841 }
17842 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17843 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
17844
17845 vty_out(vty, " import vpn\n");
17846 }
17847 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17848 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
17849 char *name;
17850
17851 for (ALL_LIST_ELEMENTS_RO(
17852 bgp->vpn_policy[afi].import_vrf, node,
17853 name))
17854 vty_out(vty, " import vrf %s\n", name);
17855 }
17856 }
17857
70cd87ca
MK
17858 /* Optimal Route Reflection */
17859 bgp_config_write_orr(vty, bgp, afi, safi);
17860
dd65f45e
DL
17861 vty_endframe(vty, " exit-address-family\n");
17862}
17863
17864int bgp_config_write(struct vty *vty)
17865{
17866 struct bgp *bgp;
17867 struct peer_group *group;
17868 struct peer *peer;
17869 struct listnode *node, *nnode;
17870 struct listnode *mnode, *mnnode;
b16bcbba
TA
17871 afi_t afi;
17872 safi_t safi;
efc9b57d 17873 uint32_t tovpn_sid_index = 0;
dd65f45e
DL
17874
17875 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
17876 vty_out(vty, "bgp route-map delay-timer %u\n",
17877 bm->rmap_update_timer);
17878
d70583f7
D
17879 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
17880 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17881 if (bm->v_update_delay != bm->v_establish_wait)
17882 vty_out(vty, " %d", bm->v_establish_wait);
17883 vty_out(vty, "\n");
17884 }
17885
9acb67cb
DS
17886 if (bm->wait_for_fib)
17887 vty_out(vty, "bgp suppress-fib-pending\n");
17888
05bd726c 17889 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17890 vty_out(vty, "bgp graceful-shutdown\n");
17891
c163f297
DS
17892 /* No-RIB (Zebra) option flag configuration */
17893 if (bgp_option_check(BGP_OPT_NO_FIB))
17894 vty_out(vty, "bgp no-rib\n");
17895
870791a3
IR
17896 if (CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
17897 vty_out(vty, "bgp send-extra-data zebra\n");
e46723a5 17898
425bd64b
PS
17899 /* BGP session DSCP value */
17900 if (bm->tcp_dscp != IPTOS_PREC_INTERNETCONTROL)
17901 vty_out(vty, "bgp session-dscp %u\n", bm->tcp_dscp >> 2);
17902
a0b937de
SW
17903 /* BGP InQ limit */
17904 if (bm->inq_limit != BM_DEFAULT_INQ_LIMIT)
17905 vty_out(vty, "bgp input-queue-limit %u\n", bm->inq_limit);
17906
dd65f45e
DL
17907 /* BGP configuration. */
17908 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17909
17910 /* skip all auto created vrf as they dont have user config */
17911 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17912 continue;
17913
17914 /* Router bgp ASN */
17915 vty_out(vty, "router bgp %u", bgp->as);
17916
17917 if (bgp->name)
17918 vty_out(vty, " %s %s",
17919 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17920 ? "view" : "vrf", bgp->name);
17921 vty_out(vty, "\n");
17922
17923 /* BGP fast-external-failover. */
17924 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17925 vty_out(vty, " no bgp fast-external-failover\n");
17926
17927 /* BGP router ID. */
3a6290bd 17928 if (bgp->router_id_static.s_addr != INADDR_ANY)
23d0a753
DA
17929 vty_out(vty, " bgp router-id %pI4\n",
17930 &bgp->router_id_static);
dd65f45e 17931
c208c586
S
17932 /* Suppress fib pending */
17933 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17934 vty_out(vty, " bgp suppress-fib-pending\n");
17935
dd65f45e 17936 /* BGP log-neighbor-changes. */
892fedb6 17937 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
5d5393b9 17938 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
dd65f45e 17939 vty_out(vty, " %sbgp log-neighbor-changes\n",
892fedb6
DA
17940 CHECK_FLAG(bgp->flags,
17941 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
dd65f45e
DL
17942 ? ""
17943 : "no ");
17944
17945 /* BGP configuration. */
892fedb6 17946 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
dd65f45e
DL
17947 vty_out(vty, " bgp always-compare-med\n");
17948
17949 /* RFC8212 default eBGP policy. */
1d3fdccf
DA
17950 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17951 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17952 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17953 CHECK_FLAG(bgp->flags,
17954 BGP_FLAG_EBGP_REQUIRES_POLICY)
17955 ? ""
17956 : "no ");
dd65f45e
DL
17957
17958 /* draft-ietf-idr-deprecate-as-set-confed-set */
7f972cd8 17959 if (bgp->reject_as_sets)
dd65f45e
DL
17960 vty_out(vty, " bgp reject-as-sets\n");
17961
2adac256
DA
17962 /* Suppress duplicate updates if the route actually not changed
17963 */
17964 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17965 != SAVE_BGP_SUPPRESS_DUPLICATES)
17966 vty_out(vty, " %sbgp suppress-duplicates\n",
17967 CHECK_FLAG(bgp->flags,
17968 BGP_FLAG_SUPPRESS_DUPLICATES)
17969 ? ""
17970 : "no ");
17971
1ae314be
DA
17972 /* Send Hard Reset CEASE Notification for 'Administrative Reset'
17973 */
17974 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET) !=
17975 SAVE_BGP_HARD_ADMIN_RESET)
17976 vty_out(vty, " %sbgp hard-administrative-reset\n",
17977 CHECK_FLAG(bgp->flags,
17978 BGP_FLAG_HARD_ADMIN_RESET)
17979 ? ""
17980 : "no ");
17981
b16bcbba
TA
17982 /* BGP default <afi>-<safi> */
17983 FOREACH_AFI_SAFI (afi, safi) {
17984 if (afi == AFI_IP && safi == SAFI_UNICAST) {
17985 if (!bgp->default_af[afi][safi])
17986 vty_out(vty, " no bgp default %s\n",
17987 get_bgp_default_af_flag(afi,
17988 safi));
17989 } else if (bgp->default_af[afi][safi])
17990 vty_out(vty, " bgp default %s\n",
17991 get_bgp_default_af_flag(afi, safi));
17992 }
e84c59af 17993
dd65f45e
DL
17994 /* BGP default local-preference. */
17995 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17996 vty_out(vty, " bgp default local-preference %u\n",
17997 bgp->default_local_pref);
17998
17999 /* BGP default show-hostname */
892fedb6 18000 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
5d5393b9 18001 != SAVE_BGP_SHOW_HOSTNAME)
dd65f45e 18002 vty_out(vty, " %sbgp default show-hostname\n",
892fedb6 18003 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
dd65f45e
DL
18004 ? ""
18005 : "no ");
18006
aef999a2
DA
18007 /* BGP default show-nexthop-hostname */
18008 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
18009 != SAVE_BGP_SHOW_HOSTNAME)
18010 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
18011 CHECK_FLAG(bgp->flags,
18012 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
18013 ? ""
18014 : "no ");
18015
dd65f45e
DL
18016 /* BGP default subgroup-pkt-queue-max. */
18017 if (bgp->default_subgroup_pkt_queue_max
18018 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
18019 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
18020 bgp->default_subgroup_pkt_queue_max);
18021
18022 /* BGP client-to-client reflection. */
892fedb6 18023 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
dd65f45e
DL
18024 vty_out(vty, " no bgp client-to-client reflection\n");
18025
18026 /* BGP cluster ID. */
18027 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
23d0a753
DA
18028 vty_out(vty, " bgp cluster-id %pI4\n",
18029 &bgp->cluster_id);
dd65f45e
DL
18030
18031 /* Disable ebgp connected nexthop check */
892fedb6 18032 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
dd65f45e
DL
18033 vty_out(vty,
18034 " bgp disable-ebgp-connected-route-check\n");
18035
18036 /* Confederation identifier*/
18037 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
18038 vty_out(vty, " bgp confederation identifier %u\n",
18039 bgp->confed_id);
18040
18041 /* Confederation peer */
18042 if (bgp->confed_peers_cnt > 0) {
18043 int i;
18044
18045 vty_out(vty, " bgp confederation peers");
18046
18047 for (i = 0; i < bgp->confed_peers_cnt; i++)
18048 vty_out(vty, " %u", bgp->confed_peers[i]);
18049
18050 vty_out(vty, "\n");
18051 }
18052
18053 /* BGP deterministic-med. */
892fedb6 18054 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
5d5393b9 18055 != SAVE_BGP_DETERMINISTIC_MED)
dd65f45e 18056 vty_out(vty, " %sbgp deterministic-med\n",
892fedb6
DA
18057 CHECK_FLAG(bgp->flags,
18058 BGP_FLAG_DETERMINISTIC_MED)
dd65f45e
DL
18059 ? ""
18060 : "no ");
18061
18062 /* BGP update-delay. */
18063 bgp_config_write_update_delay(vty, bgp);
18064
18065 if (bgp->v_maxmed_onstartup
18066 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
18067 vty_out(vty, " bgp max-med on-startup %u",
18068 bgp->v_maxmed_onstartup);
18069 if (bgp->maxmed_onstartup_value
18070 != BGP_MAXMED_VALUE_DEFAULT)
18071 vty_out(vty, " %u",
18072 bgp->maxmed_onstartup_value);
18073 vty_out(vty, "\n");
18074 }
18075 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
18076 vty_out(vty, " bgp max-med administrative");
18077 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
18078 vty_out(vty, " %u", bgp->maxmed_admin_value);
18079 vty_out(vty, "\n");
18080 }
18081
18082 /* write quanta */
18083 bgp_config_write_wpkt_quanta(vty, bgp);
18084 /* read quanta */
18085 bgp_config_write_rpkt_quanta(vty, bgp);
18086
18087 /* coalesce time */
18088 bgp_config_write_coalesce_time(vty, bgp);
18089
05bd726c 18090 /* BGP per-instance graceful-shutdown */
18091 /* BGP-wide settings and per-instance settings are mutually
18092 * exclusive.
18093 */
18094 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
18095 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
18096 vty_out(vty, " bgp graceful-shutdown\n");
18097
8606be87
DA
18098 /* Long-lived Graceful Restart */
18099 if (bgp->llgr_stale_time != BGP_DEFAULT_LLGR_STALE_TIME)
18100 vty_out(vty,
18101 " bgp long-lived-graceful-restart stale-time %u\n",
18102 bgp->llgr_stale_time);
18103
dd65f45e
DL
18104 /* BGP graceful-restart. */
18105 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
18106 vty_out(vty,
18107 " bgp graceful-restart stalepath-time %u\n",
18108 bgp->stalepath_time);
cfd47646 18109
dd65f45e
DL
18110 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
18111 vty_out(vty, " bgp graceful-restart restart-time %u\n",
18112 bgp->restart_time);
cfd47646 18113
f2ca5c5b
DA
18114 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION) !=
18115 SAVE_BGP_GRACEFUL_NOTIFICATION)
18116 vty_out(vty, " %sbgp graceful-restart notification\n",
18117 CHECK_FLAG(bgp->flags,
18118 BGP_FLAG_GRACEFUL_NOTIFICATION)
18119 ? ""
18120 : "no ");
18121
cfd47646 18122 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
18123 vty_out(vty,
18124 " bgp graceful-restart select-defer-time %u\n",
18125 bgp->select_defer_time);
18126
18127 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
dd65f45e
DL
18128 vty_out(vty, " bgp graceful-restart\n");
18129
cfd47646 18130 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
18131 vty_out(vty, " bgp graceful-restart-disable\n");
18132
dd65f45e 18133 /* BGP graceful-restart Preserve State F bit. */
892fedb6 18134 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
dd65f45e
DL
18135 vty_out(vty,
18136 " bgp graceful-restart preserve-fw-state\n");
18137
d1adb448
PG
18138 /* BGP TCP keepalive */
18139 bgp_config_tcp_keepalive(vty, bgp);
18140
dc95985f 18141 /* Stale timer for RIB */
18142 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
18143 vty_out(vty,
18144 " bgp graceful-restart rib-stale-time %u\n",
18145 bgp->rib_stale_time);
18146
dd65f45e 18147 /* BGP bestpath method. */
892fedb6 18148 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
dd65f45e 18149 vty_out(vty, " bgp bestpath as-path ignore\n");
892fedb6 18150 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
dd65f45e
DL
18151 vty_out(vty, " bgp bestpath as-path confed\n");
18152
892fedb6
DA
18153 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
18154 if (CHECK_FLAG(bgp->flags,
18155 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
dd65f45e
DL
18156 vty_out(vty,
18157 " bgp bestpath as-path multipath-relax as-set\n");
18158 } else {
18159 vty_out(vty,
18160 " bgp bestpath as-path multipath-relax\n");
18161 }
18162 }
18163
892fedb6 18164 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
dd65f45e
DL
18165 vty_out(vty,
18166 " bgp route-reflector allow-outbound-policy\n");
18167 }
892fedb6 18168 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
dd65f45e 18169 vty_out(vty, " bgp bestpath compare-routerid\n");
97a52c82
DA
18170 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_AIGP))
18171 vty_out(vty, " bgp bestpath aigp\n");
892fedb6
DA
18172 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
18173 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
dd65f45e 18174 vty_out(vty, " bgp bestpath med");
892fedb6 18175 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
dd65f45e 18176 vty_out(vty, " confed");
892fedb6
DA
18177 if (CHECK_FLAG(bgp->flags,
18178 BGP_FLAG_MED_MISSING_AS_WORST))
dd65f45e
DL
18179 vty_out(vty, " missing-as-worst");
18180 vty_out(vty, "\n");
18181 }
18182
ee88563a
JM
18183 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
18184 vty_out(vty,
18185 " bgp bestpath peer-type multipath-relax\n");
18186
f7e1c681 18187 /* Link bandwidth handling. */
18188 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
18189 vty_out(vty, " bgp bestpath bandwidth ignore\n");
18190 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
18191 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
18192 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
18193 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
18194
dd65f45e 18195 /* BGP network import check. */
892fedb6 18196 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
5d5393b9 18197 != SAVE_BGP_IMPORT_CHECK)
dd65f45e 18198 vty_out(vty, " %sbgp network import-check\n",
892fedb6 18199 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
dd65f45e
DL
18200 ? ""
18201 : "no ");
18202
18203 /* BGP timers configuration. */
5d5393b9 18204 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
9800cfff 18205 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
dd65f45e
DL
18206 vty_out(vty, " timers bgp %u %u\n",
18207 bgp->default_keepalive, bgp->default_holdtime);
18208
b042667a
TI
18209 /* BGP minimum holdtime configuration. */
18210 if (bgp->default_min_holdtime != SAVE_BGP_HOLDTIME
18211 && bgp->default_min_holdtime != 0)
18212 vty_out(vty, " bgp minimum-holdtime %u\n",
18213 bgp->default_min_holdtime);
18214
389e4f92
QY
18215 /* Conditional advertisement timer configuration */
18216 if (bgp->condition_check_period
18217 != DEFAULT_CONDITIONAL_ROUTES_POLL_TIME)
18218 vty_out(vty,
18219 " bgp conditional-advertisement timer %u\n",
18220 bgp->condition_check_period);
18221
dd65f45e
DL
18222 /* peer-group */
18223 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
18224 bgp_config_write_peer_global(vty, bgp, group->conf);
18225 }
18226
18227 /* Normal neighbor configuration. */
18228 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
18229 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
18230 bgp_config_write_peer_global(vty, bgp, peer);
18231 }
18232
18233 /* listen range and limit for dynamic BGP neighbors */
18234 bgp_config_write_listen(vty, bgp);
18235
18236 /*
18237 * BGP default autoshutdown neighbors
18238 *
18239 * This must be placed after any peer and peer-group
18240 * configuration, to avoid setting all peers to shutdown after
18241 * a daemon restart, which is undesired behavior. (see #2286)
18242 */
18243 if (bgp->autoshutdown)
18244 vty_out(vty, " bgp default shutdown\n");
18245
9cf59432
DS
18246 /* BGP instance administrative shutdown */
18247 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
18248 vty_out(vty, " bgp shutdown\n");
18249
8666265e
DS
18250 if (bgp->allow_martian)
18251 vty_out(vty, " bgp allow-martian-nexthop\n");
18252
f852eb98
PG
18253 if (bgp->fast_convergence)
18254 vty_out(vty, " bgp fast-convergence\n");
18255
a0281b2e
HS
18256 if (bgp->srv6_enabled) {
18257 vty_frame(vty, " !\n segment-routing srv6\n");
96db4340 18258 if (strlen(bgp->srv6_locator_name))
a0281b2e
HS
18259 vty_out(vty, " locator %s\n",
18260 bgp->srv6_locator_name);
ff7c3ee1 18261 vty_endframe(vty, " exit\n");
a0281b2e
HS
18262 }
18263
efc9b57d
CS
18264 tovpn_sid_index = bgp->tovpn_sid_index;
18265 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)) {
18266 vty_out(vty, " sid vpn per-vrf export auto\n");
18267 } else if (tovpn_sid_index != 0) {
18268 vty_out(vty, " sid vpn per-vrf export %d\n",
18269 tovpn_sid_index);
18270 }
a0281b2e 18271
dd65f45e
DL
18272 /* IPv4 unicast configuration. */
18273 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
18274
18275 /* IPv4 multicast configuration. */
18276 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
18277
18278 /* IPv4 labeled-unicast configuration. */
18279 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
18280
18281 /* IPv4 VPN configuration. */
18282 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
18283
18284 /* ENCAPv4 configuration. */
18285 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
18286
18287 /* FLOWSPEC v4 configuration. */
18288 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
18289
18290 /* IPv6 unicast configuration. */
18291 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
18292
18293 /* IPv6 multicast configuration. */
18294 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
18295
18296 /* IPv6 labeled-unicast configuration. */
18297 bgp_config_write_family(vty, bgp, AFI_IP6,
18298 SAFI_LABELED_UNICAST);
18299
18300 /* IPv6 VPN configuration. */
18301 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
18302
18303 /* ENCAPv6 configuration. */
18304 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
18305
18306 /* FLOWSPEC v6 configuration. */
18307 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
18308
18309 /* EVPN configuration. */
18310 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
18311
18312 hook_call(bgp_inst_config_write, bgp, vty);
18313
49e5a4a0 18314#ifdef ENABLE_BGP_VNC
dd65f45e
DL
18315 bgp_rfapi_cfg_write(vty, bgp);
18316#endif
18317
07679ad9 18318 vty_out(vty, "exit\n");
dd65f45e
DL
18319 vty_out(vty, "!\n");
18320 }
18321 return 0;
18322}
18323
ddb5b488 18324
718e3744 18325/* BGP node structure. */
d62a17ae 18326static struct cmd_node bgp_node = {
f4b8291f 18327 .name = "bgp",
62b346ee 18328 .node = BGP_NODE,
24389580 18329 .parent_node = CONFIG_NODE,
62b346ee 18330 .prompt = "%s(config-router)# ",
612c2c15 18331 .config_write = bgp_config_write,
718e3744 18332};
18333
d62a17ae 18334static struct cmd_node bgp_ipv4_unicast_node = {
f4b8291f 18335 .name = "bgp ipv4 unicast",
62b346ee 18336 .node = BGP_IPV4_NODE,
24389580 18337 .parent_node = BGP_NODE,
62b346ee 18338 .prompt = "%s(config-router-af)# ",
dd2c81b8 18339 .no_xpath = true,
718e3744 18340};
18341
d62a17ae 18342static struct cmd_node bgp_ipv4_multicast_node = {
f4b8291f 18343 .name = "bgp ipv4 multicast",
62b346ee 18344 .node = BGP_IPV4M_NODE,
24389580 18345 .parent_node = BGP_NODE,
62b346ee 18346 .prompt = "%s(config-router-af)# ",
dd2c81b8 18347 .no_xpath = true,
718e3744 18348};
18349
d62a17ae 18350static struct cmd_node bgp_ipv4_labeled_unicast_node = {
f4b8291f 18351 .name = "bgp ipv4 labeled unicast",
62b346ee 18352 .node = BGP_IPV4L_NODE,
24389580 18353 .parent_node = BGP_NODE,
62b346ee 18354 .prompt = "%s(config-router-af)# ",
dd2c81b8 18355 .no_xpath = true,
f51bae9c
DS
18356};
18357
d62a17ae 18358static struct cmd_node bgp_ipv6_unicast_node = {
a17cfb3f 18359 .name = "bgp ipv6 unicast",
62b346ee 18360 .node = BGP_IPV6_NODE,
24389580 18361 .parent_node = BGP_NODE,
62b346ee 18362 .prompt = "%s(config-router-af)# ",
dd2c81b8 18363 .no_xpath = true,
718e3744 18364};
18365
d62a17ae 18366static struct cmd_node bgp_ipv6_multicast_node = {
f4b8291f 18367 .name = "bgp ipv6 multicast",
62b346ee 18368 .node = BGP_IPV6M_NODE,
24389580 18369 .parent_node = BGP_NODE,
62b346ee 18370 .prompt = "%s(config-router-af)# ",
dd2c81b8 18371 .no_xpath = true,
25ffbdc1 18372};
18373
d62a17ae 18374static struct cmd_node bgp_ipv6_labeled_unicast_node = {
f4b8291f 18375 .name = "bgp ipv6 labeled unicast",
62b346ee 18376 .node = BGP_IPV6L_NODE,
24389580 18377 .parent_node = BGP_NODE,
62b346ee 18378 .prompt = "%s(config-router-af)# ",
dd2c81b8 18379 .no_xpath = true,
f51bae9c
DS
18380};
18381
62b346ee 18382static struct cmd_node bgp_vpnv4_node = {
f4b8291f 18383 .name = "bgp vpnv4",
62b346ee 18384 .node = BGP_VPNV4_NODE,
24389580 18385 .parent_node = BGP_NODE,
62b346ee 18386 .prompt = "%s(config-router-af)# ",
dd2c81b8 18387 .no_xpath = true,
62b346ee 18388};
6b0655a2 18389
62b346ee 18390static struct cmd_node bgp_vpnv6_node = {
f4b8291f 18391 .name = "bgp vpnv6",
62b346ee 18392 .node = BGP_VPNV6_NODE,
24389580 18393 .parent_node = BGP_NODE,
62b346ee 18394 .prompt = "%s(config-router-af-vpnv6)# ",
dd2c81b8 18395 .no_xpath = true,
62b346ee 18396};
8ecd3266 18397
62b346ee 18398static struct cmd_node bgp_evpn_node = {
f4b8291f 18399 .name = "bgp evpn",
62b346ee 18400 .node = BGP_EVPN_NODE,
24389580 18401 .parent_node = BGP_NODE,
62b346ee 18402 .prompt = "%s(config-router-evpn)# ",
dd2c81b8 18403 .no_xpath = true,
62b346ee 18404};
4e0b7b6d 18405
62b346ee 18406static struct cmd_node bgp_evpn_vni_node = {
f4b8291f 18407 .name = "bgp evpn vni",
62b346ee 18408 .node = BGP_EVPN_VNI_NODE,
24389580 18409 .parent_node = BGP_EVPN_NODE,
62b346ee 18410 .prompt = "%s(config-router-af-vni)# ",
62b346ee 18411};
90e60aa7 18412
62b346ee 18413static struct cmd_node bgp_flowspecv4_node = {
f4b8291f 18414 .name = "bgp ipv4 flowspec",
62b346ee 18415 .node = BGP_FLOWSPECV4_NODE,
24389580 18416 .parent_node = BGP_NODE,
62b346ee 18417 .prompt = "%s(config-router-af)# ",
dd2c81b8 18418 .no_xpath = true,
62b346ee 18419};
7c40bf39 18420
62b346ee 18421static struct cmd_node bgp_flowspecv6_node = {
f4b8291f 18422 .name = "bgp ipv6 flowspec",
62b346ee 18423 .node = BGP_FLOWSPECV6_NODE,
24389580 18424 .parent_node = BGP_NODE,
62b346ee 18425 .prompt = "%s(config-router-af-vpnv6)# ",
dd2c81b8 18426 .no_xpath = true,
62b346ee 18427};
7c40bf39 18428
bfaab44d
HS
18429static struct cmd_node bgp_srv6_node = {
18430 .name = "bgp srv6",
18431 .node = BGP_SRV6_NODE,
18432 .parent_node = BGP_NODE,
18433 .prompt = "%s(config-router-srv6)# ",
18434};
18435
d62a17ae 18436static void community_list_vty(void);
1f8ae70b 18437
8c20061f
DA
18438static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
18439{
18440 struct bgp *bgp;
18441 struct peer_group *group;
18442 struct listnode *lnbgp, *lnpeer;
18443
18444 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18445 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
18446 vector_set(comps,
18447 XSTRDUP(MTYPE_COMPLETION, group->name));
18448 }
18449}
18450
18451static void bgp_ac_peer(vector comps, struct cmd_token *token)
b8a815e5 18452{
d62a17ae 18453 struct bgp *bgp;
18454 struct peer *peer;
d62a17ae 18455 struct listnode *lnbgp, *lnpeer;
b8a815e5 18456
d62a17ae 18457 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18458 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
18459 /* only provide suggestions on the appropriate input
18460 * token type,
18461 * they'll otherwise show up multiple times */
18462 enum cmd_token_type match_type;
18463 char *name = peer->host;
d48ed3e0 18464
d62a17ae 18465 if (peer->conf_if) {
18466 match_type = VARIABLE_TKN;
18467 name = peer->conf_if;
18468 } else if (strchr(peer->host, ':'))
18469 match_type = IPV6_TKN;
18470 else
18471 match_type = IPV4_TKN;
d48ed3e0 18472
d62a17ae 18473 if (token->type != match_type)
18474 continue;
d48ed3e0 18475
d62a17ae 18476 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
18477 }
d62a17ae 18478 }
b8a815e5
DL
18479}
18480
8c20061f
DA
18481static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
18482{
18483 bgp_ac_peer(comps, token);
84de1483
DA
18484
18485 if (token->type == VARIABLE_TKN)
18486 bgp_ac_peergroup(comps, token);
8c20061f
DA
18487}
18488
b8a815e5 18489static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 18490 {.varname = "neighbor", .completions = bgp_ac_neighbor},
18491 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 18492 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 18493 {.completions = NULL}};
18494
47a306a0
DS
18495static const struct cmd_variable_handler bgp_var_peergroup[] = {
18496 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
18497 {.completions = NULL} };
18498
aa24a36a
DA
18499DEFINE_HOOK(bgp_config_end, (struct bgp *bgp), (bgp));
18500
18501static struct thread *t_bgp_cfg;
18502
18503bool bgp_config_inprocess(void)
18504{
18505 return thread_is_scheduled(t_bgp_cfg);
18506}
18507
18508static void bgp_config_finish(struct thread *t)
18509{
18510 struct listnode *node;
18511 struct bgp *bgp;
18512
18513 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp))
18514 hook_call(bgp_config_end, bgp);
18515}
18516
18517static void bgp_config_start(void)
18518{
18519#define BGP_PRE_CONFIG_MAX_WAIT_SECONDS 600
18520 THREAD_OFF(t_bgp_cfg);
18521 thread_add_timer(bm->master, bgp_config_finish, NULL,
18522 BGP_PRE_CONFIG_MAX_WAIT_SECONDS, &t_bgp_cfg);
18523}
18524
18525/* When we receive a hook the configuration is read,
18526 * we start a timer to make sure we postpone sending
18527 * EoR before route-maps are processed.
18528 * This is especially valid if using `bgp route-map delay-timer`.
18529 */
18530static void bgp_config_end(void)
18531{
18532#define BGP_POST_CONFIG_DELAY_SECONDS 1
18533 uint32_t bgp_post_config_delay =
18534 thread_is_scheduled(bm->t_rmap_update)
18535 ? thread_timer_remain_second(bm->t_rmap_update)
18536 : BGP_POST_CONFIG_DELAY_SECONDS;
18537
18538 /* If BGP config processing thread isn't running, then
18539 * we can return and rely it's properly handled.
18540 */
18541 if (!bgp_config_inprocess())
18542 return;
18543
18544 THREAD_OFF(t_bgp_cfg);
18545
18546 /* Start a new timer to make sure we don't send EoR
18547 * before route-maps are processed.
18548 */
18549 thread_add_timer(bm->master, bgp_config_finish, NULL,
18550 bgp_post_config_delay, &t_bgp_cfg);
18551}
18552
4cd690ae
PG
18553static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
18554{
18555 int write = 0;
18556 struct interface *ifp;
18557 struct bgp_interface *iifp;
18558
18559 FOR_ALL_INTERFACES (vrf, ifp) {
18560 iifp = ifp->info;
18561 if (!iifp)
18562 continue;
18563
18564 if_vty_config_start(vty, ifp);
18565
18566 if (CHECK_FLAG(iifp->flags,
18567 BGP_INTERFACE_MPLS_BGP_FORWARDING)) {
18568 vty_out(vty, " mpls bgp forwarding\n");
18569 write++;
18570 }
18571
18572 if_vty_config_end(vty);
18573 }
18574
18575 return write;
18576}
18577
18578/* Configuration write function for bgpd. */
18579static int config_write_interface(struct vty *vty)
18580{
18581 int write = 0;
18582 struct vrf *vrf = NULL;
18583
18584 /* Display all VRF aware OSPF interface configuration */
18585 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
18586 write += config_write_interface_one(vty, vrf);
18587 }
18588
18589 return write;
18590}
18591
18592DEFPY(mpls_bgp_forwarding, mpls_bgp_forwarding_cmd,
18593 "[no$no] mpls bgp forwarding",
18594 NO_STR MPLS_STR BGP_STR
18595 "Enable MPLS forwarding for eBGP directly connected peers\n")
18596{
18597 bool check;
18598 struct bgp_interface *iifp;
18599
18600 VTY_DECLVAR_CONTEXT(interface, ifp);
18601 iifp = ifp->info;
18602 if (!iifp) {
18603 vty_out(vty, "Interface %s not available\n", ifp->name);
18604 return CMD_WARNING_CONFIG_FAILED;
18605 }
18606 check = CHECK_FLAG(iifp->flags, BGP_INTERFACE_MPLS_BGP_FORWARDING);
18607 if (check != !no) {
18608 if (no)
18609 UNSET_FLAG(iifp->flags,
18610 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18611 else
18612 SET_FLAG(iifp->flags,
18613 BGP_INTERFACE_MPLS_BGP_FORWARDING);
18614 /* trigger a nht update on eBGP sessions */
18615 if (if_is_operative(ifp))
18616 bgp_nht_ifp_up(ifp);
18617 }
18618 return CMD_SUCCESS;
18619}
18620
a0b937de
SW
18621DEFPY (bgp_inq_limit,
18622 bgp_inq_limit_cmd,
18623 "bgp input-queue-limit (1-4294967295)$limit",
18624 BGP_STR
18625 "Set the BGP Input Queue limit for all peers when message parsing\n"
18626 "Input-Queue limit\n")
18627{
18628 bm->inq_limit = limit;
18629
18630 return CMD_SUCCESS;
18631}
18632
18633DEFPY (no_bgp_inq_limit,
18634 no_bgp_inq_limit_cmd,
18635 "no bgp input-queue-limit [(1-4294967295)$limit]",
18636 NO_STR
18637 BGP_STR
18638 "Set the BGP Input Queue limit for all peers when message parsing\n"
18639 "Input-Queue limit\n")
18640{
18641 bm->inq_limit = BM_DEFAULT_INQ_LIMIT;
18642
18643 return CMD_SUCCESS;
18644}
18645
4cd690ae
PG
18646/* Initialization of BGP interface. */
18647static void bgp_vty_if_init(void)
18648{
18649 /* Install interface node. */
18650 if_cmd_init(config_write_interface);
18651
18652 /* "mpls bgp forwarding" commands. */
18653 install_element(INTERFACE_NODE, &mpls_bgp_forwarding_cmd);
18654}
18655
d62a17ae 18656void bgp_vty_init(void)
18657{
18658 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 18659 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 18660
aa24a36a
DA
18661 cmd_init_config_callbacks(bgp_config_start, bgp_config_end);
18662
d62a17ae 18663 /* Install bgp top node. */
612c2c15
DL
18664 install_node(&bgp_node);
18665 install_node(&bgp_ipv4_unicast_node);
18666 install_node(&bgp_ipv4_multicast_node);
18667 install_node(&bgp_ipv4_labeled_unicast_node);
18668 install_node(&bgp_ipv6_unicast_node);
18669 install_node(&bgp_ipv6_multicast_node);
18670 install_node(&bgp_ipv6_labeled_unicast_node);
18671 install_node(&bgp_vpnv4_node);
18672 install_node(&bgp_vpnv6_node);
18673 install_node(&bgp_evpn_node);
18674 install_node(&bgp_evpn_vni_node);
18675 install_node(&bgp_flowspecv4_node);
18676 install_node(&bgp_flowspecv6_node);
bfaab44d 18677 install_node(&bgp_srv6_node);
d62a17ae 18678
18679 /* Install default VTY commands to new nodes. */
18680 install_default(BGP_NODE);
18681 install_default(BGP_IPV4_NODE);
18682 install_default(BGP_IPV4M_NODE);
18683 install_default(BGP_IPV4L_NODE);
18684 install_default(BGP_IPV6_NODE);
18685 install_default(BGP_IPV6M_NODE);
18686 install_default(BGP_IPV6L_NODE);
18687 install_default(BGP_VPNV4_NODE);
18688 install_default(BGP_VPNV6_NODE);
7c40bf39 18689 install_default(BGP_FLOWSPECV4_NODE);
18690 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 18691 install_default(BGP_EVPN_NODE);
18692 install_default(BGP_EVPN_VNI_NODE);
bfaab44d 18693 install_default(BGP_SRV6_NODE);
d62a17ae 18694
a0b937de
SW
18695 /* "global bgp inq-limit command */
18696 install_element(CONFIG_NODE, &bgp_inq_limit_cmd);
18697 install_element(CONFIG_NODE, &no_bgp_inq_limit_cmd);
18698
8029b216
AK
18699 /* "bgp local-mac" hidden commands. */
18700 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
18701 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
18702
9acb67cb
DS
18703 /* "bgp suppress-fib-pending" global */
18704 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
18705
d62a17ae 18706 /* bgp route-map delay-timer commands. */
18707 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
18708 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18709
8666265e
DS
18710 install_element(BGP_NODE, &bgp_allow_martian_cmd);
18711
f852eb98
PG
18712 /* bgp fast-convergence command */
18713 install_element(BGP_NODE, &bgp_fast_convergence_cmd);
18714 install_element(BGP_NODE, &no_bgp_fast_convergence_cmd);
18715
d70583f7
D
18716 /* global bgp update-delay command */
18717 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
18718 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
18719
05bd726c 18720 /* global bgp graceful-shutdown command */
18721 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
18722 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
18723
d62a17ae 18724 /* Dummy commands (Currently not supported) */
18725 install_element(BGP_NODE, &no_synchronization_cmd);
18726 install_element(BGP_NODE, &no_auto_summary_cmd);
18727
18728 /* "router bgp" commands. */
18729 install_element(CONFIG_NODE, &router_bgp_cmd);
18730
18731 /* "no router bgp" commands. */
18732 install_element(CONFIG_NODE, &no_router_bgp_cmd);
18733
425bd64b
PS
18734 /* "bgp session-dscp command */
18735 install_element(CONFIG_NODE, &bgp_session_dscp_cmd);
18736 install_element(CONFIG_NODE, &no_bgp_session_dscp_cmd);
18737
d62a17ae 18738 /* "bgp router-id" commands. */
18739 install_element(BGP_NODE, &bgp_router_id_cmd);
18740 install_element(BGP_NODE, &no_bgp_router_id_cmd);
18741
c208c586
S
18742 /* "bgp suppress-fib-pending" command */
18743 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
18744
d62a17ae 18745 /* "bgp cluster-id" commands. */
18746 install_element(BGP_NODE, &bgp_cluster_id_cmd);
18747 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
18748
c163f297
DS
18749 /* "bgp no-rib" commands. */
18750 install_element(CONFIG_NODE, &bgp_norib_cmd);
18751 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
18752
e46723a5
DS
18753 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
18754
d62a17ae 18755 /* "bgp confederation" commands. */
18756 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
18757 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
18758
18759 /* "bgp confederation peers" commands. */
18760 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
18761 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
18762
18763 /* bgp max-med command */
18764 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
18765 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
18766 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
18767 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
18768 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
18769
d864dd9e
EB
18770 /* "neighbor role" commands. */
18771 install_element(BGP_NODE, &neighbor_role_cmd);
18772 install_element(BGP_NODE, &neighbor_role_strict_cmd);
18773 install_element(BGP_NODE, &no_neighbor_role_cmd);
18774
97a52c82
DA
18775 /* "neighbor aigp" commands. */
18776 install_element(BGP_NODE, &neighbor_aigp_cmd);
18777
4f770cf1
DA
18778 /* "neighbor graceful-shutdown" command */
18779 install_element(BGP_NODE, &neighbor_graceful_shutdown_cmd);
18780
d62a17ae 18781 /* bgp disable-ebgp-connected-nh-check */
18782 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
18783 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
18784
18785 /* bgp update-delay command */
18786 install_element(BGP_NODE, &bgp_update_delay_cmd);
18787 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
d62a17ae 18788
18789 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
555e09d4 18790 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
d62a17ae 18791
18792 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
18793 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
18794
18795 /* "maximum-paths" commands. */
18796 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
18797 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
18798 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
18799 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
18800 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
18801 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
18802 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
18803 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
18804 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
18805 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
18806 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18807 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
18808 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
18809 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18810 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
18811
39edabac
PG
18812 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
18813 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
18814 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
18815 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18816 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
d62a17ae 18817 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
18818 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
18819 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
18820 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18821 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18822
18823 /* "timers bgp" commands. */
18824 install_element(BGP_NODE, &bgp_timers_cmd);
18825 install_element(BGP_NODE, &no_bgp_timers_cmd);
18826
b042667a
TI
18827 /* "minimum-holdtime" commands. */
18828 install_element(BGP_NODE, &bgp_minimum_holdtime_cmd);
18829 install_element(BGP_NODE, &no_bgp_minimum_holdtime_cmd);
18830
d62a17ae 18831 /* route-map delay-timer commands - per instance for backwards compat.
18832 */
18833 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
18834 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18835
18836 /* "bgp client-to-client reflection" commands */
18837 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
18838 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
18839
18840 /* "bgp always-compare-med" commands */
18841 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
18842 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
18843
9dac9fc8
DA
18844 /* bgp ebgp-requires-policy */
18845 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
18846 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
18847
2adac256
DA
18848 /* bgp suppress-duplicates */
18849 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
18850 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
18851
fb29348a
DA
18852 /* bgp reject-as-sets */
18853 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
18854 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
18855
d62a17ae 18856 /* "bgp deterministic-med" commands */
18857 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
18858 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
18859
055679e9 18860 /* "bgp graceful-restart" command */
36235319
QY
18861 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
18862 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
055679e9 18863
18864 /* "bgp graceful-restart-disable" command */
36235319
QY
18865 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
18866 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
055679e9 18867
18868 /* "neighbor a:b:c:d graceful-restart" command */
36235319
QY
18869 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
18870 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
055679e9 18871
18872 /* "neighbor a:b:c:d graceful-restart-disable" command */
18873 install_element(BGP_NODE,
18874 &bgp_neighbor_graceful_restart_disable_set_cmd);
18875 install_element(BGP_NODE,
18876 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
18877
18878 /* "neighbor a:b:c:d graceful-restart-helper" command */
18879 install_element(BGP_NODE,
18880 &bgp_neighbor_graceful_restart_helper_set_cmd);
18881 install_element(BGP_NODE,
18882 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
18883
d62a17ae 18884 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
18885 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
18886 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
18887 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
cfd47646 18888 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
f009ff26 18889 install_element(BGP_NODE,
18890 &no_bgp_graceful_restart_select_defer_time_cmd);
d62a17ae 18891 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
18892 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
f2ca5c5b 18893 install_element(BGP_NODE, &bgp_graceful_restart_notification_cmd);
d62a17ae 18894
d6e3c15b 18895 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
18896 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
dc95985f 18897 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
18898 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
d6e3c15b 18899
a0b937de
SW
18900 /* "bgp inq-limit command */
18901 install_element(BGP_NODE, &bgp_inq_limit_cmd);
18902 install_element(BGP_NODE, &no_bgp_inq_limit_cmd);
18903
7f323236
DW
18904 /* "bgp graceful-shutdown" commands */
18905 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
18906 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
18907
1ae314be
DA
18908 /* "bgp hard-administrative-reset" commands */
18909 install_element(BGP_NODE, &bgp_administrative_reset_cmd);
18910
8606be87
DA
18911 /* "bgp long-lived-graceful-restart" commands */
18912 install_element(BGP_NODE, &bgp_llgr_stalepath_time_cmd);
18913 install_element(BGP_NODE, &no_bgp_llgr_stalepath_time_cmd);
18914
d62a17ae 18915 /* "bgp fast-external-failover" commands */
18916 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
18917 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
18918
97a52c82
DA
18919 /* "bgp bestpath aigp" commands */
18920 install_element(BGP_NODE, &bgp_bestpath_aigp_cmd);
18921
d62a17ae 18922 /* "bgp bestpath compare-routerid" commands */
18923 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
18924 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
18925
18926 /* "bgp bestpath as-path ignore" commands */
18927 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
18928 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
18929
18930 /* "bgp bestpath as-path confed" commands */
18931 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
18932 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
18933
18934 /* "bgp bestpath as-path multipath-relax" commands */
18935 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
18936 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
18937
ee88563a
JM
18938 /* "bgp bestpath peer-type multipath-relax" commands */
18939 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
18940 install_element(BGP_NODE,
18941 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
18942
d62a17ae 18943 /* "bgp log-neighbor-changes" commands */
18944 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
18945 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
18946
18947 /* "bgp bestpath med" commands */
18948 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
18949 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
18950
f7e1c681 18951 /* "bgp bestpath bandwidth" commands */
18952 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
ad36d216 18953 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
f7e1c681 18954
b16bcbba
TA
18955 /* "no bgp default <afi>-<safi>" commands. */
18956 install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
e84c59af 18957
d62a17ae 18958 /* "bgp network import-check" commands. */
18959 install_element(BGP_NODE, &bgp_network_import_check_cmd);
18960 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
18961 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
18962
18963 /* "bgp default local-preference" commands. */
18964 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
18965 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
18966
18967 /* bgp default show-hostname */
18968 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
18969 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
18970
aef999a2
DA
18971 /* bgp default show-nexthop-hostname */
18972 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
18973 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
18974
d62a17ae 18975 /* "bgp default subgroup-pkt-queue-max" commands. */
18976 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
18977 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
18978
18979 /* bgp ibgp-allow-policy-mods command */
18980 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
18981 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
18982
18983 /* "bgp listen limit" commands. */
18984 install_element(BGP_NODE, &bgp_listen_limit_cmd);
18985 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
18986
18987 /* "bgp listen range" commands. */
18988 install_element(BGP_NODE, &bgp_listen_range_cmd);
18989 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
18990
8175f54a 18991 /* "bgp default shutdown" command */
f26845f9 18992 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
9cf59432
DS
18993
18994 /* "bgp shutdown" commands */
18995 install_element(BGP_NODE, &bgp_shutdown_cmd);
8389c83a 18996 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
9cf59432 18997 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
1b6e7a88 18998 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
f26845f9 18999
d62a17ae 19000 /* "neighbor remote-as" commands. */
19001 install_element(BGP_NODE, &neighbor_remote_as_cmd);
19002 install_element(BGP_NODE, &neighbor_interface_config_cmd);
19003 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
19004 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
19005 install_element(BGP_NODE,
19006 &neighbor_interface_v6only_config_remote_as_cmd);
19007 install_element(BGP_NODE, &no_neighbor_cmd);
19008 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
19009
19010 /* "neighbor peer-group" commands. */
19011 install_element(BGP_NODE, &neighbor_peer_group_cmd);
19012 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
19013 install_element(BGP_NODE,
19014 &no_neighbor_interface_peer_group_remote_as_cmd);
19015
19016 /* "neighbor local-as" commands. */
19017 install_element(BGP_NODE, &neighbor_local_as_cmd);
19018 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
19019 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
19020 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
19021
19022 /* "neighbor solo" commands. */
19023 install_element(BGP_NODE, &neighbor_solo_cmd);
19024 install_element(BGP_NODE, &no_neighbor_solo_cmd);
19025
19026 /* "neighbor password" commands. */
19027 install_element(BGP_NODE, &neighbor_password_cmd);
19028 install_element(BGP_NODE, &no_neighbor_password_cmd);
19029
19030 /* "neighbor activate" commands. */
19031 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
19032 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
19033 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
19034 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
19035 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
19036 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
19037 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
19038 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
19039 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 19040 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
19041 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 19042 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
19043
19044 /* "no neighbor activate" commands. */
19045 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
19046 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
19047 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
19048 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
19049 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
19050 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
19051 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
19052 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
19053 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 19054 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
19055 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 19056 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
19057
19058 /* "neighbor peer-group" set commands. */
19059 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
19060 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
19061 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
19062 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
19063 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
19064 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
19065 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
19066 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 19067 install_element(BGP_FLOWSPECV4_NODE,
19068 &neighbor_set_peer_group_hidden_cmd);
19069 install_element(BGP_FLOWSPECV6_NODE,
19070 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 19071
19072 /* "no neighbor peer-group unset" commands. */
19073 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
19074 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19075 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19076 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19077 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19078 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19079 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19080 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 19081 install_element(BGP_FLOWSPECV4_NODE,
19082 &no_neighbor_set_peer_group_hidden_cmd);
19083 install_element(BGP_FLOWSPECV6_NODE,
19084 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 19085
19086 /* "neighbor softreconfiguration inbound" commands.*/
19087 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
19088 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
19089 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
19090 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
19091 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
19092 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
19093 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
19094 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
19095 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
19096 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
19097 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
19098 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
19099 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
19100 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
19101 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
19102 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
19103 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
19104 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 19105 install_element(BGP_FLOWSPECV4_NODE,
19106 &neighbor_soft_reconfiguration_cmd);
19107 install_element(BGP_FLOWSPECV4_NODE,
19108 &no_neighbor_soft_reconfiguration_cmd);
19109 install_element(BGP_FLOWSPECV6_NODE,
19110 &neighbor_soft_reconfiguration_cmd);
19111 install_element(BGP_FLOWSPECV6_NODE,
19112 &no_neighbor_soft_reconfiguration_cmd);
616c6ee8
PG
19113 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
19114 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 19115
19116 /* "neighbor attribute-unchanged" commands. */
19117 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
19118 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
19119 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
19120 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
19121 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
19122 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
19123 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
19124 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
19125 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
19126 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
19127 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
19128 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
19129 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
19130 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
19131 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
19132 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
19133 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
19134 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
19135
19136 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
19137 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
19138
b8ad84d2
PG
19139 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
19140 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
19141 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
19142 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
19143
d62a17ae 19144 /* "nexthop-local unchanged" commands */
19145 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
19146 install_element(BGP_IPV6_NODE,
19147 &no_neighbor_nexthop_local_unchanged_cmd);
19148
19149 /* "neighbor next-hop-self" commands. */
19150 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
19151 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
19152 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
19153 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
19154 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
19155 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
19156 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
19157 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
19158 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
19159 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
19160 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
19161 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
19162 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
19163 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
19164 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
19165 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
19166 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
19167 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
19168 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
19169 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 19170
19171 /* "neighbor next-hop-self force" commands. */
19172 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
19173 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
1bc4e531
DA
19174 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19175 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19176 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
19177 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19178 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19179 install_element(BGP_IPV4_NODE,
19180 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19181 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
19182 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19183 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19184 install_element(BGP_IPV4M_NODE,
19185 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19186 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
19187 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19188 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19189 install_element(BGP_IPV4L_NODE,
19190 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19191 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
19192 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19193 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19194 install_element(BGP_IPV6_NODE,
19195 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19196 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
19197 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19198 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19199 install_element(BGP_IPV6M_NODE,
19200 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19201 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
19202 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19203 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19204 install_element(BGP_IPV6L_NODE,
19205 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19206 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
19207 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19208 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19209 install_element(BGP_VPNV4_NODE,
19210 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 19211 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
19212 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
19213 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19214 install_element(BGP_VPNV6_NODE,
19215 &no_neighbor_nexthop_self_all_hidden_cmd);
be7e1fa3
MS
19216 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
19217 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
d62a17ae 19218
19219 /* "neighbor as-override" commands. */
19220 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
19221 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
19222 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
19223 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
19224 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
19225 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
19226 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
19227 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
19228 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
19229 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
19230 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
19231 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
19232 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
19233 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
19234 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
19235 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
19236 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
19237 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
19238
19239 /* "neighbor remove-private-AS" commands. */
19240 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
19241 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
19242 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
19243 install_element(BGP_NODE,
19244 &no_neighbor_remove_private_as_all_hidden_cmd);
19245 install_element(BGP_NODE,
19246 &neighbor_remove_private_as_replace_as_hidden_cmd);
19247 install_element(BGP_NODE,
19248 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
19249 install_element(BGP_NODE,
19250 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
19251 install_element(
19252 BGP_NODE,
19253 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
19254 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
19255 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
19256 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
19257 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
19258 install_element(BGP_IPV4_NODE,
19259 &neighbor_remove_private_as_replace_as_cmd);
19260 install_element(BGP_IPV4_NODE,
19261 &no_neighbor_remove_private_as_replace_as_cmd);
19262 install_element(BGP_IPV4_NODE,
19263 &neighbor_remove_private_as_all_replace_as_cmd);
19264 install_element(BGP_IPV4_NODE,
19265 &no_neighbor_remove_private_as_all_replace_as_cmd);
19266 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
19267 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
19268 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
19269 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
19270 install_element(BGP_IPV4M_NODE,
19271 &neighbor_remove_private_as_replace_as_cmd);
19272 install_element(BGP_IPV4M_NODE,
19273 &no_neighbor_remove_private_as_replace_as_cmd);
19274 install_element(BGP_IPV4M_NODE,
19275 &neighbor_remove_private_as_all_replace_as_cmd);
19276 install_element(BGP_IPV4M_NODE,
19277 &no_neighbor_remove_private_as_all_replace_as_cmd);
19278 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
19279 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
19280 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
19281 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
19282 install_element(BGP_IPV4L_NODE,
19283 &neighbor_remove_private_as_replace_as_cmd);
19284 install_element(BGP_IPV4L_NODE,
19285 &no_neighbor_remove_private_as_replace_as_cmd);
19286 install_element(BGP_IPV4L_NODE,
19287 &neighbor_remove_private_as_all_replace_as_cmd);
19288 install_element(BGP_IPV4L_NODE,
19289 &no_neighbor_remove_private_as_all_replace_as_cmd);
19290 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
19291 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
19292 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
19293 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
19294 install_element(BGP_IPV6_NODE,
19295 &neighbor_remove_private_as_replace_as_cmd);
19296 install_element(BGP_IPV6_NODE,
19297 &no_neighbor_remove_private_as_replace_as_cmd);
19298 install_element(BGP_IPV6_NODE,
19299 &neighbor_remove_private_as_all_replace_as_cmd);
19300 install_element(BGP_IPV6_NODE,
19301 &no_neighbor_remove_private_as_all_replace_as_cmd);
19302 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
19303 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
19304 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
19305 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
19306 install_element(BGP_IPV6M_NODE,
19307 &neighbor_remove_private_as_replace_as_cmd);
19308 install_element(BGP_IPV6M_NODE,
19309 &no_neighbor_remove_private_as_replace_as_cmd);
19310 install_element(BGP_IPV6M_NODE,
19311 &neighbor_remove_private_as_all_replace_as_cmd);
19312 install_element(BGP_IPV6M_NODE,
19313 &no_neighbor_remove_private_as_all_replace_as_cmd);
19314 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
19315 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
19316 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
19317 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
19318 install_element(BGP_IPV6L_NODE,
19319 &neighbor_remove_private_as_replace_as_cmd);
19320 install_element(BGP_IPV6L_NODE,
19321 &no_neighbor_remove_private_as_replace_as_cmd);
19322 install_element(BGP_IPV6L_NODE,
19323 &neighbor_remove_private_as_all_replace_as_cmd);
19324 install_element(BGP_IPV6L_NODE,
19325 &no_neighbor_remove_private_as_all_replace_as_cmd);
19326 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
19327 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
19328 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
19329 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
19330 install_element(BGP_VPNV4_NODE,
19331 &neighbor_remove_private_as_replace_as_cmd);
19332 install_element(BGP_VPNV4_NODE,
19333 &no_neighbor_remove_private_as_replace_as_cmd);
19334 install_element(BGP_VPNV4_NODE,
19335 &neighbor_remove_private_as_all_replace_as_cmd);
19336 install_element(BGP_VPNV4_NODE,
19337 &no_neighbor_remove_private_as_all_replace_as_cmd);
19338 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
19339 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
19340 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
19341 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
19342 install_element(BGP_VPNV6_NODE,
19343 &neighbor_remove_private_as_replace_as_cmd);
19344 install_element(BGP_VPNV6_NODE,
19345 &no_neighbor_remove_private_as_replace_as_cmd);
19346 install_element(BGP_VPNV6_NODE,
19347 &neighbor_remove_private_as_all_replace_as_cmd);
19348 install_element(BGP_VPNV6_NODE,
19349 &no_neighbor_remove_private_as_all_replace_as_cmd);
19350
19351 /* "neighbor send-community" commands.*/
19352 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
19353 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
19354 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
19355 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
19356 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
19357 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
19358 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
19359 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
19360 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
19361 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
19362 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
19363 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
19364 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
19365 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
19366 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
19367 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
19368 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
19369 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
19370 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
19371 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
19372 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
19373 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
19374 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
19375 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
19376 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
19377 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
19378 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
19379 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
19380 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
19381 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
19382 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
19383 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
19384 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
19385 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
19386 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
19387 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
19388
19389 /* "neighbor route-reflector" commands.*/
19390 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
19391 install_element(BGP_NODE,
19392 &no_neighbor_route_reflector_client_hidden_cmd);
19393 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
19394 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
19395 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
19396 install_element(BGP_IPV4M_NODE,
19397 &no_neighbor_route_reflector_client_cmd);
19398 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
19399 install_element(BGP_IPV4L_NODE,
19400 &no_neighbor_route_reflector_client_cmd);
19401 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
19402 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
19403 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
19404 install_element(BGP_IPV6M_NODE,
19405 &no_neighbor_route_reflector_client_cmd);
19406 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
19407 install_element(BGP_IPV6L_NODE,
19408 &no_neighbor_route_reflector_client_cmd);
19409 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
19410 install_element(BGP_VPNV4_NODE,
19411 &no_neighbor_route_reflector_client_cmd);
19412 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
19413 install_element(BGP_VPNV6_NODE,
19414 &no_neighbor_route_reflector_client_cmd);
7c40bf39 19415 install_element(BGP_FLOWSPECV4_NODE,
19416 &neighbor_route_reflector_client_cmd);
19417 install_element(BGP_FLOWSPECV4_NODE,
19418 &no_neighbor_route_reflector_client_cmd);
19419 install_element(BGP_FLOWSPECV6_NODE,
19420 &neighbor_route_reflector_client_cmd);
19421 install_element(BGP_FLOWSPECV6_NODE,
19422 &no_neighbor_route_reflector_client_cmd);
d62a17ae 19423 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
19424 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
19425
70cd87ca
MK
19426 /* "optimal-route-reflection" commands */
19427 install_element(BGP_IPV4_NODE, &optimal_route_reflection_cmd);
19428 install_element(BGP_IPV4M_NODE, &optimal_route_reflection_cmd);
19429 install_element(BGP_IPV4L_NODE, &optimal_route_reflection_cmd);
19430 install_element(BGP_IPV6_NODE, &optimal_route_reflection_cmd);
19431 install_element(BGP_IPV6M_NODE, &optimal_route_reflection_cmd);
19432 install_element(BGP_IPV6L_NODE, &optimal_route_reflection_cmd);
19433 install_element(BGP_VPNV4_NODE, &optimal_route_reflection_cmd);
19434 install_element(BGP_VPNV6_NODE, &optimal_route_reflection_cmd);
19435 install_element(BGP_FLOWSPECV4_NODE, &optimal_route_reflection_cmd);
19436 install_element(BGP_FLOWSPECV6_NODE, &optimal_route_reflection_cmd);
19437 install_element(BGP_EVPN_NODE, &optimal_route_reflection_cmd);
19438
19439 /* "neighbor optimal-route-reflection" commands */
19440 install_element(BGP_IPV4_NODE, &neighbor_optimal_route_reflection_cmd);
19441 install_element(BGP_IPV4M_NODE, &neighbor_optimal_route_reflection_cmd);
19442 install_element(BGP_IPV4L_NODE, &neighbor_optimal_route_reflection_cmd);
19443 install_element(BGP_IPV6_NODE, &neighbor_optimal_route_reflection_cmd);
19444 install_element(BGP_IPV6M_NODE, &neighbor_optimal_route_reflection_cmd);
19445 install_element(BGP_IPV6L_NODE, &neighbor_optimal_route_reflection_cmd);
19446 install_element(BGP_VPNV4_NODE, &neighbor_optimal_route_reflection_cmd);
19447 install_element(BGP_VPNV6_NODE, &neighbor_optimal_route_reflection_cmd);
19448 install_element(BGP_FLOWSPECV4_NODE,
19449 &neighbor_optimal_route_reflection_cmd);
19450 install_element(BGP_FLOWSPECV6_NODE,
19451 &neighbor_optimal_route_reflection_cmd);
19452 install_element(BGP_EVPN_NODE, &neighbor_optimal_route_reflection_cmd);
19453
d62a17ae 19454 /* "neighbor route-server" commands.*/
19455 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
19456 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
19457 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
19458 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
19459 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
19460 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
19461 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
19462 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
19463 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
19464 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
19465 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
19466 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
19467 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
19468 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
19469 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
19470 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
19471 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
19472 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
19473 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
19474 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 19475 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
19476 install_element(BGP_FLOWSPECV4_NODE,
19477 &no_neighbor_route_server_client_cmd);
19478 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
19479 install_element(BGP_FLOWSPECV6_NODE,
19480 &no_neighbor_route_server_client_cmd);
d62a17ae 19481
7c0e4312
DA
19482 /* "neighbor disable-addpath-rx" commands. */
19483 install_element(BGP_IPV4_NODE, &neighbor_disable_addpath_rx_cmd);
19484 install_element(BGP_IPV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19485 install_element(BGP_IPV4M_NODE, &neighbor_disable_addpath_rx_cmd);
19486 install_element(BGP_IPV4M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19487 install_element(BGP_IPV4L_NODE, &neighbor_disable_addpath_rx_cmd);
19488 install_element(BGP_IPV4L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19489 install_element(BGP_IPV6_NODE, &neighbor_disable_addpath_rx_cmd);
19490 install_element(BGP_IPV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19491 install_element(BGP_IPV6M_NODE, &neighbor_disable_addpath_rx_cmd);
19492 install_element(BGP_IPV6M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19493 install_element(BGP_IPV6L_NODE, &neighbor_disable_addpath_rx_cmd);
19494 install_element(BGP_IPV6L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19495 install_element(BGP_VPNV4_NODE, &neighbor_disable_addpath_rx_cmd);
19496 install_element(BGP_VPNV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19497 install_element(BGP_VPNV6_NODE, &neighbor_disable_addpath_rx_cmd);
19498 install_element(BGP_VPNV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19499
d62a17ae 19500 /* "neighbor addpath-tx-all-paths" commands.*/
19501 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
19502 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
19503 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19504 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19505 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19506 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19507 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19508 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19509 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19510 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19511 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19512 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19513 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19514 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19515 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19516 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19517 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19518 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19519
19520 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
19521 install_element(BGP_NODE,
19522 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19523 install_element(BGP_NODE,
19524 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19525 install_element(BGP_IPV4_NODE,
19526 &neighbor_addpath_tx_bestpath_per_as_cmd);
19527 install_element(BGP_IPV4_NODE,
19528 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19529 install_element(BGP_IPV4M_NODE,
19530 &neighbor_addpath_tx_bestpath_per_as_cmd);
19531 install_element(BGP_IPV4M_NODE,
19532 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19533 install_element(BGP_IPV4L_NODE,
19534 &neighbor_addpath_tx_bestpath_per_as_cmd);
19535 install_element(BGP_IPV4L_NODE,
19536 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19537 install_element(BGP_IPV6_NODE,
19538 &neighbor_addpath_tx_bestpath_per_as_cmd);
19539 install_element(BGP_IPV6_NODE,
19540 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19541 install_element(BGP_IPV6M_NODE,
19542 &neighbor_addpath_tx_bestpath_per_as_cmd);
19543 install_element(BGP_IPV6M_NODE,
19544 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19545 install_element(BGP_IPV6L_NODE,
19546 &neighbor_addpath_tx_bestpath_per_as_cmd);
19547 install_element(BGP_IPV6L_NODE,
19548 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19549 install_element(BGP_VPNV4_NODE,
19550 &neighbor_addpath_tx_bestpath_per_as_cmd);
19551 install_element(BGP_VPNV4_NODE,
19552 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19553 install_element(BGP_VPNV6_NODE,
19554 &neighbor_addpath_tx_bestpath_per_as_cmd);
19555 install_element(BGP_VPNV6_NODE,
19556 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19557
2b31007c
RZ
19558 /* "neighbor sender-as-path-loop-detection" commands. */
19559 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
19560 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
19561
d62a17ae 19562 /* "neighbor passive" commands. */
19563 install_element(BGP_NODE, &neighbor_passive_cmd);
19564 install_element(BGP_NODE, &no_neighbor_passive_cmd);
19565
19566
19567 /* "neighbor shutdown" commands. */
19568 install_element(BGP_NODE, &neighbor_shutdown_cmd);
19569 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
19570 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
19571 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
8336c896
DA
19572 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
19573 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
d62a17ae 19574
19575 /* "neighbor capability extended-nexthop" commands.*/
19576 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
19577 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
19578
19579 /* "neighbor capability orf prefix-list" commands.*/
19580 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
19581 install_element(BGP_NODE,
19582 &no_neighbor_capability_orf_prefix_hidden_cmd);
19583 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
19584 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
19585 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
19586 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19587 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
19588 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19589 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
19590 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
19591 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
19592 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19593 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
19594 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19595
19596 /* "neighbor capability dynamic" commands.*/
19597 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
19598 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
19599
19600 /* "neighbor dont-capability-negotiate" commands. */
19601 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
19602 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
19603
19604 /* "neighbor ebgp-multihop" commands. */
19605 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
19606 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
19607 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
19608
19609 /* "neighbor disable-connected-check" commands. */
19610 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
19611 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
19612
7ab294ea
DA
19613 /* "neighbor disable-link-bw-encoding-ieee" commands. */
19614 install_element(BGP_NODE, &neighbor_disable_link_bw_encoding_ieee_cmd);
19615 install_element(BGP_NODE,
19616 &no_neighbor_disable_link_bw_encoding_ieee_cmd);
27aa23a4 19617
d08c0c80
DA
19618 /* "neighbor extended-optional-parameters" commands. */
19619 install_element(BGP_NODE, &neighbor_extended_optional_parameters_cmd);
19620 install_element(BGP_NODE,
19621 &no_neighbor_extended_optional_parameters_cmd);
19622
47cbc09b
PM
19623 /* "neighbor enforce-first-as" commands. */
19624 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
19625 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
19626
d62a17ae 19627 /* "neighbor description" commands. */
19628 install_element(BGP_NODE, &neighbor_description_cmd);
19629 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 19630 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 19631
19632 /* "neighbor update-source" commands. "*/
19633 install_element(BGP_NODE, &neighbor_update_source_cmd);
19634 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
19635
19636 /* "neighbor default-originate" commands. */
19637 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
19638 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
19639 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
19640 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
19641 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
19642 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
19643 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
19644 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
19645 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
19646 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
19647 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
19648 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
19649 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
19650 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
19651 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
19652 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
19653 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
19654 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
19655 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
19656 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
19657 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
19658
19659 /* "neighbor port" commands. */
19660 install_element(BGP_NODE, &neighbor_port_cmd);
19661 install_element(BGP_NODE, &no_neighbor_port_cmd);
19662
19663 /* "neighbor weight" commands. */
19664 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
19665 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
19666
19667 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
19668 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
19669 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
19670 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
19671 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
19672 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
19673 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
19674 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
19675 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
19676 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
19677 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
19678 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
19679 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
19680 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
19681 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
19682 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
19683
19684 /* "neighbor override-capability" commands. */
19685 install_element(BGP_NODE, &neighbor_override_capability_cmd);
19686 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
19687
19688 /* "neighbor strict-capability-match" commands. */
19689 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
19690 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
19691
19692 /* "neighbor timers" commands. */
19693 install_element(BGP_NODE, &neighbor_timers_cmd);
19694 install_element(BGP_NODE, &no_neighbor_timers_cmd);
19695
19696 /* "neighbor timers connect" commands. */
19697 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
19698 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
19699
d43114f3
DS
19700 /* "neighbor timers delayopen" commands. */
19701 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
19702 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
19703
d62a17ae 19704 /* "neighbor advertisement-interval" commands. */
19705 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
19706 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
19707
19708 /* "neighbor interface" commands. */
19709 install_element(BGP_NODE, &neighbor_interface_cmd);
19710 install_element(BGP_NODE, &no_neighbor_interface_cmd);
19711
19712 /* "neighbor distribute" commands. */
19713 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
19714 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
19715 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
19716 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
19717 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
19718 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
19719 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
19720 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
19721 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
19722 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
19723 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
19724 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
19725 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
19726 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
19727 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
19728 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
19729 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
19730 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
19731
19732 /* "neighbor prefix-list" commands. */
19733 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
642ef664 19734 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
d62a17ae 19735 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
642ef664 19736 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 19737 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
642ef664 19738 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 19739 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
642ef664 19740 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 19741 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
642ef664 19742 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 19743 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
642ef664 19744 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 19745 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
642ef664 19746 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 19747 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
642ef664 19748 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 19749 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
642ef664 19750 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 19751 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
642ef664 19752 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 19753 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
642ef664 19754 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 19755
19756 /* "neighbor filter-list" commands. */
19757 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
19758 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
19759 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
19760 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
19761 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
19762 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
19763 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
19764 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
19765 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
19766 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
19767 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
19768 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
19769 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
19770 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
19771 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
19772 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
19773 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
19774 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 19775 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
19776 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
19777 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
19778 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 19779
19780 /* "neighbor route-map" commands. */
d6d7ed37
IR
19781 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
19782 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
d62a17ae 19783 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
0ea8d871 19784 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
d62a17ae 19785 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
0ea8d871 19786 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
d62a17ae 19787 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
0ea8d871 19788 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
d62a17ae 19789 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
0ea8d871 19790 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
d62a17ae 19791 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
0ea8d871 19792 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
d62a17ae 19793 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
0ea8d871 19794 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
d62a17ae 19795 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
0ea8d871 19796 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
d62a17ae 19797 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
0ea8d871 19798 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 19799 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
0ea8d871 19800 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
7c40bf39 19801 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
0ea8d871 19802 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549 19803 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
0ea8d871 19804 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 19805
19806 /* "neighbor unsuppress-map" commands. */
19807 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
19808 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
19809 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
19810 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
19811 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
19812 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
19813 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
19814 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
19815 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
19816 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
19817 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
19818 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
19819 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
19820 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
19821 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
19822 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
19823 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
19824 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
19825
7f7940e6 19826 /* "neighbor advertise-map" commands. */
389e4f92 19827 install_element(BGP_NODE, &bgp_condadv_period_cmd);
7f7940e6 19828 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
7f7940e6 19829 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19830 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19831 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19832 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19833 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19834 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19835 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19836 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19837
fde246e8
DA
19838 /* neighbor maximum-prefix-out commands. */
19839 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
19840 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
19841 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
19842 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19843 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
19844 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19845 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
19846 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19847 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
19848 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19849 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
19850 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19851 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
19852 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19853 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
19854 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19855 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
19856 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19857
d62a17ae 19858 /* "neighbor maximum-prefix" commands. */
19859 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
19860 install_element(BGP_NODE,
19861 &neighbor_maximum_prefix_threshold_hidden_cmd);
19862 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
19863 install_element(BGP_NODE,
19864 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
19865 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
19866 install_element(BGP_NODE,
19867 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
19868 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
19869 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
19870 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19871 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19872 install_element(BGP_IPV4_NODE,
19873 &neighbor_maximum_prefix_threshold_warning_cmd);
19874 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19875 install_element(BGP_IPV4_NODE,
19876 &neighbor_maximum_prefix_threshold_restart_cmd);
19877 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
19878 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
19879 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19880 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
19881 install_element(BGP_IPV4M_NODE,
19882 &neighbor_maximum_prefix_threshold_warning_cmd);
19883 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
19884 install_element(BGP_IPV4M_NODE,
19885 &neighbor_maximum_prefix_threshold_restart_cmd);
19886 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
19887 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
19888 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19889 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
19890 install_element(BGP_IPV4L_NODE,
19891 &neighbor_maximum_prefix_threshold_warning_cmd);
19892 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
19893 install_element(BGP_IPV4L_NODE,
19894 &neighbor_maximum_prefix_threshold_restart_cmd);
19895 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
19896 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
19897 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19898 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19899 install_element(BGP_IPV6_NODE,
19900 &neighbor_maximum_prefix_threshold_warning_cmd);
19901 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19902 install_element(BGP_IPV6_NODE,
19903 &neighbor_maximum_prefix_threshold_restart_cmd);
19904 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
19905 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
19906 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19907 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
19908 install_element(BGP_IPV6M_NODE,
19909 &neighbor_maximum_prefix_threshold_warning_cmd);
19910 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
19911 install_element(BGP_IPV6M_NODE,
19912 &neighbor_maximum_prefix_threshold_restart_cmd);
19913 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
19914 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
19915 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19916 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
19917 install_element(BGP_IPV6L_NODE,
19918 &neighbor_maximum_prefix_threshold_warning_cmd);
19919 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
19920 install_element(BGP_IPV6L_NODE,
19921 &neighbor_maximum_prefix_threshold_restart_cmd);
19922 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
19923 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
19924 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19925 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19926 install_element(BGP_VPNV4_NODE,
19927 &neighbor_maximum_prefix_threshold_warning_cmd);
19928 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19929 install_element(BGP_VPNV4_NODE,
19930 &neighbor_maximum_prefix_threshold_restart_cmd);
19931 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
19932 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
19933 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19934 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19935 install_element(BGP_VPNV6_NODE,
19936 &neighbor_maximum_prefix_threshold_warning_cmd);
19937 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19938 install_element(BGP_VPNV6_NODE,
19939 &neighbor_maximum_prefix_threshold_restart_cmd);
19940 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
19941
19942 /* "neighbor allowas-in" */
19943 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
19944 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
19945 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
19946 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
19947 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
19948 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
19949 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
19950 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
19951 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
19952 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
19953 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
19954 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
19955 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
19956 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
19957 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
19958 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
19959 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
19960 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
19961 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
19962 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
19963
46dbf9d0
DA
19964 /* neighbor accept-own */
19965 install_element(BGP_VPNV4_NODE, &neighbor_accept_own_cmd);
19966 install_element(BGP_VPNV6_NODE, &neighbor_accept_own_cmd);
19967
01da2d26
DA
19968 /* "neighbor soo" */
19969 install_element(BGP_IPV4_NODE, &neighbor_soo_cmd);
19970 install_element(BGP_IPV4_NODE, &no_neighbor_soo_cmd);
19971 install_element(BGP_IPV4M_NODE, &neighbor_soo_cmd);
19972 install_element(BGP_IPV4M_NODE, &no_neighbor_soo_cmd);
19973 install_element(BGP_IPV4L_NODE, &neighbor_soo_cmd);
19974 install_element(BGP_IPV4L_NODE, &no_neighbor_soo_cmd);
19975 install_element(BGP_IPV6_NODE, &neighbor_soo_cmd);
19976 install_element(BGP_IPV6_NODE, &no_neighbor_soo_cmd);
19977 install_element(BGP_IPV6M_NODE, &neighbor_soo_cmd);
19978 install_element(BGP_IPV6M_NODE, &no_neighbor_soo_cmd);
19979 install_element(BGP_IPV6L_NODE, &neighbor_soo_cmd);
19980 install_element(BGP_IPV6L_NODE, &no_neighbor_soo_cmd);
19981 install_element(BGP_VPNV4_NODE, &neighbor_soo_cmd);
19982 install_element(BGP_VPNV4_NODE, &no_neighbor_soo_cmd);
19983 install_element(BGP_VPNV6_NODE, &neighbor_soo_cmd);
19984 install_element(BGP_VPNV6_NODE, &no_neighbor_soo_cmd);
19985 install_element(BGP_EVPN_NODE, &neighbor_soo_cmd);
19986 install_element(BGP_EVPN_NODE, &no_neighbor_soo_cmd);
19987
d62a17ae 19988 /* address-family commands. */
19989 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
19990 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 19991#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 19992 install_element(BGP_NODE, &address_family_vpnv4_cmd);
19993 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 19994#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 19995
d62a17ae 19996 install_element(BGP_NODE, &address_family_evpn_cmd);
19997
19998 /* "exit-address-family" command. */
19999 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
20000 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
20001 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
20002 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
20003 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
20004 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
20005 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
20006 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 20007 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
20008 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 20009 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
20010
a486300b
PG
20011 /* BGP retain all route-target */
20012 install_element(BGP_VPNV4_NODE, &bgp_retain_route_target_cmd);
20013 install_element(BGP_VPNV6_NODE, &bgp_retain_route_target_cmd);
20014
d62a17ae 20015 /* "clear ip bgp commands" */
20016 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
20017
20018 /* clear ip bgp prefix */
20019 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
20020 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
20021 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
20022
20023 /* "show [ip] bgp summary" commands. */
20024 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 20025 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 20026 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 20027 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 20028 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
20029 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 20030 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
20031
20032 /* "show [ip] bgp neighbors" commands. */
20033 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
20034
36235319 20035 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
2986cac2 20036
d62a17ae 20037 /* "show [ip] bgp peer-group" commands. */
20038 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
20039
20040 /* "show [ip] bgp paths" commands. */
20041 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
20042
20043 /* "show [ip] bgp community" commands. */
20044 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
20045
20046 /* "show ip bgp large-community" commands. */
20047 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
20048 /* "show [ip] bgp attribute-info" commands. */
20049 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 20050 /* "show [ip] bgp route-leak" command */
20051 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 20052
20053 /* "redistribute" commands. */
20054 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
20055 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
20056 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
20057 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
20058 install_element(BGP_NODE,
20059 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
20060 install_element(BGP_NODE,
20061 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
20062 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
20063 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
20064 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
20065 install_element(BGP_NODE,
20066 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
20067 install_element(BGP_NODE,
20068 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
20069 install_element(BGP_NODE,
20070 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
20071 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
20072 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
20073 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
20074 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
20075 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
20076 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
20077 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
20078 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
20079 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
20080 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
20081 install_element(BGP_IPV4_NODE,
20082 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
20083 install_element(BGP_IPV4_NODE,
20084 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
20085 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
20086 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
20087 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
20088 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
20089 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
20090 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
20091
70dd370f 20092 /* import|export vpn [route-map RMAP_NAME] */
b9c7bc5a
PZ
20093 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
20094 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 20095
12a844a5
DS
20096 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
20097 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
20098
d62a17ae 20099 /* ttl_security commands */
20100 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
20101 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
20102
d1adb448
PG
20103 /* "bgp tcp-keepalive" commands */
20104 install_element(BGP_NODE, &bgp_tcp_keepalive_cmd);
20105 install_element(BGP_NODE, &no_bgp_tcp_keepalive_cmd);
20106
d62a17ae 20107 /* "show [ip] bgp memory" commands. */
20108 install_element(VIEW_NODE, &show_bgp_memory_cmd);
20109
acf71666
MK
20110 /* "show bgp martian next-hop" */
20111 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
20112
48ecf8f5
DS
20113 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
20114
d62a17ae 20115 /* "show [ip] bgp views" commands. */
20116 install_element(VIEW_NODE, &show_bgp_views_cmd);
20117
20118 /* "show [ip] bgp vrfs" commands. */
20119 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
20120
20121 /* Community-list. */
20122 community_list_vty();
ddb5b488 20123
ed0e57e3
DA
20124 community_alias_vty();
20125
ddb5b488 20126 /* vpn-policy commands */
b9c7bc5a
PZ
20127 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
20128 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
20129 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
20130 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
20131 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
20132 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
20133 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
20134 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
20135 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
20136 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
20137 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
20138 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 20139
301ad80a
PG
20140 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
20141 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
20142
b9c7bc5a
PZ
20143 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
20144 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
20145 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
20146 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
b9c7bc5a
PZ
20147 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
20148 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
20149 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
20150 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
20151 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
20152 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
4ab46701
AR
20153
20154 /* tcp-mss command */
20155 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
20156 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
bfaab44d
HS
20157
20158 /* srv6 commands */
ea372e81 20159 install_element(VIEW_NODE, &show_bgp_srv6_cmd);
bfaab44d 20160 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
0249b8b6 20161 install_element(BGP_NODE, &no_bgp_segment_routing_srv6_cmd);
a0281b2e 20162 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
0249b8b6 20163 install_element(BGP_SRV6_NODE, &no_bgp_srv6_locator_cmd);
b72c9e14
HS
20164 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
20165 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
527588aa 20166 install_element(BGP_NODE, &bgp_sid_vpn_export_cmd);
e606d8ec 20167 install_element(BGP_NODE, &no_bgp_sid_vpn_export_cmd);
4cd690ae
PG
20168
20169 bgp_vty_if_init();
718e3744 20170}
6b0655a2 20171
718e3744 20172#include "memory.h"
20173#include "bgp_regex.h"
20174#include "bgp_clist.h"
20175#include "bgp_ecommunity.h"
20176
20177/* VTY functions. */
20178
20179/* Direction value to string conversion. */
d62a17ae 20180static const char *community_direct_str(int direct)
20181{
20182 switch (direct) {
20183 case COMMUNITY_DENY:
20184 return "deny";
20185 case COMMUNITY_PERMIT:
20186 return "permit";
20187 default:
20188 return "unknown";
20189 }
718e3744 20190}
20191
20192/* Display error string. */
d62a17ae 20193static void community_list_perror(struct vty *vty, int ret)
20194{
20195 switch (ret) {
20196 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
20197 vty_out(vty, "%% Can't find community-list\n");
20198 break;
20199 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
20200 vty_out(vty, "%% Malformed community-list value\n");
20201 break;
20202 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
20203 vty_out(vty,
20204 "%% Community name conflict, previously defined as standard community\n");
20205 break;
20206 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
20207 vty_out(vty,
20208 "%% Community name conflict, previously defined as expanded community\n");
20209 break;
20210 }
718e3744 20211}
20212
5bf15956
DW
20213/* "community-list" keyword help string. */
20214#define COMMUNITY_LIST_STR "Add a community list entry\n"
20215
7336e101
SP
20216/*community-list standard */
20217DEFUN (community_list_standard,
20218 bgp_community_list_standard_cmd,
a2099c1d 20219 "bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 20220 BGP_STR
718e3744 20221 COMMUNITY_LIST_STR
20222 "Community list number (standard)\n"
5bf15956 20223 "Add an standard community-list entry\n"
718e3744 20224 "Community list name\n"
2f8cc0e5
DA
20225 "Sequence number of an entry\n"
20226 "Sequence number\n"
718e3744 20227 "Specify community to reject\n"
20228 "Specify community to accept\n"
20229 COMMUNITY_VAL_STR)
20230{
d62a17ae 20231 char *cl_name_or_number = NULL;
2f8cc0e5 20232 char *seq = NULL;
d62a17ae 20233 int direct = 0;
20234 int style = COMMUNITY_LIST_STANDARD;
d62a17ae 20235 int idx = 0;
7336e101 20236
e34627f9 20237 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20238 seq = argv[idx]->arg;
20239
20240 idx = 0;
d62a17ae 20241 argv_find(argv, argc, "(1-99)", &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_standard_all,
20264 no_bgp_community_list_standard_all_cmd,
a2099c1d 20265 "no bgp community-list <(1-99)|standard 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 (standard)\n"
20270 "Add an standard 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;
174b5cb9 20279 char *str = NULL;
d62a17ae 20280 int direct = 0;
20281 int style = COMMUNITY_LIST_STANDARD;
2f8cc0e5 20282 char *seq = NULL;
d62a17ae 20283 int idx = 0;
7336e101 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);
20300 }
20301
20302 idx = 0;
d62a17ae 20303 argv_find(argv, argc, "(1-99)", &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}
7336e101 20319
174b5cb9 20320ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
a2099c1d 20321 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME>",
174b5cb9
DA
20322 NO_STR BGP_STR COMMUNITY_LIST_STR
20323 "Community list number (standard)\n"
20324 "Add an standard community-list entry\n"
20325 "Community list name\n")
20326
7336e101
SP
20327/*community-list expanded */
20328DEFUN (community_list_expanded_all,
20329 bgp_community_list_expanded_all_cmd,
a2099c1d 20330 "bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
20331 BGP_STR
20332 COMMUNITY_LIST_STR
718e3744 20333 "Community list number (expanded)\n"
5bf15956 20334 "Add an expanded community-list entry\n"
718e3744 20335 "Community list name\n"
2f8cc0e5
DA
20336 "Sequence number of an entry\n"
20337 "Sequence number\n"
718e3744 20338 "Specify community to reject\n"
20339 "Specify community to accept\n"
20340 COMMUNITY_VAL_STR)
20341{
d62a17ae 20342 char *cl_name_or_number = NULL;
2f8cc0e5 20343 char *seq = NULL;
d62a17ae 20344 int direct = 0;
20345 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 20346 int idx = 0;
7b9a4750 20347
e34627f9 20348 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20349 seq = argv[idx]->arg;
20350
20351 idx = 0;
20352
d62a17ae 20353 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 20354 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 20355 cl_name_or_number = argv[idx]->arg;
20356 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20357 : COMMUNITY_DENY;
20358 argv_find(argv, argc, "AA:NN", &idx);
20359 char *str = argv_concat(argv, argc, idx);
42f914d4 20360
2f8cc0e5
DA
20361 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
20362 direct, style);
42f914d4 20363
d62a17ae 20364 XFREE(MTYPE_TMP, str);
42f914d4 20365
d62a17ae 20366 if (ret < 0) {
20367 /* Display error string. */
20368 community_list_perror(vty, ret);
20369 return CMD_WARNING_CONFIG_FAILED;
20370 }
42f914d4 20371
d62a17ae 20372 return CMD_SUCCESS;
718e3744 20373}
20374
7336e101
SP
20375DEFUN (no_community_list_expanded_all,
20376 no_bgp_community_list_expanded_all_cmd,
a2099c1d 20377 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
20378 NO_STR
20379 BGP_STR
20380 COMMUNITY_LIST_STR
20381 "Community list number (expanded)\n"
20382 "Add an expanded community-list entry\n"
20383 "Community list name\n"
2f8cc0e5
DA
20384 "Sequence number of an entry\n"
20385 "Sequence number\n"
7336e101
SP
20386 "Specify community to reject\n"
20387 "Specify community to accept\n"
20388 COMMUNITY_VAL_STR)
718e3744 20389{
d62a17ae 20390 char *cl_name_or_number = NULL;
2f8cc0e5 20391 char *seq = NULL;
174b5cb9 20392 char *str = NULL;
d62a17ae 20393 int direct = 0;
20394 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 20395 int idx = 0;
174b5cb9 20396
e34627f9 20397 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20398 seq = argv[idx]->arg;
20399
20400 idx = 0;
174b5cb9
DA
20401 argv_find(argv, argc, "permit", &idx);
20402 argv_find(argv, argc, "deny", &idx);
20403
20404 if (idx) {
20405 direct = argv_find(argv, argc, "permit", &idx)
20406 ? COMMUNITY_PERMIT
20407 : COMMUNITY_DENY;
20408
20409 idx = 0;
20410 argv_find(argv, argc, "AA:NN", &idx);
20411 str = argv_concat(argv, argc, idx);
7336e101 20412 }
174b5cb9
DA
20413
20414 idx = 0;
d62a17ae 20415 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 20416 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 20417 cl_name_or_number = argv[idx]->arg;
42f914d4 20418
2f8cc0e5 20419 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 20420 direct, style);
42f914d4 20421
d62a17ae 20422 XFREE(MTYPE_TMP, str);
daf9ddbb 20423
d62a17ae 20424 if (ret < 0) {
20425 community_list_perror(vty, ret);
20426 return CMD_WARNING_CONFIG_FAILED;
20427 }
42f914d4 20428
d62a17ae 20429 return CMD_SUCCESS;
718e3744 20430}
20431
36d4bb44
EB
20432ALIAS(no_community_list_expanded_all,
20433 no_bgp_community_list_expanded_all_list_cmd,
a2099c1d 20434 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME>",
36d4bb44 20435 NO_STR BGP_STR COMMUNITY_LIST_STR
174b5cb9
DA
20436 "Community list number (expanded)\n"
20437 "Add an expanded community-list entry\n"
20438 "Community list name\n")
20439
8d9b8ed9
PM
20440/* Return configuration string of community-list entry. */
20441static const char *community_list_config_str(struct community_entry *entry)
20442{
20443 const char *str;
20444
20445 if (entry->any)
20446 str = "";
20447 else {
20448 if (entry->style == COMMUNITY_LIST_STANDARD)
c0945b78 20449 str = community_str(entry->u.com, false, false);
8d9b8ed9 20450 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
c0945b78 20451 str = lcommunity_str(entry->u.lcom, false, false);
8d9b8ed9
PM
20452 else
20453 str = entry->config;
20454 }
20455 return str;
20456}
20457
d62a17ae 20458static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 20459{
d62a17ae 20460 struct community_entry *entry;
718e3744 20461
d62a17ae 20462 for (entry = list->head; entry; entry = entry->next) {
20463 if (entry == list->head) {
20464 if (all_digit(list->name))
20465 vty_out(vty, "Community %s list %s\n",
20466 entry->style == COMMUNITY_LIST_STANDARD
20467 ? "standard"
20468 : "(expanded) access",
20469 list->name);
20470 else
20471 vty_out(vty, "Named Community %s list %s\n",
20472 entry->style == COMMUNITY_LIST_STANDARD
20473 ? "standard"
20474 : "expanded",
20475 list->name);
20476 }
20477 if (entry->any)
20478 vty_out(vty, " %s\n",
20479 community_direct_str(entry->direct));
20480 else
20481 vty_out(vty, " %s %s\n",
20482 community_direct_str(entry->direct),
8d9b8ed9 20483 community_list_config_str(entry));
d62a17ae 20484 }
718e3744 20485}
20486
7336e101
SP
20487DEFUN (show_community_list,
20488 show_bgp_community_list_cmd,
20489 "show bgp community-list",
718e3744 20490 SHOW_STR
7336e101 20491 BGP_STR
718e3744 20492 "List community-list\n")
20493{
d62a17ae 20494 struct community_list *list;
20495 struct community_list_master *cm;
718e3744 20496
d62a17ae 20497 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20498 if (!cm)
20499 return CMD_SUCCESS;
718e3744 20500
d62a17ae 20501 for (list = cm->num.head; list; list = list->next)
20502 community_list_show(vty, list);
718e3744 20503
d62a17ae 20504 for (list = cm->str.head; list; list = list->next)
20505 community_list_show(vty, list);
718e3744 20506
d62a17ae 20507 return CMD_SUCCESS;
718e3744 20508}
20509
7336e101
SP
20510DEFUN (show_community_list_arg,
20511 show_bgp_community_list_arg_cmd,
a2099c1d 20512 "show bgp community-list <(1-500)|COMMUNITY_LIST_NAME> detail",
7336e101
SP
20513 SHOW_STR
20514 BGP_STR
718e3744 20515 "List community-list\n"
20516 "Community-list number\n"
960b69b9 20517 "Community-list name\n"
20518 "Detailed information on community-list\n")
718e3744 20519{
d62a17ae 20520 int idx_comm_list = 3;
20521 struct community_list *list;
718e3744 20522
e237b0d2 20523 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 20524 COMMUNITY_LIST_MASTER);
20525 if (!list) {
20526 vty_out(vty, "%% Can't find community-list\n");
20527 return CMD_WARNING;
20528 }
718e3744 20529
d62a17ae 20530 community_list_show(vty, list);
718e3744 20531
d62a17ae 20532 return CMD_SUCCESS;
718e3744 20533}
6b0655a2 20534
57d187bc
JS
20535/*
20536 * Large Community code.
20537 */
d62a17ae 20538static int lcommunity_list_set_vty(struct vty *vty, int argc,
20539 struct cmd_token **argv, int style,
20540 int reject_all_digit_name)
20541{
20542 int ret;
20543 int direct;
20544 char *str;
20545 int idx = 0;
20546 char *cl_name;
2f8cc0e5
DA
20547 char *seq = NULL;
20548
a08032fe 20549 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 20550 seq = argv[idx]->arg;
d62a17ae 20551
2f8cc0e5 20552 idx = 0;
d62a17ae 20553 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20554 : COMMUNITY_DENY;
20555
20556 /* All digit name check. */
20557 idx = 0;
a2099c1d 20558 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
d62a17ae 20559 argv_find(argv, argc, "(1-99)", &idx);
20560 argv_find(argv, argc, "(100-500)", &idx);
20561 cl_name = argv[idx]->arg;
20562 if (reject_all_digit_name && all_digit(cl_name)) {
20563 vty_out(vty, "%% Community name cannot have all digits\n");
20564 return CMD_WARNING_CONFIG_FAILED;
20565 }
20566
20567 idx = 0;
20568 argv_find(argv, argc, "AA:BB:CC", &idx);
20569 argv_find(argv, argc, "LINE", &idx);
20570 /* Concat community string argument. */
20571 if (idx)
20572 str = argv_concat(argv, argc, idx);
20573 else
20574 str = NULL;
20575
2f8cc0e5 20576 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
d62a17ae 20577
20578 /* Free temporary community list string allocated by
20579 argv_concat(). */
0a22ddfb 20580 XFREE(MTYPE_TMP, str);
d62a17ae 20581
20582 if (ret < 0) {
20583 community_list_perror(vty, ret);
20584 return CMD_WARNING_CONFIG_FAILED;
20585 }
20586 return CMD_SUCCESS;
20587}
20588
20589static int lcommunity_list_unset_vty(struct vty *vty, int argc,
20590 struct cmd_token **argv, int style)
20591{
20592 int ret;
20593 int direct = 0;
20594 char *str = NULL;
20595 int idx = 0;
2f8cc0e5 20596 char *seq = NULL;
d62a17ae 20597
a08032fe 20598 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 20599 seq = argv[idx]->arg;
d62a17ae 20600
2f8cc0e5 20601 idx = 0;
d62a17ae 20602 argv_find(argv, argc, "permit", &idx);
20603 argv_find(argv, argc, "deny", &idx);
20604
20605 if (idx) {
20606 /* Check the list direct. */
20607 if (strncmp(argv[idx]->arg, "p", 1) == 0)
20608 direct = COMMUNITY_PERMIT;
20609 else
20610 direct = COMMUNITY_DENY;
20611
20612 idx = 0;
20613 argv_find(argv, argc, "LINE", &idx);
20614 argv_find(argv, argc, "AA:AA:NN", &idx);
20615 /* Concat community string argument. */
20616 str = argv_concat(argv, argc, idx);
20617 }
20618
20619 idx = 0;
20620 argv_find(argv, argc, "(1-99)", &idx);
20621 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 20622 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
d62a17ae 20623
20624 /* Unset community list. */
2f8cc0e5 20625 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
d62a17ae 20626 style);
20627
20628 /* Free temporary community list string allocated by
20629 argv_concat(). */
0a22ddfb 20630 XFREE(MTYPE_TMP, str);
d62a17ae 20631
20632 if (ret < 0) {
20633 community_list_perror(vty, ret);
20634 return CMD_WARNING_CONFIG_FAILED;
20635 }
20636
20637 return CMD_SUCCESS;
57d187bc
JS
20638}
20639
20640/* "large-community-list" keyword help string. */
20641#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
20642#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
20643
7336e101
SP
20644DEFUN (lcommunity_list_standard,
20645 bgp_lcommunity_list_standard_cmd,
a08032fe 20646 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
20647 BGP_STR
20648 LCOMMUNITY_LIST_STR
20649 "Large Community list number (standard)\n"
2f8cc0e5
DA
20650 "Sequence number of an entry\n"
20651 "Sequence number\n"
7336e101
SP
20652 "Specify large community to reject\n"
20653 "Specify large community to accept\n"
20654 LCOMMUNITY_VAL_STR)
52951b63 20655{
d62a17ae 20656 return lcommunity_list_set_vty(vty, argc, argv,
20657 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
20658}
20659
7336e101
SP
20660DEFUN (lcommunity_list_expanded,
20661 bgp_lcommunity_list_expanded_cmd,
a08032fe 20662 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20663 BGP_STR
20664 LCOMMUNITY_LIST_STR
20665 "Large Community list number (expanded)\n"
2f8cc0e5
DA
20666 "Sequence number of an entry\n"
20667 "Sequence number\n"
7336e101
SP
20668 "Specify large community to reject\n"
20669 "Specify large community to accept\n"
20670 "An ordered list as a regular-expression\n")
57d187bc 20671{
d62a17ae 20672 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 20673 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
20674}
20675
7336e101
SP
20676DEFUN (lcommunity_list_name_standard,
20677 bgp_lcommunity_list_name_standard_cmd,
a2099c1d 20678 "bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
20679 BGP_STR
20680 LCOMMUNITY_LIST_STR
20681 "Specify standard large-community-list\n"
20682 "Large Community list name\n"
2f8cc0e5
DA
20683 "Sequence number of an entry\n"
20684 "Sequence number\n"
7336e101
SP
20685 "Specify large community to reject\n"
20686 "Specify large community to accept\n"
20687 LCOMMUNITY_VAL_STR)
52951b63 20688{
d62a17ae 20689 return lcommunity_list_set_vty(vty, argc, argv,
20690 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
20691}
20692
7336e101
SP
20693DEFUN (lcommunity_list_name_expanded,
20694 bgp_lcommunity_list_name_expanded_cmd,
a2099c1d 20695 "bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20696 BGP_STR
20697 LCOMMUNITY_LIST_STR
20698 "Specify expanded large-community-list\n"
20699 "Large Community list name\n"
2f8cc0e5
DA
20700 "Sequence number of an entry\n"
20701 "Sequence number\n"
7336e101
SP
20702 "Specify large community to reject\n"
20703 "Specify large community to accept\n"
20704 "An ordered list as a regular-expression\n")
57d187bc 20705{
d62a17ae 20706 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 20707 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
20708}
20709
4378f57c
DA
20710DEFUN (no_lcommunity_list_all,
20711 no_bgp_lcommunity_list_all_cmd,
a2099c1d 20712 "no bgp large-community-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME>",
7336e101
SP
20713 NO_STR
20714 BGP_STR
20715 LCOMMUNITY_LIST_STR
20716 "Large Community list number (standard)\n"
20717 "Large Community list number (expanded)\n"
20718 "Large Community list name\n")
57d187bc 20719{
7336e101
SP
20720 return lcommunity_list_unset_vty(vty, argc, argv,
20721 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
20722}
20723
4378f57c
DA
20724DEFUN (no_lcommunity_list_name_standard_all,
20725 no_bgp_lcommunity_list_name_standard_all_cmd,
a2099c1d 20726 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME",
4378f57c
DA
20727 NO_STR
20728 BGP_STR
20729 LCOMMUNITY_LIST_STR
20730 "Specify standard large-community-list\n"
20731 "Large Community list name\n")
20732{
20733 return lcommunity_list_unset_vty(vty, argc, argv,
20734 LARGE_COMMUNITY_LIST_STANDARD);
20735}
20736
7336e101
SP
20737DEFUN (no_lcommunity_list_name_expanded_all,
20738 no_bgp_lcommunity_list_name_expanded_all_cmd,
a2099c1d 20739 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME",
7336e101
SP
20740 NO_STR
20741 BGP_STR
20742 LCOMMUNITY_LIST_STR
20743 "Specify expanded large-community-list\n"
20744 "Large Community list name\n")
57d187bc 20745{
d62a17ae 20746 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 20747 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
20748}
20749
7336e101
SP
20750DEFUN (no_lcommunity_list_standard,
20751 no_bgp_lcommunity_list_standard_cmd,
a08032fe 20752 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
20753 NO_STR
20754 BGP_STR
20755 LCOMMUNITY_LIST_STR
20756 "Large Community list number (standard)\n"
2f8cc0e5
DA
20757 "Sequence number of an entry\n"
20758 "Sequence number\n"
7336e101
SP
20759 "Specify large community to reject\n"
20760 "Specify large community to accept\n"
20761 LCOMMUNITY_VAL_STR)
57d187bc 20762{
d62a17ae 20763 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 20764 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
20765}
20766
7336e101
SP
20767DEFUN (no_lcommunity_list_expanded,
20768 no_bgp_lcommunity_list_expanded_cmd,
a08032fe 20769 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20770 NO_STR
20771 BGP_STR
20772 LCOMMUNITY_LIST_STR
20773 "Large Community list number (expanded)\n"
2f8cc0e5
DA
20774 "Sequence number of an entry\n"
20775 "Sequence number\n"
7336e101
SP
20776 "Specify large community to reject\n"
20777 "Specify large community to accept\n"
20778 "An ordered list as a regular-expression\n")
57d187bc 20779{
d62a17ae 20780 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 20781 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
20782}
20783
7336e101
SP
20784DEFUN (no_lcommunity_list_name_standard,
20785 no_bgp_lcommunity_list_name_standard_cmd,
a2099c1d 20786 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
20787 NO_STR
20788 BGP_STR
20789 LCOMMUNITY_LIST_STR
20790 "Specify standard large-community-list\n"
20791 "Large Community list name\n"
2f8cc0e5
DA
20792 "Sequence number of an entry\n"
20793 "Sequence number\n"
7336e101
SP
20794 "Specify large community to reject\n"
20795 "Specify large community to accept\n"
20796 LCOMMUNITY_VAL_STR)
57d187bc 20797{
d62a17ae 20798 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 20799 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
20800}
20801
7336e101
SP
20802DEFUN (no_lcommunity_list_name_expanded,
20803 no_bgp_lcommunity_list_name_expanded_cmd,
a2099c1d 20804 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20805 NO_STR
20806 BGP_STR
20807 LCOMMUNITY_LIST_STR
20808 "Specify expanded large-community-list\n"
20809 "Large community list name\n"
2f8cc0e5
DA
20810 "Sequence number of an entry\n"
20811 "Sequence number\n"
7336e101
SP
20812 "Specify large community to reject\n"
20813 "Specify large community to accept\n"
20814 "An ordered list as a regular-expression\n")
57d187bc 20815{
d62a17ae 20816 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 20817 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
20818}
20819
d62a17ae 20820static void lcommunity_list_show(struct vty *vty, struct community_list *list)
20821{
20822 struct community_entry *entry;
20823
20824 for (entry = list->head; entry; entry = entry->next) {
20825 if (entry == list->head) {
20826 if (all_digit(list->name))
20827 vty_out(vty, "Large community %s list %s\n",
169b72c8 20828 entry->style ==
20829 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 20830 ? "standard"
20831 : "(expanded) access",
20832 list->name);
20833 else
20834 vty_out(vty,
20835 "Named large community %s list %s\n",
169b72c8 20836 entry->style ==
20837 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 20838 ? "standard"
20839 : "expanded",
20840 list->name);
20841 }
20842 if (entry->any)
20843 vty_out(vty, " %s\n",
20844 community_direct_str(entry->direct));
20845 else
20846 vty_out(vty, " %s %s\n",
20847 community_direct_str(entry->direct),
8d9b8ed9 20848 community_list_config_str(entry));
d62a17ae 20849 }
57d187bc
JS
20850}
20851
7336e101
SP
20852DEFUN (show_lcommunity_list,
20853 show_bgp_lcommunity_list_cmd,
20854 "show bgp large-community-list",
57d187bc 20855 SHOW_STR
7336e101 20856 BGP_STR
57d187bc
JS
20857 "List large-community list\n")
20858{
d62a17ae 20859 struct community_list *list;
20860 struct community_list_master *cm;
57d187bc 20861
d62a17ae 20862 cm = community_list_master_lookup(bgp_clist,
20863 LARGE_COMMUNITY_LIST_MASTER);
20864 if (!cm)
20865 return CMD_SUCCESS;
57d187bc 20866
d62a17ae 20867 for (list = cm->num.head; list; list = list->next)
20868 lcommunity_list_show(vty, list);
57d187bc 20869
d62a17ae 20870 for (list = cm->str.head; list; list = list->next)
20871 lcommunity_list_show(vty, list);
57d187bc 20872
d62a17ae 20873 return CMD_SUCCESS;
57d187bc
JS
20874}
20875
7336e101
SP
20876DEFUN (show_lcommunity_list_arg,
20877 show_bgp_lcommunity_list_arg_cmd,
a2099c1d 20878 "show bgp large-community-list <(1-500)|LCOMMUNITY_LIST_NAME> detail",
7336e101
SP
20879 SHOW_STR
20880 BGP_STR
57d187bc 20881 "List large-community list\n"
960b69b9 20882 "Large-community-list number\n"
20883 "Large-community-list name\n"
20884 "Detailed information on large-community-list\n")
57d187bc 20885{
d62a17ae 20886 struct community_list *list;
57d187bc 20887
e237b0d2 20888 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
d62a17ae 20889 LARGE_COMMUNITY_LIST_MASTER);
20890 if (!list) {
960b69b9 20891 vty_out(vty, "%% Can't find large-community-list\n");
d62a17ae 20892 return CMD_WARNING;
20893 }
57d187bc 20894
d62a17ae 20895 lcommunity_list_show(vty, list);
57d187bc 20896
d62a17ae 20897 return CMD_SUCCESS;
57d187bc
JS
20898}
20899
718e3744 20900/* "extcommunity-list" keyword help string. */
20901#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
20902#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
20903
7336e101
SP
20904DEFUN (extcommunity_list_standard,
20905 bgp_extcommunity_list_standard_cmd,
a2099c1d 20906 "bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 20907 BGP_STR
718e3744 20908 EXTCOMMUNITY_LIST_STR
20909 "Extended Community list number (standard)\n"
718e3744 20910 "Specify standard extcommunity-list\n"
5bf15956 20911 "Community list name\n"
2f8cc0e5
DA
20912 "Sequence number of an entry\n"
20913 "Sequence number\n"
718e3744 20914 "Specify community to reject\n"
20915 "Specify community to accept\n"
20916 EXTCOMMUNITY_VAL_STR)
20917{
d62a17ae 20918 int style = EXTCOMMUNITY_LIST_STANDARD;
20919 int direct = 0;
20920 char *cl_number_or_name = NULL;
2f8cc0e5 20921 char *seq = NULL;
42f914d4 20922
d62a17ae 20923 int idx = 0;
7b9a4750 20924
d62a17ae 20925 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 20926 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 20927 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 20928
a08032fe 20929 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20930 seq = argv[idx]->arg;
20931
d62a17ae 20932 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20933 : COMMUNITY_DENY;
20934 argv_find(argv, argc, "AA:NN", &idx);
20935 char *str = argv_concat(argv, argc, idx);
42f914d4 20936
2f8cc0e5 20937 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 20938 direct, style);
42f914d4 20939
d62a17ae 20940 XFREE(MTYPE_TMP, str);
42f914d4 20941
d62a17ae 20942 if (ret < 0) {
20943 community_list_perror(vty, ret);
20944 return CMD_WARNING_CONFIG_FAILED;
20945 }
42f914d4 20946
d62a17ae 20947 return CMD_SUCCESS;
718e3744 20948}
20949
7336e101
SP
20950DEFUN (extcommunity_list_name_expanded,
20951 bgp_extcommunity_list_name_expanded_cmd,
a2099c1d 20952 "bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20953 BGP_STR
20954 EXTCOMMUNITY_LIST_STR
5bf15956 20955 "Extended Community list number (expanded)\n"
718e3744 20956 "Specify expanded extcommunity-list\n"
20957 "Extended Community list name\n"
2f8cc0e5
DA
20958 "Sequence number of an entry\n"
20959 "Sequence number\n"
718e3744 20960 "Specify community to reject\n"
20961 "Specify community to accept\n"
20962 "An ordered list as a regular-expression\n")
20963{
d62a17ae 20964 int style = EXTCOMMUNITY_LIST_EXPANDED;
20965 int direct = 0;
20966 char *cl_number_or_name = NULL;
2f8cc0e5 20967 char *seq = NULL;
d62a17ae 20968 int idx = 0;
7336e101 20969
d62a17ae 20970 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 20971 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 20972 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 20973
a08032fe 20974 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20975 seq = argv[idx]->arg;
20976
d62a17ae 20977 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20978 : COMMUNITY_DENY;
20979 argv_find(argv, argc, "LINE", &idx);
20980 char *str = argv_concat(argv, argc, idx);
42f914d4 20981
2f8cc0e5 20982 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 20983 direct, style);
42f914d4 20984
d62a17ae 20985 XFREE(MTYPE_TMP, str);
42f914d4 20986
d62a17ae 20987 if (ret < 0) {
20988 community_list_perror(vty, ret);
20989 return CMD_WARNING_CONFIG_FAILED;
20990 }
42f914d4 20991
d62a17ae 20992 return CMD_SUCCESS;
718e3744 20993}
20994
7336e101
SP
20995DEFUN (no_extcommunity_list_standard_all,
20996 no_bgp_extcommunity_list_standard_all_cmd,
a2099c1d 20997 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
20998 NO_STR
20999 BGP_STR
21000 EXTCOMMUNITY_LIST_STR
813d4307 21001 "Extended Community list number (standard)\n"
718e3744 21002 "Specify standard extcommunity-list\n"
5bf15956 21003 "Community list name\n"
2f8cc0e5
DA
21004 "Sequence number of an entry\n"
21005 "Sequence number\n"
718e3744 21006 "Specify community to reject\n"
21007 "Specify community to accept\n"
21008 EXTCOMMUNITY_VAL_STR)
21009{
d62a17ae 21010 int style = EXTCOMMUNITY_LIST_STANDARD;
21011 int direct = 0;
21012 char *cl_number_or_name = NULL;
d4455c89 21013 char *str = NULL;
2f8cc0e5 21014 char *seq = NULL;
d62a17ae 21015 int idx = 0;
d4455c89 21016
a08032fe 21017 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
21018 seq = argv[idx]->arg;
21019
21020 idx = 0;
d4455c89
DA
21021 argv_find(argv, argc, "permit", &idx);
21022 argv_find(argv, argc, "deny", &idx);
d4455c89
DA
21023 if (idx) {
21024 direct = argv_find(argv, argc, "permit", &idx)
21025 ? COMMUNITY_PERMIT
21026 : COMMUNITY_DENY;
21027
21028 idx = 0;
21029 argv_find(argv, argc, "AA:NN", &idx);
21030 str = argv_concat(argv, argc, idx);
21031 }
21032
21033 idx = 0;
d62a17ae 21034 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 21035 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 21036 cl_number_or_name = argv[idx]->arg;
42f914d4 21037
d62a17ae 21038 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 21039 seq, direct, style);
42f914d4 21040
d62a17ae 21041 XFREE(MTYPE_TMP, str);
42f914d4 21042
d62a17ae 21043 if (ret < 0) {
21044 community_list_perror(vty, ret);
21045 return CMD_WARNING_CONFIG_FAILED;
21046 }
42f914d4 21047
d62a17ae 21048 return CMD_SUCCESS;
718e3744 21049}
21050
d4455c89
DA
21051ALIAS(no_extcommunity_list_standard_all,
21052 no_bgp_extcommunity_list_standard_all_list_cmd,
a2099c1d 21053 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME>",
36d4bb44 21054 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
21055 "Extended Community list number (standard)\n"
21056 "Specify standard extcommunity-list\n"
21057 "Community list name\n")
21058
7336e101
SP
21059DEFUN (no_extcommunity_list_expanded_all,
21060 no_bgp_extcommunity_list_expanded_all_cmd,
a2099c1d 21061 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
21062 NO_STR
21063 BGP_STR
21064 EXTCOMMUNITY_LIST_STR
718e3744 21065 "Extended Community list number (expanded)\n"
718e3744 21066 "Specify expanded extcommunity-list\n"
5bf15956 21067 "Extended Community list name\n"
2f8cc0e5
DA
21068 "Sequence number of an entry\n"
21069 "Sequence number\n"
718e3744 21070 "Specify community to reject\n"
21071 "Specify community to accept\n"
21072 "An ordered list as a regular-expression\n")
21073{
d62a17ae 21074 int style = EXTCOMMUNITY_LIST_EXPANDED;
21075 int direct = 0;
21076 char *cl_number_or_name = NULL;
d4455c89 21077 char *str = NULL;
2f8cc0e5 21078 char *seq = NULL;
d62a17ae 21079 int idx = 0;
d4455c89 21080
a08032fe 21081 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
21082 seq = argv[idx]->arg;
21083
21084 idx = 0;
d4455c89
DA
21085 argv_find(argv, argc, "permit", &idx);
21086 argv_find(argv, argc, "deny", &idx);
21087
21088 if (idx) {
21089 direct = argv_find(argv, argc, "permit", &idx)
21090 ? COMMUNITY_PERMIT
21091 : COMMUNITY_DENY;
21092
21093 idx = 0;
21094 argv_find(argv, argc, "LINE", &idx);
21095 str = argv_concat(argv, argc, idx);
21096 }
21097
21098 idx = 0;
d62a17ae 21099 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 21100 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 21101 cl_number_or_name = argv[idx]->arg;
42f914d4 21102
d62a17ae 21103 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 21104 seq, direct, style);
42f914d4 21105
d62a17ae 21106 XFREE(MTYPE_TMP, str);
42f914d4 21107
d62a17ae 21108 if (ret < 0) {
21109 community_list_perror(vty, ret);
21110 return CMD_WARNING_CONFIG_FAILED;
21111 }
42f914d4 21112
d62a17ae 21113 return CMD_SUCCESS;
718e3744 21114}
21115
d4455c89
DA
21116ALIAS(no_extcommunity_list_expanded_all,
21117 no_bgp_extcommunity_list_expanded_all_list_cmd,
a2099c1d 21118 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME>",
36d4bb44 21119 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
21120 "Extended Community list number (expanded)\n"
21121 "Specify expanded extcommunity-list\n"
21122 "Extended Community list name\n")
21123
d62a17ae 21124static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 21125{
d62a17ae 21126 struct community_entry *entry;
718e3744 21127
d62a17ae 21128 for (entry = list->head; entry; entry = entry->next) {
21129 if (entry == list->head) {
21130 if (all_digit(list->name))
21131 vty_out(vty, "Extended community %s list %s\n",
21132 entry->style == EXTCOMMUNITY_LIST_STANDARD
21133 ? "standard"
21134 : "(expanded) access",
21135 list->name);
21136 else
21137 vty_out(vty,
21138 "Named extended community %s list %s\n",
21139 entry->style == EXTCOMMUNITY_LIST_STANDARD
21140 ? "standard"
21141 : "expanded",
21142 list->name);
21143 }
21144 if (entry->any)
21145 vty_out(vty, " %s\n",
21146 community_direct_str(entry->direct));
21147 else
21148 vty_out(vty, " %s %s\n",
21149 community_direct_str(entry->direct),
8d9b8ed9 21150 community_list_config_str(entry));
d62a17ae 21151 }
718e3744 21152}
21153
7336e101
SP
21154DEFUN (show_extcommunity_list,
21155 show_bgp_extcommunity_list_cmd,
21156 "show bgp extcommunity-list",
718e3744 21157 SHOW_STR
7336e101 21158 BGP_STR
718e3744 21159 "List extended-community list\n")
21160{
d62a17ae 21161 struct community_list *list;
21162 struct community_list_master *cm;
718e3744 21163
d62a17ae 21164 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
21165 if (!cm)
21166 return CMD_SUCCESS;
718e3744 21167
d62a17ae 21168 for (list = cm->num.head; list; list = list->next)
21169 extcommunity_list_show(vty, list);
718e3744 21170
d62a17ae 21171 for (list = cm->str.head; list; list = list->next)
21172 extcommunity_list_show(vty, list);
718e3744 21173
d62a17ae 21174 return CMD_SUCCESS;
718e3744 21175}
21176
7336e101
SP
21177DEFUN (show_extcommunity_list_arg,
21178 show_bgp_extcommunity_list_arg_cmd,
a2099c1d 21179 "show bgp extcommunity-list <(1-500)|EXTCOMMUNITY_LIST_NAME> detail",
7336e101
SP
21180 SHOW_STR
21181 BGP_STR
718e3744 21182 "List extended-community list\n"
21183 "Extcommunity-list number\n"
960b69b9 21184 "Extcommunity-list name\n"
21185 "Detailed information on extcommunity-list\n")
718e3744 21186{
d62a17ae 21187 int idx_comm_list = 3;
21188 struct community_list *list;
718e3744 21189
e237b0d2 21190 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 21191 EXTCOMMUNITY_LIST_MASTER);
21192 if (!list) {
21193 vty_out(vty, "%% Can't find extcommunity-list\n");
21194 return CMD_WARNING;
21195 }
718e3744 21196
d62a17ae 21197 extcommunity_list_show(vty, list);
718e3744 21198
d62a17ae 21199 return CMD_SUCCESS;
718e3744 21200}
6b0655a2 21201
718e3744 21202/* Display community-list and extcommunity-list configuration. */
d62a17ae 21203static int community_list_config_write(struct vty *vty)
21204{
21205 struct community_list *list;
21206 struct community_entry *entry;
21207 struct community_list_master *cm;
21208 int write = 0;
21209
21210 /* Community-list. */
21211 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
21212
21213 for (list = cm->num.head; list; list = list->next)
21214 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
21215 vty_out(vty,
21216 "bgp community-list %s seq %" PRId64 " %s %s\n",
21217 list->name, entry->seq,
d62a17ae 21218 community_direct_str(entry->direct),
21219 community_list_config_str(entry));
21220 write++;
21221 }
21222 for (list = cm->str.head; list; list = list->next)
21223 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
21224 vty_out(vty,
21225 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
d62a17ae 21226 entry->style == COMMUNITY_LIST_STANDARD
21227 ? "standard"
21228 : "expanded",
2f8cc0e5
DA
21229 list->name, entry->seq,
21230 community_direct_str(entry->direct),
d62a17ae 21231 community_list_config_str(entry));
21232 write++;
21233 }
21234
21235 /* Extcommunity-list. */
21236 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
21237
21238 for (list = cm->num.head; list; list = list->next)
21239 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
21240 vty_out(vty,
21241 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
21242 list->name, entry->seq,
21243 community_direct_str(entry->direct),
d62a17ae 21244 community_list_config_str(entry));
21245 write++;
21246 }
21247 for (list = cm->str.head; list; list = list->next)
21248 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 21249 vty_out(vty,
6cde4b45 21250 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
d62a17ae 21251 entry->style == EXTCOMMUNITY_LIST_STANDARD
21252 ? "standard"
21253 : "expanded",
2f8cc0e5
DA
21254 list->name, entry->seq,
21255 community_direct_str(entry->direct),
d62a17ae 21256 community_list_config_str(entry));
21257 write++;
21258 }
21259
21260
21261 /* lcommunity-list. */
21262 cm = community_list_master_lookup(bgp_clist,
21263 LARGE_COMMUNITY_LIST_MASTER);
21264
21265 for (list = cm->num.head; list; list = list->next)
21266 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 21267 vty_out(vty,
6cde4b45 21268 "bgp large-community-list %s seq %" PRId64" %s %s\n",
2f8cc0e5
DA
21269 list->name, entry->seq,
21270 community_direct_str(entry->direct),
d62a17ae 21271 community_list_config_str(entry));
21272 write++;
21273 }
21274 for (list = cm->str.head; list; list = list->next)
21275 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 21276 vty_out(vty,
6cde4b45 21277 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
2f8cc0e5 21278
d62a17ae 21279 entry->style == LARGE_COMMUNITY_LIST_STANDARD
21280 ? "standard"
21281 : "expanded",
2f8cc0e5 21282 list->name, entry->seq, community_direct_str(entry->direct),
d62a17ae 21283 community_list_config_str(entry));
21284 write++;
21285 }
21286
21287 return write;
21288}
21289
612c2c15 21290static int community_list_config_write(struct vty *vty);
d62a17ae 21291static struct cmd_node community_list_node = {
f4b8291f 21292 .name = "community list",
62b346ee
DL
21293 .node = COMMUNITY_LIST_NODE,
21294 .prompt = "",
612c2c15 21295 .config_write = community_list_config_write,
718e3744 21296};
21297
d62a17ae 21298static void community_list_vty(void)
21299{
612c2c15 21300 install_node(&community_list_node);
d62a17ae 21301
21302 /* Community-list. */
7336e101
SP
21303 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
21304 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
21305 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 21306 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 21307 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 21308 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
21309 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
21310 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 21311
21312 /* Extcommunity-list. */
7336e101
SP
21313 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
21314 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
21315 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
d4455c89
DA
21316 install_element(CONFIG_NODE,
21317 &no_bgp_extcommunity_list_standard_all_list_cmd);
7336e101 21318 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
d4455c89
DA
21319 install_element(CONFIG_NODE,
21320 &no_bgp_extcommunity_list_expanded_all_list_cmd);
7336e101
SP
21321 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
21322 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 21323
21324 /* Large Community List */
7336e101 21325 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
7336e101
SP
21326 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
21327 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
7336e101 21328 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
4378f57c
DA
21329 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
21330 install_element(CONFIG_NODE,
21331 &no_bgp_lcommunity_list_name_standard_all_cmd);
7336e101
SP
21332 install_element(CONFIG_NODE,
21333 &no_bgp_lcommunity_list_name_expanded_all_cmd);
21334 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
21335 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
21336 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
21337 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
21338 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
21339 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
225096bc
DA
21340
21341 bgp_community_list_command_completion_setup();
5bf15956 21342}
ed0e57e3
DA
21343
21344static struct cmd_node community_alias_node = {
21345 .name = "community alias",
21346 .node = COMMUNITY_ALIAS_NODE,
21347 .prompt = "",
21348 .config_write = bgp_community_alias_write,
21349};
21350
21351void community_alias_vty(void)
21352{
21353 install_node(&community_alias_node);
21354
21355 /* Community-list. */
21356 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
b4ad2fae
DS
21357
21358 bgp_community_alias_command_completion_setup();
ed0e57e3 21359}