]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
Merge pull request #8508 from opensourcerouting/systemd-no-lib
[mirror_frr.git] / bgpd / bgp_vty.c
CommitLineData
718e3744 1/* BGP VTY interface.
896014f4
DL
2 * Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
718e3744 20
21#include <zebra.h>
22
23#include "command.h"
afec25d9 24#include "lib/json.h"
4ab46701 25#include "lib/sockopt.h"
5cb5f4d0 26#include "lib_errors.h"
ec0ab544 27#include "lib/zclient.h"
6f4eacf3 28#include "lib/printfrr.h"
718e3744 29#include "prefix.h"
30#include "plist.h"
31#include "buffer.h"
32#include "linklist.h"
33#include "stream.h"
34#include "thread.h"
35#include "log.h"
3b8b1855 36#include "memory.h"
1c0d8808 37#include "lib_vty.h"
4bf6a362 38#include "hash.h"
3f9c7369 39#include "queue.h"
039f3a34 40#include "filter.h"
5d5ba018 41#include "frrstr.h"
718e3744 42
43#include "bgpd/bgpd.h"
48ecf8f5 44#include "bgpd/bgp_attr_evpn.h"
4bf6a362 45#include "bgpd/bgp_advertise.h"
718e3744 46#include "bgpd/bgp_attr.h"
47#include "bgpd/bgp_aspath.h"
48#include "bgpd/bgp_community.h"
ed0e57e3 49#include "bgpd/bgp_community_alias.h"
4bf6a362 50#include "bgpd/bgp_ecommunity.h"
57d187bc 51#include "bgpd/bgp_lcommunity.h"
4bf6a362 52#include "bgpd/bgp_damp.h"
718e3744 53#include "bgpd/bgp_debug.h"
14454c9f 54#include "bgpd/bgp_errors.h"
e0701b79 55#include "bgpd/bgp_fsm.h"
4bf6a362 56#include "bgpd/bgp_nexthop.h"
718e3744 57#include "bgpd/bgp_open.h"
4bf6a362 58#include "bgpd/bgp_regex.h"
718e3744 59#include "bgpd/bgp_route.h"
c016b6c7 60#include "bgpd/bgp_mplsvpn.h"
718e3744 61#include "bgpd/bgp_zebra.h"
fee0f4c6 62#include "bgpd/bgp_table.h"
94f2b392 63#include "bgpd/bgp_vty.h"
165b5fff 64#include "bgpd/bgp_mpath.h"
cb1faec9 65#include "bgpd/bgp_packet.h"
3f9c7369 66#include "bgpd/bgp_updgrp.h"
c43ed2e4 67#include "bgpd/bgp_bfd.h"
555e09d4 68#include "bgpd/bgp_io.h"
94c2f693 69#include "bgpd/bgp_evpn.h"
dd65f45e 70#include "bgpd/bgp_evpn_vty.h"
b5e140c8 71#include "bgpd/bgp_evpn_mh.h"
dcc68b5e 72#include "bgpd/bgp_addpath.h"
48ecf8f5 73#include "bgpd/bgp_mac.h"
dd65f45e 74#include "bgpd/bgp_flowspec.h"
49e5a4a0 75#ifdef ENABLE_BGP_VNC
dd65f45e
DL
76#include "bgpd/rfapi/bgp_rfapi_cfg.h"
77#endif
78
ff8a8a7a
CS
79#include "northbound.h"
80#include "northbound_cli.h"
81#include "bgpd/bgp_nb.h"
82
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);
5d5393b9 129
dd65f45e
DL
130DEFINE_HOOK(bgp_inst_config_write,
131 (struct bgp *bgp, struct vty *vty),
8451921b
DL
132 (bgp, vty));
133DEFINE_HOOK(bgp_snmp_update_last_changed, (struct bgp *bgp), (bgp));
718e3744 134
d62a17ae 135static struct peer_group *listen_range_exists(struct bgp *bgp,
136 struct prefix *range, int exact);
137
055679e9 138/* Show BGP peer's information. */
139enum show_type {
140 show_all,
141 show_peer,
142 show_ipv4_all,
143 show_ipv6_all,
144 show_ipv4_peer,
145 show_ipv6_peer
146};
147
36235319
QY
148static struct peer_group *listen_range_exists(struct bgp *bgp,
149 struct prefix *range, int exact);
2986cac2 150
36235319
QY
151static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
152 struct bgp *bgp,
153 bool use_json,
154 json_object *json);
2986cac2 155
36235319
QY
156static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
157 enum show_type type,
158 const char *ip_str,
159 afi_t afi, bool use_json);
2986cac2 160
f4b8ec07
CS
161static int peer_and_group_lookup_nb(struct vty *vty, const char *peer_str,
162 char *base_xpath, int xpath_len,
163 char *abs_xpath);
164
d62a17ae 165static enum node_type bgp_node_type(afi_t afi, safi_t safi)
166{
167 switch (afi) {
168 case AFI_IP:
169 switch (safi) {
170 case SAFI_UNICAST:
171 return BGP_IPV4_NODE;
d62a17ae 172 case SAFI_MULTICAST:
173 return BGP_IPV4M_NODE;
d62a17ae 174 case SAFI_LABELED_UNICAST:
175 return BGP_IPV4L_NODE;
d62a17ae 176 case SAFI_MPLS_VPN:
177 return BGP_VPNV4_NODE;
7c40bf39 178 case SAFI_FLOWSPEC:
179 return BGP_FLOWSPECV4_NODE;
5c525538
RW
180 default:
181 /* not expected */
182 return BGP_IPV4_NODE;
d62a17ae 183 }
184 break;
185 case AFI_IP6:
186 switch (safi) {
187 case SAFI_UNICAST:
188 return BGP_IPV6_NODE;
d62a17ae 189 case SAFI_MULTICAST:
190 return BGP_IPV6M_NODE;
d62a17ae 191 case SAFI_LABELED_UNICAST:
192 return BGP_IPV6L_NODE;
d62a17ae 193 case SAFI_MPLS_VPN:
194 return BGP_VPNV6_NODE;
7c40bf39 195 case SAFI_FLOWSPEC:
196 return BGP_FLOWSPECV6_NODE;
5c525538
RW
197 default:
198 /* not expected */
199 return BGP_IPV4_NODE;
d62a17ae 200 }
201 break;
202 case AFI_L2VPN:
203 return BGP_EVPN_NODE;
b26f891d 204 case AFI_UNSPEC:
d62a17ae 205 case AFI_MAX:
206 // We should never be here but to clarify the switch statement..
207 return BGP_IPV4_NODE;
d62a17ae 208 }
209
210 // Impossible to happen
211 return BGP_IPV4_NODE;
f51bae9c 212}
20eb8864 213
5cb5f4d0
DD
214static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
215{
7d0d37de
DS
216 if (afi == AFI_IP) {
217 if (safi == SAFI_UNICAST)
218 return "IPv4 Unicast";
219 if (safi == SAFI_MULTICAST)
220 return "IPv4 Multicast";
221 if (safi == SAFI_LABELED_UNICAST)
222 return "IPv4 Labeled Unicast";
223 if (safi == SAFI_MPLS_VPN)
224 return "IPv4 VPN";
225 if (safi == SAFI_ENCAP)
226 return "IPv4 Encap";
227 if (safi == SAFI_FLOWSPEC)
228 return "IPv4 Flowspec";
229 } else if (afi == AFI_IP6) {
230 if (safi == SAFI_UNICAST)
231 return "IPv6 Unicast";
232 if (safi == SAFI_MULTICAST)
233 return "IPv6 Multicast";
234 if (safi == SAFI_LABELED_UNICAST)
235 return "IPv6 Labeled Unicast";
236 if (safi == SAFI_MPLS_VPN)
237 return "IPv6 VPN";
238 if (safi == SAFI_ENCAP)
239 return "IPv6 Encap";
240 if (safi == SAFI_FLOWSPEC)
241 return "IPv6 Flowspec";
242 } else if (afi == AFI_L2VPN) {
243 if (safi == SAFI_EVPN)
244 return "L2VPN EVPN";
245 }
246
247 return "Unknown";
5cb5f4d0
DD
248}
249
250/*
251 * Please note that we have intentionally camelCased
252 * the return strings here. So if you want
253 * to use this function, please ensure you
254 * are doing this within json output
255 */
256static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
257{
7d0d37de
DS
258 if (afi == AFI_IP) {
259 if (safi == SAFI_UNICAST)
260 return "ipv4Unicast";
261 if (safi == SAFI_MULTICAST)
262 return "ipv4Multicast";
263 if (safi == SAFI_LABELED_UNICAST)
264 return "ipv4LabeledUnicast";
265 if (safi == SAFI_MPLS_VPN)
266 return "ipv4Vpn";
267 if (safi == SAFI_ENCAP)
268 return "ipv4Encap";
269 if (safi == SAFI_FLOWSPEC)
270 return "ipv4Flowspec";
271 } else if (afi == AFI_IP6) {
272 if (safi == SAFI_UNICAST)
273 return "ipv6Unicast";
274 if (safi == SAFI_MULTICAST)
275 return "ipv6Multicast";
276 if (safi == SAFI_LABELED_UNICAST)
277 return "ipv6LabeledUnicast";
278 if (safi == SAFI_MPLS_VPN)
279 return "ipv6Vpn";
280 if (safi == SAFI_ENCAP)
281 return "ipv6Encap";
282 if (safi == SAFI_FLOWSPEC)
283 return "ipv6Flowspec";
284 } else if (afi == AFI_L2VPN) {
285 if (safi == SAFI_EVPN)
286 return "l2VpnEvpn";
287 }
288
289 return "Unknown";
5cb5f4d0
DD
290}
291
37a87b8f
CS
292/* return string maps to afi-safi specific container names
293 * defined in bgp yang file.
294 */
295const char *bgp_afi_safi_get_container_str(afi_t afi, safi_t safi)
296{
7d0d37de
DS
297 if (afi == AFI_IP) {
298 if (safi == SAFI_UNICAST)
299 return "ipv4-unicast";
300 if (safi == SAFI_MULTICAST)
301 return "ipv4-multicast";
302 if (safi == SAFI_LABELED_UNICAST)
303 return "ipv4-labeled-unicast";
304 if (safi == SAFI_MPLS_VPN)
305 return "l3vpn-ipv4-unicast";
306 if (safi == SAFI_FLOWSPEC)
307 return "ipv4-flowspec";
308 } else if (afi == AFI_IP6) {
309 if (safi == SAFI_UNICAST)
310 return "ipv6-unicast";
311 if (safi == SAFI_MULTICAST)
312 return "ipv6-multicast";
313 if (safi == SAFI_LABELED_UNICAST)
314 return "ipv6-labeled-unicast";
315 if (safi == SAFI_MPLS_VPN)
316 return "l3vpn-ipv6-unicast";
317 if (safi == SAFI_FLOWSPEC)
318 return "ipv6-flowspec";
319 } else if (afi == AFI_L2VPN) {
320 if (safi == SAFI_EVPN)
321 return "l2vpn-evpn";
322 }
323
324 return "Unknown";
37a87b8f
CS
325}
326
718e3744 327/* Utility function to get address family from current node. */
d62a17ae 328afi_t bgp_node_afi(struct vty *vty)
329{
330 afi_t afi;
331 switch (vty->node) {
332 case BGP_IPV6_NODE:
333 case BGP_IPV6M_NODE:
334 case BGP_IPV6L_NODE:
335 case BGP_VPNV6_NODE:
7c40bf39 336 case BGP_FLOWSPECV6_NODE:
d62a17ae 337 afi = AFI_IP6;
338 break;
339 case BGP_EVPN_NODE:
340 afi = AFI_L2VPN;
341 break;
342 default:
343 afi = AFI_IP;
344 break;
345 }
346 return afi;
718e3744 347}
348
349/* Utility function to get subsequent address family from current
350 node. */
d62a17ae 351safi_t bgp_node_safi(struct vty *vty)
352{
353 safi_t safi;
354 switch (vty->node) {
355 case BGP_VPNV4_NODE:
356 case BGP_VPNV6_NODE:
357 safi = SAFI_MPLS_VPN;
358 break;
359 case BGP_IPV4M_NODE:
360 case BGP_IPV6M_NODE:
361 safi = SAFI_MULTICAST;
362 break;
363 case BGP_EVPN_NODE:
364 safi = SAFI_EVPN;
365 break;
366 case BGP_IPV4L_NODE:
367 case BGP_IPV6L_NODE:
368 safi = SAFI_LABELED_UNICAST;
369 break;
7c40bf39 370 case BGP_FLOWSPECV4_NODE:
371 case BGP_FLOWSPECV6_NODE:
372 safi = SAFI_FLOWSPEC;
373 break;
d62a17ae 374 default:
375 safi = SAFI_UNICAST;
376 break;
377 }
378 return safi;
718e3744 379}
380
55f91488
QY
381/**
382 * Converts an AFI in string form to afi_t
383 *
384 * @param afi string, one of
385 * - "ipv4"
386 * - "ipv6"
81cf0de5 387 * - "l2vpn"
55f91488
QY
388 * @return the corresponding afi_t
389 */
d62a17ae 390afi_t bgp_vty_afi_from_str(const char *afi_str)
391{
392 afi_t afi = AFI_MAX; /* unknown */
393 if (strmatch(afi_str, "ipv4"))
394 afi = AFI_IP;
395 else if (strmatch(afi_str, "ipv6"))
396 afi = AFI_IP6;
81cf0de5
CS
397 else if (strmatch(afi_str, "l2vpn"))
398 afi = AFI_L2VPN;
d62a17ae 399 return afi;
400}
401
402int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
403 afi_t *afi)
404{
405 int ret = 0;
406 if (argv_find(argv, argc, "ipv4", index)) {
407 ret = 1;
408 if (afi)
409 *afi = AFI_IP;
410 } else if (argv_find(argv, argc, "ipv6", index)) {
411 ret = 1;
412 if (afi)
413 *afi = AFI_IP6;
8688b3e7
DS
414 } else if (argv_find(argv, argc, "l2vpn", index)) {
415 ret = 1;
416 if (afi)
417 *afi = AFI_L2VPN;
d62a17ae 418 }
419 return ret;
46f296b4
LB
420}
421
375a2e67 422/* supports <unicast|multicast|vpn|labeled-unicast> */
d62a17ae 423safi_t bgp_vty_safi_from_str(const char *safi_str)
424{
425 safi_t safi = SAFI_MAX; /* unknown */
426 if (strmatch(safi_str, "multicast"))
427 safi = SAFI_MULTICAST;
428 else if (strmatch(safi_str, "unicast"))
429 safi = SAFI_UNICAST;
430 else if (strmatch(safi_str, "vpn"))
431 safi = SAFI_MPLS_VPN;
81cf0de5
CS
432 else if (strmatch(safi_str, "evpn"))
433 safi = SAFI_EVPN;
d62a17ae 434 else if (strmatch(safi_str, "labeled-unicast"))
435 safi = SAFI_LABELED_UNICAST;
7c40bf39 436 else if (strmatch(safi_str, "flowspec"))
437 safi = SAFI_FLOWSPEC;
d62a17ae 438 return safi;
439}
440
441int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
442 safi_t *safi)
443{
444 int ret = 0;
445 if (argv_find(argv, argc, "unicast", index)) {
446 ret = 1;
447 if (safi)
448 *safi = SAFI_UNICAST;
449 } else if (argv_find(argv, argc, "multicast", index)) {
450 ret = 1;
451 if (safi)
452 *safi = SAFI_MULTICAST;
453 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
454 ret = 1;
455 if (safi)
456 *safi = SAFI_LABELED_UNICAST;
457 } else if (argv_find(argv, argc, "vpn", index)) {
458 ret = 1;
459 if (safi)
460 *safi = SAFI_MPLS_VPN;
8688b3e7
DS
461 } else if (argv_find(argv, argc, "evpn", index)) {
462 ret = 1;
463 if (safi)
464 *safi = SAFI_EVPN;
7c40bf39 465 } else if (argv_find(argv, argc, "flowspec", index)) {
466 ret = 1;
467 if (safi)
468 *safi = SAFI_FLOWSPEC;
d62a17ae 469 }
470 return ret;
46f296b4
LB
471}
472
b16bcbba
TA
473/*
474 * Convert an afi_t/safi_t pair to matching BGP_DEFAULT_AF* flag.
475 *
476 * afi
477 * address-family identifier
478 *
479 * safi
480 * subsequent address-family identifier
481 *
482 * Returns:
483 * default_af string corresponding to the supplied afi/safi pair.
484 * If afi/safi is invalid or if flag for afi/safi doesn't exist,
485 * return -1.
486 */
487static const char *get_bgp_default_af_flag(afi_t afi, safi_t safi)
488{
489 switch (afi) {
490 case AFI_IP:
491 switch (safi) {
492 case SAFI_UNICAST:
493 return "ipv4-unicast";
494 case SAFI_MULTICAST:
495 return "ipv4-multicast";
496 case SAFI_MPLS_VPN:
497 return "ipv4-vpn";
498 case SAFI_ENCAP:
499 return "ipv4-encap";
500 case SAFI_LABELED_UNICAST:
501 return "ipv4-labeled-unicast";
502 case SAFI_FLOWSPEC:
503 return "ipv4-flowspec";
504 default:
505 return "unknown-afi/safi";
506 }
507 break;
508 case AFI_IP6:
509 switch (safi) {
510 case SAFI_UNICAST:
511 return "ipv6-unicast";
512 case SAFI_MULTICAST:
513 return "ipv6-multicast";
514 case SAFI_MPLS_VPN:
515 return "ipv6-vpn";
516 case SAFI_ENCAP:
517 return "ipv6-encap";
518 case SAFI_LABELED_UNICAST:
519 return "ipv6-labeled-unicast";
520 case SAFI_FLOWSPEC:
521 return "ipv6-flowspec";
522 default:
523 return "unknown-afi/safi";
524 }
525 break;
526 case AFI_L2VPN:
527 switch (safi) {
528 case SAFI_EVPN:
529 return "l2vpn-evpn";
530 default:
531 return "unknown-afi/safi";
532 }
533 case AFI_UNSPEC:
534 case AFI_MAX:
535 return "unknown-afi/safi";
536 }
537 /* all AFIs are accounted for above, so this shouldn't happen */
538 return "unknown-afi/safi";
539}
540
5d5393b9
DL
541int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
542 enum bgp_instance_type inst_type)
543{
544 int ret = bgp_get(bgp, as, name, inst_type);
545
546 if (ret == BGP_CREATED) {
547 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
d43114f3 548 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
5d5393b9
DL
549
550 if (DFLT_BGP_IMPORT_CHECK)
892fedb6 551 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
5d5393b9 552 if (DFLT_BGP_SHOW_HOSTNAME)
892fedb6 553 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
aef999a2
DA
554 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
555 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
5d5393b9 556 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
892fedb6 557 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
5d5393b9 558 if (DFLT_BGP_DETERMINISTIC_MED)
892fedb6 559 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
1d3fdccf
DA
560 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
561 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2adac256
DA
562 if (DFLT_BGP_SUPPRESS_DUPLICATES)
563 SET_FLAG((*bgp)->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
5d5393b9
DL
564
565 ret = BGP_SUCCESS;
566 }
567 return ret;
568}
569
7eeee51e 570/*
f212a857 571 * bgp_vty_find_and_parse_afi_safi_bgp
7eeee51e 572 *
f212a857
DS
573 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
574 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
7eeee51e
DS
575 * to appropriate values for the calling function. This is to allow the
576 * calling function to make decisions appropriate for the show command
577 * that is being parsed.
578 *
579 * The show commands are generally of the form:
d62a17ae 580 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
581 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
7eeee51e
DS
582 *
583 * Since we use argv_find if the show command in particular doesn't have:
584 * [ip]
18c57037 585 * [<view|vrf> VIEWVRFNAME]
375a2e67 586 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
7eeee51e
DS
587 * The command parsing should still be ok.
588 *
589 * vty -> The vty for the command so we can output some useful data in
590 * the event of a parse error in the vrf.
591 * argv -> The command tokens
592 * argc -> How many command tokens we have
d62a17ae 593 * idx -> The current place in the command, generally should be 0 for this
594 * function
7eeee51e
DS
595 * afi -> The parsed afi if it was included in the show command, returned here
596 * safi -> The parsed safi if it was included in the show command, returned here
f212a857 597 * bgp -> Pointer to the bgp data structure we need to fill in.
52e5b8c4 598 * use_json -> json is configured or not
7eeee51e
DS
599 *
600 * The function returns the correct location in the parse tree for the
601 * last token found.
0e37c258
DS
602 *
603 * Returns 0 for failure to parse correctly, else the idx position of where
604 * it found the last token.
7eeee51e 605 */
d62a17ae 606int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
607 struct cmd_token **argv, int argc,
608 int *idx, afi_t *afi, safi_t *safi,
9f049418 609 struct bgp **bgp, bool use_json)
d62a17ae 610{
611 char *vrf_name = NULL;
612
613 assert(afi);
614 assert(safi);
615 assert(bgp);
616
617 if (argv_find(argv, argc, "ip", idx))
618 *afi = AFI_IP;
619
9a8bdf1c 620 if (argv_find(argv, argc, "view", idx))
d62a17ae 621 vrf_name = argv[*idx + 1]->arg;
9a8bdf1c
PG
622 else if (argv_find(argv, argc, "vrf", idx)) {
623 vrf_name = argv[*idx + 1]->arg;
624 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
625 vrf_name = NULL;
626 }
627 if (vrf_name) {
d62a17ae 628 if (strmatch(vrf_name, "all"))
629 *bgp = NULL;
630 else {
631 *bgp = bgp_lookup_by_name(vrf_name);
632 if (!*bgp) {
52e5b8c4
SP
633 if (use_json) {
634 json_object *json = NULL;
635 json = json_object_new_object();
636 json_object_string_add(
637 json, "warning",
638 "View/Vrf is unknown");
639 vty_out(vty, "%s\n",
640 json_object_to_json_string_ext(json,
641 JSON_C_TO_STRING_PRETTY));
642 json_object_free(json);
643 }
ca61fd25
DS
644 else
645 vty_out(vty, "View/Vrf %s is unknown\n",
646 vrf_name);
d62a17ae 647 *idx = 0;
648 return 0;
649 }
650 }
651 } else {
652 *bgp = bgp_get_default();
653 if (!*bgp) {
52e5b8c4
SP
654 if (use_json) {
655 json_object *json = NULL;
656 json = json_object_new_object();
657 json_object_string_add(
658 json, "warning",
659 "Default BGP instance not found");
660 vty_out(vty, "%s\n",
661 json_object_to_json_string_ext(json,
662 JSON_C_TO_STRING_PRETTY));
663 json_object_free(json);
664 }
ca61fd25
DS
665 else
666 vty_out(vty,
667 "Default BGP instance not found\n");
d62a17ae 668 *idx = 0;
669 return 0;
670 }
671 }
672
673 if (argv_find_and_parse_afi(argv, argc, idx, afi))
674 argv_find_and_parse_safi(argv, argc, idx, safi);
675
676 *idx += 1;
677 return *idx;
678}
679
f4b8ec07 680bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
d62a17ae 681{
682 struct interface *ifp = NULL;
683
684 if (su->sa.sa_family == AF_INET)
685 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
686 else if (su->sa.sa_family == AF_INET6)
687 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
688 su->sin6.sin6_scope_id,
689 bgp->vrf_id);
690
691 if (ifp)
3dc339cd 692 return true;
d62a17ae 693
3dc339cd 694 return false;
718e3744 695}
696
718e3744 697/* Utility function for looking up peer or peer group. */
f14e6fdb
DS
698/* This is used only for configuration, so disallow if attempted on
699 * a dynamic neighbor.
700 */
d62a17ae 701struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
702{
703 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
704 int ret;
705 union sockunion su;
706 struct peer *peer = NULL;
707 struct peer_group *group = NULL;
708
709 if (!bgp) {
710 return NULL;
711 }
712
713 ret = str2sockunion(peer_str, &su);
714 if (ret == 0) {
715 /* IP address, locate peer. */
716 peer = peer_lookup(bgp, &su);
717 } else {
718 /* Not IP, could match either peer configured on interface or a
719 * group. */
720 peer = peer_lookup_by_conf_if(bgp, peer_str);
721 if (!peer)
722 group = peer_group_lookup(bgp, peer_str);
723 }
724
725 if (peer) {
726 if (peer_dynamic_neighbor(peer)) {
727 vty_out(vty,
728 "%% Operation not allowed on a dynamic neighbor\n");
729 return NULL;
730 }
731
732 return peer;
733 }
734
735 if (group)
736 return group->conf;
737
738 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
739
740 return NULL;
741}
742
f4b8ec07
CS
743int bgp_nb_errmsg_return(char *errmsg, size_t errmsg_len, int ret)
744{
745 const char *str = NULL;
746
747 switch (ret) {
748 case BGP_ERR_INVALID_VALUE:
749 str = "Invalid value";
750 break;
751 case BGP_ERR_INVALID_FLAG:
752 str = "Invalid flag";
753 break;
754 case BGP_ERR_PEER_GROUP_SHUTDOWN:
755 str = "Peer-group has been shutdown. Activate the peer-group first";
756 break;
757 case BGP_ERR_PEER_FLAG_CONFLICT:
758 str = "Can't set override-capability and strict-capability-match at the same time";
759 break;
760 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
761 str = "Specify remote-as or peer-group remote AS first";
762 break;
763 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
764 str = "Cannot change the peer-group. Deconfigure first";
765 break;
766 case BGP_ERR_PEER_GROUP_MISMATCH:
767 str = "Peer is not a member of this peer-group";
768 break;
769 case BGP_ERR_PEER_FILTER_CONFLICT:
770 str = "Prefix/distribute list can not co-exist";
771 break;
772 case BGP_ERR_NOT_INTERNAL_PEER:
773 str = "Invalid command. Not an internal neighbor";
774 break;
775 case BGP_ERR_REMOVE_PRIVATE_AS:
776 str = "remove-private-AS cannot be configured for IBGP peers";
777 break;
778 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
779 str = "Local-AS allowed only for EBGP peers";
780 break;
781 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
782 str = "Cannot have local-as same as BGP AS number";
783 break;
784 case BGP_ERR_TCPSIG_FAILED:
785 str = "Error while applying TCP-Sig to session(s)";
786 break;
787 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
788 str = "ebgp-multihop and ttl-security cannot be configured together";
789 break;
790 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
791 str = "ttl-security only allowed for EBGP peers";
792 break;
793 case BGP_ERR_AS_OVERRIDE:
794 str = "as-override cannot be configured for IBGP peers";
795 break;
796 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
797 str = "Invalid limit for number of dynamic neighbors";
798 break;
799 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
800 str = "Dynamic neighbor listen range already exists";
801 break;
802 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
803 str = "Operation not allowed on a dynamic neighbor";
804 break;
805 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
806 str = "Operation not allowed on a directly connected neighbor";
807 break;
808 case BGP_ERR_PEER_SAFI_CONFLICT:
a59803d0 809 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
f4b8ec07
CS
810 break;
811 case BGP_ERR_GR_INVALID_CMD:
812 str = "The Graceful Restart command used is not valid at this moment.";
813 break;
814 case BGP_ERR_GR_OPERATION_FAILED:
815 str = "The Graceful Restart Operation failed due to an err.";
816 break;
f4b8ec07
CS
817 case BGP_ERR_PEER_GROUP_MEMBER:
818 str = "Peer-group member cannot override remote-as of peer-group";
819 break;
820 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
821 str = "Peer-group members must be all internal or all external";
822 break;
823 }
824 if (str) {
825 snprintf(errmsg, errmsg_len, "%s", str);
826 return -1;
827 }
828
829 return 0;
830}
831
d62a17ae 832int bgp_vty_return(struct vty *vty, int ret)
833{
834 const char *str = NULL;
835
836 switch (ret) {
837 case BGP_ERR_INVALID_VALUE:
838 str = "Invalid value";
839 break;
840 case BGP_ERR_INVALID_FLAG:
841 str = "Invalid flag";
842 break;
843 case BGP_ERR_PEER_GROUP_SHUTDOWN:
844 str = "Peer-group has been shutdown. Activate the peer-group first";
845 break;
846 case BGP_ERR_PEER_FLAG_CONFLICT:
847 str = "Can't set override-capability and strict-capability-match at the same time";
848 break;
849 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
850 str = "Specify remote-as or peer-group remote AS first";
851 break;
852 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
853 str = "Cannot change the peer-group. Deconfigure first";
854 break;
855 case BGP_ERR_PEER_GROUP_MISMATCH:
856 str = "Peer is not a member of this peer-group";
857 break;
858 case BGP_ERR_PEER_FILTER_CONFLICT:
859 str = "Prefix/distribute list can not co-exist";
860 break;
861 case BGP_ERR_NOT_INTERNAL_PEER:
862 str = "Invalid command. Not an internal neighbor";
863 break;
864 case BGP_ERR_REMOVE_PRIVATE_AS:
865 str = "remove-private-AS cannot be configured for IBGP peers";
866 break;
867 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
868 str = "Local-AS allowed only for EBGP peers";
869 break;
870 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
871 str = "Cannot have local-as same as BGP AS number";
872 break;
873 case BGP_ERR_TCPSIG_FAILED:
874 str = "Error while applying TCP-Sig to session(s)";
875 break;
876 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
877 str = "ebgp-multihop and ttl-security cannot be configured together";
878 break;
879 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
880 str = "ttl-security only allowed for EBGP peers";
881 break;
882 case BGP_ERR_AS_OVERRIDE:
883 str = "as-override cannot be configured for IBGP peers";
884 break;
885 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
886 str = "Invalid limit for number of dynamic neighbors";
887 break;
888 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
889 str = "Dynamic neighbor listen range already exists";
890 break;
891 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
892 str = "Operation not allowed on a dynamic neighbor";
893 break;
894 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
895 str = "Operation not allowed on a directly connected neighbor";
896 break;
897 case BGP_ERR_PEER_SAFI_CONFLICT:
a59803d0 898 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
055679e9 899 break;
900 case BGP_ERR_GR_INVALID_CMD:
901 str = "The Graceful Restart command used is not valid at this moment.";
902 break;
903 case BGP_ERR_GR_OPERATION_FAILED:
904 str = "The Graceful Restart Operation failed due to an err.";
905 break;
d62a17ae 906 }
907 if (str) {
908 vty_out(vty, "%% %s\n", str);
909 return CMD_WARNING_CONFIG_FAILED;
910 }
911 return CMD_SUCCESS;
718e3744 912}
913
7aafcaca 914/* BGP clear sort. */
d62a17ae 915enum clear_sort {
916 clear_all,
917 clear_peer,
918 clear_group,
919 clear_external,
920 clear_as
7aafcaca
DS
921};
922
ff8a8a7a
CS
923static void bgp_clear_vty_error(struct peer *peer, afi_t afi, safi_t safi,
924 int error, char *errmsg, size_t errmsg_len)
d62a17ae 925{
926 switch (error) {
927 case BGP_ERR_AF_UNCONFIGURED:
ff8a8a7a
CS
928 snprintf(errmsg, errmsg_len,
929 "%%BGP: Enable %s address family for the neighbor %s",
930 get_afi_safi_str(afi, safi, false), peer->host);
d62a17ae 931 break;
932 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
ff8a8a7a
CS
933 snprintf(
934 errmsg, errmsg_len,
935 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig",
d62a17ae 936 peer->host);
937 break;
938 default:
939 break;
940 }
7aafcaca
DS
941}
942
dc912615 943static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
c368171c 944 struct listnode **nnode, enum bgp_clear_type stype)
dc912615
DS
945{
946 int ret = 0;
2adac256 947 struct peer_af *paf;
dc912615
DS
948
949 /* if afi/.safi not specified, spin thru all of them */
950 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
951 afi_t tmp_afi;
952 safi_t tmp_safi;
953
954 FOREACH_AFI_SAFI (tmp_afi, tmp_safi) {
2adac256
DA
955 paf = peer_af_find(peer, tmp_afi, tmp_safi);
956 if (paf && paf->subgroup)
957 SET_FLAG(paf->subgroup->sflags,
958 SUBGRP_STATUS_FORCE_UPDATES);
959
dc912615
DS
960 if (!peer->afc[tmp_afi][tmp_safi])
961 continue;
962
963 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 964 ret = peer_clear(peer, nnode);
dc912615
DS
965 else
966 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
967 stype);
968 }
969 /* if afi specified and safi not, spin thru safis on this afi */
970 } else if (safi == SAFI_UNSPEC) {
971 safi_t tmp_safi;
972
973 for (tmp_safi = SAFI_UNICAST;
974 tmp_safi < SAFI_MAX; tmp_safi++) {
975 if (!peer->afc[afi][tmp_safi])
976 continue;
977
2adac256
DA
978 paf = peer_af_find(peer, afi, tmp_safi);
979 if (paf && paf->subgroup)
980 SET_FLAG(paf->subgroup->sflags,
981 SUBGRP_STATUS_FORCE_UPDATES);
982
dc912615 983 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 984 ret = peer_clear(peer, nnode);
dc912615
DS
985 else
986 ret = peer_clear_soft(peer, afi,
987 tmp_safi, stype);
988 }
989 /* both afi/safi specified, let the caller know if not defined */
990 } else {
991 if (!peer->afc[afi][safi])
992 return 1;
993
2adac256
DA
994 paf = peer_af_find(peer, afi, safi);
995 if (paf && paf->subgroup)
996 SET_FLAG(paf->subgroup->sflags,
997 SUBGRP_STATUS_FORCE_UPDATES);
998
dc912615 999 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 1000 ret = peer_clear(peer, nnode);
dc912615
DS
1001 else
1002 ret = peer_clear_soft(peer, afi, safi, stype);
1003 }
1004
1005 return ret;
1006}
1007
7aafcaca 1008/* `clear ip bgp' functions. */
ff8a8a7a 1009static int bgp_clear(struct bgp *bgp, afi_t afi, safi_t safi,
d62a17ae 1010 enum clear_sort sort, enum bgp_clear_type stype,
ff8a8a7a 1011 const char *arg, char *errmsg, size_t errmsg_len)
d62a17ae 1012{
dc912615 1013 int ret = 0;
3ae8bfa5 1014 bool found = false;
d62a17ae 1015 struct peer *peer;
dc95985f 1016
1017 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
d62a17ae 1018
1019 /* Clear all neighbors. */
1020 /*
1021 * Pass along pointer to next node to peer_clear() when walking all
3ae8bfa5
PM
1022 * nodes on the BGP instance as that may get freed if it is a
1023 * doppelganger
d62a17ae 1024 */
1025 if (sort == clear_all) {
1026 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dc95985f 1027
1028 bgp_peer_gr_flags_update(peer);
1029
36235319 1030 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
dc95985f 1031 gr_router_detected = true;
1032
c368171c 1033 ret = bgp_peer_clear(peer, afi, safi, &nnode,
dc912615 1034 stype);
d62a17ae 1035
1036 if (ret < 0)
ff8a8a7a
CS
1037 bgp_clear_vty_error(peer, afi, safi, ret,
1038 errmsg, errmsg_len);
dc95985f 1039 }
1040
36235319
QY
1041 if (gr_router_detected
1042 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1043 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1044 } else if (!gr_router_detected
1045 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1046 bgp_zebra_send_capabilities(bgp, true);
04b6bdc0 1047 }
d62a17ae 1048
1049 /* This is to apply read-only mode on this clear. */
1050 if (stype == BGP_CLEAR_SOFT_NONE)
1051 bgp->update_delay_over = 0;
1052
1053 return CMD_SUCCESS;
7aafcaca
DS
1054 }
1055
3ae8bfa5 1056 /* Clear specified neighbor. */
d62a17ae 1057 if (sort == clear_peer) {
1058 union sockunion su;
d62a17ae 1059
1060 /* Make sockunion for lookup. */
1061 ret = str2sockunion(arg, &su);
1062 if (ret < 0) {
1063 peer = peer_lookup_by_conf_if(bgp, arg);
1064 if (!peer) {
1065 peer = peer_lookup_by_hostname(bgp, arg);
1066 if (!peer) {
ff8a8a7a
CS
1067 snprintf(
1068 errmsg, errmsg_len,
1069 "Malformed address or name: %s",
d62a17ae 1070 arg);
1071 return CMD_WARNING;
1072 }
1073 }
1074 } else {
1075 peer = peer_lookup(bgp, &su);
1076 if (!peer) {
ff8a8a7a
CS
1077 snprintf(errmsg, errmsg_len,
1078 "%%BGP: Unknown neighbor - \"%s\"",
1079 arg);
d62a17ae 1080 return CMD_WARNING;
1081 }
1082 }
7aafcaca 1083
dc95985f 1084 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1085 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1086
dc912615
DS
1087 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1088
1089 /* if afi/safi not defined for this peer, let caller know */
1090 if (ret == 1)
3ae8bfa5 1091 ret = BGP_ERR_AF_UNCONFIGURED;
7aafcaca 1092
d62a17ae 1093 if (ret < 0)
ff8a8a7a
CS
1094 bgp_clear_vty_error(peer, afi, safi, ret, errmsg,
1095 errmsg_len);
7aafcaca 1096
d62a17ae 1097 return CMD_SUCCESS;
7aafcaca 1098 }
7aafcaca 1099
3ae8bfa5 1100 /* Clear all neighbors belonging to a specific peer-group. */
d62a17ae 1101 if (sort == clear_group) {
1102 struct peer_group *group;
7aafcaca 1103
d62a17ae 1104 group = peer_group_lookup(bgp, arg);
1105 if (!group) {
ff8a8a7a
CS
1106 snprintf(errmsg, errmsg_len,
1107 "%%BGP: No such peer-group %s", arg);
d62a17ae 1108 return CMD_WARNING;
1109 }
1110
1111 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
c368171c 1112 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 1113
d62a17ae 1114 if (ret < 0)
ff8a8a7a
CS
1115 bgp_clear_vty_error(peer, afi, safi, ret,
1116 errmsg, errmsg_len);
3ae8bfa5
PM
1117 else
1118 found = true;
d62a17ae 1119 }
3ae8bfa5
PM
1120
1121 if (!found)
ff8a8a7a
CS
1122 snprintf(
1123 errmsg, errmsg_len,
1124 "%%BGP: No %s peer belonging to peer-group %s is configured",
5cb5f4d0 1125 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1126
d62a17ae 1127 return CMD_SUCCESS;
7aafcaca 1128 }
7aafcaca 1129
3ae8bfa5 1130 /* Clear all external (eBGP) neighbors. */
d62a17ae 1131 if (sort == clear_external) {
1132 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1133 if (peer->sort == BGP_PEER_IBGP)
1134 continue;
7aafcaca 1135
dc95985f 1136 bgp_peer_gr_flags_update(peer);
1137
36235319 1138 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 1139 gr_router_detected = true;
dc95985f 1140
c368171c 1141 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 1142
d62a17ae 1143 if (ret < 0)
ff8a8a7a
CS
1144 bgp_clear_vty_error(peer, afi, safi, ret,
1145 errmsg, errmsg_len);
3ae8bfa5
PM
1146 else
1147 found = true;
d62a17ae 1148 }
3ae8bfa5 1149
36235319
QY
1150 if (gr_router_detected
1151 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1152 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1153 } else if (!gr_router_detected
1154 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1155 bgp_zebra_send_capabilities(bgp, true);
1156 }
1157
3ae8bfa5 1158 if (!found)
ff8a8a7a
CS
1159 snprintf(errmsg, errmsg_len,
1160 "%%BGP: No external %s peer is configured",
1161 get_afi_safi_str(afi, safi, false));
3ae8bfa5 1162
d62a17ae 1163 return CMD_SUCCESS;
1164 }
1165
3ae8bfa5 1166 /* Clear all neighbors belonging to a specific AS. */
d62a17ae 1167 if (sort == clear_as) {
3ae8bfa5 1168 as_t as = strtoul(arg, NULL, 10);
d62a17ae 1169
1170 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1171 if (peer->as != as)
1172 continue;
1173
dc95985f 1174 bgp_peer_gr_flags_update(peer);
1175
36235319 1176 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 1177 gr_router_detected = true;
dc95985f 1178
c368171c 1179 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
d62a17ae 1180
1181 if (ret < 0)
ff8a8a7a
CS
1182 bgp_clear_vty_error(peer, afi, safi, ret,
1183 errmsg, errmsg_len);
3ae8bfa5
PM
1184 else
1185 found = true;
d62a17ae 1186 }
3ae8bfa5 1187
36235319
QY
1188 if (gr_router_detected
1189 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1190 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1191 } else if (!gr_router_detected
1192 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1193 bgp_zebra_send_capabilities(bgp, true);
1194 }
1195
3ae8bfa5 1196 if (!found)
ff8a8a7a
CS
1197 snprintf(errmsg, errmsg_len,
1198 "%%BGP: No %s peer is configured with AS %s",
1199 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1200
d62a17ae 1201 return CMD_SUCCESS;
1202 }
1203
1204 return CMD_SUCCESS;
1205}
1206
ff8a8a7a
CS
1207static int bgp_clear_vty(const char *name, afi_t afi, safi_t safi,
1208 enum clear_sort sort, enum bgp_clear_type stype,
1209 const char *arg, char *errmsg, size_t errmsg_len)
d62a17ae 1210{
1211 struct bgp *bgp;
1212
1213 /* BGP structure lookup. */
1214 if (name) {
1215 bgp = bgp_lookup_by_name(name);
1216 if (bgp == NULL) {
ff8a8a7a
CS
1217 snprintf(errmsg, errmsg_len,
1218 "Can't find BGP instance %s", name);
d62a17ae 1219 return CMD_WARNING;
1220 }
1221 } else {
1222 bgp = bgp_get_default();
1223 if (bgp == NULL) {
ff8a8a7a
CS
1224 snprintf(errmsg, errmsg_len,
1225 "No BGP process is configured");
d62a17ae 1226 return CMD_WARNING;
1227 }
1228 }
1229
ff8a8a7a 1230 return bgp_clear(bgp, afi, safi, sort, stype, arg, errmsg, errmsg_len);
7aafcaca
DS
1231}
1232
1233/* clear soft inbound */
ff8a8a7a 1234int bgp_clear_star_soft_in(const char *name, char *errmsg, size_t errmsg_len)
7aafcaca 1235{
99b3ebd3
NS
1236 afi_t afi;
1237 safi_t safi;
ff8a8a7a
CS
1238 int ret;
1239
1240 FOREACH_AFI_SAFI (afi, safi) {
1241 ret = bgp_clear_vty(name, afi, safi, clear_all,
1242 BGP_CLEAR_SOFT_IN, NULL, errmsg,
1243 errmsg_len);
1244 if (ret != CMD_SUCCESS)
1245 return -1;
1246 }
99b3ebd3 1247
ff8a8a7a 1248 return 0;
7aafcaca
DS
1249}
1250
1251/* clear soft outbound */
ff8a8a7a 1252int bgp_clear_star_soft_out(const char *name, char *errmsg, size_t errmsg_len)
7aafcaca 1253{
99b3ebd3
NS
1254 afi_t afi;
1255 safi_t safi;
ff8a8a7a 1256 int ret;
99b3ebd3 1257
ff8a8a7a
CS
1258 FOREACH_AFI_SAFI (afi, safi) {
1259 ret = bgp_clear_vty(name, afi, safi, clear_all,
1260 BGP_CLEAR_SOFT_OUT, NULL, errmsg,
1261 errmsg_len);
1262 if (ret != CMD_SUCCESS)
1263 return -1;
1264 }
1265
1266 return 0;
7aafcaca
DS
1267}
1268
1269
f787d7a0 1270#ifndef VTYSH_EXTRACT_PL
2e4c2296 1271#include "bgpd/bgp_vty_clippy.c"
f787d7a0
DL
1272#endif
1273
8029b216
AK
1274DEFUN_HIDDEN (bgp_local_mac,
1275 bgp_local_mac_cmd,
093e3f23 1276 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
8029b216
AK
1277 BGP_STR
1278 "Local MAC config\n"
1279 "VxLAN Network Identifier\n"
1280 "VNI number\n"
1281 "local mac\n"
1282 "mac address\n"
1283 "mac-mobility sequence\n"
1284 "seq number\n")
1285{
1286 int rv;
1287 vni_t vni;
1288 struct ethaddr mac;
1289 struct ipaddr ip;
1290 uint32_t seq;
1291 struct bgp *bgp;
1292
1293 vni = strtoul(argv[3]->arg, NULL, 10);
1294 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1295 vty_out(vty, "%% Malformed MAC address\n");
1296 return CMD_WARNING;
1297 }
1298 memset(&ip, 0, sizeof(ip));
1299 seq = strtoul(argv[7]->arg, NULL, 10);
1300
1301 bgp = bgp_get_default();
1302 if (!bgp) {
1303 vty_out(vty, "Default BGP instance is not there\n");
1304 return CMD_WARNING;
1305 }
1306
b5e140c8
AK
1307 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1308 zero_esi);
8029b216
AK
1309 if (rv < 0) {
1310 vty_out(vty, "Internal error\n");
1311 return CMD_WARNING;
1312 }
1313
1314 return CMD_SUCCESS;
1315}
1316
1317DEFUN_HIDDEN (no_bgp_local_mac,
1318 no_bgp_local_mac_cmd,
093e3f23 1319 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
8029b216
AK
1320 NO_STR
1321 BGP_STR
1322 "Local MAC config\n"
1323 "VxLAN Network Identifier\n"
1324 "VNI number\n"
1325 "local mac\n"
1326 "mac address\n")
1327{
1328 int rv;
1329 vni_t vni;
1330 struct ethaddr mac;
1331 struct ipaddr ip;
1332 struct bgp *bgp;
1333
1334 vni = strtoul(argv[4]->arg, NULL, 10);
1335 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1336 vty_out(vty, "%% Malformed MAC address\n");
1337 return CMD_WARNING;
1338 }
1339 memset(&ip, 0, sizeof(ip));
1340
1341 bgp = bgp_get_default();
1342 if (!bgp) {
1343 vty_out(vty, "Default BGP instance is not there\n");
1344 return CMD_WARNING;
1345 }
1346
ec0ab544 1347 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
8029b216
AK
1348 if (rv < 0) {
1349 vty_out(vty, "Internal error\n");
1350 return CMD_WARNING;
1351 }
1352
1353 return CMD_SUCCESS;
1354}
1355
718e3744 1356DEFUN (no_synchronization,
1357 no_synchronization_cmd,
1358 "no synchronization",
1359 NO_STR
1360 "Perform IGP synchronization\n")
1361{
d62a17ae 1362 return CMD_SUCCESS;
718e3744 1363}
1364
1365DEFUN (no_auto_summary,
1366 no_auto_summary_cmd,
1367 "no auto-summary",
1368 NO_STR
1369 "Enable automatic network number summarization\n")
1370{
d62a17ae 1371 return CMD_SUCCESS;
718e3744 1372}
3d515fd9 1373
718e3744 1374/* "router bgp" commands. */
ff8a8a7a
CS
1375DEFUN_YANG_NOSH(router_bgp,
1376 router_bgp_cmd,
1377 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1378 ROUTER_STR BGP_STR AS_STR BGP_INSTANCE_HELP_STR)
718e3744 1379{
d62a17ae 1380 int idx_asn = 2;
1381 int idx_view_vrf = 3;
1382 int idx_vrf = 4;
ff8a8a7a 1383 int ret = CMD_SUCCESS;
d62a17ae 1384 as_t as;
1385 struct bgp *bgp;
1386 const char *name = NULL;
1387 enum bgp_instance_type inst_type;
ff8a8a7a 1388 char base_xpath[XPATH_MAXLEN];
4062b455 1389 const struct lyd_node *bgp_glb_dnode;
d62a17ae 1390
1391 // "router bgp" without an ASN
1392 if (argc == 2) {
1393 // Pending: Make VRF option available for ASN less config
4062b455
IR
1394 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1395 "frr-bgp:bgp", "bgp", VRF_DEFAULT_NAME);
d62a17ae 1396
4062b455
IR
1397 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
1398 base_xpath);
1399 if (!bgp_glb_dnode) {
d62a17ae 1400 vty_out(vty, "%% No BGP process is configured\n");
1401 return CMD_WARNING_CONFIG_FAILED;
1402 }
1403
1404 if (listcount(bm->bgp) > 1) {
996c9314 1405 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1406 return CMD_WARNING_CONFIG_FAILED;
1407 }
ff8a8a7a 1408
4062b455 1409 as = yang_dnode_get_uint32(bgp_glb_dnode, "./global/local-as");
ff8a8a7a 1410
4062b455 1411 VTY_PUSH_XPATH(BGP_NODE, base_xpath);
ff8a8a7a 1412
4062b455
IR
1413 /*
1414 * For backward compatibility with old commands we still
1415 * need to use the qobj infrastructure.
1416 */
1417 bgp = bgp_lookup(as, NULL);
1418 if (bgp)
ff8a8a7a 1419 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
4062b455
IR
1420
1421 return CMD_SUCCESS;
d62a17ae 1422 }
1423
1424 // "router bgp X"
1425 else {
d62a17ae 1426
ff8a8a7a 1427 as = strtoul(argv[idx_asn]->arg, NULL, 10);
d62a17ae 1428 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1429 if (argc > 3) {
1430 name = argv[idx_vrf]->arg;
1431
9a8bdf1c
PG
1432 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1433 if (strmatch(name, VRF_DEFAULT_NAME))
1434 name = NULL;
1435 else
1436 inst_type = BGP_INSTANCE_TYPE_VRF;
ff8a8a7a 1437 } else if (!strcmp(argv[idx_view_vrf]->text, "view")) {
d62a17ae 1438 inst_type = BGP_INSTANCE_TYPE_VIEW;
ff8a8a7a 1439 }
d62a17ae 1440 }
ff8a8a7a
CS
1441 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1442 "frr-bgp:bgp", "bgp", name ? name : VRF_DEFAULT_NAME);
1443
1444 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
87ce2564 1445 nb_cli_enqueue_change(vty, "./global/local-as", NB_OP_MODIFY,
ff8a8a7a
CS
1446 argv[idx_asn]->arg);
1447 if (inst_type == BGP_INSTANCE_TYPE_VIEW) {
87ce2564
CS
1448 nb_cli_enqueue_change(vty,
1449 "./global/instance-type-view",
ff8a8a7a 1450 NB_OP_MODIFY, "true");
d3e36770
IR
1451 } else {
1452 nb_cli_enqueue_change(vty,
1453 "./global/instance-type-view",
1454 NB_OP_MODIFY, "false");
d62a17ae 1455 }
1456
fd396924 1457 ret = nb_cli_apply_changes_clear_pending(vty, base_xpath);
ff8a8a7a
CS
1458 if (ret == CMD_SUCCESS) {
1459 VTY_PUSH_XPATH(BGP_NODE, base_xpath);
3bd70bf8 1460
ff8a8a7a
CS
1461 /*
1462 * For backward compatibility with old commands we still
1463 * need to use the qobj infrastructure.
1464 */
1465 bgp = bgp_lookup(as, name);
1466 if (bgp)
1467 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1468 }
d62a17ae 1469 }
1470
ff8a8a7a 1471 return ret;
718e3744 1472}
1473
718e3744 1474/* "no router bgp" commands. */
ff8a8a7a
CS
1475DEFUN_YANG(no_router_bgp,
1476 no_router_bgp_cmd,
1477 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1478 NO_STR ROUTER_STR BGP_STR AS_STR BGP_INSTANCE_HELP_STR)
718e3744 1479{
d62a17ae 1480 int idx_vrf = 5;
d62a17ae 1481 const char *name = NULL;
ff8a8a7a 1482 char base_xpath[XPATH_MAXLEN];
4b63e358 1483 const struct lyd_node *bgp_glb_dnode;
718e3744 1484
d62a17ae 1485 // "no router bgp" without an ASN
1486 if (argc == 3) {
1487 // Pending: Make VRF option available for ASN less config
4b63e358
CS
1488 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1489 "frr-bgp:bgp", "bgp", VRF_DEFAULT_NAME);
718e3744 1490
4b63e358
CS
1491 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
1492 base_xpath);
1493 if (!bgp_glb_dnode) {
d62a17ae 1494 vty_out(vty, "%% No BGP process is configured\n");
1495 return CMD_WARNING_CONFIG_FAILED;
1496 }
7fb21a9f 1497
d62a17ae 1498 if (listcount(bm->bgp) > 1) {
996c9314 1499 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1500 return CMD_WARNING_CONFIG_FAILED;
1501 }
1502 } else {
d62a17ae 1503 if (argc > 4)
1504 name = argv[idx_vrf]->arg;
45d1d7c9
IR
1505 else
1506 name = VRF_DEFAULT_NAME;
7fb21a9f 1507
45d1d7c9
IR
1508 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1509 "frr-bgp:bgp", "bgp", name);
d62a17ae 1510 }
718e3744 1511
ff8a8a7a 1512 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
718e3744 1513
fd396924
CH
1514 /* We want to finish any classic config after a no router */
1515 return nb_cli_apply_changes_clear_pending(vty, base_xpath);
718e3744 1516}
1517
ff8a8a7a
CS
1518void cli_show_router_bgp(struct vty *vty, struct lyd_node *dnode,
1519 bool show_defaults)
1520{
1521 const struct lyd_node *vrf_dnode;
1522 const char *vrf_name;
1523 as_t as;
6b0655a2 1524
ff8a8a7a
CS
1525 vrf_dnode = yang_dnode_get_parent(dnode, "control-plane-protocol");
1526 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
5e42cb2f 1527 as = yang_dnode_get_uint32(dnode, "./global/local-as");
718e3744 1528
ff8a8a7a
CS
1529 vty_out(vty, "!\n");
1530 vty_out(vty, "router bgp %u", as);
1531 if (!strmatch(vrf_name, VRF_DEFAULT_NAME))
1532 vty_out(vty, " vrf %s", vrf_name);
1533 vty_out(vty, "\n");
718e3744 1534}
1535
ff8a8a7a
CS
1536/* BGP router-id. */
1537
1538DEFPY_YANG(bgp_router_id, bgp_router_id_cmd, "bgp router-id A.B.C.D",
1539 BGP_STR
1540 "Override configured router identifier\n"
1541 "Manually configured router identifier\n")
718e3744 1542{
87ce2564
CS
1543 nb_cli_enqueue_change(vty, "./global/router-id", NB_OP_MODIFY,
1544 router_id_str);
718e3744 1545
ff8a8a7a
CS
1546 return nb_cli_apply_changes(vty, NULL);
1547}
718e3744 1548
ff8a8a7a
CS
1549DEFPY_YANG(no_bgp_router_id, no_bgp_router_id_cmd, "no bgp router-id [A.B.C.D]",
1550 NO_STR BGP_STR
1551 "Override configured router identifier\n"
1552 "Manually configured router identifier\n")
1553{
87ce2564 1554 nb_cli_enqueue_change(vty, "./global/router-id", NB_OP_DESTROY,
ff8a8a7a 1555 router_id_str ? router_id_str : NULL);
718e3744 1556
ff8a8a7a 1557 return nb_cli_apply_changes(vty, NULL);
718e3744 1558}
1559
ff8a8a7a
CS
1560void cli_show_router_bgp_router_id(struct vty *vty, struct lyd_node *dnode,
1561 bool show_defaults)
1562{
1563 vty_out(vty, " bgp router-id %s\n", yang_dnode_get_string(dnode, NULL));
1564}
6b0655a2 1565
ed0e57e3
DA
1566DEFPY(bgp_community_alias, bgp_community_alias_cmd,
1567 "[no$no] bgp community alias WORD$community WORD$alias",
1568 NO_STR BGP_STR
1569 "Add community specific parameters\n"
1570 "Create an alias for a community\n"
1571 "Community (AA:BB or AA:BB:CC)\n"
1572 "Alias name\n")
1573{
1574 struct community_alias ca1;
1575 struct community_alias ca2;
1576 struct community_alias *lookup_community;
1577 struct community_alias *lookup_alias;
1578
1579 if (!community_str2com(community) && !lcommunity_str2com(community)) {
1580 vty_out(vty, "Invalid community format\n");
1581 return CMD_WARNING;
1582 }
1583
1584 memset(&ca1, 0, sizeof(ca1));
1585 memset(&ca2, 0, sizeof(ca2));
1586 strlcpy(ca1.community, community, sizeof(ca1.community));
1587 strlcpy(ca1.alias, alias, sizeof(ca1.alias));
1588
1589 lookup_community = bgp_ca_community_lookup(&ca1);
1590 lookup_alias = bgp_ca_alias_lookup(&ca1);
1591
1592 if (no) {
1593 bgp_ca_alias_delete(&ca1);
1594 bgp_ca_community_delete(&ca1);
1595 } else {
1596 if (lookup_alias) {
1597 /* Lookup if community hash table has an item
1598 * with the same alias name.
1599 */
1600 strlcpy(ca2.community, lookup_alias->community,
1601 sizeof(ca2.community));
1602 if (bgp_ca_community_lookup(&ca2)) {
1603 vty_out(vty,
1604 "community (%s) already has this alias (%s)\n",
1605 lookup_alias->community,
1606 lookup_alias->alias);
1607 return CMD_WARNING;
1608 }
1609 bgp_ca_alias_delete(&ca1);
1610 }
1611
1612 if (lookup_community)
1613 bgp_ca_community_delete(&ca1);
1614
1615 bgp_ca_alias_insert(&ca1);
1616 bgp_ca_community_insert(&ca1);
1617 }
1618
1619 return CMD_SUCCESS;
1620}
1621
9acb67cb
DS
1622DEFPY (bgp_global_suppress_fib_pending,
1623 bgp_global_suppress_fib_pending_cmd,
1624 "[no] bgp suppress-fib-pending",
1625 NO_STR
1626 BGP_STR
1627 "Advertise only routes that are programmed in kernel to peers globally\n")
1628{
1629 bm_wait_for_fib_set(!no);
1630
1631 return CMD_SUCCESS;
1632}
1633
c208c586
S
1634DEFPY (bgp_suppress_fib_pending,
1635 bgp_suppress_fib_pending_cmd,
1636 "[no] bgp suppress-fib-pending",
1637 NO_STR
1638 BGP_STR
1639 "Advertise only routes that are programmed in kernel to peers\n")
1640{
1641 VTY_DECLVAR_CONTEXT(bgp, bgp);
1642
1643 bgp_suppress_fib_pending_set(bgp, !no);
1644 return CMD_SUCCESS;
1645}
1646
1647
718e3744 1648/* BGP Cluster ID. */
ff8a8a7a
CS
1649DEFUN_YANG(bgp_cluster_id,
1650 bgp_cluster_id_cmd,
1651 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1652 BGP_STR
1653 "Configure Route-Reflector Cluster-id\n"
1654 "Route-Reflector Cluster-id in IP address format\n"
1655 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1656{
d62a17ae 1657 int idx_ipv4 = 2;
718e3744 1658
87ce2564
CS
1659 nb_cli_enqueue_change(
1660 vty, "./global/route-reflector/route-reflector-cluster-id",
1661 NB_OP_MODIFY, argv[idx_ipv4]->arg);
718e3744 1662
ff8a8a7a 1663 return nb_cli_apply_changes(vty, NULL);
718e3744 1664}
1665
ff8a8a7a
CS
1666DEFUN_YANG(no_bgp_cluster_id,
1667 no_bgp_cluster_id_cmd,
1668 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1669 NO_STR BGP_STR
1670 "Configure Route-Reflector Cluster-id\n"
1671 "Route-Reflector Cluster-id in IP address format\n"
1672 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1673{
87ce2564
CS
1674 nb_cli_enqueue_change(
1675 vty, "./global/route-reflector/route-reflector-cluster-id",
1676 NB_OP_DESTROY, NULL);
718e3744 1677
ff8a8a7a 1678 return nb_cli_apply_changes(vty, NULL);
718e3744 1679}
1680
c163f297
DS
1681DEFPY (bgp_norib,
1682 bgp_norib_cmd,
1683 "bgp no-rib",
1684 BGP_STR
1685 "Disable BGP route installation to RIB (Zebra)\n")
1686{
1687 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1688 vty_out(vty,
1689 "%% No-RIB option is already set, nothing to do here.\n");
1690 return CMD_SUCCESS;
1691 }
1692
1693 bgp_option_norib_set_runtime();
1694
1695 return CMD_SUCCESS;
1696}
1697
1698DEFPY (no_bgp_norib,
1699 no_bgp_norib_cmd,
1700 "no bgp no-rib",
1701 NO_STR
1702 BGP_STR
1703 "Disable BGP route installation to RIB (Zebra)\n")
1704{
1705 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1706 vty_out(vty,
1707 "%% No-RIB option is not set, nothing to do here.\n");
1708 return CMD_SUCCESS;
1709 }
1710
1711 bgp_option_norib_unset_runtime();
1712
1713 return CMD_SUCCESS;
1714}
1715
e46723a5
DS
1716DEFPY (no_bgp_send_extra_data,
1717 no_bgp_send_extra_data_cmd,
1718 "[no] bgp send-extra-data zebra",
1719 NO_STR
1720 BGP_STR
1721 "Extra data to Zebra for display/use\n"
1722 "To zebra\n")
1723{
ec0acb80
DA
1724 if (no)
1725 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1726 else
1727 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
e46723a5
DS
1728
1729 return CMD_SUCCESS;
1730}
1731
ff8a8a7a
CS
1732DEFUN_YANG(bgp_confederation_identifier,
1733 bgp_confederation_identifier_cmd,
1734 "bgp confederation identifier (1-4294967295)",
1735 "BGP specific commands\n"
1736 "AS confederation parameters\n"
1737 "AS number\n"
1738 "Set routing domain confederation AS\n")
718e3744 1739{
d62a17ae 1740 int idx_number = 3;
718e3744 1741
87ce2564
CS
1742 nb_cli_enqueue_change(vty, "./global/confederation/identifier",
1743 NB_OP_MODIFY, argv[idx_number]->arg);
718e3744 1744
ff8a8a7a 1745 return nb_cli_apply_changes(vty, NULL);
718e3744 1746}
1747
ff8a8a7a
CS
1748DEFUN_YANG(no_bgp_confederation_identifier,
1749 no_bgp_confederation_identifier_cmd,
1750 "no bgp confederation identifier [(1-4294967295)]",
1751 NO_STR
1752 "BGP specific commands\n"
1753 "AS confederation parameters\n"
1754 "AS number\n"
1755 "Set routing domain confederation AS\n")
718e3744 1756{
87ce2564
CS
1757 nb_cli_enqueue_change(vty, "./global/confederation/identifier",
1758 NB_OP_DESTROY, NULL);
718e3744 1759
ff8a8a7a 1760 return nb_cli_apply_changes(vty, NULL);
718e3744 1761}
1762
ff8a8a7a
CS
1763void cli_show_router_bgp_confederation_identifier(struct vty *vty,
1764 struct lyd_node *dnode,
1765 bool show_defaults)
1766{
1767 vty_out(vty, " bgp confederation identifier %u\n",
1768 yang_dnode_get_uint32(dnode, NULL));
1769}
1770
1771DEFUN_YANG(bgp_confederation_peers,
1772 bgp_confederation_peers_cmd,
1773 "bgp confederation peers (1-4294967295)...",
1774 "BGP specific commands\n"
1775 "AS confederation parameters\n"
1776 "Peer ASs in BGP confederation\n" AS_STR)
718e3744 1777{
d62a17ae 1778 int idx_asn = 3;
d62a17ae 1779 int i;
718e3744 1780
ff8a8a7a 1781 for (i = idx_asn; i < argc; i++)
87ce2564 1782 nb_cli_enqueue_change(vty, "./global/confederation/member-as",
ff8a8a7a 1783 NB_OP_CREATE, argv[i]->arg);
718e3744 1784
ff8a8a7a 1785 return nb_cli_apply_changes(vty, NULL);
718e3744 1786}
1787
ff8a8a7a
CS
1788DEFUN_YANG(no_bgp_confederation_peers,
1789 no_bgp_confederation_peers_cmd,
1790 "no bgp confederation peers (1-4294967295)...",
1791 NO_STR
1792 "BGP specific commands\n"
1793 "AS confederation parameters\n"
1794 "Peer ASs in BGP confederation\n" AS_STR)
718e3744 1795{
d62a17ae 1796 int idx_asn = 4;
d62a17ae 1797 int i;
718e3744 1798
ff8a8a7a 1799 for (i = idx_asn; i < argc; i++)
87ce2564 1800 nb_cli_enqueue_change(vty, "./global/confederation/member-as",
ff8a8a7a 1801 NB_OP_DESTROY, argv[i]->arg);
0b2aa3a0 1802
ff8a8a7a
CS
1803 return nb_cli_apply_changes(vty, NULL);
1804}
1805
1806void cli_show_router_bgp_confederation_member_as(struct vty *vty,
1807 struct lyd_node *dnode,
1808 bool show_defaults)
1809{
1810 vty_out(vty, " bgp confederation peers %u \n",
1811 yang_dnode_get_uint32(dnode, NULL));
718e3744 1812}
6b0655a2 1813
5e242b0d
DS
1814/**
1815 * Central routine for maximum-paths configuration.
1816 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1817 * @set: 1 for setting values, 0 for removing the max-paths config.
1818 */
37a87b8f
CS
1819int bgp_maxpaths_config_vty(struct bgp *bgp, afi_t afi, safi_t safi,
1820 int peer_type, uint16_t maxpaths, uint16_t options,
1821 int set, char *errmsg, size_t errmsg_len)
d62a17ae 1822{
d62a17ae 1823 int ret;
d62a17ae 1824
1825 if (set) {
d62a17ae 1826 if (maxpaths > multipath_num) {
37a87b8f
CS
1827 snprintf(
1828 errmsg, errmsg_len,
d62a17ae 1829 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1830 maxpaths, multipath_num);
1831 return CMD_WARNING_CONFIG_FAILED;
1832 }
1833 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1834 options);
1835 } else
1836 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1837
1838 if (ret < 0) {
37a87b8f
CS
1839 snprintf(
1840 errmsg, errmsg_len,
d62a17ae 1841 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1842 (set == 1) ? "" : "un",
1843 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1844 maxpaths, afi, safi);
1845 return CMD_WARNING_CONFIG_FAILED;
1846 }
1847
1848 bgp_recalculate_all_bestpaths(bgp);
1849
1850 return CMD_SUCCESS;
165b5fff
JB
1851}
1852
ff8a8a7a
CS
1853void cli_show_router_bgp_med_config(struct vty *vty, struct lyd_node *dnode,
1854 bool show_defaults)
abc920f8 1855{
ff8a8a7a
CS
1856 if (yang_dnode_get_bool(dnode, "./enable-med-admin")) {
1857 uint32_t med_admin_val;
abc920f8 1858
ff8a8a7a 1859 vty_out(vty, " bgp max-med administrative");
4953391b
DA
1860 med_admin_val = yang_dnode_get_uint32(dnode, "./max-med-admin");
1861 if (med_admin_val != BGP_MAXMED_VALUE_DEFAULT)
ff8a8a7a
CS
1862 vty_out(vty, " %u", med_admin_val);
1863 vty_out(vty, "\n");
1864 }
abc920f8 1865
ff8a8a7a
CS
1866 if (yang_dnode_exists(dnode, "./max-med-onstart-up-time")) {
1867 uint32_t onstartup_val;
abc920f8 1868
ff8a8a7a
CS
1869 vty_out(vty, " bgp max-med on-startup %u",
1870 yang_dnode_get_uint32(dnode,
1871 "./max-med-onstart-up-time"));
1872 onstartup_val = yang_dnode_get_uint32(
1873 dnode, "./max-med-onstart-up-value");
1874 if (onstartup_val != BGP_MAXMED_VALUE_DEFAULT)
1875 vty_out(vty, " %u", onstartup_val);
1876
1877 vty_out(vty, "\n");
1878 }
abc920f8
DS
1879}
1880
ff8a8a7a
CS
1881DEFUN_YANG(bgp_maxmed_admin,
1882 bgp_maxmed_admin_cmd,
1883 "bgp max-med administrative ",
1884 BGP_STR
1885 "Advertise routes with max-med\n"
1886 "Administratively applied, for an indefinite period\n")
1887{
87ce2564 1888 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
ff8a8a7a
CS
1889 NB_OP_MODIFY, "true");
1890
1891 return nb_cli_apply_changes(vty, NULL);
1892}
1893
1894DEFUN_YANG(bgp_maxmed_admin_medv,
1895 bgp_maxmed_admin_medv_cmd,
1896 "bgp max-med administrative (0-4294967295)",
1897 BGP_STR
1898 "Advertise routes with max-med\n"
1899 "Administratively applied, for an indefinite period\n"
1900 "Max MED value to be used\n")
abc920f8 1901{
d62a17ae 1902 int idx_number = 3;
abc920f8 1903
87ce2564 1904 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
ff8a8a7a 1905 NB_OP_MODIFY, "true");
abc920f8 1906
87ce2564
CS
1907 nb_cli_enqueue_change(vty, "./global/med-config/max-med-admin",
1908 NB_OP_MODIFY, argv[idx_number]->arg);
abc920f8 1909
ff8a8a7a 1910 return nb_cli_apply_changes(vty, NULL);
abc920f8
DS
1911}
1912
ff8a8a7a
CS
1913DEFUN_YANG(no_bgp_maxmed_admin,
1914 no_bgp_maxmed_admin_cmd,
1915 "no bgp max-med administrative [(0-4294967295)]",
1916 NO_STR BGP_STR
1917 "Advertise routes with max-med\n"
1918 "Administratively applied, for an indefinite period\n"
1919 "Max MED value to be used\n")
abc920f8 1920{
87ce2564 1921 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
ff8a8a7a 1922 NB_OP_MODIFY, "false");
abc920f8 1923
87ce2564
CS
1924 nb_cli_enqueue_change(vty, "./global/med-config/max-med-admin",
1925 NB_OP_MODIFY, NULL);
ff8a8a7a
CS
1926
1927 return nb_cli_apply_changes(vty, NULL);
abc920f8
DS
1928}
1929
37a87b8f
CS
1930DEFUN_YANG (bgp_maxmed_onstartup,
1931 bgp_maxmed_onstartup_cmd,
1932 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1933 BGP_STR
1934 "Advertise routes with max-med\n"
1935 "Effective on a startup\n"
1936 "Time (seconds) period for max-med\n"
1937 "Max MED value to be used\n")
abc920f8 1938{
d62a17ae 1939 int idx = 0;
4668a151 1940
d62a17ae 1941 argv_find(argv, argc, "(5-86400)", &idx);
87ce2564
CS
1942 nb_cli_enqueue_change(vty,
1943 "./global/med-config/max-med-onstart-up-time",
ff8a8a7a
CS
1944 NB_OP_MODIFY, argv[idx]->arg);
1945
d62a17ae 1946 if (argv_find(argv, argc, "(0-4294967295)", &idx))
87ce2564
CS
1947 nb_cli_enqueue_change(
1948 vty, "./global/med-config/max-med-onstart-up-value",
1949 NB_OP_MODIFY, argv[idx]->arg);
d62a17ae 1950 else
87ce2564
CS
1951 nb_cli_enqueue_change(
1952 vty, "./global/med-config/max-med-onstart-up-value",
1953 NB_OP_MODIFY, NULL);
abc920f8 1954
ff8a8a7a 1955 return nb_cli_apply_changes(vty, NULL);
abc920f8
DS
1956}
1957
37a87b8f
CS
1958DEFUN_YANG (no_bgp_maxmed_onstartup,
1959 no_bgp_maxmed_onstartup_cmd,
1960 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1961 NO_STR BGP_STR
1962 "Advertise routes with max-med\n"
1963 "Effective on a startup\n"
1964 "Time (seconds) period for max-med\n"
1965 "Max MED value to be used\n")
abc920f8 1966{
87ce2564
CS
1967 nb_cli_enqueue_change(vty,
1968 "./global/med-config/max-med-onstart-up-time",
ff8a8a7a 1969 NB_OP_DESTROY, NULL);
abc920f8 1970
87ce2564
CS
1971 nb_cli_enqueue_change(vty,
1972 "./global/med-config/max-med-onstart-up-value",
ff8a8a7a 1973 NB_OP_MODIFY, NULL);
abc920f8 1974
ff8a8a7a 1975 return nb_cli_apply_changes(vty, NULL);
abc920f8
DS
1976}
1977
d70583f7
D
1978static int bgp_global_update_delay_config_vty(struct vty *vty,
1979 uint16_t update_delay,
1980 uint16_t establish_wait)
1981{
1982 struct listnode *node, *nnode;
1983 struct bgp *bgp;
1984 bool vrf_cfg = false;
1985
1986 /*
1987 * See if update-delay is set per-vrf and warn user to delete it
1988 * Note that we only need to check this if this is the first time
1989 * setting the global config.
1990 */
1991 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
1992 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1993 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1994 vty_out(vty,
1995 "%% update-delay configuration found in vrf %s\n",
1996 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
1997 ? VRF_DEFAULT_NAME
1998 : bgp->name);
1999 vrf_cfg = true;
2000 }
2001 }
2002 }
2003
2004 if (vrf_cfg) {
2005 vty_out(vty,
2006 "%%Failed: global update-delay config not permitted\n");
2007 return CMD_WARNING;
2008 }
2009
2010 if (!establish_wait) { /* update-delay <delay> */
2011 bm->v_update_delay = update_delay;
2012 bm->v_establish_wait = bm->v_update_delay;
2013 } else {
2014 /* update-delay <delay> <establish-wait> */
2015 if (update_delay < establish_wait) {
2016 vty_out(vty,
2017 "%%Failed: update-delay less than the establish-wait!\n");
2018 return CMD_WARNING_CONFIG_FAILED;
2019 }
2020
2021 bm->v_update_delay = update_delay;
2022 bm->v_establish_wait = establish_wait;
2023 }
2024
2025 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2026 bgp->v_update_delay = bm->v_update_delay;
2027 bgp->v_establish_wait = bm->v_establish_wait;
2028 }
2029
2030 return CMD_SUCCESS;
2031}
2032
2033static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
2034{
2035 struct listnode *node, *nnode;
2036 struct bgp *bgp;
2037
2038 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
2039 bm->v_establish_wait = bm->v_update_delay;
2040
2041 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2042 bgp->v_update_delay = bm->v_update_delay;
2043 bgp->v_establish_wait = bm->v_establish_wait;
2044 }
2045
2046 return CMD_SUCCESS;
2047}
2048
2049static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
2050 uint16_t establish_wait)
f188f2c4 2051{
d62a17ae 2052 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 2053
d70583f7
D
2054 /* if configured globally, per-instance config is not allowed */
2055 if (bm->v_update_delay) {
2056 vty_out(vty,
2057 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
2058 return CMD_WARNING_CONFIG_FAILED;
2059 }
2060
f188f2c4 2061
d70583f7 2062 if (!establish_wait) /* update-delay <delay> */
d62a17ae 2063 {
2064 bgp->v_update_delay = update_delay;
2065 bgp->v_establish_wait = bgp->v_update_delay;
2066 return CMD_SUCCESS;
2067 }
f188f2c4 2068
d62a17ae 2069 /* update-delay <delay> <establish-wait> */
d62a17ae 2070 if (update_delay < establish_wait) {
2071 vty_out(vty,
2072 "%%Failed: update-delay less than the establish-wait!\n");
2073 return CMD_WARNING_CONFIG_FAILED;
2074 }
f188f2c4 2075
d62a17ae 2076 bgp->v_update_delay = update_delay;
2077 bgp->v_establish_wait = establish_wait;
f188f2c4 2078
d62a17ae 2079 return CMD_SUCCESS;
f188f2c4
DS
2080}
2081
d62a17ae 2082static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 2083{
d62a17ae 2084 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 2085
d70583f7
D
2086 /* If configured globally, cannot remove from one bgp instance */
2087 if (bm->v_update_delay) {
2088 vty_out(vty,
2089 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2090 return CMD_WARNING_CONFIG_FAILED;
2091 }
d62a17ae 2092 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2093 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 2094
d62a17ae 2095 return CMD_SUCCESS;
f188f2c4
DS
2096}
2097
2b791107 2098void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 2099{
d70583f7
D
2100 /* If configured globally, no need to display per-instance value */
2101 if (bgp->v_update_delay != bm->v_update_delay) {
d62a17ae 2102 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2103 if (bgp->v_update_delay != bgp->v_establish_wait)
2104 vty_out(vty, " %d", bgp->v_establish_wait);
2105 vty_out(vty, "\n");
2106 }
f188f2c4
DS
2107}
2108
d70583f7
D
2109/* Global update-delay configuration */
2110DEFPY (bgp_global_update_delay,
2111 bgp_global_update_delay_cmd,
2112 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2113 BGP_STR
2114 "Force initial delay for best-path and updates for all bgp instances\n"
2115 "Max delay in seconds\n"
2116 "Establish wait in seconds\n")
2117{
2118 return bgp_global_update_delay_config_vty(vty, delay, wait);
2119}
f188f2c4 2120
d70583f7
D
2121/* Global update-delay deconfiguration */
2122DEFPY (no_bgp_global_update_delay,
2123 no_bgp_global_update_delay_cmd,
2124 "no bgp update-delay [(0-3600) [(1-3600)]]",
2125 NO_STR
2126 BGP_STR
f188f2c4 2127 "Force initial delay for best-path and updates\n"
d70583f7
D
2128 "Max delay in seconds\n"
2129 "Establish wait in seconds\n")
f188f2c4 2130{
d70583f7 2131 return bgp_global_update_delay_deconfig_vty(vty);
f188f2c4
DS
2132}
2133
d70583f7
D
2134/* Update-delay configuration */
2135
2136DEFPY (bgp_update_delay,
2137 bgp_update_delay_cmd,
2138 "update-delay (0-3600)$delay [(1-3600)$wait]",
f188f2c4 2139 "Force initial delay for best-path and updates\n"
d70583f7
D
2140 "Max delay in seconds\n"
2141 "Establish wait in seconds\n")
f188f2c4 2142{
d70583f7 2143 return bgp_update_delay_config_vty(vty, delay, wait);
f188f2c4
DS
2144}
2145
2146/* Update-delay deconfiguration */
d70583f7 2147DEFPY (no_bgp_update_delay,
f188f2c4 2148 no_bgp_update_delay_cmd,
838758ac
DW
2149 "no update-delay [(0-3600) [(1-3600)]]",
2150 NO_STR
f188f2c4 2151 "Force initial delay for best-path and updates\n"
d70583f7
D
2152 "Max delay in seconds\n"
2153 "Establish wait in seconds\n")
f188f2c4 2154{
d62a17ae 2155 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
2156}
2157
5e242b0d 2158
ff8a8a7a 2159int bgp_wpkt_quanta_config_vty(struct bgp *bgp, uint32_t quanta, bool set)
cb1faec9 2160{
8fa7732f
QY
2161 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2162 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
555e09d4
QY
2163
2164 return CMD_SUCCESS;
2165}
2166
ff8a8a7a 2167int bgp_rpkt_quanta_config_vty(struct bgp *bgp, uint32_t quanta, bool set)
555e09d4 2168{
8fa7732f
QY
2169 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2170 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
cb1faec9 2171
d62a17ae 2172 return CMD_SUCCESS;
cb1faec9
DS
2173}
2174
2b791107 2175void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 2176{
555e09d4
QY
2177 uint32_t quanta =
2178 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2179 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 2180 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
2181}
2182
555e09d4
QY
2183void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2184{
2185 uint32_t quanta =
2186 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2187 if (quanta != BGP_READ_PACKET_MAX)
152456fe 2188 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 2189}
cb1faec9 2190
8fa7732f
QY
2191/* Packet quanta configuration
2192 *
2193 * XXX: The value set here controls the size of a stack buffer in the IO
2194 * thread. When changing these limits be careful to prevent stack overflow.
2195 *
2196 * Furthermore, the maximums used here should correspond to
2197 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2198 */
37a87b8f
CS
2199DEFPY_YANG (bgp_wpkt_quanta,
2200 bgp_wpkt_quanta_cmd,
2201 "[no] write-quanta (1-64)$quanta",
2202 NO_STR
2203 "How many packets to write to peer socket per run\n"
2204 "Number of packets\n")
ff8a8a7a
CS
2205{
2206 if (!no)
2207 nb_cli_enqueue_change(
2208 vty,
87ce2564 2209 "./global/global-neighbor-config/packet-quanta-config/wpkt-quanta",
ff8a8a7a
CS
2210 NB_OP_MODIFY, quanta_str);
2211 else
2212 nb_cli_enqueue_change(
2213 vty,
87ce2564 2214 "./global/global-neighbor-config/packet-quanta-config/wpkt-quanta",
ff8a8a7a
CS
2215 NB_OP_MODIFY, NULL);
2216
2217 return nb_cli_apply_changes(vty, NULL);
2218}
2219
37a87b8f
CS
2220DEFPY_YANG (bgp_rpkt_quanta,
2221 bgp_rpkt_quanta_cmd,
2222 "[no] read-quanta (1-10)$quanta",
2223 NO_STR
2224 "How many packets to read from peer socket per I/O cycle\n"
2225 "Number of packets\n")
ff8a8a7a
CS
2226{
2227 if (!no)
2228 nb_cli_enqueue_change(
2229 vty,
87ce2564 2230 "./global/global-neighbor-config/packet-quanta-config/rpkt-quanta",
ff8a8a7a
CS
2231 NB_OP_MODIFY, quanta_str);
2232 else
2233 nb_cli_enqueue_change(
2234 vty,
87ce2564 2235 "./global/global-neighbor-config/packet-quanta-config/rpkt-quanta",
ff8a8a7a 2236 NB_OP_MODIFY, NULL);
cb1faec9 2237
ff8a8a7a 2238 return nb_cli_apply_changes(vty, NULL);
555e09d4
QY
2239}
2240
2b791107 2241void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 2242{
37a333fe 2243 if (!bgp->heuristic_coalesce)
d62a17ae 2244 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
2245}
2246
ff8a8a7a
CS
2247void cli_show_router_global_update_group_config_coalesce_time(
2248 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
3f9c7369 2249{
ff8a8a7a
CS
2250 vty_out(vty, " coalesce-time %u\n", yang_dnode_get_uint32(dnode, NULL));
2251}
2252
4668a151 2253
37a87b8f
CS
2254DEFUN_YANG (bgp_coalesce_time,
2255 bgp_coalesce_time_cmd,
2256 "coalesce-time (0-4294967295)",
2257 "Subgroup coalesce timer\n"
2258 "Subgroup coalesce timer value (in ms)\n")
ff8a8a7a 2259{
d62a17ae 2260 int idx = 0;
ff8a8a7a 2261
d62a17ae 2262 argv_find(argv, argc, "(0-4294967295)", &idx);
87ce2564
CS
2263 nb_cli_enqueue_change(
2264 vty, "./global/global-update-group-config/coalesce-time",
2265 NB_OP_MODIFY, argv[idx]->arg);
ff8a8a7a
CS
2266
2267 return nb_cli_apply_changes(vty, NULL);
3f9c7369
DS
2268}
2269
ff8a8a7a
CS
2270DEFUN_YANG(no_bgp_coalesce_time,
2271 no_bgp_coalesce_time_cmd,
2272 "no coalesce-time (0-4294967295)",
2273 NO_STR
2274 "Subgroup coalesce timer\n"
2275 "Subgroup coalesce timer value (in ms)\n")
3f9c7369 2276{
87ce2564
CS
2277 nb_cli_enqueue_change(
2278 vty, "./global/global-update-group-config/coalesce-time",
2279 NB_OP_MODIFY, NULL);
4668a151 2280
ff8a8a7a 2281 return nb_cli_apply_changes(vty, NULL);
3f9c7369
DS
2282}
2283
5e242b0d 2284/* Maximum-paths configuration */
37a87b8f
CS
2285DEFUN_YANG (bgp_maxpaths,
2286 bgp_maxpaths_cmd,
2287 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2288 "Forward packets over multiple paths\n"
2289 "Number of paths\n")
5e242b0d 2290{
d62a17ae 2291 int idx_number = 1;
37a87b8f
CS
2292 char base_xpath[XPATH_MAXLEN];
2293 afi_t afi;
2294 safi_t safi;
2295
2296 afi = bgp_node_afi(vty);
2297 safi = bgp_node_safi(vty);
2298
2299 snprintf(
2300 base_xpath, sizeof(base_xpath),
2301 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ebgp/maximum-paths",
2302 yang_afi_safi_value2identity(afi, safi),
2303 bgp_afi_safi_get_container_str(afi, safi));
2304
2305 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2306 argv[idx_number]->arg);
2307
2308 return nb_cli_apply_changes(vty, NULL);
2309}
2310
2311void cli_show_bgp_global_afi_safi_unicast_use_multiple_paths_ebgp_maximum_paths(
2312 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
2313{
2314 vty_out(vty, " maximum-paths %d\n",
2315 yang_dnode_get_uint16(dnode, NULL));
5e242b0d
DS
2316}
2317
d62a17ae 2318ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2319 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2320 "Forward packets over multiple paths\n"
2321 "Number of paths\n")
596c17ba 2322
37a87b8f
CS
2323DEFUN_YANG (bgp_maxpaths_ibgp,
2324 bgp_maxpaths_ibgp_cmd,
2325 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2326 "Forward packets over multiple paths\n"
2327 "iBGP-multipath\n"
2328 "Number of paths\n")
165b5fff 2329{
d62a17ae 2330 int idx_number = 2;
37a87b8f
CS
2331 char base_xpath[XPATH_MAXLEN];
2332 afi_t afi;
2333 safi_t safi;
2334
2335 afi = bgp_node_afi(vty);
2336 safi = bgp_node_safi(vty);
2337
2338 snprintf(
2339 base_xpath, sizeof(base_xpath),
2340 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2341 yang_afi_safi_value2identity(afi, safi),
2342 bgp_afi_safi_get_container_str(afi, safi));
2343
2344 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2345 argv[idx_number]->arg);
2346
2347 return nb_cli_apply_changes(vty, NULL);
5e242b0d 2348}
165b5fff 2349
d62a17ae 2350ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2351 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2352 "Forward packets over multiple paths\n"
2353 "iBGP-multipath\n"
2354 "Number of paths\n")
596c17ba 2355
37a87b8f
CS
2356DEFUN_YANG (bgp_maxpaths_ibgp_cluster,
2357 bgp_maxpaths_ibgp_cluster_cmd,
2358 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2359 "Forward packets over multiple paths\n"
2360 "iBGP-multipath\n"
2361 "Number of paths\n"
2362 "Match the cluster length\n")
5e242b0d 2363{
d62a17ae 2364 int idx_number = 2;
37a87b8f
CS
2365 char base_xpath[XPATH_MAXLEN];
2366 afi_t afi;
2367 safi_t safi;
2368
2369 afi = bgp_node_afi(vty);
2370 safi = bgp_node_safi(vty);
2371
2372 snprintf(
2373 base_xpath, sizeof(base_xpath),
2374 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2375 yang_afi_safi_value2identity(afi, safi),
2376 bgp_afi_safi_get_container_str(afi, safi));
2377
2378 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2379 argv[idx_number]->arg);
2380
2381 snprintf(
2382 base_xpath, sizeof(base_xpath),
2383 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/cluster-length-list",
2384 yang_afi_safi_value2identity(afi, safi),
2385 bgp_afi_safi_get_container_str(afi, safi));
2386
2387 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, "true");
2388
2389 return nb_cli_apply_changes(vty, NULL);
2390}
2391
2392void cli_show_bgp_global_afi_safi_ip_unicast_use_multiple_paths_ibgp_maximum_paths(
2393 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
2394{
2395 vty_out(vty, " maximum-paths ibgp %d",
2396 yang_dnode_get_uint16(dnode, "./maximum-paths"));
2397 if (yang_dnode_get_bool(dnode, "./cluster-length-list"))
2398 vty_out(vty, " equal-cluster-length");
2399 vty_out(vty, "\n");
165b5fff
JB
2400}
2401
d62a17ae 2402ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2403 "maximum-paths ibgp " CMD_RANGE_STR(
2404 1, MULTIPATH_NUM) " equal-cluster-length",
2405 "Forward packets over multiple paths\n"
2406 "iBGP-multipath\n"
2407 "Number of paths\n"
2408 "Match the cluster length\n")
596c17ba 2409
37a87b8f
CS
2410DEFUN_YANG (no_bgp_maxpaths,
2411 no_bgp_maxpaths_cmd,
2412 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2413 NO_STR
2414 "Forward packets over multiple paths\n"
2415 "Number of paths\n")
165b5fff 2416{
37a87b8f
CS
2417 char base_xpath[XPATH_MAXLEN];
2418 afi_t afi;
2419 safi_t safi;
2420
2421 afi = bgp_node_afi(vty);
2422 safi = bgp_node_safi(vty);
2423
2424 snprintf(
2425 base_xpath, sizeof(base_xpath),
2426 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ebgp/maximum-paths",
2427 yang_afi_safi_value2identity(afi, safi),
2428 bgp_afi_safi_get_container_str(afi, safi));
2429
2430 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, NULL);
2431
2432 return nb_cli_apply_changes(vty, NULL);
165b5fff
JB
2433}
2434
d62a17ae 2435ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 2436 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 2437 "Forward packets over multiple paths\n"
2438 "Number of paths\n")
596c17ba 2439
37a87b8f
CS
2440DEFUN_YANG (no_bgp_maxpaths_ibgp,
2441 no_bgp_maxpaths_ibgp_cmd,
2442 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2443 NO_STR
2444 "Forward packets over multiple paths\n"
2445 "iBGP-multipath\n"
2446 "Number of paths\n"
2447 "Match the cluster length\n")
165b5fff 2448{
37a87b8f
CS
2449 char base_xpath[XPATH_MAXLEN];
2450 afi_t afi;
2451 safi_t safi;
2452
2453 afi = bgp_node_afi(vty);
2454 safi = bgp_node_safi(vty);
2455
2456 snprintf(
2457 base_xpath, sizeof(base_xpath),
2458 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2459 yang_afi_safi_value2identity(afi, safi),
2460 bgp_afi_safi_get_container_str(afi, safi));
2461
2462 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, NULL);
2463
2464 snprintf(
2465 base_xpath, sizeof(base_xpath),
2466 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/cluster-length-list",
2467 yang_afi_safi_value2identity(afi, safi),
2468 bgp_afi_safi_get_container_str(afi, safi));
2469
2470 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, "false");
2471
2472 return nb_cli_apply_changes(vty, NULL);
165b5fff
JB
2473}
2474
d62a17ae 2475ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2476 "no maximum-paths ibgp [" CMD_RANGE_STR(
2477 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2478 NO_STR
2479 "Forward packets over multiple paths\n"
2480 "iBGP-multipath\n"
2481 "Number of paths\n"
2482 "Match the cluster length\n")
596c17ba 2483
dd65f45e
DL
2484static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2485 afi_t afi, safi_t safi)
165b5fff 2486{
00908b7a 2487 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
d62a17ae 2488 vty_out(vty, " maximum-paths %d\n",
2489 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2490 }
165b5fff 2491
00908b7a 2492 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
d62a17ae 2493 vty_out(vty, " maximum-paths ibgp %d",
2494 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2495 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
2496 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
2497 vty_out(vty, " equal-cluster-length");
2498 vty_out(vty, "\n");
2499 }
165b5fff 2500}
6b0655a2 2501
718e3744 2502/* BGP timers. */
2503
37a87b8f
CS
2504DEFUN_YANG (bgp_timers,
2505 bgp_timers_cmd,
2506 "timers bgp (0-65535) (0-65535)",
2507 "Adjust routing timers\n"
2508 "BGP timers\n"
2509 "Keepalive interval\n"
2510 "Holdtime\n")
718e3744 2511{
d62a17ae 2512 int idx_number = 2;
2513 int idx_number_2 = 3;
718e3744 2514
87ce2564 2515 nb_cli_enqueue_change(vty, "./global/global-config-timers/keepalive",
ff8a8a7a 2516 NB_OP_MODIFY, argv[idx_number]->arg);
87ce2564 2517 nb_cli_enqueue_change(vty, "./global/global-config-timers/hold-time",
ff8a8a7a 2518 NB_OP_MODIFY, argv[idx_number_2]->arg);
718e3744 2519
ff8a8a7a
CS
2520 return nb_cli_apply_changes(vty, NULL);
2521}
718e3744 2522
37a87b8f
CS
2523DEFUN_YANG (no_bgp_timers,
2524 no_bgp_timers_cmd,
2525 "no timers bgp [(0-65535) (0-65535)]",
2526 NO_STR
2527 "Adjust routing timers\n"
2528 "BGP timers\n"
2529 "Keepalive interval\n"
2530 "Holdtime\n")
ff8a8a7a 2531{
87ce2564 2532 nb_cli_enqueue_change(vty, "./global/global-config-timers/keepalive",
ff8a8a7a 2533 NB_OP_DESTROY, NULL);
87ce2564 2534 nb_cli_enqueue_change(vty, "./global/global-config-timers/hold-time",
ff8a8a7a 2535 NB_OP_DESTROY, NULL);
718e3744 2536
ff8a8a7a 2537 return nb_cli_apply_changes(vty, NULL);
718e3744 2538}
2539
ff8a8a7a
CS
2540void cli_show_router_bgp_route_reflector(struct vty *vty,
2541 struct lyd_node *dnode,
2542 bool show_defaults)
718e3744 2543{
ff8a8a7a
CS
2544 if (yang_dnode_get_bool(dnode, "./no-client-reflect"))
2545 vty_out(vty, " no bgp client-to-client reflection\n");
718e3744 2546
ff8a8a7a
CS
2547 if (yang_dnode_get_bool(dnode, "./allow-outbound-policy"))
2548 vty_out(vty, " bgp route-reflector allow-outbound-policy\n");
2549
2550 if (yang_dnode_exists(dnode, "./route-reflector-cluster-id"))
2551 vty_out(vty, " bgp cluster-id %s\n",
2552 yang_dnode_get_string(dnode,
2553 "./route-reflector-cluster-id"));
718e3744 2554}
2555
ff8a8a7a
CS
2556DEFUN_YANG(bgp_client_to_client_reflection,
2557 bgp_client_to_client_reflection_cmd,
2558 "bgp client-to-client reflection",
2559 "BGP specific commands\n"
2560 "Configure client to client route reflection\n"
2561 "reflection of routes allowed\n")
2562{
87ce2564 2563 nb_cli_enqueue_change(vty, "./global/route-reflector/no-client-reflect",
ff8a8a7a 2564 NB_OP_MODIFY, "false");
6b0655a2 2565
ff8a8a7a
CS
2566 return nb_cli_apply_changes(vty, NULL);
2567}
2568
2569DEFUN_YANG(no_bgp_client_to_client_reflection,
2570 no_bgp_client_to_client_reflection_cmd,
2571 "no bgp client-to-client reflection",
2572 NO_STR
2573 "BGP specific commands\n"
2574 "Configure client to client route reflection\n"
2575 "reflection of routes allowed\n")
718e3744 2576{
87ce2564 2577 nb_cli_enqueue_change(vty, "./global/route-reflector/no-client-reflect",
ff8a8a7a 2578 NB_OP_MODIFY, "true");
7aafcaca 2579
ff8a8a7a 2580 return nb_cli_apply_changes(vty, NULL);
718e3744 2581}
2582
ff8a8a7a
CS
2583void cli_show_router_bgp_route_selection(struct vty *vty,
2584 struct lyd_node *dnode,
2585 bool show_defaults)
718e3744 2586{
7aafcaca 2587
ff8a8a7a
CS
2588 if (yang_dnode_get_bool(dnode, "./always-compare-med"))
2589 vty_out(vty, " bgp always-compare-med\n");
2590
2591 if (yang_dnode_get_bool(dnode, "./ignore-as-path-length"))
2592 vty_out(vty, " bgp bestpath as-path ignore\n");
2593
2594 if (yang_dnode_get_bool(dnode, "./aspath-confed"))
2595 vty_out(vty, " bgp bestpath as-path confed\n");
2596
2597 if (yang_dnode_get_bool(dnode, "./external-compare-router-id"))
2598 vty_out(vty, " bgp bestpath compare-routerid\n");
2599
2600 if (yang_dnode_get_bool(dnode, "./allow-multiple-as")) {
2601 if (yang_dnode_get_bool(dnode, "./multi-path-as-set"))
2602 vty_out(vty,
2603 " bgp bestpath as-path multipath-relax as-set\n");
2604 else
2605 vty_out(vty, " bgp bestpath as-path multipath-relax\n");
2606 }
2607
2608 if (yang_dnode_get_bool(dnode, "./deterministic-med"))
2609 vty_out(vty, " bgp deterministic-med\n");
2610
2611 if (yang_dnode_get_bool(dnode, "./confed-med")
2612 || yang_dnode_get_bool(dnode, "./missing-as-worst-med")) {
2613 vty_out(vty, " bgp bestpath med");
2614 if (yang_dnode_get_bool(dnode, "./confed-med"))
2615 vty_out(vty, " confed");
2616 if (yang_dnode_get_bool(dnode, "./missing-as-worst-med"))
2617 vty_out(vty, " missing-as-worst");
2618 vty_out(vty, "\n");
2619 }
718e3744 2620}
2621
2622/* "bgp always-compare-med" configuration. */
ff8a8a7a
CS
2623DEFUN_YANG(bgp_always_compare_med,
2624 bgp_always_compare_med_cmd,
2625 "bgp always-compare-med",
2626 "BGP specific commands\n"
2627 "Allow comparing MED from different neighbors\n")
718e3744 2628{
87ce2564
CS
2629 nb_cli_enqueue_change(
2630 vty, "./global/route-selection-options/always-compare-med",
2631 NB_OP_MODIFY, "true");
7aafcaca 2632
ff8a8a7a 2633 return nb_cli_apply_changes(vty, NULL);
718e3744 2634}
2635
ff8a8a7a
CS
2636DEFUN_YANG(no_bgp_always_compare_med,
2637 no_bgp_always_compare_med_cmd,
2638 "no bgp always-compare-med",
2639 NO_STR
2640 "BGP specific commands\n"
2641 "Allow comparing MED from different neighbors\n")
718e3744 2642{
87ce2564
CS
2643 nb_cli_enqueue_change(
2644 vty, "./global/route-selection-options/always-compare-med",
2645 NB_OP_MODIFY, "false");
7aafcaca 2646
ff8a8a7a 2647 return nb_cli_apply_changes(vty, NULL);
718e3744 2648}
6b0655a2 2649
2adac256
DA
2650DEFUN_YANG(bgp_suppress_duplicates,
2651 bgp_suppress_duplicates_cmd,
2652 "bgp suppress-duplicates",
2653 "BGP specific commands\n"
2654 "Suppress duplicate updates if the route actually not changed\n")
2655{
2656 nb_cli_enqueue_change(vty, "./global/suppress-duplicates",
2657 NB_OP_MODIFY, "true");
2658 return nb_cli_apply_changes(vty, NULL);
2659}
2660
2661DEFUN_YANG(no_bgp_suppress_duplicates,
2662 no_bgp_suppress_duplicates_cmd,
2663 "no bgp suppress-duplicates",
2664 NO_STR
2665 "BGP specific commands\n"
2666 "Suppress duplicate updates if the route actually not changed\n")
2667{
2668 nb_cli_enqueue_change(vty, "./global/suppress-duplicates",
2669 NB_OP_MODIFY, "false");
2670 return nb_cli_apply_changes(vty, NULL);
2671}
2672
2673void cli_show_router_bgp_suppress_duplicates(struct vty *vty,
2674 struct lyd_node *dnode,
2675 bool show_defaults)
2676{
2677 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SUPPRESS_DUPLICATES)
2678 vty_out(vty, " bgp suppress-duplicates\n");
2679}
2680
ff8a8a7a
CS
2681DEFUN_YANG(bgp_ebgp_requires_policy,
2682 bgp_ebgp_requires_policy_cmd,
2683 "bgp ebgp-requires-policy",
2684 "BGP specific commands\n"
2685 "Require in and out policy for eBGP peers (RFC8212)\n")
2686{
87ce2564
CS
2687 nb_cli_enqueue_change(vty, "./global/ebgp-requires-policy",
2688 NB_OP_MODIFY, "true");
ff8a8a7a
CS
2689 return nb_cli_apply_changes(vty, NULL);
2690}
9dac9fc8 2691
ff8a8a7a
CS
2692DEFUN_YANG(no_bgp_ebgp_requires_policy,
2693 no_bgp_ebgp_requires_policy_cmd,
2694 "no bgp ebgp-requires-policy",
2695 NO_STR
2696 "BGP specific commands\n"
2697 "Require in and out policy for eBGP peers (RFC8212)\n")
9dac9fc8 2698{
87ce2564
CS
2699 nb_cli_enqueue_change(vty, "./global/ebgp-requires-policy",
2700 NB_OP_MODIFY, "false");
ff8a8a7a 2701 return nb_cli_apply_changes(vty, NULL);
9dac9fc8
DA
2702}
2703
ff8a8a7a
CS
2704void cli_show_router_bgp_ebgp_requires_policy(struct vty *vty,
2705 struct lyd_node *dnode,
2706 bool show_defaults)
9dac9fc8 2707{
ff8a8a7a
CS
2708 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_EBGP_REQUIRES_POLICY)
2709 vty_out(vty, " bgp ebgp-requires-policy\n");
9dac9fc8
DA
2710}
2711
fb29348a
DA
2712DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2713 "bgp reject-as-sets",
2714 "BGP specific commands\n"
2715 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2716{
2717 VTY_DECLVAR_CONTEXT(bgp, bgp);
2718 struct listnode *node, *nnode;
2719 struct peer *peer;
2720
7f972cd8 2721 bgp->reject_as_sets = true;
fb29348a
DA
2722
2723 /* Reset existing BGP sessions to reject routes
2724 * with aspath containing AS_SET or AS_CONFED_SET.
2725 */
2726 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2727 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2728 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2729 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2730 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2731 }
2732 }
2733
2734 return CMD_SUCCESS;
2735}
2736
2737DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2738 "no bgp reject-as-sets",
2739 NO_STR
2740 "BGP specific commands\n"
2741 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2742{
2743 VTY_DECLVAR_CONTEXT(bgp, bgp);
2744 struct listnode *node, *nnode;
2745 struct peer *peer;
2746
7f972cd8 2747 bgp->reject_as_sets = false;
fb29348a
DA
2748
2749 /* Reset existing BGP sessions to reject routes
2750 * with aspath containing AS_SET or AS_CONFED_SET.
2751 */
2752 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2753 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2754 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2755 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2756 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2757 }
2758 }
2759
2760 return CMD_SUCCESS;
2761}
9dac9fc8 2762
718e3744 2763/* "bgp deterministic-med" configuration. */
ff8a8a7a 2764DEFUN_YANG (bgp_deterministic_med,
718e3744 2765 bgp_deterministic_med_cmd,
2766 "bgp deterministic-med",
2767 "BGP specific commands\n"
2768 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2769{
87ce2564
CS
2770 nb_cli_enqueue_change(
2771 vty, "./global/route-selection-options/deterministic-med",
2772 NB_OP_MODIFY, "true");
7aafcaca 2773
ff8a8a7a 2774 return nb_cli_apply_changes(vty, NULL);
718e3744 2775}
2776
ff8a8a7a 2777DEFUN_YANG (no_bgp_deterministic_med,
718e3744 2778 no_bgp_deterministic_med_cmd,
2779 "no bgp deterministic-med",
2780 NO_STR
2781 "BGP specific commands\n"
2782 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2783{
87ce2564
CS
2784 nb_cli_enqueue_change(
2785 vty, "./global/route-selection-options/deterministic-med",
2786 NB_OP_MODIFY, "false");
d62a17ae 2787
ff8a8a7a 2788 return nb_cli_apply_changes(vty, NULL);
718e3744 2789}
538621f2 2790
055679e9 2791/* "bgp graceful-restart mode" configuration. */
538621f2 2792DEFUN (bgp_graceful_restart,
2ba1fe69 2793 bgp_graceful_restart_cmd,
2794 "bgp graceful-restart",
2795 "BGP specific commands\n"
2796 GR_CMD
055679e9 2797 )
538621f2 2798{
055679e9 2799 int ret = BGP_GR_FAILURE;
2800
2801 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2802 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
dc95985f 2803
d62a17ae 2804 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2805
2806 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2807
36235319
QY
2808 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2809 ret);
5cce3f05 2810
055679e9 2811 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2812 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
dc95985f 2813 vty_out(vty,
2814 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2815 return bgp_vty_return(vty, ret);
538621f2 2816}
2817
2818DEFUN (no_bgp_graceful_restart,
2ba1fe69 2819 no_bgp_graceful_restart_cmd,
2820 "no bgp graceful-restart",
2821 NO_STR
2822 "BGP specific commands\n"
2823 NO_GR_CMD
055679e9 2824 )
538621f2 2825{
d62a17ae 2826 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2827
2828 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2829 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
055679e9 2830
2831 int ret = BGP_GR_FAILURE;
2832
2833 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2834
36235319
QY
2835 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2836 ret);
5cce3f05 2837
055679e9 2838 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2839 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
dc95985f 2840 vty_out(vty,
2841 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2842
2843 return bgp_vty_return(vty, ret);
538621f2 2844}
2845
93406d87 2846DEFUN (bgp_graceful_restart_stalepath_time,
2ba1fe69 2847 bgp_graceful_restart_stalepath_time_cmd,
2848 "bgp graceful-restart stalepath-time (1-4095)",
2849 "BGP specific commands\n"
2850 "Graceful restart capability parameters\n"
2851 "Set the max time to hold onto restarting peer's stale paths\n"
2852 "Delay value (seconds)\n")
93406d87 2853{
d62a17ae 2854 VTY_DECLVAR_CONTEXT(bgp, bgp);
2855 int idx_number = 3;
d7c0a89a 2856 uint32_t stalepath;
93406d87 2857
d62a17ae 2858 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2859 bgp->stalepath_time = stalepath;
2860 return CMD_SUCCESS;
93406d87 2861}
2862
eb6f1b41 2863DEFUN (bgp_graceful_restart_restart_time,
2ba1fe69 2864 bgp_graceful_restart_restart_time_cmd,
2865 "bgp graceful-restart restart-time (1-4095)",
2866 "BGP specific commands\n"
2867 "Graceful restart capability parameters\n"
2868 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2869 "Delay value (seconds)\n")
eb6f1b41 2870{
d62a17ae 2871 VTY_DECLVAR_CONTEXT(bgp, bgp);
2872 int idx_number = 3;
d7c0a89a 2873 uint32_t restart;
eb6f1b41 2874
d62a17ae 2875 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2876 bgp->restart_time = restart;
2877 return CMD_SUCCESS;
eb6f1b41
PG
2878}
2879
cfd47646 2880DEFUN (bgp_graceful_restart_select_defer_time,
2881 bgp_graceful_restart_select_defer_time_cmd,
2882 "bgp graceful-restart select-defer-time (0-3600)",
2883 "BGP specific commands\n"
2884 "Graceful restart capability parameters\n"
2885 "Set the time to defer the BGP route selection after restart\n"
2886 "Delay value (seconds, 0 - disable)\n")
2887{
2888 VTY_DECLVAR_CONTEXT(bgp, bgp);
2889 int idx_number = 3;
2890 uint32_t defer_time;
2891
2892 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2893 bgp->select_defer_time = defer_time;
2894 if (defer_time == 0)
892fedb6 2895 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2896 else
892fedb6 2897 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2898
2899 return CMD_SUCCESS;
2900}
2901
93406d87 2902DEFUN (no_bgp_graceful_restart_stalepath_time,
2ba1fe69 2903 no_bgp_graceful_restart_stalepath_time_cmd,
2904 "no bgp graceful-restart stalepath-time [(1-4095)]",
2905 NO_STR
2906 "BGP specific commands\n"
2907 "Graceful restart capability parameters\n"
2908 "Set the max time to hold onto restarting peer's stale paths\n"
2909 "Delay value (seconds)\n")
93406d87 2910{
d62a17ae 2911 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 2912
d62a17ae 2913 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2914 return CMD_SUCCESS;
93406d87 2915}
2916
eb6f1b41 2917DEFUN (no_bgp_graceful_restart_restart_time,
2ba1fe69 2918 no_bgp_graceful_restart_restart_time_cmd,
2919 "no bgp graceful-restart restart-time [(1-4095)]",
2920 NO_STR
2921 "BGP specific commands\n"
2922 "Graceful restart capability parameters\n"
2923 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2924 "Delay value (seconds)\n")
eb6f1b41 2925{
d62a17ae 2926 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 2927
d62a17ae 2928 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2929 return CMD_SUCCESS;
eb6f1b41
PG
2930}
2931
cfd47646 2932DEFUN (no_bgp_graceful_restart_select_defer_time,
2933 no_bgp_graceful_restart_select_defer_time_cmd,
2934 "no bgp graceful-restart select-defer-time [(0-3600)]",
2935 NO_STR
2936 "BGP specific commands\n"
2937 "Graceful restart capability parameters\n"
2938 "Set the time to defer the BGP route selection after restart\n"
2939 "Delay value (seconds)\n")
2940{
2941 VTY_DECLVAR_CONTEXT(bgp, bgp);
2942
2943 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
892fedb6 2944 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2945
2946 return CMD_SUCCESS;
2947}
2948
43fc21b3 2949DEFUN (bgp_graceful_restart_preserve_fw,
2ba1fe69 2950 bgp_graceful_restart_preserve_fw_cmd,
2951 "bgp graceful-restart preserve-fw-state",
2952 "BGP specific commands\n"
2953 "Graceful restart capability parameters\n"
2954 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2955{
d62a17ae 2956 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2957 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2958 return CMD_SUCCESS;
43fc21b3
JC
2959}
2960
2961DEFUN (no_bgp_graceful_restart_preserve_fw,
2ba1fe69 2962 no_bgp_graceful_restart_preserve_fw_cmd,
2963 "no bgp graceful-restart preserve-fw-state",
2964 NO_STR
2965 "BGP specific commands\n"
2966 "Graceful restart capability parameters\n"
2967 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2968{
d62a17ae 2969 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2970 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2971 return CMD_SUCCESS;
43fc21b3
JC
2972}
2973
055679e9 2974DEFUN (bgp_graceful_restart_disable,
2ba1fe69 2975 bgp_graceful_restart_disable_cmd,
2976 "bgp graceful-restart-disable",
2977 "BGP specific commands\n"
2978 GR_DISABLE)
055679e9 2979{
2980 int ret = BGP_GR_FAILURE;
2981
2982 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2983 zlog_debug(
2ba1fe69 2984 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
dc95985f 2985
055679e9 2986 VTY_DECLVAR_CONTEXT(bgp, bgp);
2987
2988 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
2989
dc95985f 2990 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2991 bgp->peer, ret);
5cce3f05 2992
055679e9 2993 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2994 zlog_debug(
2ba1fe69 2995 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
dc95985f 2996 vty_out(vty,
2997 "Graceful restart configuration changed, reset all peers to take effect\n");
2998
055679e9 2999 return bgp_vty_return(vty, ret);
3000}
3001
3002DEFUN (no_bgp_graceful_restart_disable,
2ba1fe69 3003 no_bgp_graceful_restart_disable_cmd,
3004 "no bgp graceful-restart-disable",
3005 NO_STR
3006 "BGP specific commands\n"
3007 NO_GR_DISABLE
055679e9 3008 )
3009{
3010 VTY_DECLVAR_CONTEXT(bgp, bgp);
3011
3012 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3013 zlog_debug(
2ba1fe69 3014 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
055679e9 3015
3016 int ret = BGP_GR_FAILURE;
3017
3018 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
3019
36235319
QY
3020 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
3021 ret);
5cce3f05 3022
055679e9 3023 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3024 zlog_debug(
2ba1fe69 3025 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
dc95985f 3026 vty_out(vty,
3027 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 3028
3029 return bgp_vty_return(vty, ret);
3030}
3031
3032DEFUN (bgp_neighbor_graceful_restart_set,
2ba1fe69 3033 bgp_neighbor_graceful_restart_set_cmd,
3034 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3035 NEIGHBOR_STR
3036 NEIGHBOR_ADDR_STR2
3037 GR_NEIGHBOR_CMD
055679e9 3038 )
3039{
3040 int idx_peer = 1;
3041 struct peer *peer;
3042 int ret = BGP_GR_FAILURE;
3043
dc95985f 3044 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3045
055679e9 3046 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3047 zlog_debug(
2ba1fe69 3048 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
dc95985f 3049
055679e9 3050 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3051 if (!peer)
3052 return CMD_WARNING_CONFIG_FAILED;
3053
3054 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
3055
dc95985f 3056 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3057 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3058
3059 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3060 zlog_debug(
2ba1fe69 3061 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 3062 vty_out(vty,
3063 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3064
3065 return bgp_vty_return(vty, ret);
3066}
3067
3068DEFUN (no_bgp_neighbor_graceful_restart,
2ba1fe69 3069 no_bgp_neighbor_graceful_restart_set_cmd,
3070 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3071 NO_STR
3072 NEIGHBOR_STR
3073 NEIGHBOR_ADDR_STR2
3074 NO_GR_NEIGHBOR_CMD
055679e9 3075 )
3076{
3077 int idx_peer = 2;
3078 int ret = BGP_GR_FAILURE;
3079 struct peer *peer;
3080
dc95985f 3081 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3082
055679e9 3083 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3084 if (!peer)
3085 return CMD_WARNING_CONFIG_FAILED;
3086
3087 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3088 zlog_debug(
2ba1fe69 3089 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
055679e9 3090
3091 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
3092
dc95985f 3093 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3094 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3095
3096 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3097 zlog_debug(
2ba1fe69 3098 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 3099 vty_out(vty,
3100 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3101
3102 return bgp_vty_return(vty, ret);
3103}
3104
3105DEFUN (bgp_neighbor_graceful_restart_helper_set,
2ba1fe69 3106 bgp_neighbor_graceful_restart_helper_set_cmd,
3107 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3108 NEIGHBOR_STR
3109 NEIGHBOR_ADDR_STR2
3110 GR_NEIGHBOR_HELPER_CMD
055679e9 3111 )
3112{
3113 int idx_peer = 1;
3114 struct peer *peer;
3115 int ret = BGP_GR_FAILURE;
3116
dc95985f 3117 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3118
055679e9 3119 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3120 zlog_debug(
2ba1fe69 3121 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
dc95985f 3122
055679e9 3123 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3124
055679e9 3125 if (!peer)
3126 return CMD_WARNING_CONFIG_FAILED;
3127
3128
3129 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
5cce3f05 3130
dc95985f 3131 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3132 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
5cce3f05 3133
055679e9 3134 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3135 zlog_debug(
2ba1fe69 3136 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 3137 vty_out(vty,
3138 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3139
3140 return bgp_vty_return(vty, ret);
3141}
3142
3143DEFUN (no_bgp_neighbor_graceful_restart_helper,
2ba1fe69 3144 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3145 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3146 NO_STR
3147 NEIGHBOR_STR
3148 NEIGHBOR_ADDR_STR2
3149 NO_GR_NEIGHBOR_HELPER_CMD
055679e9 3150 )
3151{
3152 int idx_peer = 2;
3153 int ret = BGP_GR_FAILURE;
3154 struct peer *peer;
3155
dc95985f 3156 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3157
055679e9 3158 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3159 if (!peer)
3160 return CMD_WARNING_CONFIG_FAILED;
3161
3162 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3163 zlog_debug(
2ba1fe69 3164 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
055679e9 3165
36235319 3166 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
055679e9 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] no_bgp_neighbor_graceful_restart_helper_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 (bgp_neighbor_graceful_restart_disable_set,
2ba1fe69 3181 bgp_neighbor_graceful_restart_disable_set_cmd,
3182 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3183 NEIGHBOR_STR
3184 NEIGHBOR_ADDR_STR2
3185 GR_NEIGHBOR_DISABLE_CMD
055679e9 3186 )
3187{
3188 int idx_peer = 1;
3189 struct peer *peer;
3190 int ret = BGP_GR_FAILURE;
3191
dc95985f 3192 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3193
055679e9 3194 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3195 zlog_debug(
2ba1fe69 3196 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 3197
3198 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3199 if (!peer)
3200 return CMD_WARNING_CONFIG_FAILED;
3201
36235319 3202 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
055679e9 3203
3204 if (peer->bgp->t_startup)
3205 bgp_peer_gr_flags_update(peer);
3206
dc95985f 3207 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3208 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3209
055679e9 3210 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3211 zlog_debug(
2ba1fe69 3212 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3213 vty_out(vty,
3214 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3215
3216 return bgp_vty_return(vty, ret);
3217}
3218
3219DEFUN (no_bgp_neighbor_graceful_restart_disable,
2ba1fe69 3220 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3221 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3222 NO_STR
3223 NEIGHBOR_STR
3224 NEIGHBOR_ADDR_STR2
3225 NO_GR_NEIGHBOR_DISABLE_CMD
055679e9 3226 )
3227{
3228 int idx_peer = 2;
3229 int ret = BGP_GR_FAILURE;
3230 struct peer *peer;
3231
dc95985f 3232 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3233
055679e9 3234 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3235 if (!peer)
3236 return CMD_WARNING_CONFIG_FAILED;
3237
3238 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3239 zlog_debug(
2ba1fe69 3240 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 3241
3242 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3243
dc95985f 3244 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3245 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3246
3247 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3248 zlog_debug(
2ba1fe69 3249 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3250 vty_out(vty,
3251 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3252
3253 return bgp_vty_return(vty, ret);
3254}
3255
d6e3c15b 3256DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3257 bgp_graceful_restart_disable_eor_cmd,
3258 "bgp graceful-restart disable-eor",
3259 "BGP specific commands\n"
3260 "Graceful restart configuration parameters\n"
3261 "Disable EOR Check\n")
3262{
3263 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3264 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3265
d6e3c15b 3266 return CMD_SUCCESS;
3267}
3268
3269DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3270 no_bgp_graceful_restart_disable_eor_cmd,
3271 "no bgp graceful-restart disable-eor",
3272 NO_STR
3273 "BGP specific commands\n"
3274 "Graceful restart configuration parameters\n"
3275 "Disable EOR Check\n")
3276{
3277 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3278 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3279
3280 return CMD_SUCCESS;
3281}
3282
3283DEFUN (bgp_graceful_restart_rib_stale_time,
3284 bgp_graceful_restart_rib_stale_time_cmd,
3285 "bgp graceful-restart rib-stale-time (1-3600)",
3286 "BGP specific commands\n"
3287 "Graceful restart configuration parameters\n"
3288 "Specify the stale route removal timer in rib\n"
3289 "Delay value (seconds)\n")
3290{
3291 VTY_DECLVAR_CONTEXT(bgp, bgp);
3292 int idx_number = 3;
3293 uint32_t stale_time;
3294
3295 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3296 bgp->rib_stale_time = stale_time;
3297 /* Send the stale timer update message to RIB */
3298 if (bgp_zebra_stale_timer_update(bgp))
3299 return CMD_WARNING;
3300
3301 return CMD_SUCCESS;
3302}
3303
3304DEFUN (no_bgp_graceful_restart_rib_stale_time,
3305 no_bgp_graceful_restart_rib_stale_time_cmd,
3306 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3307 NO_STR
3308 "BGP specific commands\n"
3309 "Graceful restart configuration parameters\n"
3310 "Specify the stale route removal timer in rib\n"
3311 "Delay value (seconds)\n")
3312{
3313 VTY_DECLVAR_CONTEXT(bgp, bgp);
3314
3315 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3316 /* Send the stale timer update message to RIB */
3317 if (bgp_zebra_stale_timer_update(bgp))
3318 return CMD_WARNING;
3319
d6e3c15b 3320 return CMD_SUCCESS;
3321}
3322
ff8a8a7a
CS
3323static inline int bgp_initiate_graceful_shut_unshut(struct bgp *bgp,
3324 char *errmsg,
3325 size_t errmsg_len)
05bd726c 3326{
3327 bgp_static_redo_import_check(bgp);
3328 bgp_redistribute_redo(bgp);
ff8a8a7a
CS
3329 if (bgp_clear_star_soft_out(bgp->name, errmsg, errmsg_len) < 0)
3330 return -1;
3331 if (bgp_clear_star_soft_in(bgp->name, errmsg, errmsg_len) < 0)
3332 return -1;
3333
3334 return 0;
05bd726c 3335}
3336
3337static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3338{
3339 struct listnode *node, *nnode;
3340 struct bgp *bgp;
3341 bool vrf_cfg = false;
ff8a8a7a 3342 char errmsg[BUFSIZ] = {'\0'};
05bd726c 3343
3344 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3345 return CMD_SUCCESS;
3346
3347 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3348 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3349 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3350 vty_out(vty,
3351 "%% graceful-shutdown configuration found in vrf %s\n",
3352 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3353 VRF_DEFAULT_NAME : bgp->name);
3354 vrf_cfg = true;
3355 }
3356 }
3357
3358 if (vrf_cfg) {
3359 vty_out(vty,
3360 "%%Failed: global graceful-shutdown not permitted\n");
3361 return CMD_WARNING;
3362 }
3363
3364 /* Set flag globally */
3365 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3366
3367 /* Initiate processing for all BGP instances. */
ff8a8a7a
CS
3368 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3369 if (bgp_initiate_graceful_shut_unshut(bgp, errmsg,
3370 sizeof(errmsg))
3371 < 0)
3372 if (strlen(errmsg))
3373 vty_out(vty, "%s\n", errmsg);
3374 }
05bd726c 3375
3376 return CMD_SUCCESS;
3377}
3378
3379static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3380{
3381 struct listnode *node, *nnode;
3382 struct bgp *bgp;
ff8a8a7a 3383 char errmsg[BUFSIZ] = {'\0'};
05bd726c 3384
3385 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3386 return CMD_SUCCESS;
3387
3388 /* Unset flag globally */
3389 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3390
3391 /* Initiate processing for all BGP instances. */
ff8a8a7a
CS
3392 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3393 if (bgp_initiate_graceful_shut_unshut(bgp, errmsg,
3394 sizeof(errmsg))
3395 < 0)
3396 if (strlen(errmsg))
3397 vty_out(vty, "%s\n", errmsg);
3398 }
05bd726c 3399
3400 return CMD_SUCCESS;
3401}
3402
7f323236
DW
3403/* "bgp graceful-shutdown" configuration */
3404DEFUN (bgp_graceful_shutdown,
3405 bgp_graceful_shutdown_cmd,
3406 "bgp graceful-shutdown",
3407 BGP_STR
3408 "Graceful shutdown parameters\n")
3409{
05bd726c 3410 if (vty->node == CONFIG_NODE)
3411 return bgp_global_graceful_shutdown_config_vty(vty);
3412
87ce2564
CS
3413 nb_cli_enqueue_change(vty, "./global/graceful-shutdown/enable",
3414 NB_OP_MODIFY, "true");
7f323236 3415
ff8a8a7a 3416 return nb_cli_apply_changes(vty, NULL);
7f323236
DW
3417}
3418
ff8a8a7a 3419DEFUN_YANG (no_bgp_graceful_shutdown,
7f323236
DW
3420 no_bgp_graceful_shutdown_cmd,
3421 "no bgp graceful-shutdown",
3422 NO_STR
3423 BGP_STR
3424 "Graceful shutdown parameters\n")
3425{
05bd726c 3426 if (vty->node == CONFIG_NODE)
3427 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3428
87ce2564
CS
3429 nb_cli_enqueue_change(vty, "./global/graceful-shutdown/enable",
3430 NB_OP_MODIFY, "false");
05bd726c 3431
ff8a8a7a
CS
3432 return nb_cli_apply_changes(vty, NULL);
3433}
7f323236 3434
ff8a8a7a
CS
3435void cli_show_router_bgp_graceful_shutdown(struct vty *vty,
3436 struct lyd_node *dnode,
3437 bool show_defaults)
3438{
3439 if (yang_dnode_get_bool(dnode, NULL))
3440 vty_out(vty, " bgp graceful-shutdown\n");
7f323236
DW
3441}
3442
718e3744 3443/* "bgp fast-external-failover" configuration. */
ff8a8a7a 3444DEFUN_YANG (bgp_fast_external_failover,
718e3744 3445 bgp_fast_external_failover_cmd,
3446 "bgp fast-external-failover",
3447 BGP_STR
3448 "Immediately reset session if a link to a directly connected external peer goes down\n")
3449{
87ce2564
CS
3450 nb_cli_enqueue_change(vty, "./global/fast-external-failover",
3451 NB_OP_MODIFY, "false");
ff8a8a7a
CS
3452
3453 return nb_cli_apply_changes(vty, NULL);
718e3744 3454}
3455
ff8a8a7a 3456DEFUN_YANG (no_bgp_fast_external_failover,
718e3744 3457 no_bgp_fast_external_failover_cmd,
3458 "no bgp fast-external-failover",
3459 NO_STR
3460 BGP_STR
3461 "Immediately reset session if a link to a directly connected external peer goes down\n")
3462{
87ce2564
CS
3463 nb_cli_enqueue_change(vty, "./global/fast-external-failover",
3464 NB_OP_MODIFY, "true");
ff8a8a7a
CS
3465
3466 return nb_cli_apply_changes(vty, NULL);
3467}
3468
3469void cli_show_router_bgp_fast_external_failover(struct vty *vty,
3470 struct lyd_node *dnode,
3471 bool show_defaults)
3472{
3473 if (!yang_dnode_get_bool(dnode, NULL))
3474 vty_out(vty, " no bgp fast-external-failover\n");
718e3744 3475}
6b0655a2 3476
718e3744 3477/* "bgp bestpath compare-routerid" configuration. */
ff8a8a7a
CS
3478DEFUN_YANG(bgp_bestpath_compare_router_id,
3479 bgp_bestpath_compare_router_id_cmd,
3480 "bgp bestpath compare-routerid",
3481 "BGP specific commands\n"
3482 "Change the default bestpath selection\n"
3483 "Compare router-id for identical EBGP paths\n")
718e3744 3484{
ff8a8a7a 3485 nb_cli_enqueue_change(
87ce2564
CS
3486 vty,
3487 "./global/route-selection-options/external-compare-router-id",
ff8a8a7a 3488 NB_OP_MODIFY, "true");
7aafcaca 3489
ff8a8a7a 3490 return nb_cli_apply_changes(vty, NULL);
718e3744 3491}
3492
ff8a8a7a
CS
3493DEFUN_YANG(no_bgp_bestpath_compare_router_id,
3494 no_bgp_bestpath_compare_router_id_cmd,
3495 "no bgp bestpath compare-routerid",
3496 NO_STR
3497 "BGP specific commands\n"
3498 "Change the default bestpath selection\n"
3499 "Compare router-id for identical EBGP paths\n")
718e3744 3500{
ff8a8a7a 3501 nb_cli_enqueue_change(
87ce2564
CS
3502 vty,
3503 "./global/route-selection-options/external-compare-router-id",
ff8a8a7a 3504 NB_OP_MODIFY, "false");
7aafcaca 3505
ff8a8a7a 3506 return nb_cli_apply_changes(vty, NULL);
718e3744 3507}
6b0655a2 3508
718e3744 3509/* "bgp bestpath as-path ignore" configuration. */
ff8a8a7a
CS
3510DEFUN_YANG(bgp_bestpath_aspath_ignore,
3511 bgp_bestpath_aspath_ignore_cmd,
3512 "bgp bestpath as-path ignore",
3513 "BGP specific commands\n"
3514 "Change the default bestpath selection\n"
3515 "AS-path attribute\n"
3516 "Ignore as-path length in selecting a route\n")
718e3744 3517{
87ce2564
CS
3518 nb_cli_enqueue_change(
3519 vty, "./global/route-selection-options/ignore-as-path-length",
3520 NB_OP_MODIFY, "true");
7aafcaca 3521
ff8a8a7a 3522 return nb_cli_apply_changes(vty, NULL);
718e3744 3523}
3524
ff8a8a7a
CS
3525DEFUN_YANG(no_bgp_bestpath_aspath_ignore,
3526 no_bgp_bestpath_aspath_ignore_cmd,
3527 "no bgp bestpath as-path ignore",
3528 NO_STR
3529 "BGP specific commands\n"
3530 "Change the default bestpath selection\n"
3531 "AS-path attribute\n"
3532 "Ignore as-path length in selecting a route\n")
718e3744 3533{
87ce2564
CS
3534 nb_cli_enqueue_change(
3535 vty, "./global/route-selection-options/ignore-as-path-length",
3536 NB_OP_MODIFY, "false");
7aafcaca 3537
ff8a8a7a 3538 return nb_cli_apply_changes(vty, NULL);
718e3744 3539}
6b0655a2 3540
6811845b 3541/* "bgp bestpath as-path confed" configuration. */
ff8a8a7a 3542DEFUN_YANG (bgp_bestpath_aspath_confed,
6811845b 3543 bgp_bestpath_aspath_confed_cmd,
3544 "bgp bestpath as-path confed",
3545 "BGP specific commands\n"
3546 "Change the default bestpath selection\n"
3547 "AS-path attribute\n"
3548 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3549{
87ce2564
CS
3550 nb_cli_enqueue_change(vty,
3551 "./global/route-selection-options/aspath-confed",
ff8a8a7a 3552 NB_OP_MODIFY, "true");
7aafcaca 3553
ff8a8a7a 3554 return nb_cli_apply_changes(vty, NULL);
6811845b 3555}
3556
ff8a8a7a 3557DEFUN_YANG (no_bgp_bestpath_aspath_confed,
6811845b 3558 no_bgp_bestpath_aspath_confed_cmd,
3559 "no bgp bestpath as-path confed",
3560 NO_STR
3561 "BGP specific commands\n"
3562 "Change the default bestpath selection\n"
3563 "AS-path attribute\n"
3564 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3565{
87ce2564
CS
3566 nb_cli_enqueue_change(vty,
3567 "./global/route-selection-options/aspath-confed",
ff8a8a7a 3568 NB_OP_MODIFY, "false");
7aafcaca 3569
ff8a8a7a 3570 return nb_cli_apply_changes(vty, NULL);
6811845b 3571}
6b0655a2 3572
2fdd455c 3573/* "bgp bestpath as-path multipath-relax" configuration. */
ff8a8a7a 3574DEFUN_YANG (bgp_bestpath_aspath_multipath_relax,
2fdd455c 3575 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3576 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
3577 "BGP specific commands\n"
3578 "Change the default bestpath selection\n"
3579 "AS-path attribute\n"
3580 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3581 "Generate an AS_SET\n"
16fc1eec
DS
3582 "Do not generate an AS_SET\n")
3583{
d62a17ae 3584 int idx = 0;
219178b6 3585
87ce2564
CS
3586 nb_cli_enqueue_change(
3587 vty, "./global/route-selection-options/allow-multiple-as",
3588 NB_OP_MODIFY, "true");
d62a17ae 3589 if (argv_find(argv, argc, "as-set", &idx))
ff8a8a7a 3590 nb_cli_enqueue_change(
87ce2564
CS
3591 vty,
3592 "./global/route-selection-options/multi-path-as-set",
ff8a8a7a 3593 NB_OP_MODIFY, "true");
d62a17ae 3594 else
ff8a8a7a 3595 nb_cli_enqueue_change(
87ce2564
CS
3596 vty,
3597 "./global/route-selection-options/multi-path-as-set",
ff8a8a7a 3598 NB_OP_MODIFY, "false");
7aafcaca 3599
ff8a8a7a 3600 return nb_cli_apply_changes(vty, NULL);
16fc1eec
DS
3601}
3602
ff8a8a7a 3603DEFUN_YANG (no_bgp_bestpath_aspath_multipath_relax,
219178b6 3604 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3605 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
3606 NO_STR
3607 "BGP specific commands\n"
3608 "Change the default bestpath selection\n"
3609 "AS-path attribute\n"
3610 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3611 "Generate an AS_SET\n"
16fc1eec
DS
3612 "Do not generate an AS_SET\n")
3613{
87ce2564
CS
3614 nb_cli_enqueue_change(
3615 vty, "./global/route-selection-options/allow-multiple-as",
3616 NB_OP_MODIFY, "false");
3617 nb_cli_enqueue_change(
3618 vty, "./global/route-selection-options/multi-path-as-set",
3619 NB_OP_MODIFY, "false");
7aafcaca 3620
ff8a8a7a 3621 return nb_cli_apply_changes(vty, NULL);
2fdd455c 3622}
6b0655a2 3623
ee88563a
JM
3624/* "bgp bestpath peer-type multipath-relax" configuration. */
3625DEFUN(bgp_bestpath_peer_type_multipath_relax,
3626 bgp_bestpath_peer_type_multipath_relax_cmd,
3627 "bgp bestpath peer-type multipath-relax",
3628 BGP_STR
3629 "Change the default bestpath selection\n"
3630 "Peer type\n"
3631 "Allow load sharing across routes learned from different peer types\n")
3632{
3633 VTY_DECLVAR_CONTEXT(bgp, bgp);
3634 SET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3635 bgp_recalculate_all_bestpaths(bgp);
3636
3637 return CMD_SUCCESS;
3638}
3639
3640DEFUN(no_bgp_bestpath_peer_type_multipath_relax,
3641 no_bgp_bestpath_peer_type_multipath_relax_cmd,
3642 "no bgp bestpath peer-type multipath-relax",
3643 NO_STR BGP_STR
3644 "Change the default bestpath selection\n"
3645 "Peer type\n"
3646 "Allow load sharing across routes learned from different peer types\n")
3647{
3648 VTY_DECLVAR_CONTEXT(bgp, bgp);
3649 UNSET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3650 bgp_recalculate_all_bestpaths(bgp);
3651
3652 return CMD_SUCCESS;
3653}
3654
848973c7 3655/* "bgp log-neighbor-changes" configuration. */
ff8a8a7a
CS
3656DEFUN_YANG(bgp_log_neighbor_changes,
3657 bgp_log_neighbor_changes_cmd,
3658 "bgp log-neighbor-changes",
3659 "BGP specific commands\n"
3660 "Log neighbor up/down and reset reason\n")
848973c7 3661{
87ce2564
CS
3662 nb_cli_enqueue_change(
3663 vty, "./global/global-neighbor-config/log-neighbor-changes",
3664 NB_OP_MODIFY, "true");
ff8a8a7a
CS
3665
3666 return nb_cli_apply_changes(vty, NULL);
848973c7 3667}
3668
ff8a8a7a
CS
3669DEFUN_YANG(no_bgp_log_neighbor_changes,
3670 no_bgp_log_neighbor_changes_cmd,
3671 "no bgp log-neighbor-changes",
3672 NO_STR
3673 "BGP specific commands\n"
3674 "Log neighbor up/down and reset reason\n")
848973c7 3675{
87ce2564
CS
3676 nb_cli_enqueue_change(
3677 vty, "./global/global-neighbor-config/log-neighbor-changes",
3678 NB_OP_MODIFY, "false");
ff8a8a7a
CS
3679
3680 return nb_cli_apply_changes(vty, NULL);
848973c7 3681}
6b0655a2 3682
718e3744 3683/* "bgp bestpath med" configuration. */
ff8a8a7a 3684DEFUN_YANG (bgp_bestpath_med,
718e3744 3685 bgp_bestpath_med_cmd,
2d8c1a4d 3686 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 3687 "BGP specific commands\n"
3688 "Change the default bestpath selection\n"
3689 "MED attribute\n"
3690 "Compare MED among confederation paths\n"
838758ac
DW
3691 "Treat missing MED as the least preferred one\n"
3692 "Treat missing MED as the least preferred one\n"
3693 "Compare MED among confederation paths\n")
718e3744 3694{
d62a17ae 3695 int idx = 0;
ff8a8a7a
CS
3696 bool confed = false;
3697 bool worst_med = false;
3698
3699
d62a17ae 3700 if (argv_find(argv, argc, "confed", &idx))
ff8a8a7a
CS
3701 confed = true;
3702
87ce2564
CS
3703 nb_cli_enqueue_change(vty,
3704 "./global/route-selection-options/confed-med",
ff8a8a7a
CS
3705 NB_OP_MODIFY, confed ? "true" : "false");
3706
d62a17ae 3707 idx = 0;
3708 if (argv_find(argv, argc, "missing-as-worst", &idx))
ff8a8a7a 3709 worst_med = true;
e52702f2 3710
87ce2564
CS
3711 nb_cli_enqueue_change(
3712 vty, "./global/route-selection-options/missing-as-worst-med",
3713 NB_OP_MODIFY, worst_med ? "true" : "false");
7aafcaca 3714
ff8a8a7a 3715 return nb_cli_apply_changes(vty, NULL);
718e3744 3716}
3717
ff8a8a7a 3718DEFUN_YANG (no_bgp_bestpath_med,
718e3744 3719 no_bgp_bestpath_med_cmd,
2d8c1a4d 3720 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 3721 NO_STR
3722 "BGP specific commands\n"
3723 "Change the default bestpath selection\n"
3724 "MED attribute\n"
3725 "Compare MED among confederation paths\n"
3a2d747c
QY
3726 "Treat missing MED as the least preferred one\n"
3727 "Treat missing MED as the least preferred one\n"
3728 "Compare MED among confederation paths\n")
718e3744 3729{
d62a17ae 3730 int idx = 0;
ff8a8a7a 3731
d62a17ae 3732 if (argv_find(argv, argc, "confed", &idx))
87ce2564
CS
3733 nb_cli_enqueue_change(
3734 vty, "./global/route-selection-options/confed-med",
3735 NB_OP_MODIFY, "false");
ff8a8a7a 3736
d62a17ae 3737 idx = 0;
3738 if (argv_find(argv, argc, "missing-as-worst", &idx))
ff8a8a7a 3739 nb_cli_enqueue_change(
87ce2564
CS
3740 vty,
3741 "./global/route-selection-options/missing-as-worst-med",
ff8a8a7a 3742 NB_OP_MODIFY, "false");
718e3744 3743
ff8a8a7a 3744 return nb_cli_apply_changes(vty, NULL);
718e3744 3745}
3746
f7e1c681 3747/* "bgp bestpath bandwidth" configuration. */
3748DEFPY (bgp_bestpath_bw,
3749 bgp_bestpath_bw_cmd,
ad36d216 3750 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
f7e1c681 3751 "BGP specific commands\n"
3752 "Change the default bestpath selection\n"
3753 "Link Bandwidth attribute\n"
3754 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3755 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3756 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3757{
3758 VTY_DECLVAR_CONTEXT(bgp, bgp);
3759 afi_t afi;
3760 safi_t safi;
3761
ad36d216
DS
3762 if (!bw_cfg) {
3763 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3764 return CMD_ERR_INCOMPLETE;
f7e1c681 3765 }
ad36d216
DS
3766 if (!strcmp(bw_cfg, "ignore"))
3767 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3768 else if (!strcmp(bw_cfg, "skip-missing"))
3769 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3770 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3771 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3772 else
3773 return CMD_ERR_NO_MATCH;
f7e1c681 3774
3775 /* This config is used in route install, so redo that. */
3776 FOREACH_AFI_SAFI (afi, safi) {
3777 if (!bgp_fibupd_safi(safi))
3778 continue;
3779 bgp_zebra_announce_table(bgp, afi, safi);
3780 }
3781
3782 return CMD_SUCCESS;
3783}
3784
ad36d216
DS
3785DEFPY (no_bgp_bestpath_bw,
3786 no_bgp_bestpath_bw_cmd,
3787 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3788 NO_STR
3789 "BGP specific commands\n"
3790 "Change the default bestpath selection\n"
3791 "Link Bandwidth attribute\n"
3792 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3793 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3794 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3795{
3796 VTY_DECLVAR_CONTEXT(bgp, bgp);
3797 afi_t afi;
3798 safi_t safi;
3799
3800 bgp->lb_handling = BGP_LINK_BW_ECMP;
3801
3802 /* This config is used in route install, so redo that. */
3803 FOREACH_AFI_SAFI (afi, safi) {
3804 if (!bgp_fibupd_safi(safi))
3805 continue;
3806 bgp_zebra_announce_table(bgp, afi, safi);
3807 }
3808 return CMD_SUCCESS;
3809}
3810
b16bcbba 3811DEFPY(bgp_default_afi_safi, bgp_default_afi_safi_cmd,
38d11af5
TA
3812 "[no] bgp default <ipv4-unicast|"
3813 "ipv4-multicast|"
3814 "ipv4-vpn|"
3815 "ipv4-labeled-unicast|"
3816 "ipv4-flowspec|"
3817 "ipv6-unicast|"
3818 "ipv6-multicast|"
3819 "ipv6-vpn|"
3820 "ipv6-labeled-unicast|"
3821 "ipv6-flowspec|"
3822 "l2vpn-evpn>$afi_safi",
b16bcbba 3823 NO_STR
e84c59af
DA
3824 "BGP specific commands\n"
3825 "Configure BGP defaults\n"
b16bcbba 3826 "Activate ipv4-unicast for a peer by default\n"
38d11af5
TA
3827 "Activate ipv4-multicast for a peer by default\n"
3828 "Activate ipv4-vpn for a peer by default\n"
3829 "Activate ipv4-labeled-unicast for a peer by default\n"
3830 "Activate ipv4-flowspec for a peer by default\n"
3831 "Activate ipv6-unicast for a peer by default\n"
3832 "Activate ipv6-multicast for a peer by default\n"
3833 "Activate ipv6-vpn for a peer by default\n"
3834 "Activate ipv6-labeled-unicast for a peer by default\n"
3835 "Activate ipv6-flowspec for a peer by default\n"
3836 "Activate l2vpn-evpn for a peer by default\n")
e84c59af
DA
3837{
3838 VTY_DECLVAR_CONTEXT(bgp, bgp);
b16bcbba
TA
3839 char afi_safi_str[strlen(afi_safi) + 1];
3840 char *afi_safi_str_tok;
e84c59af 3841
b16bcbba
TA
3842 strlcpy(afi_safi_str, afi_safi, sizeof(afi_safi_str));
3843 char *afi_str = strtok_r(afi_safi_str, "-", &afi_safi_str_tok);
3844 char *safi_str = strtok_r(NULL, "-", &afi_safi_str_tok);
3845 afi_t afi = bgp_vty_afi_from_str(afi_str);
38d11af5 3846 safi_t safi;
e84c59af 3847
38d11af5
TA
3848 if (strmatch(safi_str, "labeled"))
3849 safi = bgp_vty_safi_from_str("labeled-unicast");
3850 else
3851 safi = bgp_vty_safi_from_str(safi_str);
b16bcbba
TA
3852
3853 if (no)
3854 bgp->default_af[afi][safi] = false;
38d11af5
TA
3855 else {
3856 if ((safi == SAFI_LABELED_UNICAST
3857 && bgp->default_af[afi][SAFI_UNICAST])
3858 || (safi == SAFI_UNICAST
3859 && bgp->default_af[afi][SAFI_LABELED_UNICAST]))
3860 bgp_vty_return(vty, BGP_ERR_PEER_SAFI_CONFLICT);
3861 else
3862 bgp->default_af[afi][safi] = true;
3863 }
718e3744 3864
d62a17ae 3865 return CMD_SUCCESS;
718e3744 3866}
6b0655a2 3867
04b6bdc0 3868/* Display hostname in certain command outputs */
ff8a8a7a 3869DEFUN_YANG (bgp_default_show_hostname,
04b6bdc0
DW
3870 bgp_default_show_hostname_cmd,
3871 "bgp default show-hostname",
3872 "BGP specific commands\n"
3873 "Configure BGP defaults\n"
0437e105 3874 "Show hostname in certain command outputs\n")
04b6bdc0 3875{
87ce2564
CS
3876 nb_cli_enqueue_change(vty, "./global/show-hostname", NB_OP_MODIFY,
3877 "true");
ff8a8a7a
CS
3878
3879 return nb_cli_apply_changes(vty, NULL);
04b6bdc0
DW
3880}
3881
ff8a8a7a
CS
3882DEFUN_YANG(no_bgp_default_show_hostname,
3883 no_bgp_default_show_hostname_cmd,
3884 "no bgp default show-hostname",
3885 NO_STR
3886 "BGP specific commands\n"
3887 "Configure BGP defaults\n"
3888 "Show hostname in certain command outputs\n")
04b6bdc0 3889{
87ce2564
CS
3890 nb_cli_enqueue_change(vty, "./global/show-hostname", NB_OP_MODIFY,
3891 "false");
ff8a8a7a
CS
3892
3893 return nb_cli_apply_changes(vty, NULL);
3894}
3895
3896void cli_show_router_bgp_show_hostname(struct vty *vty, struct lyd_node *dnode,
3897 bool show_defaults)
3898{
3899 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SHOW_HOSTNAME)
3900 vty_out(vty, " bgp default show-hostname\n");
04b6bdc0
DW
3901}
3902
aef999a2 3903/* Display hostname in certain command outputs */
232c75cd
CS
3904DEFUN_YANG(bgp_default_show_nexthop_hostname,
3905 bgp_default_show_nexthop_hostname_cmd,
3906 "bgp default show-nexthop-hostname",
3907 "BGP specific commands\n"
3908 "Configure BGP defaults\n"
3909 "Show hostname for nexthop in certain command outputs\n")
aef999a2 3910{
87ce2564
CS
3911 nb_cli_enqueue_change(vty, "./global/show-nexthop-hostname",
3912 NB_OP_MODIFY, "true");
ff8a8a7a
CS
3913
3914 return nb_cli_apply_changes(vty, NULL);
aef999a2
DA
3915}
3916
3917DEFUN (no_bgp_default_show_nexthop_hostname,
3918 no_bgp_default_show_nexthop_hostname_cmd,
3919 "no bgp default show-nexthop-hostname",
3920 NO_STR
3921 "BGP specific commands\n"
3922 "Configure BGP defaults\n"
3923 "Show hostname for nexthop in certain command outputs\n")
3924{
87ce2564
CS
3925 nb_cli_enqueue_change(vty, "./global/show-nexthop-hostname",
3926 NB_OP_MODIFY, "false");
ff8a8a7a
CS
3927
3928 return nb_cli_apply_changes(vty, NULL);
3929}
3930
3931void cli_show_router_bgp_show_nexthop_hostname(struct vty *vty,
3932 struct lyd_node *dnode,
3933 bool show_defaults)
3934{
3935 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SHOW_HOSTNAME)
3936 vty_out(vty, " bgp default show-nexthop-hostname\n");
aef999a2
DA
3937}
3938
8233ef81 3939/* "bgp network import-check" configuration. */
ff8a8a7a
CS
3940DEFUN_YANG(bgp_network_import_check,
3941 bgp_network_import_check_cmd,
3942 "bgp network import-check",
3943 "BGP specific commands\n"
3944 "BGP network command\n"
3945 "Check BGP network route exists in IGP\n")
718e3744 3946{
87ce2564
CS
3947 nb_cli_enqueue_change(vty, "./global/import-check", NB_OP_MODIFY,
3948 "true");
078430f6 3949
ff8a8a7a 3950 return nb_cli_apply_changes(vty, NULL);
718e3744 3951}
3952
d62a17ae 3953ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3954 "bgp network import-check exact",
3955 "BGP specific commands\n"
3956 "BGP network command\n"
3957 "Check BGP network route exists in IGP\n"
3958 "Match route precisely\n")
8233ef81 3959
ff8a8a7a
CS
3960DEFUN_YANG(no_bgp_network_import_check,
3961 no_bgp_network_import_check_cmd,
3962 "no bgp network import-check",
3963 NO_STR
3964 "BGP specific commands\n"
3965 "BGP network command\n"
3966 "Check BGP network route exists in IGP\n")
718e3744 3967{
87ce2564
CS
3968 nb_cli_enqueue_change(vty, "./global/import-check", NB_OP_MODIFY,
3969 "false");
5623e905 3970
ff8a8a7a 3971 return nb_cli_apply_changes(vty, NULL);
718e3744 3972}
6b0655a2 3973
ff8a8a7a
CS
3974void cli_show_router_bgp_import_check(struct vty *vty, struct lyd_node *dnode,
3975 bool show_defaults)
718e3744 3976{
ff8a8a7a
CS
3977 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_IMPORT_CHECK)
3978 vty_out(vty, " bgp network import-check\n");
3979}
718e3744 3980
ff8a8a7a
CS
3981DEFUN_YANG(bgp_default_local_preference,
3982 bgp_default_local_preference_cmd,
3983 "bgp default local-preference (0-4294967295)",
3984 "BGP specific commands\n"
3985 "Configure BGP defaults\n"
3986 "local preference (higher=more preferred)\n"
3987 "Configure default local preference value\n")
3988{
3989 int idx_number = 3;
718e3744 3990
87ce2564 3991 nb_cli_enqueue_change(vty, "./global/local-pref", NB_OP_MODIFY,
ff8a8a7a 3992 argv[idx_number]->arg);
718e3744 3993
ff8a8a7a 3994 return nb_cli_apply_changes(vty, NULL);
718e3744 3995}
3996
ff8a8a7a
CS
3997DEFUN_YANG(no_bgp_default_local_preference,
3998 no_bgp_default_local_preference_cmd,
3999 "no bgp default local-preference [(0-4294967295)]",
4000 NO_STR
4001 "BGP specific commands\n"
4002 "Configure BGP defaults\n"
4003 "local preference (higher=more preferred)\n"
4004 "Configure default local preference value\n")
718e3744 4005{
87ce2564 4006 nb_cli_enqueue_change(vty, "./global/local-pref", NB_OP_MODIFY, NULL);
7aafcaca 4007
ff8a8a7a 4008 return nb_cli_apply_changes(vty, NULL);
718e3744 4009}
4010
ff8a8a7a
CS
4011void cli_show_router_bgp_local_pref(struct vty *vty, struct lyd_node *dnode,
4012 bool show_defaults)
4013{
4014 vty_out(vty, " bgp default local-preference %u\n",
4015 yang_dnode_get_uint32(dnode, NULL));
4016}
6b0655a2 4017
ff8a8a7a
CS
4018
4019DEFUN_YANG(bgp_default_subgroup_pkt_queue_max,
4020 bgp_default_subgroup_pkt_queue_max_cmd,
4021 "bgp default subgroup-pkt-queue-max (20-100)",
4022 "BGP specific commands\n"
4023 "Configure BGP defaults\n"
4024 "subgroup-pkt-queue-max\n"
4025 "Configure subgroup packet queue max\n")
8bd9d948 4026{
d62a17ae 4027 int idx_number = 3;
3f9c7369 4028
ff8a8a7a 4029 nb_cli_enqueue_change(
87ce2564
CS
4030 vty,
4031 "./global/global-update-group-config/subgroup-pkt-queue-size",
ff8a8a7a 4032 NB_OP_MODIFY, argv[idx_number]->arg);
3f9c7369 4033
ff8a8a7a 4034 return nb_cli_apply_changes(vty, NULL);
3f9c7369
DS
4035}
4036
ff8a8a7a
CS
4037DEFUN_YANG(no_bgp_default_subgroup_pkt_queue_max,
4038 no_bgp_default_subgroup_pkt_queue_max_cmd,
4039 "no bgp default subgroup-pkt-queue-max [(20-100)]",
4040 NO_STR
4041 "BGP specific commands\n"
4042 "Configure BGP defaults\n"
4043 "subgroup-pkt-queue-max\n"
4044 "Configure subgroup packet queue max\n")
3f9c7369 4045{
ff8a8a7a 4046 nb_cli_enqueue_change(
87ce2564
CS
4047 vty,
4048 "./global/global-update-group-config/subgroup-pkt-queue-size",
ff8a8a7a
CS
4049 NB_OP_MODIFY, NULL);
4050
4051 return nb_cli_apply_changes(vty, NULL);
8bd9d948
DS
4052}
4053
ff8a8a7a
CS
4054void cli_show_router_global_update_group_config_subgroup_pkt_queue_size(
4055 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
4056{
4057 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
4058 yang_dnode_get_uint32(dnode, NULL));
4059}
813d4307 4060
ff8a8a7a
CS
4061DEFUN_YANG(bgp_rr_allow_outbound_policy,
4062 bgp_rr_allow_outbound_policy_cmd,
4063 "bgp route-reflector allow-outbound-policy",
4064 "BGP specific commands\n"
4065 "Allow modifications made by out route-map\n"
4066 "on ibgp neighbors\n")
8bd9d948 4067{
87ce2564
CS
4068 nb_cli_enqueue_change(vty,
4069 "./global/route-reflector/allow-outbound-policy",
ff8a8a7a 4070 NB_OP_MODIFY, "true");
8bd9d948 4071
ff8a8a7a
CS
4072 return nb_cli_apply_changes(vty, NULL);
4073}
8bd9d948 4074
ff8a8a7a
CS
4075DEFUN_YANG(no_bgp_rr_allow_outbound_policy,
4076 no_bgp_rr_allow_outbound_policy_cmd,
4077 "no bgp route-reflector allow-outbound-policy",
4078 NO_STR
4079 "BGP specific commands\n"
4080 "Allow modifications made by out route-map\n"
4081 "on ibgp neighbors\n")
4082{
87ce2564
CS
4083 nb_cli_enqueue_change(vty,
4084 "./global/route-reflector/allow-outbound-policy",
ff8a8a7a
CS
4085 NB_OP_MODIFY, "false");
4086
4087 return nb_cli_apply_changes(vty, NULL);
8bd9d948
DS
4088}
4089
ff8a8a7a
CS
4090
4091void cli_show_router_global_neighbor_config(struct vty *vty,
4092 struct lyd_node *dnode,
4093 bool show_defaults)
8bd9d948 4094{
ff8a8a7a
CS
4095 uint32_t write_quanta, read_quanta;
4096
4097 if (yang_dnode_get_bool(dnode, "./log-neighbor-changes"))
4098 vty_out(vty, " bgp log-neighbor-changes\n");
8bd9d948 4099
ff8a8a7a
CS
4100 if (yang_dnode_exists(dnode, "./dynamic-neighbors-limit")) {
4101 uint32_t listen_limit = yang_dnode_get_uint32(
4102 dnode, "./dynamic-neighbors-limit");
4103 vty_out(vty, " bgp listen limit %u\n", listen_limit);
d62a17ae 4104 }
8bd9d948 4105
ff8a8a7a
CS
4106 write_quanta = yang_dnode_get_uint32(
4107 dnode, "./packet-quanta-config/wpkt-quanta");
4108 if (write_quanta != BGP_WRITE_PACKET_MAX)
4109 vty_out(vty, " write-quanta %d\n", write_quanta);
4110
4111 read_quanta = yang_dnode_get_uint32(
4112 dnode, "./packet-quanta-config/rpkt-quanta");
4113
4114 if (read_quanta != BGP_READ_PACKET_MAX)
4115 vty_out(vty, " read-quanta %d\n", read_quanta);
8bd9d948
DS
4116}
4117
ff8a8a7a
CS
4118DEFUN_YANG(bgp_listen_limit,
4119 bgp_listen_limit_cmd,
5b1b6b8b 4120 "bgp listen limit (1-65535)",
ff8a8a7a
CS
4121 "BGP specific commands\n"
4122 "BGP Dynamic Neighbors listen commands\n"
4123 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4124 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 4125{
d62a17ae 4126 int idx_number = 3;
f14e6fdb 4127
ff8a8a7a 4128 nb_cli_enqueue_change(
87ce2564 4129 vty, "./global/global-neighbor-config/dynamic-neighbors-limit",
ff8a8a7a 4130 NB_OP_MODIFY, argv[idx_number]->arg);
f14e6fdb 4131
ff8a8a7a 4132 return nb_cli_apply_changes(vty, NULL);
f14e6fdb
DS
4133}
4134
ff8a8a7a
CS
4135DEFUN_YANG(no_bgp_listen_limit,
4136 no_bgp_listen_limit_cmd,
5b1b6b8b 4137 "no bgp listen limit [(1-65535)]",
ff8a8a7a
CS
4138 NO_STR
4139 "BGP specific commands\n"
4140 "BGP Dynamic Neighbors listen commands\n"
4141 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4142 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 4143{
ff8a8a7a 4144 nb_cli_enqueue_change(
87ce2564 4145 vty, "./global/global-neighbor-config/dynamic-neighbors-limit",
ff8a8a7a
CS
4146 NB_OP_DESTROY, NULL);
4147
4148 return nb_cli_apply_changes(vty, NULL);
f14e6fdb
DS
4149}
4150
4151
20eb8864 4152/*
4153 * Check if this listen range is already configured. Check for exact
4154 * match or overlap based on input.
4155 */
d62a17ae 4156static struct peer_group *listen_range_exists(struct bgp *bgp,
4157 struct prefix *range, int exact)
4158{
4159 struct listnode *node, *nnode;
4160 struct listnode *node1, *nnode1;
4161 struct peer_group *group;
4162 struct prefix *lr;
4163 afi_t afi;
4164 int match;
4165
4166 afi = family2afi(range->family);
4167 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4168 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
4169 lr)) {
4170 if (exact)
4171 match = prefix_same(range, lr);
4172 else
4173 match = (prefix_match(range, lr)
4174 || prefix_match(lr, range));
4175 if (match)
4176 return group;
4177 }
4178 }
4179
4180 return NULL;
20eb8864 4181}
4182
f14e6fdb
DS
4183DEFUN (bgp_listen_range,
4184 bgp_listen_range_cmd,
d7b9898c 4185 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
f14e6fdb 4186 "BGP specific commands\n"
d7fa34c1
QY
4187 "Configure BGP dynamic neighbors listen range\n"
4188 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
4189 NEIGHBOR_ADDR_STR
4190 "Member of the peer-group\n"
4191 "Peer-group name\n")
f14e6fdb 4192{
d62a17ae 4193 VTY_DECLVAR_CONTEXT(bgp, bgp);
4194 struct prefix range;
4195 struct peer_group *group, *existing_group;
4196 afi_t afi;
4197 int ret;
4198 int idx = 0;
4199
4200 argv_find(argv, argc, "A.B.C.D/M", &idx);
4201 argv_find(argv, argc, "X:X::X:X/M", &idx);
4202 char *prefix = argv[idx]->arg;
d7b9898c 4203 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 4204 char *peergroup = argv[idx]->arg;
4205
4206 /* Convert IP prefix string to struct prefix. */
4207 ret = str2prefix(prefix, &range);
4208 if (!ret) {
4209 vty_out(vty, "%% Malformed listen range\n");
4210 return CMD_WARNING_CONFIG_FAILED;
4211 }
4212
4213 afi = family2afi(range.family);
4214
4215 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4216 vty_out(vty,
4217 "%% Malformed listen range (link-local address)\n");
4218 return CMD_WARNING_CONFIG_FAILED;
4219 }
4220
4221 apply_mask(&range);
4222
4223 /* Check if same listen range is already configured. */
4224 existing_group = listen_range_exists(bgp, &range, 1);
4225 if (existing_group) {
4226 if (strcmp(existing_group->name, peergroup) == 0)
4227 return CMD_SUCCESS;
4228 else {
4229 vty_out(vty,
4230 "%% Same listen range is attached to peer-group %s\n",
4231 existing_group->name);
4232 return CMD_WARNING_CONFIG_FAILED;
4233 }
4234 }
4235
4236 /* Check if an overlapping listen range exists. */
4237 if (listen_range_exists(bgp, &range, 0)) {
4238 vty_out(vty,
4239 "%% Listen range overlaps with existing listen range\n");
4240 return CMD_WARNING_CONFIG_FAILED;
4241 }
4242
4243 group = peer_group_lookup(bgp, peergroup);
4244 if (!group) {
4245 vty_out(vty, "%% Configure the peer-group first\n");
4246 return CMD_WARNING_CONFIG_FAILED;
4247 }
4248
4249 ret = peer_group_listen_range_add(group, &range);
4250 return bgp_vty_return(vty, ret);
f14e6fdb
DS
4251}
4252
4253DEFUN (no_bgp_listen_range,
4254 no_bgp_listen_range_cmd,
d7b9898c 4255 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
d7fa34c1 4256 NO_STR
f14e6fdb 4257 "BGP specific commands\n"
d7fa34c1
QY
4258 "Unconfigure BGP dynamic neighbors listen range\n"
4259 "Unconfigure BGP dynamic neighbors listen range\n"
4260 NEIGHBOR_ADDR_STR
4261 "Member of the peer-group\n"
4262 "Peer-group name\n")
f14e6fdb 4263{
d62a17ae 4264 VTY_DECLVAR_CONTEXT(bgp, bgp);
4265 struct prefix range;
4266 struct peer_group *group;
4267 afi_t afi;
4268 int ret;
4269 int idx = 0;
4270
4271 argv_find(argv, argc, "A.B.C.D/M", &idx);
4272 argv_find(argv, argc, "X:X::X:X/M", &idx);
4273 char *prefix = argv[idx]->arg;
21d88a71 4274 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 4275 char *peergroup = argv[idx]->arg;
4276
4277 /* Convert IP prefix string to struct prefix. */
4278 ret = str2prefix(prefix, &range);
4279 if (!ret) {
4280 vty_out(vty, "%% Malformed listen range\n");
4281 return CMD_WARNING_CONFIG_FAILED;
4282 }
4283
4284 afi = family2afi(range.family);
4285
4286 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4287 vty_out(vty,
4288 "%% Malformed listen range (link-local address)\n");
4289 return CMD_WARNING_CONFIG_FAILED;
4290 }
4291
4292 apply_mask(&range);
4293
4294 group = peer_group_lookup(bgp, peergroup);
4295 if (!group) {
4296 vty_out(vty, "%% Peer-group does not exist\n");
4297 return CMD_WARNING_CONFIG_FAILED;
4298 }
4299
4300 ret = peer_group_listen_range_del(group, &range);
4301 return bgp_vty_return(vty, ret);
4302}
4303
2b791107 4304void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 4305{
4306 struct peer_group *group;
4307 struct listnode *node, *nnode, *rnode, *nrnode;
4308 struct prefix *range;
4309 afi_t afi;
d62a17ae 4310
4311 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4312 vty_out(vty, " bgp listen limit %d\n",
4313 bgp->dynamic_neighbors_limit);
4314
4315 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4316 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4317 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4318 nrnode, range)) {
d62a17ae 4319 vty_out(vty,
2dbe669b
DA
4320 " bgp listen range %pFX peer-group %s\n",
4321 range, group->name);
d62a17ae 4322 }
4323 }
4324 }
f14e6fdb
DS
4325}
4326
4327
ff8a8a7a
CS
4328DEFUN_YANG(bgp_disable_connected_route_check,
4329 bgp_disable_connected_route_check_cmd,
4330 "bgp disable-ebgp-connected-route-check",
4331 "BGP specific commands\n"
4332 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4333{
87ce2564
CS
4334 nb_cli_enqueue_change(vty,
4335 "./global/ebgp-multihop-connected-route-check",
ff8a8a7a 4336 NB_OP_MODIFY, "true");
7aafcaca 4337
ff8a8a7a 4338 return nb_cli_apply_changes(vty, NULL);
907f92c8
DS
4339}
4340
ff8a8a7a
CS
4341DEFUN_YANG(no_bgp_disable_connected_route_check,
4342 no_bgp_disable_connected_route_check_cmd,
4343 "no bgp disable-ebgp-connected-route-check",
4344 NO_STR
4345 "BGP specific commands\n"
4346 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4347{
87ce2564
CS
4348 nb_cli_enqueue_change(vty,
4349 "./global/ebgp-multihop-connected-route-check",
ff8a8a7a 4350 NB_OP_MODIFY, "false");
d62a17ae 4351
ff8a8a7a 4352 return nb_cli_apply_changes(vty, NULL);
d62a17ae 4353}
4354
ff8a8a7a
CS
4355void cli_show_router_global_ebgp_multihop_connected_route_check(
4356 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
4357{
4358 if (yang_dnode_get_bool(dnode, NULL))
4359 vty_out(vty, " bgp disable-ebgp-connected-route-check\n");
4360}
d62a17ae 4361
ff8a8a7a
CS
4362DEFUN_YANG(bgp_default_shutdown,
4363 bgp_default_shutdown_cmd,
4364 "[no] bgp default shutdown",
4365 NO_STR BGP_STR
4366 "Configure BGP defaults\n"
4367 "Apply administrative shutdown to newly configured peers\n")
f26845f9 4368{
87ce2564 4369 nb_cli_enqueue_change(vty, "./global/default-shutdown", NB_OP_MODIFY,
ff8a8a7a
CS
4370 strmatch(argv[0]->text, "no") ? "false" : "true");
4371
4372 return nb_cli_apply_changes(vty, NULL);
4373}
4374
4375void cli_show_router_bgp_default_shutdown(struct vty *vty,
4376 struct lyd_node *dnode,
4377 bool show_defaults)
4378{
4379 if (yang_dnode_get_bool(dnode, NULL))
4380 vty_out(vty, " bgp default shutdown\n");
f26845f9
QY
4381}
4382
736b68f3
DS
4383DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4384 BGP_STR
9ddf4b81 4385 "Administrative shutdown of the BGP instance\n"
736b68f3
DS
4386 "Add a shutdown message (RFC 8203)\n"
4387 "Shutdown message\n")
9cf59432 4388{
736b68f3 4389 char *msgstr = NULL;
8389c83a 4390
9cf59432
DS
4391 VTY_DECLVAR_CONTEXT(bgp, bgp);
4392
8389c83a 4393 if (argc > 3)
f80e35b6 4394 msgstr = argv_concat(argv, argc, 3);
8389c83a
DS
4395
4396 bgp_shutdown_enable(bgp, msgstr);
4397 XFREE(MTYPE_TMP, msgstr);
9cf59432
DS
4398
4399 return CMD_SUCCESS;
4400}
4401
736b68f3 4402DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
9ddf4b81 4403 BGP_STR "Administrative shutdown of the BGP instance\n")
1e12ebbc
DS
4404{
4405 VTY_DECLVAR_CONTEXT(bgp, bgp);
4406
4407 bgp_shutdown_enable(bgp, NULL);
4408
4409 return CMD_SUCCESS;
4410}
8389c83a 4411
736b68f3 4412DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
9ddf4b81 4413 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
9cf59432
DS
4414{
4415 VTY_DECLVAR_CONTEXT(bgp, bgp);
4416
4417 bgp_shutdown_disable(bgp);
4418
4419 return CMD_SUCCESS;
4420}
4421
9ddf4b81 4422ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
1b6e7a88 4423 "no bgp shutdown message MSG...", NO_STR BGP_STR
9ddf4b81 4424 "Administrative shutdown of the BGP instance\n"
1b6e7a88 4425 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
1b6e7a88 4426
f4b8ec07
CS
4427DEFUN_YANG(neighbor_remote_as,
4428 neighbor_remote_as_cmd,
4429 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4430 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4431 "Specify a BGP neighbor\n" AS_STR
4432 "Internal BGP peer\n"
4433 "External BGP peer\n")
718e3744 4434{
d62a17ae 4435 int idx_peer = 1;
4436 int idx_remote_as = 3;
f4b8ec07
CS
4437 char base_xpath[XPATH_MAXLEN];
4438 char unnbr_xpath[XPATH_MAXLEN];
4439 char prgrp_xpath[XPATH_MAXLEN];
4440 union sockunion su;
4441 const char *as_type_str = "as-specified";
4442
4443 if (str2sockunion(argv[idx_peer]->arg, &su) < 0) {
4444 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
4445 FRR_BGP_NEIGHBOR_UNNUM_XPATH, argv[idx_peer]->arg, "");
4446
4447 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
4448 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg, "");
4449
3bb513c3
CH
4450 if (yang_dnode_existsf(vty->candidate_config->dnode, "%s%s",
4451 VTY_CURR_XPATH, unnbr_xpath + 1)) {
f4b8ec07 4452 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
3bb513c3
CH
4453 } else if (yang_dnode_existsf(vty->candidate_config->dnode,
4454 "%s%s", VTY_CURR_XPATH,
4455 prgrp_xpath + 1)) {
f4b8ec07
CS
4456 snprintf(base_xpath, sizeof(base_xpath),
4457 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg,
4458 "");
4459 } else {
4460 vty_out(vty,
4461 "%% Create the peer-group or interface first\n");
4462 return CMD_WARNING_CONFIG_FAILED;
4463 }
4464 } else {
4465 snprintf(base_xpath, sizeof(base_xpath),
4466 FRR_BGP_NEIGHBOR_NUM_XPATH, argv[idx_peer]->arg, "");
4467 }
4468
4469 if (argv[idx_remote_as]->arg[0] == 'i') {
4470 as_type_str = "internal";
4471 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4472 as_type_str = "external";
4473 } else {
4474 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4475 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4476 }
4477 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4478 NB_OP_MODIFY, as_type_str);
4479
4480 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 4481}
4482
e84c59af
DA
4483int peer_conf_interface_create(struct bgp *bgp, const char *conf_if,
4484 bool v6only, const char *peer_group_name,
4485 int as_type, as_t as, char *errmsg,
4486 size_t errmsg_len)
d62a17ae 4487{
d62a17ae 4488 struct peer *peer;
4489 struct peer_group *group;
4490 int ret = 0;
d62a17ae 4491
4492 group = peer_group_lookup(bgp, conf_if);
4493
4494 if (group) {
f4b8ec07
CS
4495 snprintf(errmsg, errmsg_len,
4496 "Name conflict with peer-group \n");
4497 return -1;
d62a17ae 4498 }
4499
4500 peer = peer_lookup_by_conf_if(bgp, conf_if);
4501 if (peer) {
f4b8ec07 4502 if (as_type != AS_UNSPECIFIED)
e84c59af 4503 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type);
d62a17ae 4504 } else {
e84c59af
DA
4505 peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
4506 NULL);
d62a17ae 4507
4508 if (!peer) {
f4b8ec07
CS
4509 snprintf(errmsg, errmsg_len,
4510 "BGP failed to create peer\n");
4511 return -1;
d62a17ae 4512 }
4513
4514 if (v6only)
527de3dc 4515 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4516
4517 /* Request zebra to initiate IPv6 RAs on this interface. We do
4518 * this
4519 * any unnumbered peer in order to not worry about run-time
4520 * transitions
4521 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4522 * address
4523 * gets deleted later etc.)
4524 */
4525 if (peer->ifp)
4526 bgp_zebra_initiate_radv(bgp, peer);
4527 }
4528
4529 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4530 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4531 if (v6only)
527de3dc 4532 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4533 else
527de3dc 4534 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4535
4536 /* v6only flag changed. Reset bgp seesion */
4537 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4538 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4539 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4540 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4541 } else
4542 bgp_session_reset(peer);
4543 }
4544
9fb964de
PM
4545 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4546 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4547 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
dc2f50f3 4548 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
9fb964de 4549 }
d62a17ae 4550
4551 if (peer_group_name) {
4552 group = peer_group_lookup(bgp, peer_group_name);
4553 if (!group) {
f4b8ec07
CS
4554 snprintf(errmsg, errmsg_len,
4555 "Configure the peer-group first\n");
4556 return -1;
d62a17ae 4557 }
4558
8395c1f8 4559 ret = peer_group_bind(bgp, NULL, peer, group, &as);
d62a17ae 4560 }
4561
f4b8ec07 4562 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
a80beece
DS
4563}
4564
232c75cd
CS
4565DEFUN_YANG(neighbor_interface_config,
4566 neighbor_interface_config_cmd,
f4b8ec07
CS
4567 "neighbor WORD interface [peer-group PGNAME]",
4568 NEIGHBOR_STR
4569 "Interface name or neighbor tag\n"
4570 "Enable BGP on interface\n"
4571 "Member of the peer-group\n"
4572 "Peer-group name\n")
4c48cf63 4573{
d62a17ae 4574 int idx_word = 1;
4575 int idx_peer_group_word = 4;
f4b8ec07
CS
4576 char base_xpath[XPATH_MAXLEN];
4577
4578 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4579 argv[idx_word]->arg, "");
31500417 4580
f4b8ec07 4581 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 4582 if (argc > idx_peer_group_word)
f4b8ec07
CS
4583 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_MODIFY,
4584 argv[idx_peer_group_word]->arg);
4585
4586 return nb_cli_apply_changes(vty, base_xpath);
4c48cf63
DW
4587}
4588
f4b8ec07
CS
4589DEFUN_YANG(neighbor_interface_config_v6only,
4590 neighbor_interface_config_v6only_cmd,
4591 "neighbor WORD interface v6only [peer-group PGNAME]",
4592 NEIGHBOR_STR
4593 "Interface name or neighbor tag\n"
4594 "Enable BGP on interface\n"
4595 "Enable BGP with v6 link-local only\n"
4596 "Member of the peer-group\n"
4597 "Peer-group name\n")
4c48cf63 4598{
d62a17ae 4599 int idx_word = 1;
4600 int idx_peer_group_word = 5;
f4b8ec07
CS
4601 char base_xpath[XPATH_MAXLEN];
4602
4603 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4604 argv[idx_word]->arg, "");
31500417 4605
f4b8ec07 4606 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 4607 if (argc > idx_peer_group_word)
f4b8ec07
CS
4608 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_MODIFY,
4609 argv[idx_peer_group_word]->arg);
31500417 4610
f4b8ec07
CS
4611 nb_cli_enqueue_change(vty, "./v6only", NB_OP_MODIFY, "true");
4612
4613 return nb_cli_apply_changes(vty, base_xpath);
4c48cf63
DW
4614}
4615
a80beece 4616
f4b8ec07
CS
4617DEFUN_YANG(
4618 neighbor_interface_config_remote_as,
4619 neighbor_interface_config_remote_as_cmd,
4620 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4621 NEIGHBOR_STR
4622 "Interface name or neighbor tag\n"
4623 "Enable BGP on interface\n"
4624 "Specify a BGP neighbor\n" AS_STR
4625 "Internal BGP peer\n"
4626 "External BGP peer\n")
b3a39dc5 4627{
d62a17ae 4628 int idx_word = 1;
4629 int idx_remote_as = 4;
f4b8ec07
CS
4630 char base_xpath[XPATH_MAXLEN];
4631 const char *as_type_str = "as-specified";
4632
4633 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4634 argv[idx_word]->arg, "");
4635
4636 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4637
4638 if (argv[idx_remote_as]->arg[0] == 'i') {
4639 as_type_str = "internal";
4640 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4641 as_type_str = "external";
4642 } else {
4643 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4644 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4645 }
4646 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4647 NB_OP_MODIFY, as_type_str);
4648
4649 return nb_cli_apply_changes(vty, base_xpath);
b3a39dc5
DD
4650}
4651
f4b8ec07
CS
4652DEFUN_YANG(
4653 neighbor_interface_v6only_config_remote_as,
4654 neighbor_interface_v6only_config_remote_as_cmd,
4655 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4656 NEIGHBOR_STR
4657 "Interface name or neighbor tag\n"
4658 "Enable BGP with v6 link-local only\n"
4659 "Enable BGP on interface\n"
4660 "Specify a BGP neighbor\n" AS_STR
4661 "Internal BGP peer\n"
4662 "External BGP peer\n")
b3a39dc5 4663{
d62a17ae 4664 int idx_word = 1;
4665 int idx_remote_as = 5;
f4b8ec07
CS
4666 char base_xpath[XPATH_MAXLEN];
4667 const char *as_type_str = "as-specified";
4668
4669 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4670 argv[idx_word]->arg, "");
4671
4672 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4673
4674 nb_cli_enqueue_change(vty, "./v6only", NB_OP_MODIFY, "true");
4675
4676 if (argv[idx_remote_as]->arg[0] == 'i') {
4677 as_type_str = "internal";
4678 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4679 as_type_str = "external";
4680 } else {
4681 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4682 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4683 }
4684 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4685 NB_OP_MODIFY, as_type_str);
4686
4687 return nb_cli_apply_changes(vty, base_xpath);
b3a39dc5
DD
4688}
4689
f4b8ec07
CS
4690DEFUN_YANG(neighbor_peer_group, neighbor_peer_group_cmd,
4691 "neighbor WORD peer-group",
4692 NEIGHBOR_STR
4693 "Interface name or neighbor tag\n"
4694 "Configure peer-group\n")
718e3744 4695{
f4b8ec07 4696 char base_xpath[XPATH_MAXLEN];
d62a17ae 4697 int idx_word = 1;
718e3744 4698
f4b8ec07
CS
4699 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_PEER_GROUP_XPATH,
4700 argv[idx_word]->arg, "");
718e3744 4701
f4b8ec07 4702 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
718e3744 4703
f4b8ec07 4704 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4705}
4706
232c75cd
CS
4707DEFUN_YANG(no_neighbor,
4708 no_neighbor_cmd,
4709 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4710 NO_STR NEIGHBOR_STR
4711 NEIGHBOR_ADDR_STR2
4712 "Specify a BGP neighbor\n" AS_STR
4713 "Internal BGP peer\n"
4714 "External BGP peer\n")
718e3744 4715{
d62a17ae 4716 int idx_peer = 2;
f4b8ec07
CS
4717 char base_xpath[XPATH_MAXLEN];
4718 char num_xpath[XPATH_MAXLEN];
4719 char unnbr_xpath[XPATH_MAXLEN];
4720 char prgrp_xpath[XPATH_MAXLEN];
d62a17ae 4721 union sockunion su;
d62a17ae 4722
f4b8ec07
CS
4723 if (str2sockunion(argv[idx_peer]->arg, &su) == 0) {
4724 snprintf(num_xpath, sizeof(num_xpath),
4725 FRR_BGP_NEIGHBOR_NUM_XPATH, argv[idx_peer]->arg, "");
3bb513c3
CH
4726 if (yang_dnode_existsf(vty->candidate_config->dnode, "%s%s",
4727 VTY_CURR_XPATH, num_xpath + 1)) {
f4b8ec07 4728 strlcpy(base_xpath, num_xpath, sizeof(base_xpath));
d62a17ae 4729 }
f4b8ec07
CS
4730 } else {
4731 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
4732 FRR_BGP_NEIGHBOR_UNNUM_XPATH, argv[idx_peer]->arg, "");
4733
4734 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
4735 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg, "");
4736
3bb513c3
CH
4737 if (yang_dnode_existsf(vty->candidate_config->dnode, "%s%s",
4738 VTY_CURR_XPATH, unnbr_xpath + 1)) {
f4b8ec07 4739 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
3bb513c3
CH
4740 } else if (yang_dnode_existsf(vty->candidate_config->dnode,
4741 "%s%s", VTY_CURR_XPATH,
4742 prgrp_xpath + 1)) {
f4b8ec07 4743 strlcpy(base_xpath, prgrp_xpath, sizeof(base_xpath));
4e2786df 4744 } else {
f4b8ec07
CS
4745 vty_out(vty,
4746 "%% Create the peer-group or interface first\n");
d62a17ae 4747 return CMD_WARNING_CONFIG_FAILED;
4748 }
1ff9a340 4749 }
718e3744 4750
f4b8ec07
CS
4751 nb_cli_enqueue_change(vty, base_xpath, NB_OP_DESTROY, NULL);
4752
fd396924
CH
4753 /*
4754 * Need to commit any pending so this command doesn't merge with a
4755 * create into a modify, which BGP can't handle
4756 */
4757 return nb_cli_apply_changes_clear_pending(vty, NULL);
718e3744 4758}
4759
f4b8ec07
CS
4760DEFUN_YANG(no_neighbor_interface_config,
4761 no_neighbor_interface_config_cmd,
4762 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4763 NO_STR NEIGHBOR_STR
4764 "Interface name\n"
4765 "Configure BGP on interface\n"
4766 "Enable BGP with v6 link-local only\n"
4767 "Member of the peer-group\n"
4768 "Peer-group name\n"
4769 "Specify a BGP neighbor\n" AS_STR
4770 "Internal BGP peer\n"
4771 "External BGP peer\n")
a80beece 4772{
d62a17ae 4773 int idx_word = 2;
f4b8ec07 4774 char base_xpath[XPATH_MAXLEN];
d62a17ae 4775
f4b8ec07
CS
4776 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4777 argv[idx_word]->arg, "");
4778
4779 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
4780
fd396924
CH
4781 /*
4782 * Need to commit any pending so this command doesn't merge with a
4783 * create into a modify, which BGP can't handle
4784 */
4785 return nb_cli_apply_changes_clear_pending(vty, base_xpath);
a80beece
DS
4786}
4787
f4b8ec07
CS
4788DEFUN_YANG(no_neighbor_peer_group,
4789 no_neighbor_peer_group_cmd,
4790 "no neighbor WORD peer-group",
4791 NO_STR NEIGHBOR_STR
4792 "Neighbor tag\n"
4793 "Configure peer-group\n")
718e3744 4794{
f4b8ec07 4795 char base_xpath[XPATH_MAXLEN];
d62a17ae 4796 int idx_word = 2;
718e3744 4797
f4b8ec07
CS
4798 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_PEER_GROUP_XPATH,
4799 argv[idx_word]->arg, "");
4800
4801 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
4802
fd396924
CH
4803 /*
4804 * Need to commit any pending so this command doesn't merge with a
4805 * create into a modify, which BGP can't handle
4806 */
4807 return nb_cli_apply_changes_clear_pending(vty, base_xpath);
718e3744 4808}
4809
f4b8ec07
CS
4810DEFUN_YANG(no_neighbor_interface_peer_group_remote_as,
4811 no_neighbor_interface_peer_group_remote_as_cmd,
4812 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4813 NO_STR NEIGHBOR_STR
4814 "Interface name or neighbor tag\n"
4815 "Specify a BGP neighbor\n" AS_STR
4816 "Internal BGP peer\n"
4817 "External BGP peer\n")
718e3744 4818{
f4b8ec07
CS
4819 int idx_peer = 2;
4820 char base_xpath[XPATH_MAXLEN];
4821 char unnbr_xpath[XPATH_MAXLEN];
4822 char prgrp_xpath[XPATH_MAXLEN];
d62a17ae 4823
f4b8ec07
CS
4824 snprintf(unnbr_xpath, sizeof(unnbr_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4825 argv[idx_peer]->arg, "");
d62a17ae 4826
f4b8ec07
CS
4827 snprintf(prgrp_xpath, sizeof(prgrp_xpath), FRR_BGP_PEER_GROUP_XPATH,
4828 argv[idx_peer]->arg, "");
4829
3bb513c3
CH
4830 if (yang_dnode_existsf(vty->candidate_config->dnode, "%s%s",
4831 VTY_CURR_XPATH, unnbr_xpath + 1)) {
f4b8ec07 4832 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
3bb513c3
CH
4833 } else if (yang_dnode_existsf(vty->candidate_config->dnode, "%s%s",
4834 VTY_CURR_XPATH, prgrp_xpath + 1)) {
f4b8ec07
CS
4835 strlcpy(base_xpath, prgrp_xpath, sizeof(base_xpath));
4836 } else {
d62a17ae 4837 vty_out(vty, "%% Create the peer-group or interface first\n");
4838 return CMD_WARNING_CONFIG_FAILED;
4839 }
f4b8ec07
CS
4840
4841 strlcat(base_xpath, "/neighbor-remote-as/remote-as-type",
4842 sizeof(base_xpath));
4843
4844 nb_cli_enqueue_change(vty, base_xpath, NB_OP_DESTROY, NULL);
4845
fd396924
CH
4846 /*
4847 * Need to commit any pending so this command doesn't merge with a
4848 * create into a modify, which BGP can't handle
4849 */
4850 return nb_cli_apply_changes_clear_pending(vty, NULL);
718e3744 4851}
6b0655a2 4852
f4b8ec07
CS
4853DEFUN_YANG(neighbor_local_as,
4854 neighbor_local_as_cmd,
4855 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4856 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4857 "Specify a local-as number\n"
4858 "AS number used as local AS\n")
718e3744 4859{
d62a17ae 4860 int idx_peer = 1;
4861 int idx_number = 3;
f4b8ec07 4862 char base_xpath[XPATH_MAXLEN];
718e3744 4863
f4b8ec07
CS
4864 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4865 sizeof(base_xpath), NULL)
4866 < 0)
d62a17ae 4867 return CMD_WARNING_CONFIG_FAILED;
718e3744 4868
f4b8ec07
CS
4869 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4870 argv[idx_number]->arg);
4871
4872 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4873}
4874
f4b8ec07
CS
4875DEFUN_YANG(
4876 neighbor_local_as_no_prepend, neighbor_local_as_no_prepend_cmd,
4877 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
4878 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4879 "Specify a local-as number\n"
4880 "AS number used as local AS\n"
4881 "Do not prepend local-as to updates from ebgp peers\n")
718e3744 4882{
d62a17ae 4883 int idx_peer = 1;
4884 int idx_number = 3;
f4b8ec07 4885 char base_xpath[XPATH_MAXLEN];
718e3744 4886
f4b8ec07
CS
4887 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4888 sizeof(base_xpath), NULL)
4889 < 0)
d62a17ae 4890 return CMD_WARNING_CONFIG_FAILED;
718e3744 4891
f4b8ec07
CS
4892 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4893 argv[idx_number]->arg);
4894 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4895 "true");
4896
4897 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4898}
4899
f4b8ec07
CS
4900DEFUN_YANG(
4901 neighbor_local_as_no_prepend_replace_as,
4902 neighbor_local_as_no_prepend_replace_as_cmd,
4903 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4904 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4905 "Specify a local-as number\n"
4906 "AS number used as local AS\n"
4907 "Do not prepend local-as to updates from ebgp peers\n"
4908 "Do not prepend local-as to updates from ibgp peers\n")
9d3f9705 4909{
d62a17ae 4910 int idx_peer = 1;
4911 int idx_number = 3;
f4b8ec07 4912 char base_xpath[XPATH_MAXLEN];
9d3f9705 4913
f4b8ec07
CS
4914 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4915 sizeof(base_xpath), NULL)
4916 < 0)
d62a17ae 4917 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 4918
f4b8ec07
CS
4919 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4920 argv[idx_number]->arg);
4921 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4922 "true");
ba51dd26 4923 nb_cli_enqueue_change(vty, "./local-as/replace-as", NB_OP_MODIFY,
f4b8ec07
CS
4924 "true");
4925
4926 return nb_cli_apply_changes(vty, base_xpath);
9d3f9705
AC
4927}
4928
f4b8ec07
CS
4929DEFUN_YANG(no_neighbor_local_as,
4930 no_neighbor_local_as_cmd,
4931 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
4932 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4933 "Specify a local-as number\n"
4934 "AS number used as local AS\n"
4935 "Do not prepend local-as to updates from ebgp peers\n"
4936 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 4937{
d62a17ae 4938 int idx_peer = 2;
f4b8ec07 4939 char base_xpath[XPATH_MAXLEN];
718e3744 4940
f4b8ec07
CS
4941 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4942 sizeof(base_xpath), NULL)
4943 < 0)
d62a17ae 4944 return CMD_WARNING_CONFIG_FAILED;
718e3744 4945
f4b8ec07
CS
4946 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_DESTROY, NULL);
4947 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4948 "false");
ba51dd26 4949 nb_cli_enqueue_change(vty, "./local-as/replace-as", NB_OP_MODIFY,
f4b8ec07
CS
4950 "false");
4951
4952 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4953}
4954
718e3744 4955
3f9c7369
DS
4956DEFUN (neighbor_solo,
4957 neighbor_solo_cmd,
9ccf14f7 4958 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4959 NEIGHBOR_STR
4960 NEIGHBOR_ADDR_STR2
4961 "Solo peer - part of its own update group\n")
4962{
d62a17ae 4963 int idx_peer = 1;
4964 struct peer *peer;
4965 int ret;
3f9c7369 4966
d62a17ae 4967 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4968 if (!peer)
4969 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4970
d62a17ae 4971 ret = update_group_adjust_soloness(peer, 1);
4972 return bgp_vty_return(vty, ret);
3f9c7369
DS
4973}
4974
4975DEFUN (no_neighbor_solo,
4976 no_neighbor_solo_cmd,
9ccf14f7 4977 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4978 NO_STR
4979 NEIGHBOR_STR
4980 NEIGHBOR_ADDR_STR2
4981 "Solo peer - part of its own update group\n")
4982{
d62a17ae 4983 int idx_peer = 2;
4984 struct peer *peer;
4985 int ret;
3f9c7369 4986
d62a17ae 4987 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4988 if (!peer)
4989 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4990
d62a17ae 4991 ret = update_group_adjust_soloness(peer, 0);
4992 return bgp_vty_return(vty, ret);
3f9c7369
DS
4993}
4994
f4b8ec07
CS
4995DEFUN_YANG(neighbor_password,
4996 neighbor_password_cmd,
4997 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
4998 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4999 "Set a password\n"
5000 "The password\n")
0df7c91f 5001{
d62a17ae 5002 int idx_peer = 1;
5003 int idx_line = 3;
f4b8ec07 5004 char base_xpath[XPATH_MAXLEN];
0df7c91f 5005
f4b8ec07
CS
5006 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5007 sizeof(base_xpath), NULL)
5008 < 0)
d62a17ae 5009 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 5010
f4b8ec07
CS
5011 nb_cli_enqueue_change(vty, "./password", NB_OP_MODIFY,
5012 argv[idx_line]->arg);
5013
5014 return nb_cli_apply_changes(vty, base_xpath);
0df7c91f
PJ
5015}
5016
f4b8ec07
CS
5017DEFUN_YANG(no_neighbor_password,
5018 no_neighbor_password_cmd,
5019 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
5020 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5021 "Set a password\n"
5022 "The password\n")
0df7c91f 5023{
d62a17ae 5024 int idx_peer = 2;
f4b8ec07 5025 char base_xpath[XPATH_MAXLEN];
0df7c91f 5026
f4b8ec07
CS
5027 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5028 sizeof(base_xpath), NULL)
5029 < 0)
d62a17ae 5030 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 5031
f4b8ec07
CS
5032 nb_cli_enqueue_change(vty, "./password", NB_OP_DESTROY, NULL);
5033
5034 return nb_cli_apply_changes(vty, base_xpath);
0df7c91f 5035}
6b0655a2 5036
f4b8ec07
CS
5037DEFUN_YANG(neighbor_activate,
5038 neighbor_activate_cmd,
5039 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5040 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5041 "Enable the Address Family for this Neighbor\n")
718e3744 5042{
d62a17ae 5043 int idx_peer = 1;
f4b8ec07 5044 char base_xpath[XPATH_MAXLEN];
f4b8ec07
CS
5045 char af_xpath[XPATH_MAXLEN];
5046 afi_t afi = bgp_node_afi(vty);
5047 safi_t safi = bgp_node_safi(vty);
718e3744 5048
f4b8ec07
CS
5049 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5050 yang_afi_safi_value2identity(afi, safi));
555c8ab7
CS
5051 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5052 sizeof(base_xpath), af_xpath)
f4b8ec07 5053 < 0)
d62a17ae 5054 return CMD_WARNING_CONFIG_FAILED;
718e3744 5055
555c8ab7 5056 nb_cli_enqueue_change(vty, "./enabled", NB_OP_MODIFY, "true");
f4b8ec07
CS
5057
5058 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5059}
5060
d62a17ae 5061ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
5062 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5063 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5064 "Enable the Address Family for this Neighbor\n")
596c17ba 5065
f4b8ec07
CS
5066DEFUN_YANG(no_neighbor_activate,
5067 no_neighbor_activate_cmd,
5068 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5069 NO_STR NEIGHBOR_STR
5070 NEIGHBOR_ADDR_STR2
5071 "Enable the Address Family for this Neighbor\n")
718e3744 5072{
d62a17ae 5073 int idx_peer = 2;
f4b8ec07
CS
5074 char base_xpath[XPATH_MAXLEN];
5075 char af_xpath[XPATH_MAXLEN];
5076 afi_t afi = bgp_node_afi(vty);
5077 safi_t safi = bgp_node_safi(vty);
718e3744 5078
f4b8ec07
CS
5079 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5080 yang_afi_safi_value2identity(afi, safi));
5081
5082 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5083 sizeof(base_xpath), af_xpath)
5084 < 0)
d62a17ae 5085 return CMD_WARNING_CONFIG_FAILED;
718e3744 5086
f4b8ec07
CS
5087 nb_cli_enqueue_change(vty, "./enabled", NB_OP_MODIFY, "false");
5088
5089 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5090}
6b0655a2 5091
d62a17ae 5092ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
5093 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5094 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5095 "Enable the Address Family for this Neighbor\n")
596c17ba 5096
2a059a54
DS
5097DEFUN (neighbor_set_peer_group,
5098 neighbor_set_peer_group_cmd,
5099 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5100 NEIGHBOR_STR
5101 NEIGHBOR_ADDR_STR2
5102 "Member of the peer-group\n"
5103 "Peer-group name\n")
718e3744 5104{
2a059a54 5105 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 5106 int idx_peer = 1;
5107 int idx_word = 3;
2a059a54
DS
5108 int ret;
5109 as_t as;
5110 union sockunion su;
5111 struct peer *peer;
5112 struct peer_group *group;
d62a17ae 5113
2a059a54
DS
5114 ret = str2sockunion(argv[idx_peer]->arg, &su);
5115 if (ret < 0) {
5116 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
5117 if (!peer) {
5118 vty_out(vty, "%% Malformed address or name: %s\n",
5119 argv[idx_peer]->arg);
5120 return CMD_WARNING_CONFIG_FAILED;
5121 }
5122 } else {
5123 if (peer_address_self_check(bgp, &su)) {
5124 vty_out(vty,
5125 "%% Can not configure the local system as neighbor\n");
5126 return CMD_WARNING_CONFIG_FAILED;
5127 }
5128
5129 /* Disallow for dynamic neighbor. */
5130 peer = peer_lookup(bgp, &su);
5131 if (peer && peer_dynamic_neighbor(peer)) {
5132 vty_out(vty,
5133 "%% Operation not allowed on a dynamic neighbor\n");
5134 return CMD_WARNING_CONFIG_FAILED;
5135 }
5136 }
5137
5138 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5139 if (!group) {
5140 vty_out(vty, "%% Configure the peer-group first\n");
d62a17ae 5141 return CMD_WARNING_CONFIG_FAILED;
2a059a54 5142 }
d62a17ae 5143
2a059a54 5144 ret = peer_group_bind(bgp, &su, peer, group, &as);
d62a17ae 5145
2a059a54
DS
5146 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
5147 vty_out(vty,
5148 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
5149 as);
5150 return CMD_WARNING_CONFIG_FAILED;
5151 }
5152
5153 return bgp_vty_return(vty, ret);
d62a17ae 5154}
5155
5156ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
d7b9898c 5157 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 5158 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5159 "Member of the peer-group\n"
5160 "Peer-group name\n")
596c17ba 5161
f4b8ec07
CS
5162DEFUN_YANG (no_neighbor_set_peer_group,
5163 no_neighbor_set_peer_group_cmd,
71cc0c88 5164 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
f4b8ec07
CS
5165 NO_STR
5166 NEIGHBOR_STR
5167 NEIGHBOR_ADDR_STR2
5168 "Member of the peer-group\n"
5169 "Peer-group name\n")
718e3744 5170{
d62a17ae 5171 int idx_peer = 2;
f4b8ec07 5172 char base_xpath[XPATH_MAXLEN];
d62a17ae 5173
f4b8ec07
CS
5174 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5175 sizeof(base_xpath), NULL)
5176 < 0)
d62a17ae 5177 return CMD_WARNING_CONFIG_FAILED;
b3a3290e 5178
f4b8ec07 5179 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_DESTROY, NULL);
718e3744 5180
fd396924
CH
5181 /*
5182 * Need to commit any pending so this command doesn't merge with a
5183 * create into a modify, which BGP can't handle
5184 */
5185 return nb_cli_apply_changes_clear_pending(vty, base_xpath);
718e3744 5186}
6b0655a2 5187
d62a17ae 5188ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
71cc0c88 5189 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 5190 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5191 "Member of the peer-group\n"
5192 "Peer-group name\n")
596c17ba 5193
d62a17ae 5194static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
47cbc09b 5195 uint32_t flag, int set)
718e3744 5196{
d62a17ae 5197 int ret;
5198 struct peer *peer;
718e3744 5199
d62a17ae 5200 peer = peer_and_group_lookup_vty(vty, ip_str);
5201 if (!peer)
5202 return CMD_WARNING_CONFIG_FAILED;
718e3744 5203
7ebe625c
QY
5204 /*
5205 * If 'neighbor <interface>', then this is for directly connected peers,
5206 * we should not accept disable-connected-check.
5207 */
5208 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5209 vty_out(vty,
3efd0893 5210 "%s is directly connected peer, cannot accept disable-connected-check\n",
7ebe625c
QY
5211 ip_str);
5212 return CMD_WARNING_CONFIG_FAILED;
5213 }
5214
d62a17ae 5215 if (!set && flag == PEER_FLAG_SHUTDOWN)
5216 peer_tx_shutdown_message_unset(peer);
ae9b0e11 5217
d62a17ae 5218 if (set)
5219 ret = peer_flag_set(peer, flag);
5220 else
5221 ret = peer_flag_unset(peer, flag);
718e3744 5222
d62a17ae 5223 return bgp_vty_return(vty, ret);
718e3744 5224}
5225
47cbc09b 5226static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
718e3744 5227{
d62a17ae 5228 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 5229}
5230
d62a17ae 5231static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
47cbc09b 5232 uint32_t flag)
718e3744 5233{
d62a17ae 5234 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 5235}
5236
f4b8ec07
CS
5237int peer_flag_modify_nb(struct bgp *bgp, const char *ip_str, struct peer *peer,
5238 uint32_t flag, bool set, char *errmsg,
5239 size_t errmsg_len)
5240{
5241 int ret;
5242
5243 /*
5244 * If 'neighbor <interface>', then this is for directly connected peers,
5245 * we should not accept disable-connected-check.
5246 */
5247 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5248 snprintf(
5249 errmsg, errmsg_len,
5250 "%s is directly connected peer, cannot accept disable-connected-check\n",
5251 ip_str);
5252 return -1;
5253 }
5254
5255 if (!set && flag == PEER_FLAG_SHUTDOWN)
5256 peer_tx_shutdown_message_unset(peer);
5257
5258 if (set)
5259 ret = peer_flag_set(peer, flag);
5260 else
5261 ret = peer_flag_unset(peer, flag);
5262
5263 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
5264}
5265
718e3744 5266/* neighbor passive. */
f4b8ec07
CS
5267DEFUN_YANG(neighbor_passive,
5268 neighbor_passive_cmd,
5269 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5270 NEIGHBOR_STR
5271 NEIGHBOR_ADDR_STR2
5272 "Don't send open messages to this neighbor\n")
718e3744 5273{
d62a17ae 5274 int idx_peer = 1;
f4b8ec07
CS
5275 char base_xpath[XPATH_MAXLEN];
5276
5277 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5278 sizeof(base_xpath), NULL)
5279 < 0)
5280 return CMD_WARNING_CONFIG_FAILED;
5281
5282 nb_cli_enqueue_change(vty, "./passive-mode", NB_OP_MODIFY, "true");
5283
5284 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5285}
5286
f4b8ec07
CS
5287DEFUN_YANG(no_neighbor_passive,
5288 no_neighbor_passive_cmd,
5289 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5290 NO_STR NEIGHBOR_STR
5291 NEIGHBOR_ADDR_STR2
5292 "Don't send open messages to this neighbor\n")
718e3744 5293{
d62a17ae 5294 int idx_peer = 2;
f4b8ec07
CS
5295 char base_xpath[XPATH_MAXLEN];
5296
5297 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5298 sizeof(base_xpath), NULL)
5299 < 0)
5300 return CMD_WARNING_CONFIG_FAILED;
5301
5302 nb_cli_enqueue_change(vty, "./passive-mode", NB_OP_MODIFY, "false");
5303
5304 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5305}
6b0655a2 5306
718e3744 5307/* neighbor shutdown. */
f4b8ec07
CS
5308DEFUN_YANG(neighbor_shutdown_msg,
5309 neighbor_shutdown_msg_cmd,
5310 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5311 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5312 "Administratively shut down this neighbor\n"
5313 "Add a shutdown message (RFC 8203)\n"
5314 "Shutdown message\n")
718e3744 5315{
d62a17ae 5316 int idx_peer = 1;
f4b8ec07
CS
5317 char base_xpath[XPATH_MAXLEN];
5318
5319 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5320 sizeof(base_xpath), NULL)
5321 < 0)
5322 return CMD_WARNING_CONFIG_FAILED;
73d70fa6 5323
d62a17ae 5324 if (argc >= 5) {
d62a17ae 5325 char *message;
73d70fa6 5326
d62a17ae 5327 message = argv_concat(argv, argc, 4);
f4b8ec07
CS
5328 nb_cli_enqueue_change(vty, "./admin-shutdown/message",
5329 NB_OP_MODIFY, message);
d62a17ae 5330 }
73d70fa6 5331
f4b8ec07
CS
5332 nb_cli_enqueue_change(vty, "./admin-shutdown/enable", NB_OP_MODIFY,
5333 "true");
5334
5335 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5336}
5337
232c75cd 5338ALIAS_YANG(neighbor_shutdown_msg, neighbor_shutdown_cmd,
d62a17ae 5339 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5340 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5341 "Administratively shut down this neighbor\n")
73d70fa6 5342
f4b8ec07
CS
5343DEFUN_YANG(no_neighbor_shutdown_msg,
5344 no_neighbor_shutdown_msg_cmd,
5345 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5346 NO_STR NEIGHBOR_STR
5347 NEIGHBOR_ADDR_STR2
5348 "Administratively shut down this neighbor\n"
5349 "Remove a shutdown message (RFC 8203)\n"
5350 "Shutdown message\n")
718e3744 5351{
d62a17ae 5352 int idx_peer = 2;
f4b8ec07 5353 char base_xpath[XPATH_MAXLEN];
73d70fa6 5354
f4b8ec07
CS
5355 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5356 sizeof(base_xpath), NULL)
5357 < 0)
5358 return CMD_WARNING_CONFIG_FAILED;
5359
5360 nb_cli_enqueue_change(vty, "./admin-shutdown/enable", NB_OP_MODIFY,
5361 "false");
5362
5363 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5364}
6b0655a2 5365
232c75cd 5366ALIAS_YANG(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
d62a17ae 5367 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5368 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5369 "Administratively shut down this neighbor\n")
73d70fa6 5370
8336c896
DA
5371DEFUN(neighbor_shutdown_rtt,
5372 neighbor_shutdown_rtt_cmd,
5373 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5374 NEIGHBOR_STR
5375 NEIGHBOR_ADDR_STR2
5376 "Administratively shut down this neighbor\n"
5377 "Shutdown if round-trip-time is higher than expected\n"
5378 "Round-trip-time in milliseconds\n"
5379 "Specify the number of keepalives before shutdown\n"
5380 "The number of keepalives with higher RTT to shutdown\n")
5381{
5382 int idx_peer = 1;
5383 int idx_rtt = 4;
5384 int idx_count = 0;
5385 struct peer *peer;
5386
5387 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5388
5389 if (!peer)
5390 return CMD_WARNING_CONFIG_FAILED;
5391
5392 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5393
5394 if (argv_find(argv, argc, "count", &idx_count))
5395 peer->rtt_keepalive_conf =
5396 strtol(argv[idx_count + 1]->arg, NULL, 10);
5397
5398 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5399 PEER_FLAG_RTT_SHUTDOWN);
5400}
5401
5402DEFUN(no_neighbor_shutdown_rtt,
5403 no_neighbor_shutdown_rtt_cmd,
5404 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5405 NO_STR
5406 NEIGHBOR_STR
5407 NEIGHBOR_ADDR_STR2
5408 "Administratively shut down this neighbor\n"
5409 "Shutdown if round-trip-time is higher than expected\n"
5410 "Round-trip-time in milliseconds\n"
5411 "Specify the number of keepalives before shutdown\n"
5412 "The number of keepalives with higher RTT to shutdown\n")
5413{
5414 int idx_peer = 2;
5415 struct peer *peer;
5416
5417 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5418
5419 if (!peer)
5420 return CMD_WARNING_CONFIG_FAILED;
5421
5422 peer->rtt_expected = 0;
5423 peer->rtt_keepalive_conf = 1;
5424
5425 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5426 PEER_FLAG_RTT_SHUTDOWN);
5427}
5428
718e3744 5429/* neighbor capability dynamic. */
f4b8ec07
CS
5430DEFUN_YANG (neighbor_capability_dynamic,
5431 neighbor_capability_dynamic_cmd,
5432 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5433 NEIGHBOR_STR
5434 NEIGHBOR_ADDR_STR2
5435 "Advertise capability to the peer\n"
5436 "Advertise dynamic capability to this neighbor\n")
718e3744 5437{
d62a17ae 5438 int idx_peer = 1;
f4b8ec07
CS
5439 char base_xpath[XPATH_MAXLEN];
5440
5441 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5442 sizeof(base_xpath), NULL)
5443 < 0)
5444 return CMD_WARNING_CONFIG_FAILED;
5445
5446 nb_cli_enqueue_change(vty, "./capability-options/dynamic-capability",
5447 NB_OP_MODIFY, "true");
5448
5449 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5450}
5451
f4b8ec07
CS
5452DEFUN_YANG (no_neighbor_capability_dynamic,
5453 no_neighbor_capability_dynamic_cmd,
5454 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5455 NO_STR
5456 NEIGHBOR_STR
5457 NEIGHBOR_ADDR_STR2
5458 "Advertise capability to the peer\n"
5459 "Advertise dynamic capability to this neighbor\n")
718e3744 5460{
d62a17ae 5461 int idx_peer = 2;
f4b8ec07
CS
5462 char base_xpath[XPATH_MAXLEN];
5463
5464 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5465 sizeof(base_xpath), NULL)
5466 < 0)
5467 return CMD_WARNING_CONFIG_FAILED;
5468
5469 nb_cli_enqueue_change(vty, "./capability-options/dynamic-capability",
5470 NB_OP_MODIFY, "false");
5471
5472 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5473}
6b0655a2 5474
718e3744 5475/* neighbor dont-capability-negotiate */
5476DEFUN (neighbor_dont_capability_negotiate,
5477 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5478 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5479 NEIGHBOR_STR
5480 NEIGHBOR_ADDR_STR2
5481 "Do not perform capability negotiation\n")
5482{
d62a17ae 5483 int idx_peer = 1;
5484 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5485 PEER_FLAG_DONT_CAPABILITY);
718e3744 5486}
5487
5488DEFUN (no_neighbor_dont_capability_negotiate,
5489 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5490 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5491 NO_STR
5492 NEIGHBOR_STR
5493 NEIGHBOR_ADDR_STR2
5494 "Do not perform capability negotiation\n")
5495{
d62a17ae 5496 int idx_peer = 2;
5497 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5498 PEER_FLAG_DONT_CAPABILITY);
718e3744 5499}
6b0655a2 5500
8a92a8a0 5501/* neighbor capability extended next hop encoding */
f4b8ec07
CS
5502DEFUN_YANG (neighbor_capability_enhe,
5503 neighbor_capability_enhe_cmd,
5504 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5505 NEIGHBOR_STR
5506 NEIGHBOR_ADDR_STR2
5507 "Advertise capability to the peer\n"
5508 "Advertise extended next-hop capability to the peer\n")
8a92a8a0 5509{
d62a17ae 5510 int idx_peer = 1;
f4b8ec07
CS
5511 char base_xpath[XPATH_MAXLEN];
5512
5513 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5514 sizeof(base_xpath), NULL)
5515 < 0)
5516 return CMD_WARNING_CONFIG_FAILED;
5517
5518 nb_cli_enqueue_change(
5519 vty, "./capability-options/extended-nexthop-capability",
5520 NB_OP_MODIFY, "true");
5521
5522 return nb_cli_apply_changes(vty, base_xpath);
8a92a8a0
DS
5523}
5524
f4b8ec07
CS
5525DEFUN_YANG (no_neighbor_capability_enhe,
5526 no_neighbor_capability_enhe_cmd,
5527 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5528 NO_STR
5529 NEIGHBOR_STR
5530 NEIGHBOR_ADDR_STR2
5531 "Advertise capability to the peer\n"
5532 "Advertise extended next-hop capability to the peer\n")
8a92a8a0 5533{
d62a17ae 5534 int idx_peer = 2;
f4b8ec07
CS
5535 char base_xpath[XPATH_MAXLEN];
5536
5537 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5538 sizeof(base_xpath), NULL)
5539 < 0)
5540 return CMD_WARNING_CONFIG_FAILED;
5541
5542 nb_cli_enqueue_change(
5543 vty, "./capability-options/extended-nexthop-capability",
5544 NB_OP_MODIFY, "false");
5545
5546 return nb_cli_apply_changes(vty, base_xpath);
5547}
5548
5549int peer_af_flag_modify_nb(struct peer *peer, afi_t afi, safi_t safi,
5550 uint32_t flag, int set, char *errmsg,
5551 size_t errmsg_len)
5552{
5553 int ret;
5554
5555 if (set)
5556 ret = peer_af_flag_set(peer, afi, safi, flag);
5557 else
5558 ret = peer_af_flag_unset(peer, afi, safi, flag);
5559
5560 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
8a92a8a0
DS
5561}
5562
d62a17ae 5563static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5564 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 5565 int set)
718e3744 5566{
d62a17ae 5567 int ret;
5568 struct peer *peer;
718e3744 5569
d62a17ae 5570 peer = peer_and_group_lookup_vty(vty, peer_str);
5571 if (!peer)
5572 return CMD_WARNING_CONFIG_FAILED;
718e3744 5573
d62a17ae 5574 if (set)
5575 ret = peer_af_flag_set(peer, afi, safi, flag);
5576 else
5577 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 5578
d62a17ae 5579 return bgp_vty_return(vty, ret);
718e3744 5580}
5581
d62a17ae 5582static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5583 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5584{
d62a17ae 5585 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 5586}
5587
d62a17ae 5588static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5589 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5590{
d62a17ae 5591 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 5592}
6b0655a2 5593
718e3744 5594/* neighbor capability orf prefix-list. */
5595DEFUN (neighbor_capability_orf_prefix,
5596 neighbor_capability_orf_prefix_cmd,
9ccf14f7 5597 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5598 NEIGHBOR_STR
5599 NEIGHBOR_ADDR_STR2
5600 "Advertise capability to the peer\n"
5601 "Advertise ORF capability to the peer\n"
5602 "Advertise prefixlist ORF capability to this neighbor\n"
5603 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5604 "Capability to RECEIVE the ORF from this neighbor\n"
5605 "Capability to SEND the ORF to this neighbor\n")
5606{
d62a17ae 5607 int idx_send_recv = 5;
db45f64d
DS
5608 char *peer_str = argv[1]->arg;
5609 struct peer *peer;
5610 afi_t afi = bgp_node_afi(vty);
5611 safi_t safi = bgp_node_safi(vty);
d62a17ae 5612
db45f64d
DS
5613 peer = peer_and_group_lookup_vty(vty, peer_str);
5614 if (!peer)
d62a17ae 5615 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5616
db45f64d
DS
5617 if (strmatch(argv[idx_send_recv]->text, "send"))
5618 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5619 PEER_FLAG_ORF_PREFIX_SM);
5620
5621 if (strmatch(argv[idx_send_recv]->text, "receive"))
5622 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5623 PEER_FLAG_ORF_PREFIX_RM);
5624
5625 if (strmatch(argv[idx_send_recv]->text, "both"))
5626 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5627 PEER_FLAG_ORF_PREFIX_SM)
5628 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5629 PEER_FLAG_ORF_PREFIX_RM);
5630
5631 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5632}
5633
5634ALIAS_HIDDEN(
5635 neighbor_capability_orf_prefix,
5636 neighbor_capability_orf_prefix_hidden_cmd,
5637 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5638 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5639 "Advertise capability to the peer\n"
5640 "Advertise ORF capability to the peer\n"
5641 "Advertise prefixlist ORF capability to this neighbor\n"
5642 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5643 "Capability to RECEIVE the ORF from this neighbor\n"
5644 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5645
718e3744 5646DEFUN (no_neighbor_capability_orf_prefix,
5647 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 5648 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5649 NO_STR
5650 NEIGHBOR_STR
5651 NEIGHBOR_ADDR_STR2
5652 "Advertise capability to the peer\n"
5653 "Advertise ORF capability to the peer\n"
5654 "Advertise prefixlist ORF capability to this neighbor\n"
5655 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5656 "Capability to RECEIVE the ORF from this neighbor\n"
5657 "Capability to SEND the ORF to this neighbor\n")
5658{
d62a17ae 5659 int idx_send_recv = 6;
db45f64d
DS
5660 char *peer_str = argv[2]->arg;
5661 struct peer *peer;
5662 afi_t afi = bgp_node_afi(vty);
5663 safi_t safi = bgp_node_safi(vty);
d62a17ae 5664
db45f64d
DS
5665 peer = peer_and_group_lookup_vty(vty, peer_str);
5666 if (!peer)
d62a17ae 5667 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5668
db45f64d
DS
5669 if (strmatch(argv[idx_send_recv]->text, "send"))
5670 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5671 PEER_FLAG_ORF_PREFIX_SM);
5672
5673 if (strmatch(argv[idx_send_recv]->text, "receive"))
5674 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5675 PEER_FLAG_ORF_PREFIX_RM);
5676
5677 if (strmatch(argv[idx_send_recv]->text, "both"))
5678 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5679 PEER_FLAG_ORF_PREFIX_SM)
5680 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5681 PEER_FLAG_ORF_PREFIX_RM);
5682
5683 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5684}
5685
5686ALIAS_HIDDEN(
5687 no_neighbor_capability_orf_prefix,
5688 no_neighbor_capability_orf_prefix_hidden_cmd,
5689 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5690 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5691 "Advertise capability to the peer\n"
5692 "Advertise ORF capability to the peer\n"
5693 "Advertise prefixlist ORF capability to this neighbor\n"
5694 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5695 "Capability to RECEIVE the ORF from this neighbor\n"
5696 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5697
718e3744 5698/* neighbor next-hop-self. */
f4b8ec07
CS
5699DEFUN_YANG (neighbor_nexthop_self,
5700 neighbor_nexthop_self_cmd,
5701 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5702 NEIGHBOR_STR
5703 NEIGHBOR_ADDR_STR2
5704 "Disable the next hop calculation for this neighbor\n")
718e3744 5705{
d62a17ae 5706 int idx_peer = 1;
f4b8ec07
CS
5707 char base_xpath[XPATH_MAXLEN];
5708 char af_xpath[XPATH_MAXLEN];
5709 char attr_xpath[XPATH_MAXLEN];
5710 afi_t afi = bgp_node_afi(vty);
5711 safi_t safi = bgp_node_safi(vty);
5712
f4b8ec07
CS
5713 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5714 yang_afi_safi_value2identity(afi, safi));
5715
5716 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5717 sizeof(base_xpath), af_xpath)
5718 < 0)
5719 return CMD_WARNING_CONFIG_FAILED;
5720
5721 snprintf(attr_xpath, sizeof(attr_xpath),
5722 "./%s/nexthop-self/next-hop-self",
5723 bgp_afi_safi_get_container_str(afi, safi));
5724
5725 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5726
5727 return nb_cli_apply_changes(vty, base_xpath);
a538debe 5728}
9e7a53c1 5729
d62a17ae 5730ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5731 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5732 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5733 "Disable the next hop calculation for this neighbor\n")
596c17ba 5734
f4b8ec07
CS
5735/* neighbor next-hop-self. */
5736DEFUN_YANG(neighbor_nexthop_self_force,
5737 neighbor_nexthop_self_force_cmd,
5738 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5739 NEIGHBOR_STR
5740 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{
5744 int idx_peer = 1;
5745 char base_xpath[XPATH_MAXLEN];
5746 char af_xpath[XPATH_MAXLEN];
5747 char attr_xpath[XPATH_MAXLEN];
5748 afi_t afi = bgp_node_afi(vty);
5749 safi_t safi = bgp_node_safi(vty);
5750
f4b8ec07
CS
5751 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5752 yang_afi_safi_value2identity(afi, safi));
5753
5754 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5755 sizeof(base_xpath), af_xpath)
5756 < 0)
5757 return CMD_WARNING_CONFIG_FAILED;
5758
5759 snprintf(attr_xpath, sizeof(attr_xpath),
5760 "./%s/nexthop-self/next-hop-self-force",
5761 bgp_afi_safi_get_container_str(afi, safi));
5762
5763 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5764
5765 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5766}
5767
d62a17ae 5768ALIAS_HIDDEN(neighbor_nexthop_self_force,
5769 neighbor_nexthop_self_force_hidden_cmd,
5770 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5771 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5772 "Disable the next hop calculation for this neighbor\n"
5773 "Set the next hop to self for reflected routes\n")
596c17ba 5774
1bc4e531
DA
5775ALIAS_HIDDEN(neighbor_nexthop_self_force,
5776 neighbor_nexthop_self_all_hidden_cmd,
5777 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5778 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5779 "Disable the next hop calculation for this neighbor\n"
5780 "Set the next hop to self for reflected routes\n")
5781
f4b8ec07
CS
5782DEFUN_YANG (no_neighbor_nexthop_self,
5783 no_neighbor_nexthop_self_cmd,
5784 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5785 NO_STR
5786 NEIGHBOR_STR
5787 NEIGHBOR_ADDR_STR2
5788 "Disable the next hop calculation for this neighbor\n")
718e3744 5789{
d62a17ae 5790 int idx_peer = 2;
f4b8ec07
CS
5791 char base_xpath[XPATH_MAXLEN];
5792 char af_xpath[XPATH_MAXLEN];
5793 char attr_xpath[XPATH_MAXLEN];
5794 afi_t afi = bgp_node_afi(vty);
5795 safi_t safi = bgp_node_safi(vty);
5796
5797 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5798 yang_afi_safi_value2identity(afi, safi));
5799
5800 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5801 sizeof(base_xpath), af_xpath)
5802 < 0)
5803 return CMD_WARNING_CONFIG_FAILED;
5804
5805 snprintf(attr_xpath, sizeof(attr_xpath),
5806 "./%s/nexthop-self/next-hop-self",
5807 bgp_afi_safi_get_container_str(afi, safi));
5808
5809 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5810
5811 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5812}
6b0655a2 5813
d62a17ae 5814ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5815 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5816 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5817 "Disable the next hop calculation for this neighbor\n")
596c17ba 5818
f4b8ec07
CS
5819DEFUN_YANG (no_neighbor_nexthop_self_force,
5820 no_neighbor_nexthop_self_force_cmd,
5821 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5822 NO_STR
5823 NEIGHBOR_STR
5824 NEIGHBOR_ADDR_STR2
5825 "Disable the next hop calculation for this neighbor\n"
5826 "Set the next hop to self for reflected routes\n")
88b8ed8d 5827{
d62a17ae 5828 int idx_peer = 2;
f4b8ec07
CS
5829 char base_xpath[XPATH_MAXLEN];
5830 char af_xpath[XPATH_MAXLEN];
5831 char attr_xpath[XPATH_MAXLEN];
5832 afi_t afi = bgp_node_afi(vty);
5833 safi_t safi = bgp_node_safi(vty);
5834
f4b8ec07
CS
5835 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5836 yang_afi_safi_value2identity(afi, safi));
5837
5838 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5839 sizeof(base_xpath), af_xpath)
5840 < 0)
5841 return CMD_WARNING_CONFIG_FAILED;
5842
5843 snprintf(attr_xpath, sizeof(attr_xpath),
5844 "./%s/nexthop-self/next-hop-self-force",
5845 bgp_afi_safi_get_container_str(afi, safi));
5846
5847 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5848
5849 return nb_cli_apply_changes(vty, base_xpath);
88b8ed8d 5850}
a538debe 5851
d62a17ae 5852ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5853 no_neighbor_nexthop_self_force_hidden_cmd,
5854 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5855 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5856 "Disable the next hop calculation for this neighbor\n"
5857 "Set the next hop to self for reflected routes\n")
596c17ba 5858
1bc4e531
DA
5859ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5860 no_neighbor_nexthop_self_all_hidden_cmd,
5861 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5862 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5863 "Disable the next hop calculation for this neighbor\n"
5864 "Set the next hop to self for reflected routes\n")
5865
c7122e14 5866/* neighbor as-override */
f4b8ec07
CS
5867DEFUN_YANG (neighbor_as_override,
5868 neighbor_as_override_cmd,
5869 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5870 NEIGHBOR_STR
5871 NEIGHBOR_ADDR_STR2
5872 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5873{
d62a17ae 5874 int idx_peer = 1;
f4b8ec07
CS
5875 char base_xpath[XPATH_MAXLEN];
5876 char af_xpath[XPATH_MAXLEN];
5877 char attr_xpath[XPATH_MAXLEN];
5878 afi_t afi = bgp_node_afi(vty);
5879 safi_t safi = bgp_node_safi(vty);
5880
5881 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5882 yang_afi_safi_value2identity(afi, safi));
5883
5884 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5885 sizeof(base_xpath), af_xpath)
5886 < 0)
5887 return CMD_WARNING_CONFIG_FAILED;
5888
5889 snprintf(attr_xpath, sizeof(attr_xpath),
5890 "./%s/as-path-options/replace-peer-as",
5891 bgp_afi_safi_get_container_str(afi, safi));
5892
5893 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5894
5895 return nb_cli_apply_changes(vty, base_xpath);
c7122e14
DS
5896}
5897
d62a17ae 5898ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5899 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5900 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5901 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5902
f4b8ec07
CS
5903DEFUN_YANG (no_neighbor_as_override,
5904 no_neighbor_as_override_cmd,
5905 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5906 NO_STR
5907 NEIGHBOR_STR
5908 NEIGHBOR_ADDR_STR2
5909 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5910{
d62a17ae 5911 int idx_peer = 2;
f4b8ec07
CS
5912 char base_xpath[XPATH_MAXLEN];
5913 char af_xpath[XPATH_MAXLEN];
5914 char attr_xpath[XPATH_MAXLEN];
5915 afi_t afi = bgp_node_afi(vty);
5916 safi_t safi = bgp_node_safi(vty);
5917
5918 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5919 yang_afi_safi_value2identity(afi, safi));
5920
5921 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5922 sizeof(base_xpath), af_xpath)
5923 < 0)
5924 return CMD_WARNING_CONFIG_FAILED;
5925
5926 snprintf(attr_xpath, sizeof(attr_xpath),
5927 "./%s/as-path-options/replace-peer-as",
5928 bgp_afi_safi_get_container_str(afi, safi));
5929
5930 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5931
5932 return nb_cli_apply_changes(vty, base_xpath);
c7122e14
DS
5933}
5934
d62a17ae 5935ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5936 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5937 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5938 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5939
718e3744 5940/* neighbor remove-private-AS. */
f4b8ec07
CS
5941DEFUN_YANG (neighbor_remove_private_as,
5942 neighbor_remove_private_as_cmd,
5943 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5944 NEIGHBOR_STR
5945 NEIGHBOR_ADDR_STR2
5946 "Remove private ASNs in outbound updates\n")
718e3744 5947{
d62a17ae 5948 int idx_peer = 1;
f4b8ec07
CS
5949 char base_xpath[XPATH_MAXLEN];
5950 char af_xpath[XPATH_MAXLEN];
5951 char attr_xpath[XPATH_MAXLEN];
5952 afi_t afi = bgp_node_afi(vty);
5953 safi_t safi = bgp_node_safi(vty);
5954
5955 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5956 yang_afi_safi_value2identity(afi, safi));
5957
5958 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5959 sizeof(base_xpath), af_xpath)
5960 < 0)
5961 return CMD_WARNING_CONFIG_FAILED;
5962
5963 snprintf(attr_xpath, sizeof(attr_xpath),
5964 "./%s/private-as/remove-private-as",
5965 bgp_afi_safi_get_container_str(afi, safi));
5966
5967 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5968
5969 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5970}
5971
d62a17ae 5972ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5973 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5974 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5975 "Remove private ASNs in outbound updates\n")
596c17ba 5976
f4b8ec07
CS
5977DEFUN_YANG (neighbor_remove_private_as_all,
5978 neighbor_remove_private_as_all_cmd,
5979 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5980 NEIGHBOR_STR
5981 NEIGHBOR_ADDR_STR2
5982 "Remove private ASNs in outbound updates\n"
5983 "Apply to all AS numbers\n")
5000f21c 5984{
d62a17ae 5985 int idx_peer = 1;
f4b8ec07
CS
5986 char base_xpath[XPATH_MAXLEN];
5987 char af_xpath[XPATH_MAXLEN];
5988 char attr_xpath[XPATH_MAXLEN];
5989 afi_t afi = bgp_node_afi(vty);
5990 safi_t safi = bgp_node_safi(vty);
5991
f4b8ec07
CS
5992 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5993 yang_afi_safi_value2identity(afi, safi));
5994
5995 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5996 sizeof(base_xpath), af_xpath)
5997 < 0)
5998 return CMD_WARNING_CONFIG_FAILED;
5999
6000 snprintf(attr_xpath, sizeof(attr_xpath),
6001 "./%s/private-as/remove-private-as-all",
6002 bgp_afi_safi_get_container_str(afi, safi));
6003
6004 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
6005
6006 return nb_cli_apply_changes(vty, base_xpath);
5000f21c
DS
6007}
6008
d62a17ae 6009ALIAS_HIDDEN(neighbor_remove_private_as_all,
6010 neighbor_remove_private_as_all_hidden_cmd,
6011 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
6012 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6013 "Remove private ASNs in outbound updates\n"
6014 "Apply to all AS numbers")
596c17ba 6015
f4b8ec07
CS
6016DEFUN_YANG (neighbor_remove_private_as_replace_as,
6017 neighbor_remove_private_as_replace_as_cmd,
6018 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
6019 NEIGHBOR_STR
6020 NEIGHBOR_ADDR_STR2
6021 "Remove private ASNs in outbound updates\n"
6022 "Replace private ASNs with our ASN in outbound updates\n")
5000f21c 6023{
d62a17ae 6024 int idx_peer = 1;
f4b8ec07
CS
6025 char base_xpath[XPATH_MAXLEN];
6026 char af_xpath[XPATH_MAXLEN];
6027 char attr_xpath[XPATH_MAXLEN];
6028 afi_t afi = bgp_node_afi(vty);
6029 safi_t safi = bgp_node_safi(vty);
6030
f4b8ec07
CS
6031 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6032 yang_afi_safi_value2identity(afi, safi));
6033
6034 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6035 sizeof(base_xpath), af_xpath)
6036 < 0)
6037 return CMD_WARNING_CONFIG_FAILED;
6038
6039 snprintf(attr_xpath, sizeof(attr_xpath),
6040 "./%s/private-as/remove-private-as-replace",
6041 bgp_afi_safi_get_container_str(afi, safi));
6042
6043 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
6044
6045 return nb_cli_apply_changes(vty, base_xpath);
5000f21c
DS
6046}
6047
d62a17ae 6048ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
6049 neighbor_remove_private_as_replace_as_hidden_cmd,
6050 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
6051 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6052 "Remove private ASNs in outbound updates\n"
6053 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 6054
f4b8ec07
CS
6055DEFUN_YANG (neighbor_remove_private_as_all_replace_as,
6056 neighbor_remove_private_as_all_replace_as_cmd,
6057 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6058 NEIGHBOR_STR
6059 NEIGHBOR_ADDR_STR2
6060 "Remove private ASNs in outbound updates\n"
6061 "Apply to all AS numbers\n"
6062 "Replace private ASNs with our ASN in outbound updates\n")
5000f21c 6063{
d62a17ae 6064 int idx_peer = 1;
f4b8ec07
CS
6065 char base_xpath[XPATH_MAXLEN];
6066 char af_xpath[XPATH_MAXLEN];
6067 char attr_xpath[XPATH_MAXLEN];
6068 afi_t afi = bgp_node_afi(vty);
6069 safi_t safi = bgp_node_safi(vty);
6070
f4b8ec07
CS
6071 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6072 yang_afi_safi_value2identity(afi, safi));
6073
6074 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6075 sizeof(base_xpath), af_xpath)
6076 < 0)
6077 return CMD_WARNING_CONFIG_FAILED;
6078
6079 snprintf(attr_xpath, sizeof(attr_xpath),
6080 "./%s/private-as/remove-private-as-all-replace",
6081 bgp_afi_safi_get_container_str(afi, safi));
6082
6083 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
6084
6085 return nb_cli_apply_changes(vty, base_xpath);
5000f21c
DS
6086}
6087
d62a17ae 6088ALIAS_HIDDEN(
6089 neighbor_remove_private_as_all_replace_as,
6090 neighbor_remove_private_as_all_replace_as_hidden_cmd,
6091 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6092 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6093 "Remove private ASNs in outbound updates\n"
6094 "Apply to all AS numbers\n"
6095 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 6096
f4b8ec07
CS
6097DEFUN_YANG (no_neighbor_remove_private_as,
6098 no_neighbor_remove_private_as_cmd,
6099 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
6100 NO_STR
6101 NEIGHBOR_STR
6102 NEIGHBOR_ADDR_STR2
6103 "Remove private ASNs in outbound updates\n")
718e3744 6104{
d62a17ae 6105 int idx_peer = 2;
f4b8ec07
CS
6106 char base_xpath[XPATH_MAXLEN];
6107 char af_xpath[XPATH_MAXLEN];
6108 char attr_xpath[XPATH_MAXLEN];
6109 afi_t afi = bgp_node_afi(vty);
6110 safi_t safi = bgp_node_safi(vty);
6111
6112 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6113 yang_afi_safi_value2identity(afi, safi));
6114
6115 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6116 sizeof(base_xpath), af_xpath)
6117 < 0)
6118 return CMD_WARNING_CONFIG_FAILED;
6119
6120 snprintf(attr_xpath, sizeof(attr_xpath),
6121 "./%s/private-as/remove-private-as",
6122 bgp_afi_safi_get_container_str(afi, safi));
6123
6124 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6125
6126 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6127}
6b0655a2 6128
d62a17ae 6129ALIAS_HIDDEN(no_neighbor_remove_private_as,
6130 no_neighbor_remove_private_as_hidden_cmd,
6131 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
6132 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6133 "Remove private ASNs in outbound updates\n")
596c17ba 6134
f4b8ec07
CS
6135DEFUN_YANG (no_neighbor_remove_private_as_all,
6136 no_neighbor_remove_private_as_all_cmd,
6137 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
6138 NO_STR
6139 NEIGHBOR_STR
6140 NEIGHBOR_ADDR_STR2
6141 "Remove private ASNs in outbound updates\n"
6142 "Apply to all AS numbers\n")
88b8ed8d 6143{
d62a17ae 6144 int idx_peer = 2;
f4b8ec07
CS
6145 char base_xpath[XPATH_MAXLEN];
6146 char af_xpath[XPATH_MAXLEN];
6147 char attr_xpath[XPATH_MAXLEN];
6148 afi_t afi = bgp_node_afi(vty);
6149 safi_t safi = bgp_node_safi(vty);
6150
f4b8ec07
CS
6151 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6152 yang_afi_safi_value2identity(afi, safi));
6153
6154 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6155 sizeof(base_xpath), af_xpath)
6156 < 0)
6157 return CMD_WARNING_CONFIG_FAILED;
6158
6159 snprintf(attr_xpath, sizeof(attr_xpath),
6160 "./%s/private-as/remove-private-as-all",
6161 bgp_afi_safi_get_container_str(afi, safi));
6162
6163 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6164
6165 return nb_cli_apply_changes(vty, base_xpath);
88b8ed8d 6166}
5000f21c 6167
d62a17ae 6168ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
6169 no_neighbor_remove_private_as_all_hidden_cmd,
6170 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
6171 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6172 "Remove private ASNs in outbound updates\n"
6173 "Apply to all AS numbers\n")
596c17ba 6174
f4b8ec07
CS
6175DEFUN_YANG (no_neighbor_remove_private_as_replace_as,
6176 no_neighbor_remove_private_as_replace_as_cmd,
6177 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
6178 NO_STR
6179 NEIGHBOR_STR
6180 NEIGHBOR_ADDR_STR2
6181 "Remove private ASNs in outbound updates\n"
6182 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 6183{
d62a17ae 6184 int idx_peer = 2;
f4b8ec07
CS
6185 char base_xpath[XPATH_MAXLEN];
6186 char af_xpath[XPATH_MAXLEN];
6187 char attr_xpath[XPATH_MAXLEN];
6188 afi_t afi = bgp_node_afi(vty);
6189 safi_t safi = bgp_node_safi(vty);
6190
f4b8ec07
CS
6191 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6192 yang_afi_safi_value2identity(afi, safi));
6193
6194 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6195 sizeof(base_xpath), af_xpath)
6196 < 0)
6197 return CMD_WARNING_CONFIG_FAILED;
6198
6199 snprintf(attr_xpath, sizeof(attr_xpath),
6200 "./%s/private-as/remove-private-as-replace",
6201 bgp_afi_safi_get_container_str(afi, safi));
6202
6203 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6204
6205 return nb_cli_apply_changes(vty, base_xpath);
88b8ed8d 6206}
5000f21c 6207
d62a17ae 6208ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
6209 no_neighbor_remove_private_as_replace_as_hidden_cmd,
6210 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
6211 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6212 "Remove private ASNs in outbound updates\n"
6213 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 6214
f4b8ec07
CS
6215DEFUN_YANG (no_neighbor_remove_private_as_all_replace_as,
6216 no_neighbor_remove_private_as_all_replace_as_cmd,
6217 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6218 NO_STR
6219 NEIGHBOR_STR
6220 NEIGHBOR_ADDR_STR2
6221 "Remove private ASNs in outbound updates\n"
6222 "Apply to all AS numbers\n"
6223 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 6224{
d62a17ae 6225 int idx_peer = 2;
f4b8ec07
CS
6226 char base_xpath[XPATH_MAXLEN];
6227 char af_xpath[XPATH_MAXLEN];
6228 char attr_xpath[XPATH_MAXLEN];
6229 afi_t afi = bgp_node_afi(vty);
6230 safi_t safi = bgp_node_safi(vty);
6231
f4b8ec07
CS
6232 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6233 yang_afi_safi_value2identity(afi, safi));
6234
6235 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6236 sizeof(base_xpath), af_xpath)
6237 < 0)
6238 return CMD_WARNING_CONFIG_FAILED;
6239
6240 snprintf(attr_xpath, sizeof(attr_xpath),
6241 "./%s/private-as/remove-private-as-all-replace",
6242 bgp_afi_safi_get_container_str(afi, safi));
6243
6244 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6245
6246 return nb_cli_apply_changes(vty, base_xpath);
88b8ed8d 6247}
5000f21c 6248
d62a17ae 6249ALIAS_HIDDEN(
6250 no_neighbor_remove_private_as_all_replace_as,
6251 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
6252 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6253 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6254 "Remove private ASNs in outbound updates\n"
6255 "Apply to all AS numbers\n"
6256 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 6257
5000f21c 6258
718e3744 6259/* neighbor send-community. */
f4b8ec07
CS
6260DEFUN_YANG (neighbor_send_community,
6261 neighbor_send_community_cmd,
6262 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6263 NEIGHBOR_STR
6264 NEIGHBOR_ADDR_STR2
6265 "Send Community attribute to this neighbor\n")
718e3744 6266{
d62a17ae 6267 int idx_peer = 1;
e48a9a90
CS
6268 char *peer_str = argv[idx_peer]->arg;
6269 char base_xpath[XPATH_MAXLEN];
6270 char af_xpath[XPATH_MAXLEN];
6271 char std_xpath[XPATH_MAXLEN];
6272 afi_t afi = bgp_node_afi(vty);
6273 safi_t safi = bgp_node_safi(vty);
27c05d4d 6274
e48a9a90
CS
6275 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6276 yang_afi_safi_value2identity(afi, safi));
6277
6278 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6279 sizeof(base_xpath), af_xpath)
6280 < 0)
6281 return CMD_WARNING_CONFIG_FAILED;
6282
6283 snprintf(std_xpath, sizeof(std_xpath),
6284 "./%s/send-community/send-community",
6285 bgp_afi_safi_get_container_str(afi, safi));
6286
6287 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6288
6289 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6290}
6291
d62a17ae 6292ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
6293 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6294 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6295 "Send Community attribute to this neighbor\n")
596c17ba 6296
f4b8ec07
CS
6297DEFUN_YANG (no_neighbor_send_community,
6298 no_neighbor_send_community_cmd,
6299 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6300 NO_STR
6301 NEIGHBOR_STR
6302 NEIGHBOR_ADDR_STR2
6303 "Send Community attribute to this neighbor\n")
718e3744 6304{
d62a17ae 6305 int idx_peer = 2;
e48a9a90
CS
6306 char *peer_str = argv[idx_peer]->arg;
6307 char base_xpath[XPATH_MAXLEN];
6308 char af_xpath[XPATH_MAXLEN];
6309 char std_xpath[XPATH_MAXLEN];
6310 afi_t afi = bgp_node_afi(vty);
6311 safi_t safi = bgp_node_safi(vty);
27c05d4d 6312
e48a9a90
CS
6313 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6314 yang_afi_safi_value2identity(afi, safi));
6315
6316 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6317 sizeof(base_xpath), af_xpath)
6318 < 0)
6319 return CMD_WARNING_CONFIG_FAILED;
6320
6321 snprintf(std_xpath, sizeof(std_xpath),
6322 "./%s/send-community/send-community",
6323 bgp_afi_safi_get_container_str(afi, safi));
6324
6325 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6326
6327 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6328}
6b0655a2 6329
d62a17ae 6330ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
6331 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6332 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6333 "Send Community attribute to this neighbor\n")
596c17ba 6334
718e3744 6335/* neighbor send-community extended. */
f4b8ec07
CS
6336DEFUN_YANG (neighbor_send_community_type,
6337 neighbor_send_community_type_cmd,
6338 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6339 NEIGHBOR_STR
6340 NEIGHBOR_ADDR_STR2
6341 "Send Community attribute to this neighbor\n"
6342 "Send Standard and Extended Community attributes\n"
6343 "Send Standard, Large and Extended Community attributes\n"
6344 "Send Extended Community attributes\n"
6345 "Send Standard Community attributes\n"
6346 "Send Large Community attributes\n")
718e3744 6347{
27c05d4d 6348 const char *type = argv[argc - 1]->text;
db45f64d 6349 char *peer_str = argv[1]->arg;
f4b8ec07
CS
6350 char base_xpath[XPATH_MAXLEN];
6351 char af_xpath[XPATH_MAXLEN];
6352 char std_xpath[XPATH_MAXLEN];
6353 char ext_xpath[XPATH_MAXLEN];
6354 char lrg_xpath[XPATH_MAXLEN];
db45f64d
DS
6355 afi_t afi = bgp_node_afi(vty);
6356 safi_t safi = bgp_node_safi(vty);
d62a17ae 6357
f4b8ec07
CS
6358 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6359 yang_afi_safi_value2identity(afi, safi));
6360
6361 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6362 sizeof(base_xpath), af_xpath)
6363 < 0)
db45f64d 6364 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6365
f4b8ec07
CS
6366 if (strmatch(type, "standard")) {
6367 snprintf(std_xpath, sizeof(std_xpath),
6368 "./%s/send-community/send-community",
6369 bgp_afi_safi_get_container_str(afi, safi));
db45f64d 6370
f4b8ec07
CS
6371 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6372 }
db45f64d 6373
f4b8ec07
CS
6374 if (strmatch(type, "extended")) {
6375 snprintf(ext_xpath, sizeof(ext_xpath),
6376 "./%s/send-community/send-ext-community",
6377 bgp_afi_safi_get_container_str(afi, safi));
6378
6379 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
6380 }
6381
6382 if (strmatch(type, "large")) {
6383 snprintf(lrg_xpath, sizeof(lrg_xpath),
6384 "./%s/send-community/send-large-community",
6385 bgp_afi_safi_get_container_str(afi, safi));
6386
6387 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "true");
6388 }
db45f64d
DS
6389
6390 if (strmatch(type, "both")) {
f4b8ec07
CS
6391 snprintf(std_xpath, sizeof(std_xpath),
6392 "./%s/send-community/send-community",
6393 bgp_afi_safi_get_container_str(afi, safi));
6394
6395 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6396
6397 snprintf(ext_xpath, sizeof(ext_xpath),
6398 "./%s/send-community/send-ext-community",
6399 bgp_afi_safi_get_container_str(afi, safi));
6400
6401 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
db45f64d 6402 }
f4b8ec07
CS
6403
6404 if (strmatch(type, "all")) {
6405 snprintf(std_xpath, sizeof(std_xpath),
6406 "./%s/send-community/send-community",
6407 bgp_afi_safi_get_container_str(afi, safi));
6408
6409 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6410
6411 snprintf(ext_xpath, sizeof(ext_xpath),
6412 "./%s/send-community/send-ext-community",
6413 bgp_afi_safi_get_container_str(afi, safi));
6414
6415 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
6416
6417 snprintf(lrg_xpath, sizeof(lrg_xpath),
6418 "./%s/send-community/send-large-community",
6419 bgp_afi_safi_get_container_str(afi, safi));
6420
6421 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "true");
6422 }
6423
6424 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 6425}
6426
6427ALIAS_HIDDEN(
6428 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
6429 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6430 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6431 "Send Community attribute to this neighbor\n"
6432 "Send Standard and Extended Community attributes\n"
6433 "Send Standard, Large and Extended Community attributes\n"
6434 "Send Extended Community attributes\n"
6435 "Send Standard Community attributes\n"
6436 "Send Large Community attributes\n")
596c17ba 6437
f4b8ec07
CS
6438DEFUN_YANG (no_neighbor_send_community_type,
6439 no_neighbor_send_community_type_cmd,
6440 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6441 NO_STR
6442 NEIGHBOR_STR
6443 NEIGHBOR_ADDR_STR2
6444 "Send Community attribute to this neighbor\n"
6445 "Send Standard and Extended Community attributes\n"
6446 "Send Standard, Large and Extended Community attributes\n"
6447 "Send Extended Community attributes\n"
6448 "Send Standard Community attributes\n"
6449 "Send Large Community attributes\n")
718e3744 6450{
d62a17ae 6451 const char *type = argv[argc - 1]->text;
db45f64d 6452 char *peer_str = argv[2]->arg;
f4b8ec07
CS
6453 char base_xpath[XPATH_MAXLEN];
6454 char af_xpath[XPATH_MAXLEN];
6455 char std_xpath[XPATH_MAXLEN];
6456 char ext_xpath[XPATH_MAXLEN];
6457 char lrg_xpath[XPATH_MAXLEN];
db45f64d
DS
6458 afi_t afi = bgp_node_afi(vty);
6459 safi_t safi = bgp_node_safi(vty);
6460
f4b8ec07
CS
6461 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6462 yang_afi_safi_value2identity(afi, safi));
6463
6464 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6465 sizeof(base_xpath), af_xpath)
6466 < 0)
6467 return CMD_WARNING_CONFIG_FAILED;
6468
6469 if (strmatch(type, "standard")) {
6470 snprintf(std_xpath, sizeof(std_xpath),
6471 "./%s/send-community/send-community",
6472 bgp_afi_safi_get_container_str(afi, safi));
6473
6474 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6475 }
6476
6477 if (strmatch(type, "extended")) {
6478 snprintf(ext_xpath, sizeof(ext_xpath),
6479 "./%s/send-community/send-ext-community",
6480 bgp_afi_safi_get_container_str(afi, safi));
6481
6482 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
6483 }
6484
6485 if (strmatch(type, "large")) {
6486 snprintf(lrg_xpath, sizeof(lrg_xpath),
6487 "./%s/send-community/send-large-community",
6488 bgp_afi_safi_get_container_str(afi, safi));
6489
6490 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "false");
6491 }
6492
6493 if (strmatch(type, "both")) {
6494 snprintf(std_xpath, sizeof(std_xpath),
6495 "./%s/send-community/send-community",
6496 bgp_afi_safi_get_container_str(afi, safi));
6497
6498 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6499
6500 snprintf(ext_xpath, sizeof(ext_xpath),
6501 "./%s/send-community/send-ext-community",
6502 bgp_afi_safi_get_container_str(afi, safi));
6503
6504 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
6505 }
6506
6507 if (strmatch(type, "all")) {
6508 snprintf(std_xpath, sizeof(std_xpath),
6509 "./%s/send-community/send-community",
6510 bgp_afi_safi_get_container_str(afi, safi));
db45f64d 6511
f4b8ec07 6512 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
db45f64d 6513
f4b8ec07
CS
6514 snprintf(ext_xpath, sizeof(ext_xpath),
6515 "./%s/send-community/send-ext-community",
6516 bgp_afi_safi_get_container_str(afi, safi));
db45f64d 6517
f4b8ec07 6518 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
db45f64d 6519
f4b8ec07
CS
6520 snprintf(lrg_xpath, sizeof(lrg_xpath),
6521 "./%s/send-community/send-large-community",
6522 bgp_afi_safi_get_container_str(afi, safi));
d62a17ae 6523
f4b8ec07 6524 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "false");
27c05d4d
PM
6525 }
6526
f4b8ec07 6527 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 6528}
6529
6530ALIAS_HIDDEN(
6531 no_neighbor_send_community_type,
6532 no_neighbor_send_community_type_hidden_cmd,
6533 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6534 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6535 "Send Community attribute to this neighbor\n"
6536 "Send Standard and Extended Community attributes\n"
6537 "Send Standard, Large and Extended Community attributes\n"
6538 "Send Extended Community attributes\n"
6539 "Send Standard Community attributes\n"
6540 "Send Large Community attributes\n")
596c17ba 6541
718e3744 6542/* neighbor soft-reconfig. */
f4b8ec07
CS
6543DEFUN_YANG (neighbor_soft_reconfiguration,
6544 neighbor_soft_reconfiguration_cmd,
6545 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6546 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6547 "Per neighbor soft reconfiguration\n"
6548 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 6549{
d62a17ae 6550 int idx_peer = 1;
f4b8ec07
CS
6551 char base_xpath[XPATH_MAXLEN];
6552 char af_xpath[XPATH_MAXLEN];
6553 char soft_xpath[XPATH_MAXLEN];
6554 afi_t afi = bgp_node_afi(vty);
6555 safi_t safi = bgp_node_safi(vty);
6556
f4b8ec07
CS
6557 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6558 yang_afi_safi_value2identity(afi, safi));
6559
6560 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6561 sizeof(base_xpath), af_xpath)
6562 < 0)
6563 return CMD_WARNING_CONFIG_FAILED;
6564
6565 snprintf(soft_xpath, sizeof(soft_xpath), "./%s/soft-reconfiguration",
6566 bgp_afi_safi_get_container_str(afi, safi));
6567
6568 nb_cli_enqueue_change(vty, soft_xpath, NB_OP_MODIFY, "true");
6569
6570 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6571}
6572
d62a17ae 6573ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6574 neighbor_soft_reconfiguration_hidden_cmd,
6575 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6576 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6577 "Per neighbor soft reconfiguration\n"
6578 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 6579
f4b8ec07
CS
6580DEFUN_YANG (no_neighbor_soft_reconfiguration,
6581 no_neighbor_soft_reconfiguration_cmd,
6582 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6583 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6584 "Per neighbor soft reconfiguration\n"
6585 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 6586{
d62a17ae 6587 int idx_peer = 2;
f4b8ec07
CS
6588 char base_xpath[XPATH_MAXLEN];
6589 char af_xpath[XPATH_MAXLEN];
6590 char soft_xpath[XPATH_MAXLEN];
6591 afi_t afi = bgp_node_afi(vty);
6592 safi_t safi = bgp_node_safi(vty);
6593
6594 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6595 yang_afi_safi_value2identity(afi, safi));
6596
6597 snprintf(soft_xpath, sizeof(soft_xpath), "./%s/soft-reconfiguration",
6598 bgp_afi_safi_get_container_str(afi, safi));
6599
6600 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6601 sizeof(base_xpath), af_xpath)
6602 < 0)
6603 return CMD_WARNING_CONFIG_FAILED;
6604
6605 nb_cli_enqueue_change(vty, soft_xpath, NB_OP_MODIFY, "false");
6606
6607 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6608}
6b0655a2 6609
d62a17ae 6610ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6611 no_neighbor_soft_reconfiguration_hidden_cmd,
6612 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6613 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6614 "Per neighbor soft reconfiguration\n"
6615 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 6616
f4b8ec07
CS
6617DEFUN_YANG (neighbor_route_reflector_client,
6618 neighbor_route_reflector_client_cmd,
6619 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6620 NEIGHBOR_STR
6621 NEIGHBOR_ADDR_STR2
6622 "Configure a neighbor as Route Reflector client\n")
718e3744 6623{
d62a17ae 6624 int idx_peer = 1;
f4b8ec07
CS
6625 char base_xpath[XPATH_MAXLEN];
6626 char af_xpath[XPATH_MAXLEN];
6627 char attr_xpath[XPATH_MAXLEN];
6628 afi_t afi = bgp_node_afi(vty);
6629 safi_t safi = bgp_node_safi(vty);
718e3744 6630
f4b8ec07
CS
6631 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6632 yang_afi_safi_value2identity(afi, safi));
718e3744 6633
f4b8ec07
CS
6634 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6635 sizeof(base_xpath), af_xpath)
6636 < 0)
d62a17ae 6637 return CMD_WARNING_CONFIG_FAILED;
718e3744 6638
f4b8ec07
CS
6639 snprintf(attr_xpath, sizeof(attr_xpath),
6640 "./%s/route-reflector/route-reflector-client",
6641 bgp_afi_safi_get_container_str(afi, safi));
6642
6643 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
6644
6645 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6646}
6647
d62a17ae 6648ALIAS_HIDDEN(neighbor_route_reflector_client,
6649 neighbor_route_reflector_client_hidden_cmd,
6650 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6651 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6652 "Configure a neighbor as Route Reflector client\n")
596c17ba 6653
f4b8ec07
CS
6654DEFUN_YANG (no_neighbor_route_reflector_client,
6655 no_neighbor_route_reflector_client_cmd,
6656 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6657 NO_STR
6658 NEIGHBOR_STR
6659 NEIGHBOR_ADDR_STR2
6660 "Configure a neighbor as Route Reflector client\n")
718e3744 6661{
d62a17ae 6662 int idx_peer = 2;
f4b8ec07
CS
6663 char base_xpath[XPATH_MAXLEN];
6664 char af_xpath[XPATH_MAXLEN];
6665 char attr_xpath[XPATH_MAXLEN];
6666 afi_t afi = bgp_node_afi(vty);
6667 safi_t safi = bgp_node_safi(vty);
6668
6669 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6670 yang_afi_safi_value2identity(afi, safi));
6671
6672 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6673 sizeof(base_xpath), af_xpath)
6674 < 0)
6675 return CMD_WARNING_CONFIG_FAILED;
6676
6677 snprintf(attr_xpath, sizeof(attr_xpath),
6678 "./%s/route-reflector/route-reflector-client",
6679 bgp_afi_safi_get_container_str(afi, safi));
6680
6681 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6682
6683 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6684}
6b0655a2 6685
d62a17ae 6686ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6687 no_neighbor_route_reflector_client_hidden_cmd,
6688 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6689 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6690 "Configure a neighbor as Route Reflector client\n")
596c17ba 6691
718e3744 6692/* neighbor route-server-client. */
f4b8ec07
CS
6693DEFUN_YANG (neighbor_route_server_client,
6694 neighbor_route_server_client_cmd,
6695 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6696 NEIGHBOR_STR
6697 NEIGHBOR_ADDR_STR2
6698 "Configure a neighbor as Route Server client\n")
718e3744 6699{
d62a17ae 6700 int idx_peer = 1;
f4b8ec07
CS
6701 char base_xpath[XPATH_MAXLEN];
6702 char af_xpath[XPATH_MAXLEN];
6703 char attr_xpath[XPATH_MAXLEN];
6704 afi_t afi = bgp_node_afi(vty);
6705 safi_t safi = bgp_node_safi(vty);
2a3d5731 6706
f4b8ec07
CS
6707 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6708 yang_afi_safi_value2identity(afi, safi));
6709
6710 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6711 sizeof(base_xpath), af_xpath)
6712 < 0)
d62a17ae 6713 return CMD_WARNING_CONFIG_FAILED;
f4b8ec07
CS
6714
6715 snprintf(attr_xpath, sizeof(attr_xpath),
6716 "./%s/route-server/route-server-client",
6717 bgp_afi_safi_get_container_str(afi, safi));
6718
6719 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
6720
6721 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6722}
6723
d62a17ae 6724ALIAS_HIDDEN(neighbor_route_server_client,
6725 neighbor_route_server_client_hidden_cmd,
6726 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6727 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6728 "Configure a neighbor as Route Server client\n")
596c17ba 6729
f4b8ec07
CS
6730DEFUN_YANG (no_neighbor_route_server_client,
6731 no_neighbor_route_server_client_cmd,
6732 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6733 NO_STR
6734 NEIGHBOR_STR
6735 NEIGHBOR_ADDR_STR2
6736 "Configure a neighbor as Route Server client\n")
fee0f4c6 6737{
d62a17ae 6738 int idx_peer = 2;
f4b8ec07
CS
6739 char base_xpath[XPATH_MAXLEN];
6740 char af_xpath[XPATH_MAXLEN];
6741 char attr_xpath[XPATH_MAXLEN];
6742 afi_t afi = bgp_node_afi(vty);
6743 safi_t safi = bgp_node_safi(vty);
6744
6745 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6746 yang_afi_safi_value2identity(afi, safi));
6747
6748 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6749 sizeof(base_xpath), af_xpath)
6750 < 0)
6751 return CMD_WARNING_CONFIG_FAILED;
6752
6753 snprintf(attr_xpath, sizeof(attr_xpath),
6754 "./%s/route-server/route-server-client",
6755 bgp_afi_safi_get_container_str(afi, safi));
6756
6757 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6758
6759 return nb_cli_apply_changes(vty, base_xpath);
fee0f4c6 6760}
6b0655a2 6761
d62a17ae 6762ALIAS_HIDDEN(no_neighbor_route_server_client,
6763 no_neighbor_route_server_client_hidden_cmd,
6764 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6765 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6766 "Configure a neighbor as Route Server client\n")
596c17ba 6767
fee0f4c6 6768DEFUN (neighbor_nexthop_local_unchanged,
6769 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 6770 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 6771 NEIGHBOR_STR
6772 NEIGHBOR_ADDR_STR2
6773 "Configure treatment of outgoing link-local nexthop attribute\n"
6774 "Leave link-local nexthop unchanged for this peer\n")
6775{
d62a17ae 6776 int idx_peer = 1;
6777 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6778 bgp_node_safi(vty),
6779 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 6780}
6b0655a2 6781
fee0f4c6 6782DEFUN (no_neighbor_nexthop_local_unchanged,
6783 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 6784 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 6785 NO_STR
6786 NEIGHBOR_STR
6787 NEIGHBOR_ADDR_STR2
6788 "Configure treatment of outgoing link-local-nexthop attribute\n"
6789 "Leave link-local nexthop unchanged for this peer\n")
718e3744 6790{
d62a17ae 6791 int idx_peer = 2;
6792 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6793 bgp_node_afi(vty), bgp_node_safi(vty),
6794 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 6795}
6b0655a2 6796
f4b8ec07
CS
6797DEFUN_YANG (neighbor_attr_unchanged,
6798 neighbor_attr_unchanged_cmd,
6799 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6800 NEIGHBOR_STR
6801 NEIGHBOR_ADDR_STR2
6802 "BGP attribute is propagated unchanged to this neighbor\n"
6803 "As-path attribute\n"
6804 "Nexthop attribute\n"
6805 "Med attribute\n")
718e3744 6806{
d62a17ae 6807 int idx = 0;
8eeb0335 6808 char *peer_str = argv[1]->arg;
db45f64d
DS
6809 bool aspath = false;
6810 bool nexthop = false;
6811 bool med = false;
8eeb0335
DW
6812 afi_t afi = bgp_node_afi(vty);
6813 safi_t safi = bgp_node_safi(vty);
f4b8ec07
CS
6814 char base_xpath[XPATH_MAXLEN];
6815 char af_xpath[XPATH_MAXLEN];
6816 char as_xpath[XPATH_MAXLEN];
6817 char nxthop_xpath[XPATH_MAXLEN];
6818 char med_xpath[XPATH_MAXLEN];
8eeb0335 6819
f4b8ec07
CS
6820 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6821 yang_afi_safi_value2identity(afi, safi));
6822
6823 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6824 sizeof(base_xpath), af_xpath)
6825 < 0)
8eeb0335 6826 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6827
6828 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
6829 aspath = true;
6830
d62a17ae 6831 idx = 0;
6832 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6833 nexthop = true;
6834
d62a17ae 6835 idx = 0;
6836 if (argv_find(argv, argc, "med", &idx))
db45f64d 6837 med = true;
d62a17ae 6838
f4b8ec07
CS
6839 snprintf(as_xpath, sizeof(as_xpath),
6840 "./%s/attr-unchanged/as-path-unchanged",
6841 bgp_afi_safi_get_container_str(afi, safi));
6842 snprintf(nxthop_xpath, sizeof(nxthop_xpath),
6843 "./%s/attr-unchanged/next-hop-unchanged",
6844 bgp_afi_safi_get_container_str(afi, safi));
6845 snprintf(med_xpath, sizeof(med_xpath),
6846 "./%s/attr-unchanged/med-unchanged",
6847 bgp_afi_safi_get_container_str(afi, safi));
6848
8eeb0335 6849 /* no flags means all of them! */
db45f64d 6850 if (!aspath && !nexthop && !med) {
f4b8ec07
CS
6851 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "true");
6852 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "true");
6853 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "true");
8eeb0335 6854 } else {
f4b8ec07
CS
6855 if (!aspath)
6856 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY,
6857 "false");
6858 else
6859 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY,
6860 "true");
6861
6862 if (!nexthop)
6863 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY,
6864 "false");
6865 else
6866 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY,
6867 "true");
6868
6869 if (!med)
6870 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY,
6871 "false");
6872 else
6873 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY,
6874 "true");
d62a17ae 6875 }
6876
f4b8ec07 6877 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 6878}
6879
6880ALIAS_HIDDEN(
6881 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6882 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6883 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6884 "BGP attribute is propagated unchanged to this neighbor\n"
6885 "As-path attribute\n"
6886 "Nexthop attribute\n"
6887 "Med attribute\n")
596c17ba 6888
f4b8ec07
CS
6889DEFUN_YANG (no_neighbor_attr_unchanged,
6890 no_neighbor_attr_unchanged_cmd,
6891 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6892 NO_STR
6893 NEIGHBOR_STR
6894 NEIGHBOR_ADDR_STR2
6895 "BGP attribute is propagated unchanged to this neighbor\n"
6896 "As-path attribute\n"
6897 "Nexthop attribute\n"
6898 "Med attribute\n")
718e3744 6899{
d62a17ae 6900 int idx = 0;
db45f64d 6901 char *peer_str = argv[2]->arg;
db45f64d
DS
6902 bool aspath = false;
6903 bool nexthop = false;
6904 bool med = false;
6905 afi_t afi = bgp_node_afi(vty);
6906 safi_t safi = bgp_node_safi(vty);
f4b8ec07
CS
6907 char base_xpath[XPATH_MAXLEN];
6908 char af_xpath[XPATH_MAXLEN];
6909 char as_xpath[XPATH_MAXLEN];
6910 char nxthop_xpath[XPATH_MAXLEN];
6911 char med_xpath[XPATH_MAXLEN];
db45f64d 6912
f4b8ec07
CS
6913 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6914 yang_afi_safi_value2identity(afi, safi));
6915
6916 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6917 sizeof(base_xpath), af_xpath)
6918 < 0)
db45f64d 6919 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6920
6921 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
6922 aspath = true;
6923
d62a17ae 6924 idx = 0;
6925 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6926 nexthop = true;
6927
d62a17ae 6928 idx = 0;
6929 if (argv_find(argv, argc, "med", &idx))
db45f64d 6930 med = true;
d62a17ae 6931
f4b8ec07
CS
6932 snprintf(as_xpath, sizeof(as_xpath),
6933 "./%s/attr-unchanged/as-path-unchanged",
6934 bgp_afi_safi_get_container_str(afi, safi));
6935 snprintf(nxthop_xpath, sizeof(nxthop_xpath),
6936 "./%s/attr-unchanged/next-hop-unchanged",
6937 bgp_afi_safi_get_container_str(afi, safi));
6938 snprintf(med_xpath, sizeof(med_xpath),
6939 "./%s/attr-unchanged/med-unchanged",
6940 bgp_afi_safi_get_container_str(afi, safi));
6941
6942 /* no flags means all of them! */
6943 if (!aspath && !nexthop && !med) {
6944 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "false");
6945 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "false");
6946 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "false");
6947 }
db45f64d
DS
6948
6949 if (aspath)
f4b8ec07 6950 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "false");
db45f64d
DS
6951
6952 if (nexthop)
f4b8ec07 6953 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "false");
d62a17ae 6954
db45f64d 6955 if (med)
f4b8ec07 6956 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "false");
db45f64d 6957
f4b8ec07 6958 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 6959}
6960
6961ALIAS_HIDDEN(
6962 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6963 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6964 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6965 "BGP attribute is propagated unchanged to this neighbor\n"
6966 "As-path attribute\n"
6967 "Nexthop attribute\n"
6968 "Med attribute\n")
718e3744 6969
f4b8ec07
CS
6970/* neighbor ebgp-multihop. */
6971DEFUN_YANG (neighbor_ebgp_multihop,
6972 neighbor_ebgp_multihop_cmd,
6973 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6974 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6975 "Allow EBGP neighbors not on directly connected networks\n")
718e3744 6976{
f4b8ec07
CS
6977 int idx_peer = 1;
6978 char base_xpath[XPATH_MAXLEN];
718e3744 6979
f4b8ec07
CS
6980 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6981 sizeof(base_xpath), NULL)
6982 < 0)
d62a17ae 6983 return CMD_WARNING_CONFIG_FAILED;
718e3744 6984
f4b8ec07
CS
6985 nb_cli_enqueue_change(vty, "./ebgp-multihop/enabled", NB_OP_MODIFY,
6986 "true");
718e3744 6987
f4b8ec07 6988 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6989}
6990
f4b8ec07
CS
6991DEFUN_YANG (neighbor_ebgp_multihop_ttl,
6992 neighbor_ebgp_multihop_ttl_cmd,
6993 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6994 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6995 "Allow EBGP neighbors not on directly connected networks\n"
6996 "maximum hop count\n")
718e3744 6997{
f4b8ec07
CS
6998 int idx_peer = 1;
6999 int idx_number = 3;
7000 char base_xpath[XPATH_MAXLEN];
718e3744 7001
f4b8ec07
CS
7002 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7003 sizeof(base_xpath), NULL)
7004 < 0)
d62a17ae 7005 return CMD_WARNING_CONFIG_FAILED;
718e3744 7006
f4b8ec07
CS
7007 nb_cli_enqueue_change(vty, "./ebgp-multihop/multihop-ttl", NB_OP_MODIFY,
7008 argv[idx_number]->arg);
718e3744 7009
f4b8ec07 7010 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7011}
7012
f4b8ec07
CS
7013DEFUN_YANG (no_neighbor_ebgp_multihop,
7014 no_neighbor_ebgp_multihop_cmd,
7015 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
7016 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7017 "Allow EBGP neighbors not on directly connected networks\n"
7018 "maximum hop count\n")
718e3744 7019{
d62a17ae 7020 int idx_peer = 2;
f4b8ec07
CS
7021 char base_xpath[XPATH_MAXLEN];
7022
7023 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7024 sizeof(base_xpath), NULL)
7025 < 0)
7026 return CMD_WARNING_CONFIG_FAILED;
7027
7028 if (argc > 4)
7029 nb_cli_enqueue_change(vty, "./ebgp-multihop/multihop-ttl",
7030 NB_OP_DESTROY, NULL);
7031 else
7032 nb_cli_enqueue_change(vty, "./ebgp-multihop/enabled",
7033 NB_OP_MODIFY, "false");
7034
7035 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7036}
7037
6b0655a2 7038
6ffd2079 7039/* disable-connected-check */
f4b8ec07
CS
7040DEFUN_YANG (neighbor_disable_connected_check,
7041 neighbor_disable_connected_check_cmd,
7042 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
7043 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7044 "one-hop away EBGP peer using loopback address\n"
7045 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 7046{
d62a17ae 7047 int idx_peer = 1;
f4b8ec07
CS
7048 char base_xpath[XPATH_MAXLEN];
7049
7050 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7051 sizeof(base_xpath), NULL)
7052 < 0)
7053 return CMD_WARNING_CONFIG_FAILED;
7054
7055 nb_cli_enqueue_change(vty, "./ebgp-multihop/disable-connected-check",
7056 NB_OP_MODIFY, "true");
7057
7058 return nb_cli_apply_changes(vty, base_xpath);
6ffd2079 7059}
7060
f4b8ec07
CS
7061DEFUN_YANG (no_neighbor_disable_connected_check,
7062 no_neighbor_disable_connected_check_cmd,
7063 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
7064 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7065 "one-hop away EBGP peer using loopback address\n"
7066 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 7067{
d62a17ae 7068 int idx_peer = 2;
f4b8ec07
CS
7069 char base_xpath[XPATH_MAXLEN];
7070
7071 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7072 sizeof(base_xpath), NULL)
7073 < 0)
7074 return CMD_WARNING_CONFIG_FAILED;
7075
7076 nb_cli_enqueue_change(vty, "./ebgp-multihop/disable-connected-check",
7077 NB_OP_MODIFY, "false");
7078
7079 return nb_cli_apply_changes(vty, base_xpath);
6ffd2079 7080}
7081
47cbc09b
PM
7082
7083/* enforce-first-as */
f4b8ec07
CS
7084DEFUN_YANG (neighbor_enforce_first_as,
7085 neighbor_enforce_first_as_cmd,
7086 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
7087 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7088 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
7089{
7090 int idx_peer = 1;
f4b8ec07 7091 char base_xpath[XPATH_MAXLEN];
47cbc09b 7092
f4b8ec07
CS
7093 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7094 sizeof(base_xpath), NULL)
7095 < 0)
7096 return CMD_WARNING_CONFIG_FAILED;
7097
7098 nb_cli_enqueue_change(vty, "./enforce-first-as", NB_OP_MODIFY, "true");
7099
7100 return nb_cli_apply_changes(vty, base_xpath);
47cbc09b
PM
7101}
7102
f4b8ec07
CS
7103DEFUN_YANG (no_neighbor_enforce_first_as,
7104 no_neighbor_enforce_first_as_cmd,
7105 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
7106 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7107 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
7108{
7109 int idx_peer = 2;
f4b8ec07 7110 char base_xpath[XPATH_MAXLEN];
47cbc09b 7111
f4b8ec07
CS
7112 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7113 sizeof(base_xpath), NULL)
7114 < 0)
7115 return CMD_WARNING_CONFIG_FAILED;
7116
7117 nb_cli_enqueue_change(vty, "./enforce-first-as", NB_OP_MODIFY, "false");
7118
7119 return nb_cli_apply_changes(vty, base_xpath);
47cbc09b
PM
7120}
7121
f4b8ec07
CS
7122static int peer_and_group_lookup_nb(struct vty *vty, const char *peer_str,
7123 char *base_xpath, int xpath_len,
7124 char *xpath)
7125{
7126 union sockunion su;
7127 char num_xpath[XPATH_MAXLEN];
7128 char unnbr_xpath[XPATH_MAXLEN];
7129 char prgrp_xpath[XPATH_MAXLEN];
7130
7131 if (str2sockunion(peer_str, &su) == 0) {
7132 snprintf(num_xpath, sizeof(num_xpath),
7133 "/neighbors/neighbor[remote-address='%s']", peer_str);
3bb513c3
CH
7134 if (yang_dnode_existsf(vty->candidate_config->dnode, "%s%s",
7135 VTY_CURR_XPATH, num_xpath)) {
f4b8ec07
CS
7136 snprintf(base_xpath, xpath_len,
7137 FRR_BGP_NEIGHBOR_NUM_XPATH, peer_str,
7138 xpath ? xpath : "");
7139 } else {
7140 vty_out(vty,
7141 "%% Specify remote-as or peer-group commands first\n");
7142 return -1;
7143 }
7144
7145 } else {
7146 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
7147 "/neighbors/unnumbered-neighbor[interface='%s']",
7148 peer_str);
7149
7150 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
7151 "/peer-groups/peer-group[peer-group-name='%s']",
7152 peer_str);
7153
3bb513c3
CH
7154 if (yang_dnode_existsf(vty->candidate_config->dnode, "%s%s",
7155 VTY_CURR_XPATH, unnbr_xpath)) {
f4b8ec07
CS
7156 snprintf(base_xpath, xpath_len,
7157 FRR_BGP_NEIGHBOR_UNNUM_XPATH, peer_str,
7158 xpath ? xpath : "");
3bb513c3
CH
7159 } else if (yang_dnode_existsf(vty->candidate_config->dnode,
7160 "%s%s", VTY_CURR_XPATH,
7161 prgrp_xpath)) {
f4b8ec07
CS
7162 snprintf(base_xpath, xpath_len,
7163 FRR_BGP_PEER_GROUP_XPATH, peer_str,
7164 xpath ? xpath : "");
7165 } else {
7166 vty_out(vty,
7167 "%% Create the peer-group or interface first\n");
7168 return -1;
7169 }
7170 }
7171
7172 return 0;
7173}
47cbc09b 7174
f4b8ec07
CS
7175DEFUN_YANG (neighbor_description,
7176 neighbor_description_cmd,
7177 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
7178 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7179 "Neighbor specific description\n"
7180 "Up to 80 characters describing this neighbor\n")
718e3744 7181{
d62a17ae 7182 int idx_peer = 1;
7183 int idx_line = 3;
f4b8ec07
CS
7184 int ret;
7185 char base_xpath[XPATH_MAXLEN];
d62a17ae 7186 char *str;
718e3744 7187
f4b8ec07
CS
7188 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7189 sizeof(base_xpath), NULL)
7190 < 0)
d62a17ae 7191 return CMD_WARNING_CONFIG_FAILED;
718e3744 7192
d62a17ae 7193 str = argv_concat(argv, argc, idx_line);
718e3744 7194
f4b8ec07
CS
7195 nb_cli_enqueue_change(vty, "./description", NB_OP_MODIFY, str);
7196
7197 ret = nb_cli_apply_changes(vty, base_xpath);
718e3744 7198
d62a17ae 7199 XFREE(MTYPE_TMP, str);
718e3744 7200
f4b8ec07 7201 return ret;
718e3744 7202}
7203
f4b8ec07
CS
7204DEFUN_YANG (no_neighbor_description,
7205 no_neighbor_description_cmd,
7206 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
7207 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7208 "Neighbor specific description\n")
718e3744 7209{
d62a17ae 7210 int idx_peer = 2;
f4b8ec07
CS
7211 char base_xpath[XPATH_MAXLEN];
7212
7213 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7214 sizeof(base_xpath), NULL)
7215 < 0)
d62a17ae 7216 return CMD_WARNING_CONFIG_FAILED;
718e3744 7217
f4b8ec07 7218 nb_cli_enqueue_change(vty, "./description", NB_OP_DESTROY, NULL);
718e3744 7219
f4b8ec07 7220 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7221}
7222
232c75cd 7223ALIAS_YANG(no_neighbor_description, no_neighbor_description_comment_cmd,
a14810f4
PM
7224 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
7225 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7226 "Neighbor specific description\n"
7227 "Up to 80 characters describing this neighbor\n")
6b0655a2 7228
d62a17ae 7229#define BGP_UPDATE_SOURCE_HELP_STR \
7230 "IPv4 address\n" \
7231 "IPv6 address\n" \
7232 "Interface name (requires zebra to be running)\n"
369688c0 7233
f4b8ec07
CS
7234DEFUN_YANG (neighbor_update_source,
7235 neighbor_update_source_cmd,
7236 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
7237 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7238 "Source of routing updates\n"
7239 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 7240{
d62a17ae 7241 int idx_peer = 1;
7242 int idx_peer_2 = 3;
f4b8ec07
CS
7243 union sockunion su;
7244 char base_xpath[XPATH_MAXLEN];
7245
7246 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7247 sizeof(base_xpath), NULL)
7248 < 0)
7249 return CMD_WARNING_CONFIG_FAILED;
7250
f4b8ec07
CS
7251 if (str2sockunion(argv[idx_peer_2]->arg, &su) == 0)
7252 nb_cli_enqueue_change(vty, "./update-source/ip", NB_OP_MODIFY,
d62a17ae 7253 argv[idx_peer_2]->arg);
f4b8ec07
CS
7254 else
7255 nb_cli_enqueue_change(vty, "./update-source/interface",
7256 NB_OP_MODIFY, argv[idx_peer_2]->arg);
7257
7258 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7259}
7260
f4b8ec07
CS
7261DEFUN_YANG (no_neighbor_update_source,
7262 no_neighbor_update_source_cmd,
7263 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
7264 NO_STR NEIGHBOR_STR
7265 NEIGHBOR_ADDR_STR2
7266 "Source of routing updates\n"
7267 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 7268{
d62a17ae 7269 int idx_peer = 2;
f4b8ec07 7270 char base_xpath[XPATH_MAXLEN];
f4b8ec07
CS
7271
7272 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7273 sizeof(base_xpath), NULL)
7274 < 0)
7275 return CMD_WARNING_CONFIG_FAILED;
7276
555c8ab7
CS
7277 nb_cli_enqueue_change(vty, "./update-source/ip", NB_OP_DESTROY, NULL);
7278 nb_cli_enqueue_change(vty, "./update-source/interface", NB_OP_DESTROY,
7279 NULL);
f4b8ec07
CS
7280
7281 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7282}
6b0655a2 7283
d62a17ae 7284static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
7285 afi_t afi, safi_t safi,
7286 const char *rmap, int set)
718e3744 7287{
d62a17ae 7288 int ret;
7289 struct peer *peer;
80912664 7290 struct route_map *route_map = NULL;
718e3744 7291
d62a17ae 7292 peer = peer_and_group_lookup_vty(vty, peer_str);
7293 if (!peer)
7294 return CMD_WARNING_CONFIG_FAILED;
718e3744 7295
1de27621 7296 if (set) {
80912664
DS
7297 if (rmap)
7298 route_map = route_map_lookup_warn_noexist(vty, rmap);
1de27621
DA
7299 ret = peer_default_originate_set(peer, afi, safi,
7300 rmap, route_map);
7301 } else
d62a17ae 7302 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 7303
d62a17ae 7304 return bgp_vty_return(vty, ret);
718e3744 7305}
7306
7307/* neighbor default-originate. */
7308DEFUN (neighbor_default_originate,
7309 neighbor_default_originate_cmd,
9ccf14f7 7310 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 7311 NEIGHBOR_STR
7312 NEIGHBOR_ADDR_STR2
7313 "Originate default route to this neighbor\n")
7314{
d62a17ae 7315 int idx_peer = 1;
7316 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7317 bgp_node_afi(vty),
7318 bgp_node_safi(vty), NULL, 1);
718e3744 7319}
7320
d62a17ae 7321ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
7322 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
7323 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7324 "Originate default route to this neighbor\n")
596c17ba 7325
718e3744 7326DEFUN (neighbor_default_originate_rmap,
7327 neighbor_default_originate_rmap_cmd,
9ccf14f7 7328 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 7329 NEIGHBOR_STR
7330 NEIGHBOR_ADDR_STR2
7331 "Originate default route to this neighbor\n"
7332 "Route-map to specify criteria to originate default\n"
7333 "route-map name\n")
7334{
d62a17ae 7335 int idx_peer = 1;
7336 int idx_word = 4;
7337 return peer_default_originate_set_vty(
7338 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7339 argv[idx_word]->arg, 1);
718e3744 7340}
7341
d62a17ae 7342ALIAS_HIDDEN(
7343 neighbor_default_originate_rmap,
7344 neighbor_default_originate_rmap_hidden_cmd,
7345 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
7346 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7347 "Originate default route to this neighbor\n"
7348 "Route-map to specify criteria to originate default\n"
7349 "route-map name\n")
596c17ba 7350
718e3744 7351DEFUN (no_neighbor_default_originate,
7352 no_neighbor_default_originate_cmd,
a636c635 7353 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 7354 NO_STR
7355 NEIGHBOR_STR
7356 NEIGHBOR_ADDR_STR2
a636c635
DW
7357 "Originate default route to this neighbor\n"
7358 "Route-map to specify criteria to originate default\n"
7359 "route-map name\n")
718e3744 7360{
d62a17ae 7361 int idx_peer = 2;
7362 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7363 bgp_node_afi(vty),
7364 bgp_node_safi(vty), NULL, 0);
718e3744 7365}
7366
d62a17ae 7367ALIAS_HIDDEN(
7368 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
7369 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
7370 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7371 "Originate default route to this neighbor\n"
7372 "Route-map to specify criteria to originate default\n"
7373 "route-map name\n")
596c17ba 7374
6b0655a2 7375
f418446b 7376/* Set specified peer's BGP port. */
f4b8ec07
CS
7377DEFUN_YANG (neighbor_port,
7378 neighbor_port_cmd,
7379 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
7380 NEIGHBOR_STR
7381 NEIGHBOR_ADDR_STR
7382 "Neighbor's BGP port\n"
7383 "TCP port number\n")
718e3744 7384{
d62a17ae 7385 int idx_ip = 1;
7386 int idx_number = 3;
f4b8ec07 7387 char base_xpath[XPATH_MAXLEN];
718e3744 7388
f4b8ec07
CS
7389 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7390 argv[idx_ip]->arg, "");
718e3744 7391
f4b8ec07
CS
7392 nb_cli_enqueue_change(vty, "./local-port", NB_OP_MODIFY,
7393 argv[idx_number]->arg);
7394
7395 return nb_cli_apply_changes(vty, base_xpath);
7396}
6b0655a2 7397
f4b8ec07
CS
7398DEFUN_YANG (no_neighbor_port,
7399 no_neighbor_port_cmd,
7400 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
7401 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR
7402 "Neighbor's BGP port\n"
7403 "TCP port number\n")
718e3744 7404{
f4b8ec07
CS
7405 int idx_ip = 2;
7406 char base_xpath[XPATH_MAXLEN];
718e3744 7407
f4b8ec07
CS
7408 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7409 argv[idx_ip]->arg, "");
718e3744 7410
f4b8ec07 7411 nb_cli_enqueue_change(vty, "./local-port", NB_OP_DESTROY, NULL);
718e3744 7412
f4b8ec07 7413 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7414}
7415
f4b8ec07
CS
7416DEFUN_YANG (neighbor_weight,
7417 neighbor_weight_cmd,
7418 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7419 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7420 "Set default weight for routes from this neighbor\n"
7421 "default weight\n")
718e3744 7422{
f4b8ec07
CS
7423 int idx_peer = 1;
7424 int idx_number = 3;
7425 char base_xpath[XPATH_MAXLEN];
7426 char af_xpath[XPATH_MAXLEN];
7427 char attr_xpath[XPATH_MAXLEN];
7428 afi_t afi = bgp_node_afi(vty);
7429 safi_t safi = bgp_node_safi(vty);
718e3744 7430
f4b8ec07
CS
7431 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7432 yang_afi_safi_value2identity(afi, safi));
7433
7434 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7435 sizeof(base_xpath), af_xpath)
7436 < 0)
d62a17ae 7437 return CMD_WARNING_CONFIG_FAILED;
718e3744 7438
f4b8ec07
CS
7439 snprintf(attr_xpath, sizeof(attr_xpath), "./%s/weight/weight-attribute",
7440 bgp_afi_safi_get_container_str(afi, safi));
718e3744 7441
f4b8ec07
CS
7442 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY,
7443 argv[idx_number]->arg);
7444
7445 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7446}
7447
d62a17ae 7448ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
7449 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7450 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7451 "Set default weight for routes from this neighbor\n"
7452 "default weight\n")
596c17ba 7453
f4b8ec07
CS
7454DEFUN_YANG (no_neighbor_weight,
7455 no_neighbor_weight_cmd,
7456 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7457 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7458 "Set default weight for routes from this neighbor\n"
7459 "default weight\n")
718e3744 7460{
d62a17ae 7461 int idx_peer = 2;
f4b8ec07
CS
7462 char base_xpath[XPATH_MAXLEN];
7463 char af_xpath[XPATH_MAXLEN];
7464 char attr_xpath[XPATH_MAXLEN];
7465 afi_t afi = bgp_node_afi(vty);
7466 safi_t safi = bgp_node_safi(vty);
7467
7468 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7469 yang_afi_safi_value2identity(afi, safi));
7470
7471 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7472 sizeof(base_xpath), af_xpath)
7473 < 0)
7474 return CMD_WARNING_CONFIG_FAILED;
7475
7476 snprintf(attr_xpath, sizeof(attr_xpath), "./%s/weight/weight-attribute",
7477 bgp_afi_safi_get_container_str(afi, safi));
7478
7479 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_DESTROY, NULL);
7480
7481 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7482}
7483
d62a17ae 7484ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
7485 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7486 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7487 "Set default weight for routes from this neighbor\n"
7488 "default weight\n")
596c17ba 7489
6b0655a2 7490
718e3744 7491/* Override capability negotiation. */
8611c7f3
CS
7492DEFUN_YANG (neighbor_override_capability,
7493 neighbor_override_capability_cmd,
7494 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7495 NEIGHBOR_STR
7496 NEIGHBOR_ADDR_STR2
7497 "Override capability negotiation result\n")
718e3744 7498{
d62a17ae 7499 int idx_peer = 1;
8611c7f3
CS
7500 char base_xpath[XPATH_MAXLEN];
7501
7502 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7503 sizeof(base_xpath), NULL)
7504 < 0)
7505 return CMD_WARNING_CONFIG_FAILED;
7506
7507 nb_cli_enqueue_change(
7508 vty, "./capability-options/override-capability",
7509 NB_OP_MODIFY, "true");
7510
7511 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7512}
7513
8611c7f3
CS
7514DEFUN_YANG (no_neighbor_override_capability,
7515 no_neighbor_override_capability_cmd,
7516 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7517 NO_STR
7518 NEIGHBOR_STR
7519 NEIGHBOR_ADDR_STR2
7520 "Override capability negotiation result\n")
718e3744 7521{
d62a17ae 7522 int idx_peer = 2;
8611c7f3
CS
7523 char base_xpath[XPATH_MAXLEN];
7524
7525 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7526 sizeof(base_xpath), NULL)
7527 < 0)
7528 return CMD_WARNING_CONFIG_FAILED;
7529
7530 nb_cli_enqueue_change(
7531 vty, "./capability-options/override-capability",
7532 NB_OP_MODIFY, "false");
7533
7534 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7535}
6b0655a2 7536
8611c7f3
CS
7537DEFUN_YANG (neighbor_strict_capability,
7538 neighbor_strict_capability_cmd,
7539 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7540 NEIGHBOR_STR
7541 NEIGHBOR_ADDR_STR2
7542 "Strict capability negotiation match\n")
718e3744 7543{
9fb964de 7544 int idx_peer = 1;
8611c7f3 7545 char base_xpath[XPATH_MAXLEN];
9fb964de 7546
8611c7f3
CS
7547 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7548 sizeof(base_xpath), NULL)
7549 < 0)
7550 return CMD_WARNING_CONFIG_FAILED;
7551
7552 nb_cli_enqueue_change(
7553 vty, "./capability-options/strict-capability",
7554 NB_OP_MODIFY, "true");
7555
7556 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7557}
7558
8611c7f3
CS
7559DEFUN_YANG (no_neighbor_strict_capability,
7560 no_neighbor_strict_capability_cmd,
7561 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7562 NO_STR
7563 NEIGHBOR_STR
7564 NEIGHBOR_ADDR_STR2
7565 "Strict capability negotiation match\n")
718e3744 7566{
9fb964de 7567 int idx_peer = 2;
8611c7f3 7568 char base_xpath[XPATH_MAXLEN];
9fb964de 7569
8611c7f3
CS
7570 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7571 sizeof(base_xpath), NULL)
7572 < 0)
7573 return CMD_WARNING_CONFIG_FAILED;
7574
7575 nb_cli_enqueue_change(
7576 vty, "./capability-options/strict-capability",
7577 NB_OP_MODIFY, "false");
7578
7579 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7580}
6b0655a2 7581
f4b8ec07
CS
7582DEFUN_YANG (neighbor_timers,
7583 neighbor_timers_cmd,
7584 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
7585 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7586 "BGP per neighbor timers\n"
7587 "Keepalive interval\n"
7588 "Holdtime\n")
718e3744 7589{
f4b8ec07
CS
7590 int idx_peer = 1;
7591 int idx_number = 3;
7592 int idx_number_2 = 4;
7593 char base_xpath[XPATH_MAXLEN];
718e3744 7594
f4b8ec07
CS
7595 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7596 sizeof(base_xpath), NULL)
7597 < 0)
d62a17ae 7598 return CMD_WARNING_CONFIG_FAILED;
718e3744 7599
f4b8ec07
CS
7600 nb_cli_enqueue_change(vty, "./timers/keepalive", NB_OP_MODIFY,
7601 argv[idx_number]->arg);
718e3744 7602
f4b8ec07
CS
7603 nb_cli_enqueue_change(vty, "./timers/hold-time", NB_OP_MODIFY,
7604 argv[idx_number_2]->arg);
718e3744 7605
f4b8ec07 7606 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7607}
6b0655a2 7608
f4b8ec07
CS
7609DEFUN_YANG (no_neighbor_timers,
7610 no_neighbor_timers_cmd,
7611 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
7612 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7613 "BGP per neighbor timers\n"
7614 "Keepalive interval\n"
7615 "Holdtime\n")
718e3744 7616{
f4b8ec07
CS
7617 int idx_peer = 2;
7618 char base_xpath[XPATH_MAXLEN];
718e3744 7619
f4b8ec07
CS
7620 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7621 sizeof(base_xpath), NULL)
7622 < 0)
d62a17ae 7623 return CMD_WARNING_CONFIG_FAILED;
718e3744 7624
f4b8ec07 7625 nb_cli_enqueue_change(vty, "./timers/hold-time", NB_OP_DESTROY, NULL);
718e3744 7626
f4b8ec07 7627 nb_cli_enqueue_change(vty, "./timers/keepalive", NB_OP_DESTROY, NULL);
718e3744 7628
f4b8ec07 7629 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7630}
6b0655a2 7631
f4b8ec07
CS
7632DEFUN_YANG (neighbor_timers_connect,
7633 neighbor_timers_connect_cmd,
7634 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7635 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7636 "BGP per neighbor timers\n"
7637 "BGP connect timer\n"
7638 "Connect timer\n")
718e3744 7639{
f4b8ec07
CS
7640 int idx_peer = 1;
7641 int idx_number = 4;
7642 char base_xpath[XPATH_MAXLEN];
718e3744 7643
f4b8ec07
CS
7644 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7645 sizeof(base_xpath), NULL)
7646 < 0)
d62a17ae 7647 return CMD_WARNING_CONFIG_FAILED;
718e3744 7648
f4b8ec07
CS
7649 nb_cli_enqueue_change(vty, "./timers/connect-time", NB_OP_MODIFY,
7650 argv[idx_number]->arg);
718e3744 7651
f4b8ec07 7652 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7653}
7654
f4b8ec07
CS
7655DEFUN_YANG (no_neighbor_timers_connect,
7656 no_neighbor_timers_connect_cmd,
7657 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7658 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7659 "BGP per neighbor timers\n"
7660 "BGP connect timer\n"
7661 "Connect timer\n")
718e3744 7662{
f4b8ec07
CS
7663 int idx_peer = 2;
7664 char base_xpath[XPATH_MAXLEN];
718e3744 7665
f4b8ec07
CS
7666 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7667 sizeof(base_xpath), NULL)
7668 < 0)
d62a17ae 7669 return CMD_WARNING_CONFIG_FAILED;
718e3744 7670
f4b8ec07
CS
7671 nb_cli_enqueue_change(vty, "./timers/connect-time", NB_OP_DESTROY,
7672 NULL);
718e3744 7673
f4b8ec07 7674 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7675}
7676
d43114f3
DS
7677DEFPY (neighbor_timers_delayopen,
7678 neighbor_timers_delayopen_cmd,
7679 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
7680 NEIGHBOR_STR
7681 NEIGHBOR_ADDR_STR2
7682 "BGP per neighbor timers\n"
7683 "RFC 4271 DelayOpenTimer\n"
7684 "DelayOpenTime timer interval\n")
7685{
7686 struct peer *peer;
7687
7688 peer = peer_and_group_lookup_vty(vty, neighbor);
7689 if (!peer)
7690 return CMD_WARNING_CONFIG_FAILED;
7691
7692 if (!interval) {
7693 if (peer_timers_delayopen_unset(peer))
7694 return CMD_WARNING_CONFIG_FAILED;
7695 } else {
7696 if (peer_timers_delayopen_set(peer, interval))
7697 return CMD_WARNING_CONFIG_FAILED;
7698 }
7699
7700 return CMD_SUCCESS;
7701}
7702
7703DEFPY (no_neighbor_timers_delayopen,
7704 no_neighbor_timers_delayopen_cmd,
7705 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7706 NO_STR
7707 NEIGHBOR_STR
7708 NEIGHBOR_ADDR_STR2
7709 "BGP per neighbor timers\n"
7710 "RFC 4271 DelayOpenTimer\n"
7711 "DelayOpenTime timer interval\n")
7712{
7713 struct peer *peer;
7714
7715 peer = peer_and_group_lookup_vty(vty, neighbor);
7716 if (!peer)
7717 return CMD_WARNING_CONFIG_FAILED;
7718
7719 if (peer_timers_delayopen_unset(peer))
7720 return CMD_WARNING_CONFIG_FAILED;
7721
7722 return CMD_SUCCESS;
7723}
7724
f4b8ec07
CS
7725DEFUN_YANG (neighbor_advertise_interval,
7726 neighbor_advertise_interval_cmd,
7727 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7728 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7729 "Minimum interval between sending BGP routing updates\n"
7730 "time in seconds\n")
718e3744 7731{
d62a17ae 7732 int idx_peer = 1;
f4b8ec07
CS
7733 int idx_number = 3;
7734 char base_xpath[XPATH_MAXLEN];
718e3744 7735
f4b8ec07
CS
7736 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7737 sizeof(base_xpath), NULL)
7738 < 0)
d62a17ae 7739 return CMD_WARNING_CONFIG_FAILED;
718e3744 7740
f4b8ec07
CS
7741 nb_cli_enqueue_change(vty, "./timers/advertise-interval", NB_OP_MODIFY,
7742 argv[idx_number]->arg);
718e3744 7743
f4b8ec07 7744 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7745}
7746
f4b8ec07
CS
7747DEFUN_YANG (no_neighbor_advertise_interval,
7748 no_neighbor_advertise_interval_cmd,
7749 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7750 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7751 "Minimum interval between sending BGP routing updates\n"
7752 "time in seconds\n")
718e3744 7753{
d62a17ae 7754 int idx_peer = 2;
f4b8ec07
CS
7755 char base_xpath[XPATH_MAXLEN];
7756
7757 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7758 sizeof(base_xpath), NULL)
7759 < 0)
7760 return CMD_WARNING_CONFIG_FAILED;
7761
7762 nb_cli_enqueue_change(vty, "./timers/advertise-interval", NB_OP_DESTROY,
7763 NULL);
7764
7765 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7766}
7767
6b0655a2 7768
518f0eb1
DS
7769/* Time to wait before processing route-map updates */
7770DEFUN (bgp_set_route_map_delay_timer,
7771 bgp_set_route_map_delay_timer_cmd,
6147e2c6 7772 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
7773 SET_STR
7774 "BGP route-map delay timer\n"
7775 "Time in secs to wait before processing route-map changes\n"
f414725f 7776 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 7777{
d62a17ae 7778 int idx_number = 3;
d7c0a89a 7779 uint32_t rmap_delay_timer;
d62a17ae 7780
7781 if (argv[idx_number]->arg) {
7782 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7783 bm->rmap_update_timer = rmap_delay_timer;
7784
7785 /* if the dynamic update handling is being disabled, and a timer
7786 * is
7787 * running, stop the timer and act as if the timer has already
7788 * fired.
7789 */
7790 if (!rmap_delay_timer && bm->t_rmap_update) {
7791 BGP_TIMER_OFF(bm->t_rmap_update);
7792 thread_execute(bm->master, bgp_route_map_update_timer,
7793 NULL, 0);
7794 }
7795 return CMD_SUCCESS;
7796 } else {
7797 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7798 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 7799 }
518f0eb1
DS
7800}
7801
7802DEFUN (no_bgp_set_route_map_delay_timer,
7803 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 7804 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 7805 NO_STR
3a2d747c 7806 BGP_STR
518f0eb1 7807 "Default BGP route-map delay timer\n"
8334fd5a
DW
7808 "Reset to default time to wait for processing route-map changes\n"
7809 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 7810{
518f0eb1 7811
d62a17ae 7812 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 7813
d62a17ae 7814 return CMD_SUCCESS;
518f0eb1
DS
7815}
7816
f4b8ec07
CS
7817DEFUN_YANG (neighbor_interface,
7818 neighbor_interface_cmd,
7819 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7820 NEIGHBOR_STR NEIGHBOR_ADDR_STR
7821 "Interface\n"
7822 "Interface name\n")
718e3744 7823{
f4b8ec07
CS
7824 int idx_ip = 1;
7825 int idx_word = 3;
7826 char base_xpath[XPATH_MAXLEN];
718e3744 7827
f4b8ec07
CS
7828 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7829 argv[idx_ip]->arg, "");
718e3744 7830
f4b8ec07
CS
7831 nb_cli_enqueue_change(vty, "./local-interface", NB_OP_MODIFY,
7832 argv[idx_word]->arg);
718e3744 7833
f4b8ec07 7834 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7835}
7836
f4b8ec07
CS
7837DEFUN_YANG (no_neighbor_interface,
7838 no_neighbor_interface_cmd,
7839 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
7840 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7841 "Interface\n"
7842 "Interface name\n")
718e3744 7843{
d62a17ae 7844 int idx_peer = 2;
f4b8ec07
CS
7845 char base_xpath[XPATH_MAXLEN];
7846
7847 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7848 argv[idx_peer]->arg, "");
7849
7850 nb_cli_enqueue_change(vty, "./local-interface", NB_OP_DESTROY, NULL);
7851
7852 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7853}
6b0655a2 7854
718e3744 7855DEFUN (neighbor_distribute_list,
7856 neighbor_distribute_list_cmd,
9ccf14f7 7857 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 7858 NEIGHBOR_STR
7859 NEIGHBOR_ADDR_STR2
7860 "Filter updates to/from this neighbor\n"
7861 "IP access-list number\n"
7862 "IP access-list number (expanded range)\n"
7863 "IP Access-list name\n"
7864 "Filter incoming updates\n"
7865 "Filter outgoing updates\n")
7866{
d62a17ae 7867 int idx_peer = 1;
7868 int idx_acl = 3;
7869 int direct, ret;
7870 struct peer *peer;
a8206004 7871
d62a17ae 7872 const char *pstr = argv[idx_peer]->arg;
7873 const char *acl = argv[idx_acl]->arg;
7874 const char *inout = argv[argc - 1]->text;
a8206004 7875
d62a17ae 7876 peer = peer_and_group_lookup_vty(vty, pstr);
7877 if (!peer)
7878 return CMD_WARNING_CONFIG_FAILED;
a8206004 7879
d62a17ae 7880 /* Check filter direction. */
7881 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7882 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7883 direct, acl);
a8206004 7884
d62a17ae 7885 return bgp_vty_return(vty, ret);
718e3744 7886}
7887
d62a17ae 7888ALIAS_HIDDEN(
7889 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
7890 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7891 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7892 "Filter updates to/from this neighbor\n"
7893 "IP access-list number\n"
7894 "IP access-list number (expanded range)\n"
7895 "IP Access-list name\n"
7896 "Filter incoming updates\n"
7897 "Filter outgoing updates\n")
596c17ba 7898
718e3744 7899DEFUN (no_neighbor_distribute_list,
7900 no_neighbor_distribute_list_cmd,
9ccf14f7 7901 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 7902 NO_STR
7903 NEIGHBOR_STR
7904 NEIGHBOR_ADDR_STR2
7905 "Filter updates to/from this neighbor\n"
7906 "IP access-list number\n"
7907 "IP access-list number (expanded range)\n"
7908 "IP Access-list name\n"
7909 "Filter incoming updates\n"
7910 "Filter outgoing updates\n")
7911{
d62a17ae 7912 int idx_peer = 2;
7913 int direct, ret;
7914 struct peer *peer;
a8206004 7915
d62a17ae 7916 const char *pstr = argv[idx_peer]->arg;
7917 const char *inout = argv[argc - 1]->text;
a8206004 7918
d62a17ae 7919 peer = peer_and_group_lookup_vty(vty, pstr);
7920 if (!peer)
7921 return CMD_WARNING_CONFIG_FAILED;
a8206004 7922
d62a17ae 7923 /* Check filter direction. */
7924 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7925 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7926 direct);
a8206004 7927
d62a17ae 7928 return bgp_vty_return(vty, ret);
718e3744 7929}
6b0655a2 7930
d62a17ae 7931ALIAS_HIDDEN(
7932 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
7933 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7934 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7935 "Filter updates to/from this neighbor\n"
7936 "IP access-list number\n"
7937 "IP access-list number (expanded range)\n"
7938 "IP Access-list name\n"
7939 "Filter incoming updates\n"
7940 "Filter outgoing updates\n")
596c17ba 7941
718e3744 7942/* Set prefix list to the peer. */
d9986d26
CS
7943DEFPY_YANG(
7944 neighbor_prefix_list, neighbor_prefix_list_cmd,
7945 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor_str prefix-list WORD$prefix_str <in|out>$direction",
7946 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7947 "Filter updates to/from this neighbor\n"
7948 "Name of a prefix list\n"
7949 "Filter incoming updates\n"
7950 "Filter outgoing updates\n")
718e3744 7951{
d9986d26
CS
7952 char base_xpath[XPATH_MAXLEN];
7953 char af_xpath[XPATH_MAXLEN];
c6685575 7954 char plist_xpath[XPATH_MAXLEN];
d9986d26
CS
7955 afi_t afi = bgp_node_afi(vty);
7956 safi_t safi = bgp_node_safi(vty);
718e3744 7957
d9986d26
CS
7958 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7959 yang_afi_safi_value2identity(afi, safi));
7960 if (peer_and_group_lookup_nb(vty, neighbor_str, base_xpath,
7961 sizeof(base_xpath), af_xpath)
7962 < 0)
d62a17ae 7963 return CMD_WARNING_CONFIG_FAILED;
e52702f2 7964
d9986d26
CS
7965 if (strmatch(direction, "in"))
7966 snprintf(plist_xpath, sizeof(plist_xpath),
7967 "./%s/filter-config/plist-import",
7968 bgp_afi_safi_get_container_str(afi, safi));
7969 else if (strmatch(direction, "out"))
7970 snprintf(plist_xpath, sizeof(plist_xpath),
7971 "./%s/filter-config/plist-export",
7972 bgp_afi_safi_get_container_str(afi, safi));
718e3744 7973
d9986d26
CS
7974 if (!no)
7975 nb_cli_enqueue_change(vty, plist_xpath, NB_OP_MODIFY,
7976 prefix_str);
7977 else
7978 nb_cli_enqueue_change(vty, plist_xpath, NB_OP_DESTROY, NULL);
718e3744 7979
d9986d26 7980 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7981}
7982
d62a17ae 7983ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7984 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7985 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7986 "Filter updates to/from this neighbor\n"
7987 "Name of a prefix list\n"
7988 "Filter incoming updates\n"
7989 "Filter outgoing updates\n")
596c17ba 7990
d62a17ae 7991static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7992 safi_t safi, const char *name_str,
7993 const char *direct_str)
718e3744 7994{
d62a17ae 7995 int ret;
7996 struct peer *peer;
7997 int direct = FILTER_IN;
718e3744 7998
d62a17ae 7999 peer = peer_and_group_lookup_vty(vty, ip_str);
8000 if (!peer)
8001 return CMD_WARNING_CONFIG_FAILED;
718e3744 8002
d62a17ae 8003 /* Check filter direction. */
8004 if (strncmp(direct_str, "i", 1) == 0)
8005 direct = FILTER_IN;
8006 else if (strncmp(direct_str, "o", 1) == 0)
8007 direct = FILTER_OUT;
718e3744 8008
d62a17ae 8009 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 8010
d62a17ae 8011 return bgp_vty_return(vty, ret);
718e3744 8012}
8013
d62a17ae 8014static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
8015 safi_t safi, const char *direct_str)
718e3744 8016{
d62a17ae 8017 int ret;
8018 struct peer *peer;
8019 int direct = FILTER_IN;
718e3744 8020
d62a17ae 8021 peer = peer_and_group_lookup_vty(vty, ip_str);
8022 if (!peer)
8023 return CMD_WARNING_CONFIG_FAILED;
718e3744 8024
d62a17ae 8025 /* Check filter direction. */
8026 if (strncmp(direct_str, "i", 1) == 0)
8027 direct = FILTER_IN;
8028 else if (strncmp(direct_str, "o", 1) == 0)
8029 direct = FILTER_OUT;
718e3744 8030
d62a17ae 8031 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 8032
d62a17ae 8033 return bgp_vty_return(vty, ret);
718e3744 8034}
8035
8036DEFUN (neighbor_filter_list,
8037 neighbor_filter_list_cmd,
9ccf14f7 8038 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 8039 NEIGHBOR_STR
8040 NEIGHBOR_ADDR_STR2
8041 "Establish BGP filters\n"
8042 "AS path access-list name\n"
8043 "Filter incoming routes\n"
8044 "Filter outgoing routes\n")
8045{
d62a17ae 8046 int idx_peer = 1;
8047 int idx_word = 3;
8048 int idx_in_out = 4;
8049 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
8050 bgp_node_safi(vty), argv[idx_word]->arg,
8051 argv[idx_in_out]->arg);
718e3744 8052}
8053
d62a17ae 8054ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
8055 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
8056 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8057 "Establish BGP filters\n"
8058 "AS path access-list name\n"
8059 "Filter incoming routes\n"
8060 "Filter outgoing routes\n")
596c17ba 8061
718e3744 8062DEFUN (no_neighbor_filter_list,
8063 no_neighbor_filter_list_cmd,
9ccf14f7 8064 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 8065 NO_STR
8066 NEIGHBOR_STR
8067 NEIGHBOR_ADDR_STR2
8068 "Establish BGP filters\n"
8069 "AS path access-list name\n"
8070 "Filter incoming routes\n"
8071 "Filter outgoing routes\n")
8072{
d62a17ae 8073 int idx_peer = 2;
8074 int idx_in_out = 5;
8075 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
8076 bgp_node_afi(vty), bgp_node_safi(vty),
8077 argv[idx_in_out]->arg);
718e3744 8078}
6b0655a2 8079
d62a17ae 8080ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
8081 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
8082 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8083 "Establish BGP filters\n"
8084 "AS path access-list name\n"
8085 "Filter incoming routes\n"
8086 "Filter outgoing routes\n")
596c17ba 8087
7f7940e6
MK
8088/* Set advertise-map to the peer. */
8089static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
8090 afi_t afi, safi_t safi,
cf2ad4d8
MK
8091 const char *advertise_str,
8092 const char *condition_str, bool condition,
8093 bool set)
7f7940e6
MK
8094{
8095 int ret = CMD_WARNING_CONFIG_FAILED;
8096 struct peer *peer;
8097 struct route_map *advertise_map;
8098 struct route_map *condition_map;
8099
8100 peer = peer_and_group_lookup_vty(vty, ip_str);
8101 if (!peer)
8102 return ret;
8103
8104 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
8105 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
8106
cf2ad4d8
MK
8107 if (set)
8108 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
8109 advertise_map, condition_str,
8110 condition_map, condition);
8111 else
8112 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
8113 advertise_map, condition_str,
8114 condition_map, condition);
7f7940e6
MK
8115
8116 return bgp_vty_return(vty, ret);
8117}
8118
cf2ad4d8 8119DEFPY (neighbor_advertise_map,
7f7940e6 8120 neighbor_advertise_map_cmd,
52b84062 8121 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor advertise-map WORD$advertise_str <exist-map|non-exist-map>$exist WORD$condition_str",
cf2ad4d8 8122 NO_STR
7f7940e6
MK
8123 NEIGHBOR_STR
8124 NEIGHBOR_ADDR_STR2
8125 "Route-map to conditionally advertise routes\n"
8126 "Name of advertise map\n"
8127 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 8128 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 8129 "Name of the exist or non exist map\n")
7f7940e6 8130{
7f7940e6
MK
8131 bool condition = CONDITION_EXIST;
8132
52b84062 8133 if (!strcmp(exist, "non-exist-map"))
7f7940e6
MK
8134 condition = CONDITION_NON_EXIST;
8135
52b84062
MK
8136 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
8137 bgp_node_safi(vty), advertise_str,
8138 condition_str, condition, !no);
7f7940e6
MK
8139}
8140
8141ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
52b84062 8142 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor advertise-map WORD$advertise_str <exist-map|non-exist-map>$exist WORD$condition_str",
7f7940e6
MK
8143 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8144 "Route-map to conditionally advertise routes\n"
8145 "Name of advertise map\n"
8146 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 8147 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 8148 "Name of the exist or non exist map\n")
7f7940e6 8149
718e3744 8150/* Set route-map to the peer. */
c6685575
CS
8151DEFPY_YANG(
8152 neighbor_route_map, neighbor_route_map_cmd,
8153 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor_str route-map WORD$rmap_str <in|out>$direction",
8154 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8155 "Apply route map to neighbor\n"
8156 "Name of route map\n"
8157 "Apply map to incoming routes\n"
8158 "Apply map to outbound routes\n")
718e3744 8159{
c6685575
CS
8160 char base_xpath[XPATH_MAXLEN];
8161 char af_xpath[XPATH_MAXLEN];
8162 char rmap_xpath[XPATH_MAXLEN];
8163 afi_t afi = bgp_node_afi(vty);
8164 safi_t safi = bgp_node_safi(vty);
718e3744 8165
c6685575
CS
8166 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8167 yang_afi_safi_value2identity(afi, safi));
8168 if (peer_and_group_lookup_nb(vty, neighbor_str, base_xpath,
8169 sizeof(base_xpath), af_xpath)
8170 < 0)
d62a17ae 8171 return CMD_WARNING_CONFIG_FAILED;
718e3744 8172
c6685575
CS
8173 if (strmatch(direction, "in"))
8174 snprintf(rmap_xpath, sizeof(rmap_xpath),
8175 "./%s/filter-config/rmap-import",
8176 bgp_afi_safi_get_container_str(afi, safi));
8177 else if (strmatch(direction, "out"))
8178 snprintf(rmap_xpath, sizeof(rmap_xpath),
8179 "./%s/filter-config/rmap-export",
8180 bgp_afi_safi_get_container_str(afi, safi));
718e3744 8181
c6685575 8182 if (!no) {
3bb513c3 8183 if (!yang_dnode_existsf(
c6685575
CS
8184 vty->candidate_config->dnode,
8185 "/frr-route-map:lib/route-map[name='%s']",
8186 rmap_str)) {
8187 if (vty_shell_serv(vty))
8188 vty_out(vty,
8189 "The route-map '%s' does not exist.\n",
8190 rmap_str);
8191 }
8192 nb_cli_enqueue_change(vty, rmap_xpath, NB_OP_MODIFY, rmap_str);
8193 } else
8194 nb_cli_enqueue_change(vty, rmap_xpath, NB_OP_DESTROY, NULL);
718e3744 8195
c6685575 8196 return nb_cli_apply_changes(vty, base_xpath);
718e3744 8197}
8198
718e3744 8199/* Set unsuppress-map to the peer. */
d62a17ae 8200static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
8201 afi_t afi, safi_t safi,
8202 const char *name_str)
718e3744 8203{
d62a17ae 8204 int ret;
8205 struct peer *peer;
1de27621 8206 struct route_map *route_map;
718e3744 8207
d62a17ae 8208 peer = peer_and_group_lookup_vty(vty, ip_str);
8209 if (!peer)
8210 return CMD_WARNING_CONFIG_FAILED;
718e3744 8211
1de27621
DA
8212 route_map = route_map_lookup_warn_noexist(vty, name_str);
8213 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
718e3744 8214
d62a17ae 8215 return bgp_vty_return(vty, ret);
718e3744 8216}
8217
8218/* Unset route-map from the peer. */
d62a17ae 8219static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
8220 afi_t afi, safi_t safi)
718e3744 8221{
d62a17ae 8222 int ret;
8223 struct peer *peer;
718e3744 8224
d62a17ae 8225 peer = peer_and_group_lookup_vty(vty, ip_str);
8226 if (!peer)
8227 return CMD_WARNING_CONFIG_FAILED;
718e3744 8228
d62a17ae 8229 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 8230
d62a17ae 8231 return bgp_vty_return(vty, ret);
718e3744 8232}
8233
8234DEFUN (neighbor_unsuppress_map,
8235 neighbor_unsuppress_map_cmd,
9ccf14f7 8236 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 8237 NEIGHBOR_STR
8238 NEIGHBOR_ADDR_STR2
8239 "Route-map to selectively unsuppress suppressed routes\n"
8240 "Name of route map\n")
8241{
d62a17ae 8242 int idx_peer = 1;
8243 int idx_word = 3;
8244 return peer_unsuppress_map_set_vty(
8245 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8246 argv[idx_word]->arg);
718e3744 8247}
8248
d62a17ae 8249ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
8250 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8251 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8252 "Route-map to selectively unsuppress suppressed routes\n"
8253 "Name of route map\n")
596c17ba 8254
718e3744 8255DEFUN (no_neighbor_unsuppress_map,
8256 no_neighbor_unsuppress_map_cmd,
9ccf14f7 8257 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 8258 NO_STR
8259 NEIGHBOR_STR
8260 NEIGHBOR_ADDR_STR2
8261 "Route-map to selectively unsuppress suppressed routes\n"
8262 "Name of route map\n")
8263{
d62a17ae 8264 int idx_peer = 2;
8265 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
8266 bgp_node_afi(vty),
8267 bgp_node_safi(vty));
718e3744 8268}
6b0655a2 8269
d62a17ae 8270ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
8271 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8272 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8273 "Route-map to selectively unsuppress suppressed routes\n"
8274 "Name of route map\n")
596c17ba 8275
fde246e8 8276/* Maximum number of prefix to be sent to the neighbor. */
232c75cd
CS
8277DEFUN_YANG(neighbor_maximum_prefix_out,
8278 neighbor_maximum_prefix_out_cmd,
8279 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
8280 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8281 "Maximum number of prefixes to be sent to this peer\n"
8282 "Maximum no. of prefix limit\n")
fde246e8 8283{
04261dec
CS
8284 char base_xpath[XPATH_MAXLEN];
8285 char af_xpath[XPATH_MAXLEN];
8286 char attr_xpath[XPATH_MAXLEN];
fde246e8
DA
8287 int idx_peer = 1;
8288 int idx_number = 3;
fde246e8
DA
8289 afi_t afi = bgp_node_afi(vty);
8290 safi_t safi = bgp_node_safi(vty);
8291
04261dec
CS
8292 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8293 yang_afi_safi_value2identity(afi, safi));
8294 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8295 sizeof(base_xpath), af_xpath)
8296 < 0)
fde246e8
DA
8297 return CMD_WARNING_CONFIG_FAILED;
8298
04261dec
CS
8299 snprintf(attr_xpath, sizeof(attr_xpath),
8300 "/%s/prefix-limit/direction-list[direction='out']",
8301 bgp_afi_safi_get_container_str(afi, safi));
8302 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
fde246e8 8303
04261dec 8304 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
fde246e8 8305
04261dec
CS
8306 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8307 argv[idx_number]->arg);
8308
8309 return nb_cli_apply_changes(vty, base_xpath);
fde246e8
DA
8310}
8311
232c75cd
CS
8312DEFUN_YANG(no_neighbor_maximum_prefix_out,
8313 no_neighbor_maximum_prefix_out_cmd,
8314 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out",
8315 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8316 "Maximum number of prefixes to be sent to this peer\n")
fde246e8 8317{
04261dec
CS
8318 char base_xpath[XPATH_MAXLEN];
8319 char af_xpath[XPATH_MAXLEN];
8320 char attr_xpath[XPATH_MAXLEN];
fde246e8 8321 int idx_peer = 2;
fde246e8
DA
8322 afi_t afi = bgp_node_afi(vty);
8323 safi_t safi = bgp_node_safi(vty);
8324
04261dec
CS
8325 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8326 yang_afi_safi_value2identity(afi, safi));
8327 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8328 sizeof(base_xpath), af_xpath)
8329 < 0)
fde246e8
DA
8330 return CMD_WARNING_CONFIG_FAILED;
8331
04261dec
CS
8332 snprintf(attr_xpath, sizeof(attr_xpath),
8333 "/%s/prefix-limit/direction-list[direction='out']",
8334 bgp_afi_safi_get_container_str(afi, safi));
8335 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8336
8337 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
fde246e8 8338
04261dec 8339 return nb_cli_apply_changes(vty, base_xpath);
fde246e8
DA
8340}
8341
9cbd06e0
DA
8342/* Maximum number of prefix configuration. Prefix count is different
8343 for each peer configuration. So this configuration can be set for
718e3744 8344 each peer configuration. */
232c75cd
CS
8345DEFUN_YANG(neighbor_maximum_prefix,
8346 neighbor_maximum_prefix_cmd,
8347 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8348 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8349 "Maximum number of prefix accept from this peer\n"
8350 "maximum no. of prefix limit\n"
8351 "Force checking all received routes not only accepted\n")
718e3744 8352{
d62a17ae 8353 int idx_peer = 1;
8354 int idx_number = 3;
9cbd06e0 8355 int idx_force = 0;
04261dec
CS
8356 char base_xpath[XPATH_MAXLEN];
8357 char af_xpath[XPATH_MAXLEN];
8358 char attr_xpath[XPATH_MAXLEN];
8359 afi_t afi = bgp_node_afi(vty);
8360 safi_t safi = bgp_node_safi(vty);
8361
8362 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8363 yang_afi_safi_value2identity(afi, safi));
8364 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8365 sizeof(base_xpath), af_xpath)
8366 < 0)
8367 return CMD_WARNING_CONFIG_FAILED;
8368
8369 snprintf(attr_xpath, sizeof(attr_xpath),
8370 "/%s/prefix-limit/direction-list[direction='in']",
8371 bgp_afi_safi_get_container_str(afi, safi));
8372 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8373
8374 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
9cbd06e0 8375
04261dec
CS
8376 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8377 argv[idx_number]->arg);
9cbd06e0 8378 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8379 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8380 "true");
9cbd06e0 8381
04261dec 8382 return nb_cli_apply_changes(vty, base_xpath);
718e3744 8383}
8384
d62a17ae 8385ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 8386 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
d62a17ae 8387 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8388 "Maximum number of prefix accept from this peer\n"
9cbd06e0
DA
8389 "maximum no. of prefix limit\n"
8390 "Force checking all received routes not only accepted\n")
596c17ba 8391
232c75cd
CS
8392DEFUN_YANG(neighbor_maximum_prefix_threshold,
8393 neighbor_maximum_prefix_threshold_cmd,
8394 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8395 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8396 "Maximum number of prefix accept from this peer\n"
8397 "maximum no. of prefix limit\n"
8398 "Threshold value (%) at which to generate a warning msg\n"
8399 "Force checking all received routes not only accepted\n")
e0701b79 8400{
d62a17ae 8401 int idx_peer = 1;
8402 int idx_number = 3;
8403 int idx_number_2 = 4;
9cbd06e0 8404 int idx_force = 0;
04261dec
CS
8405 char base_xpath[XPATH_MAXLEN];
8406 char af_xpath[XPATH_MAXLEN];
8407 char attr_xpath[XPATH_MAXLEN];
8408 afi_t afi = bgp_node_afi(vty);
8409 safi_t safi = bgp_node_safi(vty);
8410
8411 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8412 yang_afi_safi_value2identity(afi, safi));
8413 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8414 sizeof(base_xpath), af_xpath)
8415 < 0)
8416 return CMD_WARNING_CONFIG_FAILED;
8417
8418 snprintf(attr_xpath, sizeof(attr_xpath),
8419 "/%s/prefix-limit/direction-list[direction='in']",
8420 bgp_afi_safi_get_container_str(afi, safi));
8421 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8422
8423 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8424
8425 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8426 argv[idx_number]->arg);
8427
8428 nb_cli_enqueue_change(vty, "./options/shutdown-threshold-pct",
8429 NB_OP_MODIFY, argv[idx_number_2]->arg);
9cbd06e0
DA
8430
8431 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8432 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8433 "true");
9cbd06e0 8434
04261dec 8435 return nb_cli_apply_changes(vty, base_xpath);
0a486e5f 8436}
e0701b79 8437
d62a17ae 8438ALIAS_HIDDEN(
8439 neighbor_maximum_prefix_threshold,
8440 neighbor_maximum_prefix_threshold_hidden_cmd,
9cbd06e0 8441 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
d62a17ae 8442 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8443 "Maximum number of prefix accept from this peer\n"
8444 "maximum no. of prefix limit\n"
9cbd06e0
DA
8445 "Threshold value (%) at which to generate a warning msg\n"
8446 "Force checking all received routes not only accepted\n")
596c17ba 8447
232c75cd
CS
8448DEFUN_YANG(neighbor_maximum_prefix_warning,
8449 neighbor_maximum_prefix_warning_cmd,
8450 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8451 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8452 "Maximum number of prefix accept from this peer\n"
8453 "maximum no. of prefix limit\n"
8454 "Only give warning message when limit is exceeded\n"
8455 "Force checking all received routes not only accepted\n")
718e3744 8456{
d62a17ae 8457 int idx_peer = 1;
8458 int idx_number = 3;
9cbd06e0 8459 int idx_force = 0;
04261dec
CS
8460 char base_xpath[XPATH_MAXLEN];
8461 char af_xpath[XPATH_MAXLEN];
8462 char attr_xpath[XPATH_MAXLEN];
8463 afi_t afi = bgp_node_afi(vty);
8464 safi_t safi = bgp_node_safi(vty);
8465
8466 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8467 yang_afi_safi_value2identity(afi, safi));
8468 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8469 sizeof(base_xpath), af_xpath)
8470 < 0)
8471 return CMD_WARNING_CONFIG_FAILED;
9cbd06e0 8472
04261dec
CS
8473 snprintf(attr_xpath, sizeof(attr_xpath),
8474 "/%s/prefix-limit/direction-list[direction='in']",
8475 bgp_afi_safi_get_container_str(afi, safi));
8476 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8477
8478 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8479
8480 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8481 argv[idx_number]->arg);
8482
8483 nb_cli_enqueue_change(vty, "./options/warning-only", NB_OP_MODIFY,
8484 "true");
9cbd06e0 8485 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8486 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8487 "true");
9cbd06e0 8488
04261dec 8489 return nb_cli_apply_changes(vty, base_xpath);
718e3744 8490}
8491
d62a17ae 8492ALIAS_HIDDEN(
8493 neighbor_maximum_prefix_warning,
8494 neighbor_maximum_prefix_warning_hidden_cmd,
9cbd06e0 8495 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
d62a17ae 8496 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8497 "Maximum number of prefix accept from this peer\n"
8498 "maximum no. of prefix limit\n"
9cbd06e0
DA
8499 "Only give warning message when limit is exceeded\n"
8500 "Force checking all received routes not only accepted\n")
596c17ba 8501
232c75cd
CS
8502DEFUN_YANG(neighbor_maximum_prefix_threshold_warning,
8503 neighbor_maximum_prefix_threshold_warning_cmd,
8504 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8505 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8506 "Maximum number of prefix accept from this peer\n"
8507 "maximum no. of prefix limit\n"
8508 "Threshold value (%) at which to generate a warning msg\n"
8509 "Only give warning message when limit is exceeded\n"
8510 "Force checking all received routes not only accepted\n")
e0701b79 8511{
d62a17ae 8512 int idx_peer = 1;
8513 int idx_number = 3;
8514 int idx_number_2 = 4;
9cbd06e0 8515 int idx_force = 0;
04261dec
CS
8516 char base_xpath[XPATH_MAXLEN];
8517 char af_xpath[XPATH_MAXLEN];
8518 char attr_xpath[XPATH_MAXLEN];
8519 afi_t afi = bgp_node_afi(vty);
8520 safi_t safi = bgp_node_safi(vty);
9cbd06e0 8521
04261dec
CS
8522 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8523 yang_afi_safi_value2identity(afi, safi));
8524 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8525 sizeof(base_xpath), af_xpath)
8526 < 0)
8527 return CMD_WARNING_CONFIG_FAILED;
8528
8529 snprintf(attr_xpath, sizeof(attr_xpath),
8530 "/%s/prefix-limit/direction-list[direction='in']",
8531 bgp_afi_safi_get_container_str(afi, safi));
8532 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8533
8534 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8535
8536 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8537 argv[idx_number]->arg);
8538 nb_cli_enqueue_change(vty, "./options/tw-shutdown-threshold-pct",
8539 NB_OP_MODIFY, argv[idx_number_2]->arg);
8540 nb_cli_enqueue_change(vty, "./options/tw-warning-only", NB_OP_MODIFY,
8541 "true");
9cbd06e0 8542 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8543 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8544 "true");
9cbd06e0 8545
04261dec 8546 return nb_cli_apply_changes(vty, base_xpath);
0a486e5f 8547}
8548
d62a17ae 8549ALIAS_HIDDEN(
8550 neighbor_maximum_prefix_threshold_warning,
8551 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
9cbd06e0 8552 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
d62a17ae 8553 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8554 "Maximum number of prefix accept from this peer\n"
8555 "maximum no. of prefix limit\n"
8556 "Threshold value (%) at which to generate a warning msg\n"
9cbd06e0
DA
8557 "Only give warning message when limit is exceeded\n"
8558 "Force checking all received routes not only accepted\n")
596c17ba 8559
232c75cd
CS
8560DEFUN_YANG(neighbor_maximum_prefix_restart,
8561 neighbor_maximum_prefix_restart_cmd,
8562 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8563 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8564 "Maximum number of prefix accept from this peer\n"
8565 "maximum no. of prefix limit\n"
8566 "Restart bgp connection after limit is exceeded\n"
8567 "Restart interval in minutes\n"
8568 "Force checking all received routes not only accepted\n")
0a486e5f 8569{
d62a17ae 8570 int idx_peer = 1;
8571 int idx_number = 3;
8572 int idx_number_2 = 5;
9cbd06e0 8573 int idx_force = 0;
04261dec
CS
8574 char base_xpath[XPATH_MAXLEN];
8575 char af_xpath[XPATH_MAXLEN];
8576 char attr_xpath[XPATH_MAXLEN];
8577 afi_t afi = bgp_node_afi(vty);
8578 safi_t safi = bgp_node_safi(vty);
9cbd06e0 8579
04261dec
CS
8580 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8581 yang_afi_safi_value2identity(afi, safi));
8582 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8583 sizeof(base_xpath), af_xpath)
8584 < 0)
8585 return CMD_WARNING_CONFIG_FAILED;
8586
8587 snprintf(attr_xpath, sizeof(attr_xpath),
8588 "/%s/prefix-limit/direction-list[direction='in']",
8589 bgp_afi_safi_get_container_str(afi, safi));
8590 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8591
8592 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8593
8594 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8595 argv[idx_number]->arg);
8596 nb_cli_enqueue_change(vty, "./options/restart-timer", NB_OP_MODIFY,
8597 argv[idx_number_2]->arg);
9cbd06e0 8598 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8599 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8600 "true");
9cbd06e0 8601
04261dec 8602 return nb_cli_apply_changes(vty, base_xpath);
0a486e5f 8603}
8604
d62a17ae 8605ALIAS_HIDDEN(
8606 neighbor_maximum_prefix_restart,
8607 neighbor_maximum_prefix_restart_hidden_cmd,
9cbd06e0 8608 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
d62a17ae 8609 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8610 "Maximum number of prefix accept from this peer\n"
8611 "maximum no. of prefix limit\n"
8612 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
8613 "Restart interval in minutes\n"
8614 "Force checking all received routes not only accepted\n")
596c17ba 8615
232c75cd
CS
8616DEFUN_YANG(neighbor_maximum_prefix_threshold_restart,
8617 neighbor_maximum_prefix_threshold_restart_cmd,
8618 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8619 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8620 "Maximum number of prefixes to accept from this peer\n"
8621 "maximum no. of prefix limit\n"
8622 "Threshold value (%) at which to generate a warning msg\n"
8623 "Restart bgp connection after limit is exceeded\n"
8624 "Restart interval in minutes\n"
8625 "Force checking all received routes not only accepted\n")
0a486e5f 8626{
d62a17ae 8627 int idx_peer = 1;
8628 int idx_number = 3;
8629 int idx_number_2 = 4;
8630 int idx_number_3 = 6;
9cbd06e0 8631 int idx_force = 0;
04261dec
CS
8632 char base_xpath[XPATH_MAXLEN];
8633 char af_xpath[XPATH_MAXLEN];
8634 char attr_xpath[XPATH_MAXLEN];
8635 afi_t afi = bgp_node_afi(vty);
8636 safi_t safi = bgp_node_safi(vty);
9cbd06e0 8637
04261dec
CS
8638 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8639 yang_afi_safi_value2identity(afi, safi));
8640 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8641 sizeof(base_xpath), af_xpath)
8642 < 0)
8643 return CMD_WARNING_CONFIG_FAILED;
8644
8645 snprintf(attr_xpath, sizeof(attr_xpath),
8646 "/%s/prefix-limit/direction-list[direction='in']",
8647 bgp_afi_safi_get_container_str(afi, safi));
8648 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8649
8650 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8651
8652 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8653 argv[idx_number]->arg);
8654 nb_cli_enqueue_change(vty, "./options/tr-shutdown-threshold-pct",
8655 NB_OP_MODIFY, argv[idx_number_2]->arg);
8656 nb_cli_enqueue_change(vty, "./options/tr-restart-timer", NB_OP_MODIFY,
8657 argv[idx_number_3]->arg);
9cbd06e0 8658 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8659 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8660 "true");
9cbd06e0 8661
04261dec 8662 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 8663}
8664
8665ALIAS_HIDDEN(
8666 neighbor_maximum_prefix_threshold_restart,
8667 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
9cbd06e0 8668 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
d62a17ae 8669 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8670 "Maximum number of prefixes to accept from this peer\n"
8671 "maximum no. of prefix limit\n"
8672 "Threshold value (%) at which to generate a warning msg\n"
8673 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
8674 "Restart interval in minutes\n"
8675 "Force checking all received routes not only accepted\n")
596c17ba 8676
232c75cd
CS
8677DEFUN_YANG(no_neighbor_maximum_prefix,
8678 no_neighbor_maximum_prefix_cmd,
8679 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8680 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8681 "Maximum number of prefixes to accept from this peer\n"
8682 "maximum no. of prefix limit\n"
8683 "Threshold value (%) at which to generate a warning msg\n"
8684 "Restart bgp connection after limit is exceeded\n"
8685 "Restart interval in minutes\n"
8686 "Only give warning message when limit is exceeded\n"
8687 "Force checking all received routes not only accepted\n")
718e3744 8688{
d62a17ae 8689 int idx_peer = 2;
04261dec
CS
8690 char base_xpath[XPATH_MAXLEN];
8691 char af_xpath[XPATH_MAXLEN];
8692 char attr_xpath[XPATH_MAXLEN];
8693 afi_t afi = bgp_node_afi(vty);
8694 safi_t safi = bgp_node_safi(vty);
8695
8696 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8697 yang_afi_safi_value2identity(afi, safi));
8698 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8699 sizeof(base_xpath), af_xpath)
8700 < 0)
8701 return CMD_WARNING_CONFIG_FAILED;
8702
8703 snprintf(attr_xpath, sizeof(attr_xpath),
8704 "/%s/prefix-limit/direction-list[direction='in']",
8705 bgp_afi_safi_get_container_str(afi, safi));
8706 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8707
8708 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
8709
8710 return nb_cli_apply_changes(vty, base_xpath);
718e3744 8711}
e52702f2 8712
d62a17ae 8713ALIAS_HIDDEN(
8714 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 8715 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
d62a17ae 8716 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8717 "Maximum number of prefixes to accept from this peer\n"
8718 "maximum no. of prefix limit\n"
8719 "Threshold value (%) at which to generate a warning msg\n"
8720 "Restart bgp connection after limit is exceeded\n"
8721 "Restart interval in minutes\n"
9cbd06e0
DA
8722 "Only give warning message when limit is exceeded\n"
8723 "Force checking all received routes not only accepted\n")
596c17ba 8724
718e3744 8725
718e3744 8726/* "neighbor allowas-in" */
8727DEFUN (neighbor_allowas_in,
8728 neighbor_allowas_in_cmd,
fd8503f5 8729 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 8730 NEIGHBOR_STR
8731 NEIGHBOR_ADDR_STR2
31500417 8732 "Accept as-path with my AS present in it\n"
f79f7a7b 8733 "Number of occurrences of AS number\n"
fd8503f5 8734 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 8735{
d62a17ae 8736 int idx_peer = 1;
8737 int idx_number_origin = 3;
8738 int ret;
8739 int origin = 0;
8740 struct peer *peer;
8741 int allow_num = 0;
8742
8743 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8744 if (!peer)
8745 return CMD_WARNING_CONFIG_FAILED;
8746
8747 if (argc <= idx_number_origin)
8748 allow_num = 3;
8749 else {
8750 if (argv[idx_number_origin]->type == WORD_TKN)
8751 origin = 1;
8752 else
8753 allow_num = atoi(argv[idx_number_origin]->arg);
8754 }
8755
8756 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8757 allow_num, origin);
8758
8759 return bgp_vty_return(vty, ret);
8760}
8761
8762ALIAS_HIDDEN(
8763 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8764 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8765 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8766 "Accept as-path with my AS present in it\n"
f79f7a7b 8767 "Number of occurrences of AS number\n"
d62a17ae 8768 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 8769
718e3744 8770DEFUN (no_neighbor_allowas_in,
8771 no_neighbor_allowas_in_cmd,
fd8503f5 8772 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 8773 NO_STR
8774 NEIGHBOR_STR
8775 NEIGHBOR_ADDR_STR2
8334fd5a 8776 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8777 "Number of occurrences of AS number\n"
fd8503f5 8778 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 8779{
d62a17ae 8780 int idx_peer = 2;
8781 int ret;
8782 struct peer *peer;
718e3744 8783
d62a17ae 8784 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8785 if (!peer)
8786 return CMD_WARNING_CONFIG_FAILED;
718e3744 8787
d62a17ae 8788 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8789 bgp_node_safi(vty));
718e3744 8790
d62a17ae 8791 return bgp_vty_return(vty, ret);
718e3744 8792}
6b0655a2 8793
d62a17ae 8794ALIAS_HIDDEN(
8795 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8796 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8797 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8798 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8799 "Number of occurrences of AS number\n"
d62a17ae 8800 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 8801
f4b8ec07
CS
8802DEFUN_YANG (neighbor_ttl_security,
8803 neighbor_ttl_security_cmd,
8804 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8805 NEIGHBOR_STR
8806 NEIGHBOR_ADDR_STR2
8807 "BGP ttl-security parameters\n"
8808 "Specify the maximum number of hops to the BGP peer\n"
8809 "Number of hops to BGP peer\n")
fa411a21 8810{
d62a17ae 8811 int idx_peer = 1;
8812 int idx_number = 4;
f4b8ec07 8813 char base_xpath[XPATH_MAXLEN];
d62a17ae 8814
f4b8ec07
CS
8815 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8816 sizeof(base_xpath), NULL)
8817 < 0)
d62a17ae 8818 return CMD_WARNING_CONFIG_FAILED;
8819
f4b8ec07
CS
8820 nb_cli_enqueue_change(vty, "./ttl-security", NB_OP_MODIFY,
8821 argv[idx_number]->arg);
7ebe625c 8822
f4b8ec07 8823 return nb_cli_apply_changes(vty, base_xpath);
fa411a21
NH
8824}
8825
232c75cd
CS
8826DEFUN_YANG(no_neighbor_ttl_security,
8827 no_neighbor_ttl_security_cmd,
8828 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8829 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8830 "BGP ttl-security parameters\n"
8831 "Specify the maximum number of hops to the BGP peer\n"
8832 "Number of hops to BGP peer\n")
fa411a21 8833{
d62a17ae 8834 int idx_peer = 2;
f4b8ec07 8835 char base_xpath[XPATH_MAXLEN];
fa411a21 8836
f4b8ec07
CS
8837 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8838 sizeof(base_xpath), NULL)
8839 < 0)
d62a17ae 8840 return CMD_WARNING_CONFIG_FAILED;
fa411a21 8841
f4b8ec07
CS
8842 nb_cli_enqueue_change(vty, "./ttl-security", NB_OP_DESTROY, NULL);
8843
8844 return nb_cli_apply_changes(vty, base_xpath);
fa411a21 8845}
6b0655a2 8846
adbac85e
DW
8847DEFUN (neighbor_addpath_tx_all_paths,
8848 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8849 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8850 NEIGHBOR_STR
8851 NEIGHBOR_ADDR_STR2
8852 "Use addpath to advertise all paths to a neighbor\n")
8853{
d62a17ae 8854 int idx_peer = 1;
8855 struct peer *peer;
adbac85e 8856
d62a17ae 8857 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8858 if (!peer)
8859 return CMD_WARNING_CONFIG_FAILED;
adbac85e 8860
dcc68b5e
MS
8861 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8862 BGP_ADDPATH_ALL);
8863 return CMD_SUCCESS;
adbac85e
DW
8864}
8865
d62a17ae 8866ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8867 neighbor_addpath_tx_all_paths_hidden_cmd,
8868 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8869 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8870 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8871
adbac85e
DW
8872DEFUN (no_neighbor_addpath_tx_all_paths,
8873 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8874 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8875 NO_STR
8876 NEIGHBOR_STR
8877 NEIGHBOR_ADDR_STR2
8878 "Use addpath to advertise all paths to a neighbor\n")
8879{
d62a17ae 8880 int idx_peer = 2;
dcc68b5e
MS
8881 struct peer *peer;
8882
8883 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8884 if (!peer)
8885 return CMD_WARNING_CONFIG_FAILED;
8886
8887 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8888 != BGP_ADDPATH_ALL) {
8889 vty_out(vty,
8890 "%% Peer not currently configured to transmit all paths.");
8891 return CMD_WARNING_CONFIG_FAILED;
8892 }
8893
8894 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8895 BGP_ADDPATH_NONE);
8896
8897 return CMD_SUCCESS;
adbac85e
DW
8898}
8899
d62a17ae 8900ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8901 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8902 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8903 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8904 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8905
06370dac
DW
8906DEFUN (neighbor_addpath_tx_bestpath_per_as,
8907 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8908 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8909 NEIGHBOR_STR
8910 NEIGHBOR_ADDR_STR2
8911 "Use addpath to advertise the bestpath per each neighboring AS\n")
8912{
d62a17ae 8913 int idx_peer = 1;
8914 struct peer *peer;
06370dac 8915
d62a17ae 8916 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8917 if (!peer)
8918 return CMD_WARNING_CONFIG_FAILED;
06370dac 8919
dcc68b5e
MS
8920 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8921 BGP_ADDPATH_BEST_PER_AS);
8922
8923 return CMD_SUCCESS;
06370dac
DW
8924}
8925
d62a17ae 8926ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8927 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8928 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8929 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8930 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8931
06370dac
DW
8932DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8933 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8934 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8935 NO_STR
8936 NEIGHBOR_STR
8937 NEIGHBOR_ADDR_STR2
8938 "Use addpath to advertise the bestpath per each neighboring AS\n")
8939{
d62a17ae 8940 int idx_peer = 2;
dcc68b5e
MS
8941 struct peer *peer;
8942
8943 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8944 if (!peer)
8945 return CMD_WARNING_CONFIG_FAILED;
8946
8947 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8948 != BGP_ADDPATH_BEST_PER_AS) {
8949 vty_out(vty,
8950 "%% Peer not currently configured to transmit all best path per as.");
8951 return CMD_WARNING_CONFIG_FAILED;
8952 }
8953
8954 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8955 BGP_ADDPATH_NONE);
8956
8957 return CMD_SUCCESS;
06370dac
DW
8958}
8959
d62a17ae 8960ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8961 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8962 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8963 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8964 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8965
2b31007c
RZ
8966DEFPY(
8967 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8968 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8969 NEIGHBOR_STR
8970 NEIGHBOR_ADDR_STR2
8971 "Detect AS loops before sending to neighbor\n")
8972{
8973 struct peer *peer;
8974
8975 peer = peer_and_group_lookup_vty(vty, neighbor);
8976 if (!peer)
8977 return CMD_WARNING_CONFIG_FAILED;
8978
8979 peer->as_path_loop_detection = true;
8980
8981 return CMD_SUCCESS;
8982}
8983
8984DEFPY(
8985 no_neighbor_aspath_loop_detection,
8986 no_neighbor_aspath_loop_detection_cmd,
8987 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8988 NO_STR
8989 NEIGHBOR_STR
8990 NEIGHBOR_ADDR_STR2
8991 "Detect AS loops before sending to neighbor\n")
8992{
8993 struct peer *peer;
8994
8995 peer = peer_and_group_lookup_vty(vty, neighbor);
8996 if (!peer)
8997 return CMD_WARNING_CONFIG_FAILED;
8998
8999 peer->as_path_loop_detection = false;
9000
9001 return CMD_SUCCESS;
9002}
9003
0221327c
DS
9004DEFPY(neighbor_damp,
9005 neighbor_damp_cmd,
9006 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor dampening [(1-45)$half [(1-20000)$reuse (1-20000)$suppress (1-255)$max]]",
9007 NEIGHBOR_STR
9008 NEIGHBOR_ADDR_STR2
9009 "Enable neighbor route-flap dampening\n"
9010 "Half-life time for the penalty\n"
9011 "Value to start reusing a route\n"
9012 "Value to start suppressing a route\n"
9013 "Maximum duration to suppress a stable route\n")
9014{
9015 struct peer *peer = peer_and_group_lookup_vty(vty, neighbor);
9016
9017 if (!peer)
9018 return CMD_WARNING_CONFIG_FAILED;
9019 if (!half)
9020 half = DEFAULT_HALF_LIFE;
9021 if (!reuse) {
9022 reuse = DEFAULT_REUSE;
9023 suppress = DEFAULT_SUPPRESS;
9024 max = half * 4;
9025 }
9026 if (suppress < reuse) {
9027 vty_out(vty,
9028 "Suppress value cannot be less than reuse value\n");
9029 return CMD_WARNING_CONFIG_FAILED;
9030 }
9031 bgp_peer_damp_enable(peer, bgp_node_afi(vty), bgp_node_safi(vty),
9032 half * 60, reuse, suppress, max * 60);
9033 return CMD_SUCCESS;
9034}
9035
9036DEFPY(no_neighbor_damp,
9037 no_neighbor_damp_cmd,
9038 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor dampening [HALF [REUSE SUPPRESS MAX]]",
9039 NO_STR
9040 NEIGHBOR_STR
9041 NEIGHBOR_ADDR_STR2
9042 "Enable neighbor route-flap dampening\n"
9043 "Half-life time for the penalty\n"
9044 "Value to start reusing a route\n"
9045 "Value to start suppressing a route\n"
9046 "Maximum duration to suppress a stable route\n")
9047{
9048 struct peer *peer = peer_and_group_lookup_vty(vty, neighbor);
9049
9050 if (!peer)
9051 return CMD_WARNING_CONFIG_FAILED;
9052 bgp_peer_damp_disable(peer, bgp_node_afi(vty), bgp_node_safi(vty));
9053 return CMD_SUCCESS;
9054}
9055
9056DEFPY (show_ip_bgp_neighbor_damp_param,
9057 show_ip_bgp_neighbor_damp_param_cmd,
9058 "show [ip] bgp [<ipv4|ipv6> [unicast]] neighbors <A.B.C.D|X:X::X:X|WORD>$neighbor dampening parameters [json]$json",
9059 SHOW_STR
9060 IP_STR
9061 BGP_STR
9062 BGP_AFI_HELP_STR
9063 "Address Family modifier\n"
9064 NEIGHBOR_STR
9065 NEIGHBOR_ADDR_STR2
9066 "Neighbor route-flap dampening information\n"
9067 "Display detail of configured dampening parameters\n"
9068 JSON_STR)
9069{
9070 bool use_json = false;
9071 int idx = 0;
9072 afi_t afi = AFI_IP;
9073 safi_t safi = SAFI_UNICAST;
9074 struct peer *peer;
9075
9076 if (argv_find(argv, argc, "ip", &idx))
9077 afi = AFI_IP;
9078 if (argv_find(argv, argc, "ipv4", &idx))
9079 afi = AFI_IP;
9080 if (argv_find(argv, argc, "ipv6", &idx))
9081 afi = AFI_IP6;
9082 peer = peer_and_group_lookup_vty(vty, neighbor);
9083 if (!peer)
9084 return CMD_WARNING;
9085 if (json)
9086 use_json = true;
9087 bgp_show_peer_dampening_parameters(vty, peer, afi, safi, use_json);
9088 return CMD_SUCCESS;
9089}
9090
b9c7bc5a 9091static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
c6423c31 9092 struct ecommunity **list, bool is_rt6)
ddb5b488 9093{
b9c7bc5a
PZ
9094 struct ecommunity *ecom = NULL;
9095 struct ecommunity *ecomadd;
ddb5b488 9096
b9c7bc5a 9097 for (; argc; --argc, ++argv) {
9a659715
PG
9098 if (is_rt6)
9099 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
9100 ECOMMUNITY_ROUTE_TARGET,
9101 0);
9102 else
9103 ecomadd = ecommunity_str2com(argv[0]->arg,
9104 ECOMMUNITY_ROUTE_TARGET,
9105 0);
b9c7bc5a
PZ
9106 if (!ecomadd) {
9107 vty_out(vty, "Malformed community-list value\n");
9108 if (ecom)
9109 ecommunity_free(&ecom);
9110 return CMD_WARNING_CONFIG_FAILED;
9111 }
ddb5b488 9112
b9c7bc5a
PZ
9113 if (ecom) {
9114 ecommunity_merge(ecom, ecomadd);
9115 ecommunity_free(&ecomadd);
9116 } else {
9117 ecom = ecomadd;
9118 }
9119 }
9120
9121 if (*list) {
9122 ecommunity_free(&*list);
ddb5b488 9123 }
b9c7bc5a
PZ
9124 *list = ecom;
9125
9126 return CMD_SUCCESS;
ddb5b488
PZ
9127}
9128
37a87b8f
CS
9129bool vpn_policy_check_import(struct bgp *bgp, afi_t afi, safi_t safi,
9130 bool v2vimport, char *errmsg, size_t errmsg_len)
9131{
9132 if (!v2vimport) {
9133 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9134 BGP_CONFIG_VRF_TO_VRF_IMPORT)
9135 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9136 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
9137 snprintf(
9138 errmsg, errmsg_len, "%s",
9139 "%% error: Please unconfigure import vrf commands before using vpn commands");
9140 return false;
9141 }
9142 } else {
9143 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9144 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
9145 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9146 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
9147 snprintf(
9148 errmsg, errmsg_len, "%s",
9149 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands");
9150 return false;
9151 }
9152 }
9153 return true;
9154}
9155
0ca70ba5
DS
9156/*
9157 * v2vimport is true if we are handling a `import vrf ...` command
9158 */
9159static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 9160{
0ca70ba5
DS
9161 afi_t afi;
9162
ddb5b488 9163 switch (vty->node) {
b9c7bc5a 9164 case BGP_IPV4_NODE:
0ca70ba5
DS
9165 afi = AFI_IP;
9166 break;
b9c7bc5a 9167 case BGP_IPV6_NODE:
0ca70ba5
DS
9168 afi = AFI_IP6;
9169 break;
ddb5b488
PZ
9170 default:
9171 vty_out(vty,
b9c7bc5a 9172 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 9173 return AFI_MAX;
ddb5b488 9174 }
69b07479 9175
0ca70ba5
DS
9176 if (!v2vimport) {
9177 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9178 BGP_CONFIG_VRF_TO_VRF_IMPORT)
9179 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9180 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
9181 vty_out(vty,
9182 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
9183 return AFI_MAX;
9184 }
9185 } else {
9186 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9187 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
9188 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9189 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
9190 vty_out(vty,
9191 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
9192 return AFI_MAX;
9193 }
9194 }
9195 return afi;
ddb5b488
PZ
9196}
9197
37a87b8f
CS
9198DEFPY_YANG(
9199 af_rd_vpn_export,
9200 af_rd_vpn_export_cmd,
9201 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
9202 NO_STR
9203 "Specify route distinguisher\n"
9204 "Between current address-family and vpn\n"
9205 "For routes leaked from current address-family to vpn\n"
9206 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
ddb5b488 9207{
37a87b8f 9208 char base_xpath[XPATH_MAXLEN];
ddb5b488 9209 afi_t afi;
37a87b8f 9210 safi_t safi;
b9c7bc5a 9211 int idx = 0;
b9c7bc5a 9212
37a87b8f
CS
9213 afi = bgp_node_afi(vty);
9214 safi = bgp_node_safi(vty);
ddb5b488 9215
37a87b8f
CS
9216 snprintf(
9217 base_xpath, sizeof(base_xpath),
9218 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9219 yang_afi_safi_value2identity(afi, safi),
9220 bgp_afi_safi_get_container_str(afi, safi));
ddb5b488 9221
37a87b8f
CS
9222 if (argv_find(argv, argc, "no", &idx))
9223 nb_cli_enqueue_change(vty, "./rd", NB_OP_DESTROY, NULL);
9224 else
9225 nb_cli_enqueue_change(vty, "./rd", NB_OP_MODIFY, rd_str);
ddb5b488 9226
37a87b8f
CS
9227 return nb_cli_apply_changes(vty, base_xpath);
9228}
ddb5b488 9229
37a87b8f
CS
9230void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rd(
9231 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9232{
9233 int indent = 2;
69b07479 9234
37a87b8f
CS
9235 vty_out(vty, "%*srd vpn export %s\n", indent, "",
9236 yang_dnode_get_string(dnode, NULL));
ddb5b488
PZ
9237}
9238
b9c7bc5a
PZ
9239ALIAS (af_rd_vpn_export,
9240 af_no_rd_vpn_export_cmd,
9241 "no rd vpn export",
ddb5b488 9242 NO_STR
b9c7bc5a
PZ
9243 "Specify route distinguisher\n"
9244 "Between current address-family and vpn\n"
9245 "For routes leaked from current address-family to vpn\n")
ddb5b488 9246
b9c7bc5a
PZ
9247DEFPY (af_label_vpn_export,
9248 af_label_vpn_export_cmd,
e70e9f8e 9249 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 9250 NO_STR
ddb5b488 9251 "label value for VRF\n"
b9c7bc5a
PZ
9252 "Between current address-family and vpn\n"
9253 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
9254 "Label Value <0-1048575>\n"
9255 "Automatically assign a label\n")
ddb5b488
PZ
9256{
9257 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 9258 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 9259 afi_t afi;
b9c7bc5a 9260 int idx = 0;
c6423c31 9261 bool yes = true;
b9c7bc5a
PZ
9262
9263 if (argv_find(argv, argc, "no", &idx))
c6423c31 9264 yes = false;
ddb5b488 9265
21a16cc2
PZ
9266 /* If "no ...", squash trailing parameter */
9267 if (!yes)
9268 label_auto = NULL;
9269
e70e9f8e
PZ
9270 if (yes) {
9271 if (!label_auto)
9272 label = label_val; /* parser should force unsigned */
9273 }
ddb5b488 9274
0ca70ba5 9275 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9276 if (afi == AFI_MAX)
9277 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 9278
e70e9f8e 9279
69b07479
DS
9280 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9281 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
9282 /* no change */
9283 return CMD_SUCCESS;
e70e9f8e 9284
69b07479
DS
9285 /*
9286 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9287 */
9288 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9289 bgp_get_default(), bgp);
9290
9291 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9292 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
9293
9294 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
9295
9296 /*
9297 * label has previously been automatically
9298 * assigned by labelpool: release it
9299 *
9300 * NB if tovpn_label == MPLS_LABEL_NONE it
9301 * means the automatic assignment is in flight
9302 * and therefore the labelpool callback must
9303 * detect that the auto label is not needed.
9304 */
9305
9306 bgp_lp_release(LP_TYPE_VRF,
9307 &bgp->vpn_policy[afi],
9308 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 9309 }
69b07479
DS
9310 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9311 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9312 }
ddb5b488 9313
69b07479
DS
9314 bgp->vpn_policy[afi].tovpn_label = label;
9315 if (label_auto) {
9316 SET_FLAG(bgp->vpn_policy[afi].flags,
9317 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9318 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
9319 vpn_leak_label_callback);
ddb5b488
PZ
9320 }
9321
69b07479
DS
9322 /* post-change: re-export vpn routes */
9323 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9324 bgp_get_default(), bgp);
9325
0d020cd6 9326 hook_call(bgp_snmp_update_last_changed, bgp);
ddb5b488
PZ
9327 return CMD_SUCCESS;
9328}
9329
b72c9e14
HS
9330DEFPY (af_sid_vpn_export,
9331 af_sid_vpn_export_cmd,
9332 "[no] sid vpn export <(1-255)$sid_idx|auto$sid_auto>",
9333 NO_STR
9334 "sid value for VRF\n"
9335 "Between current address-family and vpn\n"
9336 "For routes leaked from current address-family to vpn\n"
9337 "Sid allocation index\n"
9338 "Automatically assign a label\n")
9339{
9340 VTY_DECLVAR_CONTEXT(bgp, bgp);
9341 afi_t afi;
9342 int debug = 0;
9343 int idx = 0;
9344 bool yes = true;
9345
9346 if (argv_find(argv, argc, "no", &idx))
9347 yes = false;
9348 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
9349 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
9350
9351 afi = vpn_policy_getafi(vty, bgp, false);
9352 if (afi == AFI_MAX)
9353 return CMD_WARNING_CONFIG_FAILED;
9354
9355 if (!yes) {
9356 /* implement me */
9357 vty_out(vty, "It's not implemented");
9358 return CMD_WARNING_CONFIG_FAILED;
9359 }
9360
9361 /* skip when it's already configured */
9362 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9363 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9364 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
9365 return CMD_SUCCESS;
9366
7de4c885
HS
9367 /*
9368 * mode change between sid_idx and sid_auto isn't supported.
9369 * user must negate sid vpn export when they want to change the mode
9370 */
b72c9e14
HS
9371 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9372 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9373 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
9374 vty_out(vty, "it's already configured as %s.\n",
9375 sid_auto ? "auto-mode" : "idx-mode");
9376 return CMD_WARNING_CONFIG_FAILED;
9377 }
9378
9379 /* pre-change */
9380 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9381 bgp_get_default(), bgp);
9382
9383 if (sid_auto) {
9384 /* SID allocation auto-mode */
9385 if (debug)
9386 zlog_debug("%s: auto sid alloc.", __func__);
9387 SET_FLAG(bgp->vpn_policy[afi].flags,
9388 BGP_VPN_POLICY_TOVPN_SID_AUTO);
9389 } else {
9390 /* SID allocation index-mode */
9391 if (debug)
9392 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
9393 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
9394 }
9395
9396 /* post-change */
9397 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9398 bgp_get_default(), bgp);
9399 return CMD_SUCCESS;
9400}
9401
b9c7bc5a
PZ
9402ALIAS (af_label_vpn_export,
9403 af_no_label_vpn_export_cmd,
9404 "no label vpn export",
9405 NO_STR
9406 "label value for VRF\n"
9407 "Between current address-family and vpn\n"
9408 "For routes leaked from current address-family to vpn\n")
ddb5b488 9409
37a87b8f 9410DEFPY_YANG (af_nexthop_vpn_export,
b9c7bc5a 9411 af_nexthop_vpn_export_cmd,
8c85ca28 9412 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
b9c7bc5a 9413 NO_STR
ddb5b488 9414 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
9415 "Between current address-family and vpn\n"
9416 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
9417 "IPv4 prefix\n"
9418 "IPv6 prefix\n")
9419{
37a87b8f 9420 char base_xpath[XPATH_MAXLEN];
ddb5b488 9421 afi_t afi;
37a87b8f
CS
9422 safi_t safi;
9423 int idx = 0;
ddb5b488
PZ
9424 struct prefix p;
9425
8c85ca28
QY
9426 if (!no) {
9427 if (!nexthop_su) {
9428 vty_out(vty, "%% Nexthop required\n");
9429 return CMD_WARNING_CONFIG_FAILED;
9430 }
8c85ca28 9431 if (!sockunion2hostprefix(nexthop_su, &p))
b9c7bc5a
PZ
9432 return CMD_WARNING_CONFIG_FAILED;
9433 }
ddb5b488 9434
37a87b8f
CS
9435 afi = bgp_node_afi(vty);
9436 safi = bgp_node_safi(vty);
ddb5b488 9437
37a87b8f
CS
9438 snprintf(
9439 base_xpath, sizeof(base_xpath),
9440 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9441 yang_afi_safi_value2identity(afi, safi),
9442 bgp_afi_safi_get_container_str(afi, safi));
ddb5b488 9443
37a87b8f
CS
9444 if (argv_find(argv, argc, "no", &idx))
9445 nb_cli_enqueue_change(vty, "./nexthop", NB_OP_DESTROY, NULL);
9446 else
9447 nb_cli_enqueue_change(vty, "./nexthop", NB_OP_MODIFY,
9448 nexthop_su_str);
ddb5b488 9449
37a87b8f
CS
9450 return nb_cli_apply_changes(vty, base_xpath);
9451}
69b07479 9452
37a87b8f
CS
9453void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_nexthop(
9454 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9455{
9456 int indent = 2;
9457
9458 vty_out(vty, "%*snexthop vpn export %s\n", indent, "",
9459 yang_dnode_get_string(dnode, NULL));
ddb5b488
PZ
9460}
9461
b9c7bc5a 9462static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 9463{
b9c7bc5a
PZ
9464 if (!strcmp(dstr, "import")) {
9465 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9466 } else if (!strcmp(dstr, "export")) {
9467 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9468 } else if (!strcmp(dstr, "both")) {
9469 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9470 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9471 } else {
9472 vty_out(vty, "%% direction parse error\n");
9473 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9474 }
ddb5b488
PZ
9475 return CMD_SUCCESS;
9476}
9477
b9c7bc5a
PZ
9478DEFPY (af_rt_vpn_imexport,
9479 af_rt_vpn_imexport_cmd,
9480 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9481 NO_STR
9482 "Specify route target list\n"
ddb5b488 9483 "Specify route target list\n"
b9c7bc5a
PZ
9484 "Between current address-family and vpn\n"
9485 "For routes leaked from vpn to current address-family: match any\n"
9486 "For routes leaked from current address-family to vpn: set\n"
9487 "both import: match any and export: set\n"
ddb5b488
PZ
9488 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9489{
9490 VTY_DECLVAR_CONTEXT(bgp, bgp);
9491 int ret;
9492 struct ecommunity *ecom = NULL;
9493 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
9494 vpn_policy_direction_t dir;
9495 afi_t afi;
9496 int idx = 0;
c6423c31 9497 bool yes = true;
ddb5b488 9498
b9c7bc5a 9499 if (argv_find(argv, argc, "no", &idx))
c6423c31 9500 yes = false;
b9c7bc5a 9501
0ca70ba5 9502 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9503 if (afi == AFI_MAX)
9504 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9505
b9c7bc5a 9506 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
9507 if (ret != CMD_SUCCESS)
9508 return ret;
9509
b9c7bc5a
PZ
9510 if (yes) {
9511 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9512 vty_out(vty, "%% Missing RTLIST\n");
9513 return CMD_WARNING_CONFIG_FAILED;
9514 }
c6423c31 9515 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
b9c7bc5a
PZ
9516 if (ret != CMD_SUCCESS) {
9517 return ret;
9518 }
ddb5b488
PZ
9519 }
9520
69b07479
DS
9521 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9522 if (!dodir[dir])
ddb5b488 9523 continue;
ddb5b488 9524
69b07479 9525 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 9526
69b07479
DS
9527 if (yes) {
9528 if (bgp->vpn_policy[afi].rtlist[dir])
9529 ecommunity_free(
9530 &bgp->vpn_policy[afi].rtlist[dir]);
9531 bgp->vpn_policy[afi].rtlist[dir] =
9532 ecommunity_dup(ecom);
9533 } else {
9534 if (bgp->vpn_policy[afi].rtlist[dir])
9535 ecommunity_free(
9536 &bgp->vpn_policy[afi].rtlist[dir]);
9537 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 9538 }
69b07479
DS
9539
9540 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 9541 }
69b07479 9542
d555f3e9
PZ
9543 if (ecom)
9544 ecommunity_free(&ecom);
ddb5b488
PZ
9545
9546 return CMD_SUCCESS;
9547}
9548
b9c7bc5a
PZ
9549ALIAS (af_rt_vpn_imexport,
9550 af_no_rt_vpn_imexport_cmd,
9551 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
9552 NO_STR
9553 "Specify route target list\n"
b9c7bc5a
PZ
9554 "Specify route target list\n"
9555 "Between current address-family and vpn\n"
9556 "For routes leaked from vpn to current address-family\n"
9557 "For routes leaked from current address-family to vpn\n"
9558 "both import and export\n")
9559
37a87b8f 9560DEFPY_YANG (af_route_map_vpn_imexport,
b9c7bc5a
PZ
9561 af_route_map_vpn_imexport_cmd,
9562/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9563 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9564 NO_STR
ddb5b488 9565 "Specify route map\n"
b9c7bc5a
PZ
9566 "Between current address-family and vpn\n"
9567 "For routes leaked from vpn to current address-family\n"
9568 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
9569 "name of route-map\n")
9570{
37a87b8f 9571 char base_xpath[XPATH_MAXLEN];
ddb5b488 9572 afi_t afi;
37a87b8f 9573 safi_t safi;
ddb5b488 9574 int idx = 0;
ddb5b488 9575
37a87b8f
CS
9576 afi = bgp_node_afi(vty);
9577 safi = bgp_node_safi(vty);
ddb5b488 9578
37a87b8f
CS
9579 snprintf(
9580 base_xpath, sizeof(base_xpath),
9581 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9582 yang_afi_safi_value2identity(afi, safi),
9583 bgp_afi_safi_get_container_str(afi, safi));
9584
9585 if (argv_find(argv, argc, "no", &idx)) {
9586 if (!strcmp(direction_str, "import"))
9587 nb_cli_enqueue_change(vty, "./rmap-import",
9588 NB_OP_DESTROY, NULL);
9589 else if (!strcmp(direction_str, "export"))
9590 nb_cli_enqueue_change(vty, "./rmap-export",
9591 NB_OP_DESTROY, NULL);
9592 } else {
9593 if (!strcmp(direction_str, "import"))
9594 nb_cli_enqueue_change(vty, "./rmap-import",
9595 NB_OP_MODIFY, rmap_str);
9596 if (!strcmp(direction_str, "export"))
9597 nb_cli_enqueue_change(vty, "./rmap-export",
9598 NB_OP_MODIFY, rmap_str);
9599 }
9600 return nb_cli_apply_changes(vty, base_xpath);
9601}
ddb5b488 9602
37a87b8f
CS
9603void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_import(
9604 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9605{
9606 int indent = 2;
ddb5b488 9607
37a87b8f
CS
9608 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
9609 yang_dnode_get_string(dnode, NULL));
9610}
69b07479 9611
37a87b8f
CS
9612void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_export(
9613 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9614{
9615 int indent = 2;
ddb5b488 9616
37a87b8f
CS
9617 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
9618 yang_dnode_get_string(dnode, NULL));
ddb5b488
PZ
9619}
9620
b9c7bc5a
PZ
9621ALIAS (af_route_map_vpn_imexport,
9622 af_no_route_map_vpn_imexport_cmd,
9623 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
9624 NO_STR
9625 "Specify route map\n"
b9c7bc5a
PZ
9626 "Between current address-family and vpn\n"
9627 "For routes leaked from vpn to current address-family\n"
9628 "For routes leaked from current address-family to vpn\n")
9629
bb4f6190 9630DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
ae6a6fb4 9631 "import vrf route-map RMAP$rmap_str",
bb4f6190
DS
9632 "Import routes from another VRF\n"
9633 "Vrf routes being filtered\n"
9634 "Specify route map\n"
9635 "name of route-map\n")
9636{
9637 VTY_DECLVAR_CONTEXT(bgp, bgp);
bb4f6190
DS
9638 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
9639 afi_t afi;
bb4f6190
DS
9640 struct bgp *bgp_default;
9641
0ca70ba5 9642 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
9643 if (afi == AFI_MAX)
9644 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
9645
9646 bgp_default = bgp_get_default();
9647 if (!bgp_default) {
9648 int32_t ret;
9649 as_t as = bgp->as;
9650
9651 /* Auto-create assuming the same AS */
5d5393b9
DL
9652 ret = bgp_get_vty(&bgp_default, &as, NULL,
9653 BGP_INSTANCE_TYPE_DEFAULT);
bb4f6190
DS
9654
9655 if (ret) {
9656 vty_out(vty,
9657 "VRF default is not configured as a bgp instance\n");
9658 return CMD_WARNING;
9659 }
9660 }
9661
69b07479 9662 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 9663
ae6a6fb4
DS
9664 if (bgp->vpn_policy[afi].rmap_name[dir])
9665 XFREE(MTYPE_ROUTE_MAP_NAME,
9666 bgp->vpn_policy[afi].rmap_name[dir]);
9667 bgp->vpn_policy[afi].rmap_name[dir] =
9668 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9669 bgp->vpn_policy[afi].rmap[dir] =
9670 route_map_lookup_warn_noexist(vty, rmap_str);
9671 if (!bgp->vpn_policy[afi].rmap[dir])
9672 return CMD_SUCCESS;
9673
9674 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9675 BGP_CONFIG_VRF_TO_VRF_IMPORT);
bb4f6190 9676
69b07479
DS
9677 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9678
bb4f6190
DS
9679 return CMD_SUCCESS;
9680}
9681
ae6a6fb4
DS
9682DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9683 "no import vrf route-map [RMAP$rmap_str]",
bb4f6190
DS
9684 NO_STR
9685 "Import routes from another VRF\n"
9686 "Vrf routes being filtered\n"
ae6a6fb4
DS
9687 "Specify route map\n"
9688 "name of route-map\n")
9689{
9690 VTY_DECLVAR_CONTEXT(bgp, bgp);
9691 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
9692 afi_t afi;
9693
9694 afi = vpn_policy_getafi(vty, bgp, true);
9695 if (afi == AFI_MAX)
9696 return CMD_WARNING_CONFIG_FAILED;
9697
9698 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9699
9700 if (bgp->vpn_policy[afi].rmap_name[dir])
9701 XFREE(MTYPE_ROUTE_MAP_NAME,
9702 bgp->vpn_policy[afi].rmap_name[dir]);
9703 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9704 bgp->vpn_policy[afi].rmap[dir] = NULL;
9705
9706 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9707 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9708 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9709
9710 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9711
9712 return CMD_SUCCESS;
9713}
bb4f6190 9714
37a87b8f
CS
9715DEFPY_YANG(bgp_imexport_vrf,
9716 bgp_imexport_vrf_cmd,
9717 "[no] import vrf VIEWVRFNAME$import_name",
9718 NO_STR
9719 "Import routes from another VRF\n"
9720 "VRF to import from\n"
9721 "The name of the VRF\n")
12a844a5 9722{
37a87b8f 9723 char base_xpath[XPATH_MAXLEN];
12a844a5
DS
9724 safi_t safi;
9725 afi_t afi;
37a87b8f 9726 int32_t idx = 0;
12a844a5 9727
867f0cca 9728 if (import_name == NULL) {
9729 vty_out(vty, "%% Missing import name\n");
9730 return CMD_WARNING;
9731 }
9732
ae6a6fb4
DS
9733 if (strcmp(import_name, "route-map") == 0) {
9734 vty_out(vty, "%% Must include route-map name\n");
9735 return CMD_WARNING;
9736 }
9737
37a87b8f 9738 afi = bgp_node_afi(vty);
12a844a5
DS
9739 safi = bgp_node_safi(vty);
9740
37a87b8f
CS
9741 snprintf(
9742 base_xpath, sizeof(base_xpath),
9743 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/import-vrf-list[vrf='%s']",
9744 yang_afi_safi_value2identity(afi, safi),
9745 bgp_afi_safi_get_container_str(afi, safi), import_name);
25679caa 9746
37a87b8f
CS
9747 if (argv_find(argv, argc, "no", &idx))
9748 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
9749 else
9750 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
12a844a5 9751
37a87b8f
CS
9752 return nb_cli_apply_changes(vty, base_xpath);
9753}
12a844a5 9754
37a87b8f
CS
9755void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vrfs(
9756 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9757{
9758 vty_out(vty, " import vrf %s\n",
9759 yang_dnode_get_string(dnode, "./vrf"));
12a844a5
DS
9760}
9761
b9c7bc5a 9762/* This command is valid only in a bgp vrf instance or the default instance */
37a87b8f 9763DEFPY_YANG (bgp_imexport_vpn,
b9c7bc5a
PZ
9764 bgp_imexport_vpn_cmd,
9765 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
9766 NO_STR
9767 "Import routes to this address-family\n"
9768 "Export routes from this address-family\n"
9769 "to/from default instance VPN RIB\n")
ddb5b488 9770{
37a87b8f 9771 char base_xpath[XPATH_MAXLEN];
b9c7bc5a 9772 safi_t safi;
37a87b8f
CS
9773 afi_t afi;
9774 int32_t idx = 0;
ddb5b488 9775
b9c7bc5a
PZ
9776 afi = bgp_node_afi(vty);
9777 safi = bgp_node_safi(vty);
ddb5b488 9778
b9c7bc5a 9779 if (!strcmp(direction_str, "import")) {
37a87b8f
CS
9780 snprintf(
9781 base_xpath, sizeof(base_xpath),
9782 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/import-vpn",
9783 yang_afi_safi_value2identity(afi, safi),
9784 bgp_afi_safi_get_container_str(afi, safi));
b9c7bc5a 9785 } else if (!strcmp(direction_str, "export")) {
37a87b8f
CS
9786 snprintf(
9787 base_xpath, sizeof(base_xpath),
9788 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/export-vpn",
9789 yang_afi_safi_value2identity(afi, safi),
9790 bgp_afi_safi_get_container_str(afi, safi));
b9c7bc5a
PZ
9791 } else {
9792 vty_out(vty, "%% unknown direction %s\n", direction_str);
9793 return CMD_WARNING_CONFIG_FAILED;
9794 }
9795
37a87b8f
CS
9796 if (argv_find(argv, argc, "no", &idx))
9797 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
9798 else
9799 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, "true");
ddb5b488 9800
37a87b8f
CS
9801 return nb_cli_apply_changes(vty, base_xpath);
9802}
ddb5b488 9803
37a87b8f
CS
9804void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vpn(
9805 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9806{
9807 if (yang_dnode_get_bool(dnode, NULL))
9808 vty_out(vty, " import vpn\n");
9809}
9810
9811void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_export_vpn(
9812 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9813{
9814 if (yang_dnode_get_bool(dnode, NULL))
9815 vty_out(vty, " export vpn\n");
ddb5b488
PZ
9816}
9817
301ad80a
PG
9818DEFPY (af_routetarget_import,
9819 af_routetarget_import_cmd,
9a659715 9820 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
301ad80a
PG
9821 NO_STR
9822 "Specify route target list\n"
9823 "Specify route target list\n"
9a659715
PG
9824 "Specify route target list\n"
9825 "Specify route target list\n"
301ad80a
PG
9826 "Flow-spec redirect type route target\n"
9827 "Import routes to this address-family\n"
9a659715 9828 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
301ad80a
PG
9829{
9830 VTY_DECLVAR_CONTEXT(bgp, bgp);
9831 int ret;
9832 struct ecommunity *ecom = NULL;
301ad80a 9833 afi_t afi;
9a659715 9834 int idx = 0, idx_unused = 0;
c6423c31
PG
9835 bool yes = true;
9836 bool rt6 = false;
301ad80a
PG
9837
9838 if (argv_find(argv, argc, "no", &idx))
c6423c31 9839 yes = false;
301ad80a 9840
9a659715
PG
9841 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9842 argv_find(argv, argc, "route-target6", &idx_unused))
c6423c31 9843 rt6 = true;
301ad80a 9844
0ca70ba5 9845 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9846 if (afi == AFI_MAX)
9847 return CMD_WARNING_CONFIG_FAILED;
9848
9a659715
PG
9849 if (rt6 && afi != AFI_IP6)
9850 return CMD_WARNING_CONFIG_FAILED;
9851
301ad80a
PG
9852 if (yes) {
9853 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9854 vty_out(vty, "%% Missing RTLIST\n");
9855 return CMD_WARNING_CONFIG_FAILED;
9856 }
9a659715 9857 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
301ad80a
PG
9858 if (ret != CMD_SUCCESS)
9859 return ret;
9860 }
69b07479
DS
9861
9862 if (yes) {
9863 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9864 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9865 .import_redirect_rtlist);
69b07479
DS
9866 bgp->vpn_policy[afi].import_redirect_rtlist =
9867 ecommunity_dup(ecom);
9868 } else {
9869 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9870 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9871 .import_redirect_rtlist);
69b07479 9872 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 9873 }
69b07479 9874
301ad80a
PG
9875 if (ecom)
9876 ecommunity_free(&ecom);
9877
9878 return CMD_SUCCESS;
9879}
9880
37a87b8f
CS
9881void cli_show_bgp_global_afi_safi_header(struct vty *vty,
9882 struct lyd_node *dnode,
9883 bool show_defaults)
9884{
9885 const char *af_name;
9886 afi_t afi;
9887 safi_t safi;
9888
9889 af_name = yang_dnode_get_string(dnode, "./afi-safi-name");
9890 yang_afi_safi_identity2value(af_name, &afi, &safi);
9891
9892 vty_out(vty, " !\n address-family ");
9893 if (afi == AFI_IP) {
9894 if (safi == SAFI_UNICAST)
9895 vty_out(vty, "ipv4 unicast");
9896 else if (safi == SAFI_LABELED_UNICAST)
9897 vty_out(vty, "ipv4 labeled-unicast");
9898 else if (safi == SAFI_MULTICAST)
9899 vty_out(vty, "ipv4 multicast");
9900 else if (safi == SAFI_MPLS_VPN)
9901 vty_out(vty, "ipv4 vpn");
9902 else if (safi == SAFI_ENCAP)
9903 vty_out(vty, "ipv4 encap");
9904 else if (safi == SAFI_FLOWSPEC)
9905 vty_out(vty, "ipv4 flowspec");
9906 } else if (afi == AFI_IP6) {
9907 if (safi == SAFI_UNICAST)
9908 vty_out(vty, "ipv6 unicast");
9909 else if (safi == SAFI_LABELED_UNICAST)
9910 vty_out(vty, "ipv6 labeled-unicast");
9911 else if (safi == SAFI_MULTICAST)
9912 vty_out(vty, "ipv6 multicast");
9913 else if (safi == SAFI_MPLS_VPN)
9914 vty_out(vty, "ipv6 vpn");
9915 else if (safi == SAFI_ENCAP)
9916 vty_out(vty, "ipv6 encap");
9917 else if (safi == SAFI_FLOWSPEC)
9918 vty_out(vty, "ipv6 flowspec");
9919 } else if (afi == AFI_L2VPN) {
9920 if (safi == SAFI_EVPN)
9921 vty_out(vty, "l2vpn evpn");
9922 }
9923 vty_out(vty, "\n");
9924}
9925
505e5056 9926DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 9927 address_family_ipv4_safi_cmd,
9928 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9929 "Enter Address Family command mode\n"
9930 "Address Family\n"
9931 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 9932{
f51bae9c 9933
37a87b8f
CS
9934 safi_t safi = SAFI_UNICAST;
9935 const struct lyd_node *vrf_dnode, *bgp_glb_dnode;
9936 const char *vrf_name = NULL;
9937
d62a17ae 9938 if (argc == 3) {
37a87b8f
CS
9939 safi = bgp_vty_safi_from_str(argv[2]->text);
9940
9941 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
9942 VTY_CURR_XPATH);
9943 vrf_dnode = yang_dnode_get_parent(bgp_glb_dnode,
9944 "control-plane-protocol");
9945 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
9946
9947 if (!strmatch(vrf_name, VRF_DEFAULT_NAME)
a4d82a8a 9948 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9949 && safi != SAFI_EVPN) {
31947174
MK
9950 vty_out(vty,
9951 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9952 return CMD_WARNING_CONFIG_FAILED;
9953 }
37a87b8f
CS
9954 }
9955 vty->node = bgp_node_type(AFI_IP, safi);
718e3744 9956
d62a17ae 9957 return CMD_SUCCESS;
718e3744 9958}
9959
505e5056 9960DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 9961 address_family_ipv6_safi_cmd,
9962 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9963 "Enter Address Family command mode\n"
9964 "Address Family\n"
9965 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 9966{
37a87b8f
CS
9967 safi_t safi = SAFI_UNICAST;
9968 const struct lyd_node *vrf_dnode, *bgp_glb_dnode;
9969 const char *vrf_name = NULL;
9970
d62a17ae 9971 if (argc == 3) {
37a87b8f
CS
9972 safi = bgp_vty_safi_from_str(argv[2]->text);
9973 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
9974 VTY_CURR_XPATH);
9975 vrf_dnode = yang_dnode_get_parent(bgp_glb_dnode,
9976 "control-plane-protocol");
9977 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
9978
9979 if (!strmatch(vrf_name, VRF_DEFAULT_NAME)
a4d82a8a 9980 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9981 && safi != SAFI_EVPN) {
31947174
MK
9982 vty_out(vty,
9983 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9984 return CMD_WARNING_CONFIG_FAILED;
9985 }
37a87b8f
CS
9986 }
9987 vty->node = bgp_node_type(AFI_IP6, safi);
25ffbdc1 9988
d62a17ae 9989 return CMD_SUCCESS;
25ffbdc1 9990}
718e3744 9991
d6902373 9992#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 9993DEFUN_NOSH (address_family_vpnv4,
718e3744 9994 address_family_vpnv4_cmd,
8334fd5a 9995 "address-family vpnv4 [unicast]",
718e3744 9996 "Enter Address Family command mode\n"
8c3deaae 9997 "Address Family\n"
3a2d747c 9998 "Address Family modifier\n")
718e3744 9999{
d62a17ae 10000 vty->node = BGP_VPNV4_NODE;
10001 return CMD_SUCCESS;
718e3744 10002}
10003
505e5056 10004DEFUN_NOSH (address_family_vpnv6,
8ecd3266 10005 address_family_vpnv6_cmd,
8334fd5a 10006 "address-family vpnv6 [unicast]",
8ecd3266 10007 "Enter Address Family command mode\n"
8c3deaae 10008 "Address Family\n"
3a2d747c 10009 "Address Family modifier\n")
8ecd3266 10010{
d62a17ae 10011 vty->node = BGP_VPNV6_NODE;
10012 return CMD_SUCCESS;
8ecd3266 10013}
64e4a6c5 10014#endif /* KEEP_OLD_VPN_COMMANDS */
d6902373 10015
505e5056 10016DEFUN_NOSH (address_family_evpn,
4e0b7b6d 10017 address_family_evpn_cmd,
7111c1a0 10018 "address-family l2vpn evpn",
4e0b7b6d 10019 "Enter Address Family command mode\n"
7111c1a0
QY
10020 "Address Family\n"
10021 "Address Family modifier\n")
4e0b7b6d 10022{
2131d5cf 10023 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 10024 vty->node = BGP_EVPN_NODE;
10025 return CMD_SUCCESS;
4e0b7b6d
PG
10026}
10027
bfaab44d
HS
10028DEFUN_NOSH (bgp_segment_routing_srv6,
10029 bgp_segment_routing_srv6_cmd,
10030 "segment-routing srv6",
10031 "Segment-Routing configuration\n"
10032 "Segment-Routing SRv6 configuration\n")
10033{
10034 VTY_DECLVAR_CONTEXT(bgp, bgp);
92a9e6f2 10035 bgp->srv6_enabled = true;
bfaab44d
HS
10036 vty->node = BGP_SRV6_NODE;
10037 return CMD_SUCCESS;
10038}
10039
a0281b2e
HS
10040DEFPY (bgp_srv6_locator,
10041 bgp_srv6_locator_cmd,
10042 "locator NAME$name",
10043 "Specify SRv6 locator\n"
10044 "Specify SRv6 locator\n")
10045{
10046 VTY_DECLVAR_CONTEXT(bgp, bgp);
7de4c885 10047 int ret;
a0281b2e
HS
10048
10049 if (strlen(bgp->srv6_locator_name) > 0
10050 && strcmp(name, bgp->srv6_locator_name) != 0) {
10051 vty_out(vty, "srv6 locator is already configured\n");
10052 return CMD_WARNING_CONFIG_FAILED;
7de4c885
HS
10053 }
10054
10055 snprintf(bgp->srv6_locator_name,
10056 sizeof(bgp->srv6_locator_name), "%s", name);
a0281b2e 10057
7de4c885 10058 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
a0281b2e
HS
10059 if (ret < 0)
10060 return CMD_WARNING_CONFIG_FAILED;
10061
10062 return CMD_SUCCESS;
10063}
10064
ea372e81
HS
10065DEFPY (show_bgp_srv6,
10066 show_bgp_srv6_cmd,
10067 "show bgp segment-routing srv6",
10068 SHOW_STR
10069 BGP_STR
10070 "BGP Segment Routing\n"
10071 "BGP Segment Routing SRv6\n")
10072{
10073 struct bgp *bgp;
10074 struct listnode *node;
10075 struct prefix_ipv6 *chunk;
10076 struct bgp_srv6_function *func;
10077 struct in6_addr *tovpn4_sid;
10078 struct in6_addr *tovpn6_sid;
10079 char buf[256];
10080 char buf_tovpn4_sid[256];
10081 char buf_tovpn6_sid[256];
10082
10083 bgp = bgp_get_default();
96db4340 10084 if (!bgp)
ea372e81
HS
10085 return CMD_SUCCESS;
10086
10087 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
10088 vty_out(vty, "locator_chunks:\n");
10089 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk)) {
10090 prefix2str(chunk, buf, sizeof(buf));
10091 vty_out(vty, "- %s\n", buf);
10092 }
10093
10094 vty_out(vty, "functions:\n");
10095 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
10096 inet_ntop(AF_INET6, &func->sid, buf, sizeof(buf));
10097 vty_out(vty, "- sid: %s\n", buf);
10098 vty_out(vty, " locator: %s\n", func->locator_name);
10099 }
10100
10101 vty_out(vty, "bgps:\n");
10102 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
10103 vty_out(vty, "- name: %s\n",
10104 bgp->name ? bgp->name : "default");
10105
10106 tovpn4_sid = bgp->vpn_policy[AFI_IP].tovpn_sid;
10107 tovpn6_sid = bgp->vpn_policy[AFI_IP6].tovpn_sid;
10108 if (tovpn4_sid)
10109 inet_ntop(AF_INET6, tovpn4_sid, buf_tovpn4_sid,
10110 sizeof(buf_tovpn4_sid));
10111 if (tovpn6_sid)
10112 inet_ntop(AF_INET6, tovpn6_sid, buf_tovpn6_sid,
10113 sizeof(buf_tovpn6_sid));
10114
10115 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %s\n",
10116 tovpn4_sid ? buf_tovpn4_sid : "none");
10117 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %s\n",
10118 tovpn6_sid ? buf_tovpn6_sid : "none");
10119 }
10120
10121 return CMD_SUCCESS;
10122}
10123
505e5056 10124DEFUN_NOSH (exit_address_family,
718e3744 10125 exit_address_family_cmd,
10126 "exit-address-family",
10127 "Exit from Address Family configuration mode\n")
10128{
d62a17ae 10129 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
10130 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
10131 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
10132 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
10133 || vty->node == BGP_EVPN_NODE
10134 || vty->node == BGP_FLOWSPECV4_NODE
10135 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 10136 vty->node = BGP_NODE;
10137 return CMD_SUCCESS;
718e3744 10138}
6b0655a2 10139
37a87b8f
CS
10140void cli_show_bgp_global_afi_safi_header_end(struct vty *vty,
10141 struct lyd_node *dnode
10142 __attribute__((__unused__)))
10143{
10144 vty_out(vty, " exit-address-family\n");
10145}
10146
8ad7271d 10147/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 10148static int bgp_clear_prefix(struct vty *vty, const char *view_name,
10149 const char *ip_str, afi_t afi, safi_t safi,
10150 struct prefix_rd *prd)
10151{
10152 int ret;
10153 struct prefix match;
9bcb3eef
DS
10154 struct bgp_dest *dest;
10155 struct bgp_dest *rm;
d62a17ae 10156 struct bgp *bgp;
10157 struct bgp_table *table;
10158 struct bgp_table *rib;
10159
10160 /* BGP structure lookup. */
10161 if (view_name) {
10162 bgp = bgp_lookup_by_name(view_name);
10163 if (bgp == NULL) {
10164 vty_out(vty, "%% Can't find BGP instance %s\n",
10165 view_name);
10166 return CMD_WARNING;
10167 }
10168 } else {
10169 bgp = bgp_get_default();
10170 if (bgp == NULL) {
10171 vty_out(vty, "%% No BGP process is configured\n");
10172 return CMD_WARNING;
10173 }
10174 }
10175
10176 /* Check IP address argument. */
10177 ret = str2prefix(ip_str, &match);
10178 if (!ret) {
10179 vty_out(vty, "%% address is malformed\n");
10180 return CMD_WARNING;
10181 }
10182
10183 match.family = afi2family(afi);
10184 rib = bgp->rib[afi][safi];
10185
10186 if (safi == SAFI_MPLS_VPN) {
9bcb3eef
DS
10187 for (dest = bgp_table_top(rib); dest;
10188 dest = bgp_route_next(dest)) {
10189 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 10190
9bcb3eef 10191 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
d62a17ae 10192 continue;
10193
9bcb3eef 10194 table = bgp_dest_get_bgp_table_info(dest);
b54892e0
DS
10195 if (table == NULL)
10196 continue;
10197
4953391b
DA
10198 rm = bgp_node_match(table, &match);
10199 if (rm != NULL) {
b54892e0 10200 const struct prefix *rm_p =
9bcb3eef 10201 bgp_dest_get_prefix(rm);
b54892e0
DS
10202
10203 if (rm_p->prefixlen == match.prefixlen) {
10204 SET_FLAG(rm->flags,
10205 BGP_NODE_USER_CLEAR);
10206 bgp_process(bgp, rm, afi, safi);
d62a17ae 10207 }
9bcb3eef 10208 bgp_dest_unlock_node(rm);
d62a17ae 10209 }
10210 }
10211 } else {
4953391b
DA
10212 dest = bgp_node_match(rib, &match);
10213 if (dest != NULL) {
9bcb3eef 10214 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 10215
9bcb3eef
DS
10216 if (dest_p->prefixlen == match.prefixlen) {
10217 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
10218 bgp_process(bgp, dest, afi, safi);
d62a17ae 10219 }
9bcb3eef 10220 bgp_dest_unlock_node(dest);
d62a17ae 10221 }
10222 }
10223
10224 return CMD_SUCCESS;
8ad7271d
DS
10225}
10226
b09b5ae0 10227/* one clear bgp command to rule them all */
718e3744 10228DEFUN (clear_ip_bgp_all,
10229 clear_ip_bgp_all_cmd,
453c92f6 10230 "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>]",
718e3744 10231 CLEAR_STR
10232 IP_STR
10233 BGP_STR
838758ac 10234 BGP_INSTANCE_HELP_STR
510afcd6 10235 BGP_AFI_HELP_STR
fd5e7b70 10236 "Address Family\n"
510afcd6 10237 BGP_SAFI_WITH_LABEL_HELP_STR
fd5e7b70 10238 "Address Family modifier\n"
b09b5ae0 10239 "Clear all peers\n"
453c92f6 10240 "BGP IPv4 neighbor to clear\n"
a80beece 10241 "BGP IPv6 neighbor to clear\n"
838758ac 10242 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
10243 "Clear peers with the AS number\n"
10244 "Clear all external peers\n"
718e3744 10245 "Clear all members of peer-group\n"
b09b5ae0 10246 "BGP peer-group name\n"
b09b5ae0
DW
10247 BGP_SOFT_STR
10248 BGP_SOFT_IN_STR
b09b5ae0
DW
10249 BGP_SOFT_OUT_STR
10250 BGP_SOFT_IN_STR
10251 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 10252 BGP_SOFT_OUT_STR)
718e3744 10253{
d62a17ae 10254 char *vrf = NULL;
10255
dc912615
DS
10256 afi_t afi = AFI_UNSPEC;
10257 safi_t safi = SAFI_UNSPEC;
d62a17ae 10258 enum clear_sort clr_sort = clear_peer;
10259 enum bgp_clear_type clr_type;
10260 char *clr_arg = NULL;
10261
10262 int idx = 0;
ff8a8a7a
CS
10263 char errmsg[BUFSIZ] = {'\0'};
10264 int ret;
d62a17ae 10265
10266 /* clear [ip] bgp */
10267 if (argv_find(argv, argc, "ip", &idx))
10268 afi = AFI_IP;
10269
9a8bdf1c
PG
10270 /* [<vrf> VIEWVRFNAME] */
10271 if (argv_find(argv, argc, "vrf", &idx)) {
10272 vrf = argv[idx + 1]->arg;
10273 idx += 2;
10274 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10275 vrf = NULL;
10276 } else if (argv_find(argv, argc, "view", &idx)) {
10277 /* [<view> VIEWVRFNAME] */
d62a17ae 10278 vrf = argv[idx + 1]->arg;
10279 idx += 2;
10280 }
d62a17ae 10281 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
10282 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
10283 argv_find_and_parse_safi(argv, argc, &idx, &safi);
10284
d7b9898c 10285 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
d62a17ae 10286 if (argv_find(argv, argc, "*", &idx)) {
10287 clr_sort = clear_all;
10288 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
10289 clr_sort = clear_peer;
10290 clr_arg = argv[idx]->arg;
10291 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
10292 clr_sort = clear_peer;
10293 clr_arg = argv[idx]->arg;
10294 } else if (argv_find(argv, argc, "peer-group", &idx)) {
10295 clr_sort = clear_group;
10296 idx++;
10297 clr_arg = argv[idx]->arg;
d7b9898c 10298 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
d62a17ae 10299 clr_sort = clear_peer;
10300 clr_arg = argv[idx]->arg;
8fa7d444
DS
10301 } else if (argv_find(argv, argc, "WORD", &idx)) {
10302 clr_sort = clear_peer;
10303 clr_arg = argv[idx]->arg;
d62a17ae 10304 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
10305 clr_sort = clear_as;
10306 clr_arg = argv[idx]->arg;
10307 } else if (argv_find(argv, argc, "external", &idx)) {
10308 clr_sort = clear_external;
10309 }
10310
10311 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
10312 if (argv_find(argv, argc, "soft", &idx)) {
10313 if (argv_find(argv, argc, "in", &idx)
10314 || argv_find(argv, argc, "out", &idx))
10315 clr_type = strmatch(argv[idx]->text, "in")
10316 ? BGP_CLEAR_SOFT_IN
10317 : BGP_CLEAR_SOFT_OUT;
10318 else
10319 clr_type = BGP_CLEAR_SOFT_BOTH;
10320 } else if (argv_find(argv, argc, "in", &idx)) {
10321 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
10322 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
10323 : BGP_CLEAR_SOFT_IN;
10324 } else if (argv_find(argv, argc, "out", &idx)) {
10325 clr_type = BGP_CLEAR_SOFT_OUT;
10326 } else
10327 clr_type = BGP_CLEAR_SOFT_NONE;
10328
ff8a8a7a
CS
10329 ret = bgp_clear_vty(vrf, afi, safi, clr_sort, clr_type, clr_arg, errmsg,
10330 sizeof(errmsg));
10331 if (ret != NB_OK)
10332 vty_out(vty, "Error description: %s\n", errmsg);
10333
10334 return ret;
838758ac 10335}
01080f7c 10336
8ad7271d
DS
10337DEFUN (clear_ip_bgp_prefix,
10338 clear_ip_bgp_prefix_cmd,
18c57037 10339 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
10340 CLEAR_STR
10341 IP_STR
10342 BGP_STR
838758ac 10343 BGP_INSTANCE_HELP_STR
8ad7271d 10344 "Clear bestpath and re-advertise\n"
0c7b1b01 10345 "IPv4 prefix\n")
8ad7271d 10346{
d62a17ae 10347 char *vrf = NULL;
10348 char *prefix = NULL;
8ad7271d 10349
d62a17ae 10350 int idx = 0;
01080f7c 10351
d62a17ae 10352 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
10353 if (argv_find(argv, argc, "vrf", &idx)) {
10354 vrf = argv[idx + 1]->arg;
10355 idx += 2;
10356 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10357 vrf = NULL;
10358 } else if (argv_find(argv, argc, "view", &idx)) {
10359 /* [<view> VIEWVRFNAME] */
10360 vrf = argv[idx + 1]->arg;
10361 idx += 2;
10362 }
0c7b1b01 10363
d62a17ae 10364 prefix = argv[argc - 1]->arg;
8ad7271d 10365
d62a17ae 10366 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 10367}
8ad7271d 10368
b09b5ae0
DW
10369DEFUN (clear_bgp_ipv6_safi_prefix,
10370 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 10371 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 10372 CLEAR_STR
3a2d747c 10373 IP_STR
718e3744 10374 BGP_STR
8c3deaae 10375 "Address Family\n"
46f296b4 10376 BGP_SAFI_HELP_STR
b09b5ae0 10377 "Clear bestpath and re-advertise\n"
0c7b1b01 10378 "IPv6 prefix\n")
718e3744 10379{
9b475e76
PG
10380 int idx_safi = 0;
10381 int idx_ipv6_prefix = 0;
10382 safi_t safi = SAFI_UNICAST;
10383 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10384 argv[idx_ipv6_prefix]->arg : NULL;
10385
10386 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 10387 return bgp_clear_prefix(
9b475e76
PG
10388 vty, NULL, prefix, AFI_IP6,
10389 safi, NULL);
838758ac 10390}
01080f7c 10391
b09b5ae0
DW
10392DEFUN (clear_bgp_instance_ipv6_safi_prefix,
10393 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 10394 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 10395 CLEAR_STR
3a2d747c 10396 IP_STR
718e3744 10397 BGP_STR
838758ac 10398 BGP_INSTANCE_HELP_STR
8c3deaae 10399 "Address Family\n"
46f296b4 10400 BGP_SAFI_HELP_STR
b09b5ae0 10401 "Clear bestpath and re-advertise\n"
0c7b1b01 10402 "IPv6 prefix\n")
718e3744 10403{
9b475e76 10404 int idx_safi = 0;
9a8bdf1c 10405 int idx_vrfview = 0;
9b475e76
PG
10406 int idx_ipv6_prefix = 0;
10407 safi_t safi = SAFI_UNICAST;
10408 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10409 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 10410 char *vrfview = NULL;
9b475e76 10411
9a8bdf1c
PG
10412 /* [<view|vrf> VIEWVRFNAME] */
10413 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
10414 vrfview = argv[idx_vrfview + 1]->arg;
10415 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
10416 vrfview = NULL;
10417 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
10418 /* [<view> VIEWVRFNAME] */
10419 vrfview = argv[idx_vrfview + 1]->arg;
10420 }
9b475e76
PG
10421 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10422
d62a17ae 10423 return bgp_clear_prefix(
9b475e76
PG
10424 vty, vrfview, prefix,
10425 AFI_IP6, safi, NULL);
718e3744 10426}
10427
b09b5ae0
DW
10428DEFUN (show_bgp_views,
10429 show_bgp_views_cmd,
d6e3c605 10430 "show [ip] bgp views",
b09b5ae0 10431 SHOW_STR
d6e3c605 10432 IP_STR
01080f7c 10433 BGP_STR
b09b5ae0 10434 "Show the defined BGP views\n")
01080f7c 10435{
d62a17ae 10436 struct list *inst = bm->bgp;
10437 struct listnode *node;
10438 struct bgp *bgp;
01080f7c 10439
d62a17ae 10440 vty_out(vty, "Defined BGP views:\n");
10441 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10442 /* Skip VRFs. */
10443 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
10444 continue;
10445 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
10446 bgp->as);
10447 }
e52702f2 10448
d62a17ae 10449 return CMD_SUCCESS;
e0081f70
ML
10450}
10451
8386ac43 10452DEFUN (show_bgp_vrfs,
10453 show_bgp_vrfs_cmd,
d6e3c605 10454 "show [ip] bgp vrfs [json]",
8386ac43 10455 SHOW_STR
d6e3c605 10456 IP_STR
8386ac43 10457 BGP_STR
10458 "Show BGP VRFs\n"
9973d184 10459 JSON_STR)
8386ac43 10460{
fe1dc5a3 10461 char buf[ETHER_ADDR_STRLEN];
d62a17ae 10462 struct list *inst = bm->bgp;
10463 struct listnode *node;
10464 struct bgp *bgp;
9f049418 10465 bool uj = use_json(argc, argv);
d62a17ae 10466 json_object *json = NULL;
10467 json_object *json_vrfs = NULL;
10468 int count = 0;
d62a17ae 10469
d62a17ae 10470 if (uj) {
10471 json = json_object_new_object();
10472 json_vrfs = json_object_new_object();
10473 }
10474
10475 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10476 const char *name, *type;
10477 struct peer *peer;
7fe96307 10478 struct listnode *node2, *nnode2;
d62a17ae 10479 int peers_cfg, peers_estb;
10480 json_object *json_vrf = NULL;
d62a17ae 10481
10482 /* Skip Views. */
10483 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
10484 continue;
10485
10486 count++;
efb4077a 10487 if (!uj && count == 1) {
fe1dc5a3 10488 vty_out(vty,
efb4077a 10489 "%4s %-5s %-16s %9s %10s %-37s\n",
3c0e7aa4 10490 "Type", "Id", "routerId", "#PeersCfg",
efb4077a
CS
10491 "#PeersEstb", "Name");
10492 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
10493 "L3-VNI", "RouterMAC", "Interface");
10494 }
d62a17ae 10495
10496 peers_cfg = peers_estb = 0;
10497 if (uj)
10498 json_vrf = json_object_new_object();
10499
10500
7fe96307 10501 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
d62a17ae 10502 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10503 continue;
10504 peers_cfg++;
feb17238 10505 if (peer_established(peer))
d62a17ae 10506 peers_estb++;
10507 }
10508
10509 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
5742e42b 10510 name = VRF_DEFAULT_NAME;
d62a17ae 10511 type = "DFLT";
10512 } else {
10513 name = bgp->name;
10514 type = "VRF";
10515 }
10516
a8bf7d9c 10517
d62a17ae 10518 if (uj) {
a4d82a8a
PZ
10519 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10520 ? -1
10521 : (int64_t)bgp->vrf_id;
23d0a753
DA
10522 char buf[BUFSIZ] = {0};
10523
d62a17ae 10524 json_object_string_add(json_vrf, "type", type);
10525 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
10526 json_object_string_add(json_vrf, "routerId",
23d0a753
DA
10527 inet_ntop(AF_INET,
10528 &bgp->router_id, buf,
10529 sizeof(buf)));
d62a17ae 10530 json_object_int_add(json_vrf, "numConfiguredPeers",
10531 peers_cfg);
10532 json_object_int_add(json_vrf, "numEstablishedPeers",
10533 peers_estb);
10534
fe1dc5a3 10535 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
10536 json_object_string_add(
10537 json_vrf, "rmac",
10538 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
efb4077a
CS
10539 json_object_string_add(json_vrf, "interface",
10540 ifindex2ifname(bgp->l3vni_svi_ifindex,
10541 bgp->vrf_id));
d62a17ae 10542 json_object_object_add(json_vrfs, name, json_vrf);
efb4077a 10543 } else {
23d0a753 10544 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
a4d82a8a
PZ
10545 type,
10546 bgp->vrf_id == VRF_UNKNOWN ? -1
10547 : (int)bgp->vrf_id,
23d0a753 10548 &bgp->router_id, peers_cfg, peers_estb, name);
efb4077a
CS
10549 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
10550 bgp->l3vni,
10551 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
10552 ifindex2ifname(bgp->l3vni_svi_ifindex,
10553 bgp->vrf_id));
10554 }
d62a17ae 10555 }
10556
10557 if (uj) {
10558 json_object_object_add(json, "vrfs", json_vrfs);
10559
10560 json_object_int_add(json, "totalVrfs", count);
10561
996c9314
LB
10562 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10563 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 10564 json_object_free(json);
10565 } else {
10566 if (count)
10567 vty_out(vty,
10568 "\nTotal number of VRFs (including default): %d\n",
10569 count);
10570 }
10571
10572 return CMD_SUCCESS;
8386ac43 10573}
10574
48ecf8f5
DS
10575DEFUN (show_bgp_mac_hash,
10576 show_bgp_mac_hash_cmd,
10577 "show bgp mac hash",
10578 SHOW_STR
10579 BGP_STR
10580 "Mac Address\n"
10581 "Mac Address database\n")
10582{
10583 bgp_mac_dump_table(vty);
10584
10585 return CMD_SUCCESS;
10586}
acf71666 10587
e3b78da8 10588static void show_tip_entry(struct hash_bucket *bucket, void *args)
acf71666 10589{
0291c246 10590 struct vty *vty = (struct vty *)args;
e3b78da8 10591 struct tip_addr *tip = (struct tip_addr *)bucket->data;
acf71666 10592
23d0a753 10593 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
acf71666
MK
10594}
10595
10596static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10597{
10598 vty_out(vty, "self nexthop database:\n");
af97a18b 10599 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
10600
10601 vty_out(vty, "Tunnel-ip database:\n");
10602 hash_iterate(bgp->tip_hash,
e3b78da8 10603 (void (*)(struct hash_bucket *, void *))show_tip_entry,
acf71666
MK
10604 vty);
10605}
10606
15c81ca4
DS
10607DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10608 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10609 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
10610 "martian next-hops\n"
10611 "martian next-hop database\n")
acf71666 10612{
0291c246 10613 struct bgp *bgp = NULL;
15c81ca4 10614 int idx = 0;
9a8bdf1c
PG
10615 char *name = NULL;
10616
10617 /* [<vrf> VIEWVRFNAME] */
10618 if (argv_find(argv, argc, "vrf", &idx)) {
10619 name = argv[idx + 1]->arg;
10620 if (name && strmatch(name, VRF_DEFAULT_NAME))
10621 name = NULL;
10622 } else if (argv_find(argv, argc, "view", &idx))
10623 /* [<view> VIEWVRFNAME] */
10624 name = argv[idx + 1]->arg;
10625 if (name)
10626 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
10627 else
10628 bgp = bgp_get_default();
acf71666 10629
acf71666
MK
10630 if (!bgp) {
10631 vty_out(vty, "%% No BGP process is configured\n");
10632 return CMD_WARNING;
10633 }
10634 bgp_show_martian_nexthops(vty, bgp);
10635
10636 return CMD_SUCCESS;
10637}
10638
f412b39a 10639DEFUN (show_bgp_memory,
4bf6a362 10640 show_bgp_memory_cmd,
7fa12b13 10641 "show [ip] bgp memory",
4bf6a362 10642 SHOW_STR
3a2d747c 10643 IP_STR
4bf6a362
PJ
10644 BGP_STR
10645 "Global BGP memory statistics\n")
10646{
d62a17ae 10647 char memstrbuf[MTYPE_MEMSTR_LEN];
10648 unsigned long count;
10649
10650 /* RIB related usage stats */
10651 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10652 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10653 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9bcb3eef 10654 count * sizeof(struct bgp_dest)));
d62a17ae 10655
10656 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10657 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10658 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 10659 count * sizeof(struct bgp_path_info)));
d62a17ae 10660 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10661 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10662 count,
4b7e6066
DS
10663 mtype_memstr(
10664 memstrbuf, sizeof(memstrbuf),
10665 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 10666
10667 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10668 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10669 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10670 count * sizeof(struct bgp_static)));
10671
10672 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10673 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10674 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10675 count * sizeof(struct bpacket)));
10676
10677 /* Adj-In/Out */
10678 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10679 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10680 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10681 count * sizeof(struct bgp_adj_in)));
10682 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10683 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10684 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10685 count * sizeof(struct bgp_adj_out)));
10686
10687 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10688 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10689 count,
10690 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10691 count * sizeof(struct bgp_nexthop_cache)));
10692
10693 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10694 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10695 count,
10696 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10697 count * sizeof(struct bgp_damp_info)));
10698
10699 /* Attributes */
10700 count = attr_count();
10701 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10702 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10703 count * sizeof(struct attr)));
10704
10705 if ((count = attr_unknown_count()))
10706 vty_out(vty, "%ld unknown attributes\n", count);
10707
10708 /* AS_PATH attributes */
10709 count = aspath_count();
10710 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10711 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10712 count * sizeof(struct aspath)));
10713
10714 count = mtype_stats_alloc(MTYPE_AS_SEG);
10715 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10716 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10717 count * sizeof(struct assegment)));
10718
10719 /* Other attributes */
10720 if ((count = community_count()))
10721 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
10722 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10723 count * sizeof(struct community)));
d62a17ae 10724 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
10725 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
10726 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10727 count * sizeof(struct ecommunity)));
d62a17ae 10728 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10729 vty_out(vty,
10730 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
10731 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10732 count * sizeof(struct lcommunity)));
d62a17ae 10733
10734 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10735 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10736 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10737 count * sizeof(struct cluster_list)));
10738
10739 /* Peer related usage */
10740 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10741 vty_out(vty, "%ld peers, using %s of memory\n", count,
10742 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10743 count * sizeof(struct peer)));
10744
10745 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10746 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10747 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10748 count * sizeof(struct peer_group)));
10749
10750 /* Other */
d62a17ae 10751 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10752 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
10753 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10754 count * sizeof(regex_t)));
d62a17ae 10755 return CMD_SUCCESS;
4bf6a362 10756}
fee0f4c6 10757
57a9c8a8
DS
10758static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10759{
10760 json_object *bestpath = json_object_new_object();
10761
892fedb6 10762 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
57a9c8a8
DS
10763 json_object_string_add(bestpath, "asPath", "ignore");
10764
892fedb6 10765 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
57a9c8a8
DS
10766 json_object_string_add(bestpath, "asPath", "confed");
10767
892fedb6
DA
10768 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10769 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
a4d82a8a 10770 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
10771 "as-set");
10772 else
a4d82a8a 10773 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
10774 "true");
10775 } else
a4d82a8a 10776 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8 10777
ee88563a
JM
10778 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
10779 json_object_boolean_true_add(bestpath, "peerTypeRelax");
10780
892fedb6 10781 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
57a9c8a8 10782 json_object_string_add(bestpath, "compareRouterId", "true");
892fedb6
DA
10783 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10784 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10785 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
a4d82a8a 10786 json_object_string_add(bestpath, "med", "confed");
892fedb6 10787 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
57a9c8a8
DS
10788 json_object_string_add(bestpath, "med",
10789 "missing-as-worst");
10790 else
10791 json_object_string_add(bestpath, "med", "true");
10792 }
10793
10794 json_object_object_add(json, "bestPath", bestpath);
10795}
10796
3577f1c5
DD
10797/* Print the error code/subcode for why the peer is down */
10798static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10799 json_object *json_peer, bool use_json)
10800{
10801 const char *code_str;
10802 const char *subcode_str;
10803
10804 if (use_json) {
10805 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10806 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10807 char errorcodesubcode_hexstr[5];
10808 char errorcodesubcode_str[256];
10809
10810 code_str = bgp_notify_code_str(peer->notify.code);
10811 subcode_str = bgp_notify_subcode_str(
10812 peer->notify.code,
10813 peer->notify.subcode);
10814
772270f3
QY
10815 snprintf(errorcodesubcode_hexstr,
10816 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10817 peer->notify.code, peer->notify.subcode);
3577f1c5
DD
10818 json_object_string_add(json_peer,
10819 "lastErrorCodeSubcode",
10820 errorcodesubcode_hexstr);
10821 snprintf(errorcodesubcode_str, 255, "%s%s",
10822 code_str, subcode_str);
10823 json_object_string_add(json_peer,
10824 "lastNotificationReason",
10825 errorcodesubcode_str);
10826 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10827 && peer->notify.code == BGP_NOTIFY_CEASE
10828 && (peer->notify.subcode
10829 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10830 || peer->notify.subcode
10831 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10832 && peer->notify.length) {
10833 char msgbuf[1024];
10834 const char *msg_str;
10835
10836 msg_str = bgp_notify_admin_message(
10837 msgbuf, sizeof(msgbuf),
10838 (uint8_t *)peer->notify.data,
10839 peer->notify.length);
10840 if (msg_str)
10841 json_object_string_add(
10842 json_peer,
10843 "lastShutdownDescription",
10844 msg_str);
10845 }
10846
c258527b 10847 }
3577f1c5
DD
10848 json_object_string_add(json_peer, "lastResetDueTo",
10849 peer_down_str[(int)peer->last_reset]);
05912a17
DD
10850 json_object_int_add(json_peer, "lastResetCode",
10851 peer->last_reset);
3577f1c5
DD
10852 } else {
10853 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10854 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10855 code_str = bgp_notify_code_str(peer->notify.code);
10856 subcode_str =
10857 bgp_notify_subcode_str(peer->notify.code,
10858 peer->notify.subcode);
10859 vty_out(vty, " Notification %s (%s%s)\n",
10860 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10861 ? "sent"
10862 : "received",
10863 code_str, subcode_str);
10864 } else {
e91c24c8 10865 vty_out(vty, " %s\n",
3577f1c5
DD
10866 peer_down_str[(int)peer->last_reset]);
10867 }
10868 }
10869}
10870
10871static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10872 safi_t safi)
10873{
feb17238 10874 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
3577f1c5
DD
10875}
10876
10877static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10878 struct peer *peer, json_object *json_peer,
10879 int max_neighbor_width, bool use_json)
10880{
10881 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10882 int len;
10883
10884 if (use_json) {
10885 if (peer_dynamic_neighbor(peer))
10886 json_object_boolean_true_add(json_peer,
10887 "dynamicPeer");
10888 if (peer->hostname)
10889 json_object_string_add(json_peer, "hostname",
10890 peer->hostname);
10891
10892 if (peer->domainname)
10893 json_object_string_add(json_peer, "domainname",
10894 peer->domainname);
10895 json_object_int_add(json_peer, "connectionsEstablished",
10896 peer->established);
10897 json_object_int_add(json_peer, "connectionsDropped",
10898 peer->dropped);
10899 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10900 use_json, json_peer);
feb17238 10901 if (peer_established(peer))
3577f1c5
DD
10902 json_object_string_add(json_peer, "lastResetDueTo",
10903 "AFI/SAFI Not Negotiated");
10904 else
10905 bgp_show_peer_reset(NULL, peer, json_peer, true);
10906 } else {
10907 dn_flag[1] = '\0';
10908 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10909 if (peer->hostname
892fedb6 10910 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
3577f1c5
DD
10911 len = vty_out(vty, "%s%s(%s)", dn_flag,
10912 peer->hostname, peer->host);
10913 else
10914 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10915
10916 /* pad the neighbor column with spaces */
10917 if (len < max_neighbor_width)
10918 vty_out(vty, "%*s", max_neighbor_width - len,
10919 " ");
e91c24c8 10920 vty_out(vty, "%7d %7d %9s", peer->established,
3577f1c5
DD
10921 peer->dropped,
10922 peer_uptime(peer->uptime, timebuf,
10923 BGP_UPTIME_LEN, 0, NULL));
feb17238 10924 if (peer_established(peer))
3577f1c5
DD
10925 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10926 else
10927 bgp_show_peer_reset(vty, peer, NULL,
10928 false);
10929 }
10930}
c258527b 10931
cb75bb31
DA
10932/* If the peer's description includes whitespaces
10933 * then return the first occurrence. Also strip description
10934 * to the given size if needed.
10935 */
10936static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10937{
10938 static char stripped[BUFSIZ];
10939 char *pnt;
10940 uint32_t len = size > strlen(desc) ? strlen(desc) : size;
10941
10942 pnt = strchr(desc, ' ');
10943 if (pnt)
10944 len = size > (uint32_t)(pnt - desc) ? (uint32_t)(pnt - desc)
10945 : size;
10946
10947 strlcpy(stripped, desc, len + 1);
10948
10949 return stripped;
10950}
3577f1c5 10951
8c1d4cd5
LS
10952/* Determine whether var peer should be filtered out of the summary. */
10953static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
10954 struct peer *fpeer, int as_type,
10955 as_t as)
10956{
10957
10958 /* filter neighbor XXXX */
10959 if (fpeer && fpeer != peer)
10960 return true;
10961
10962 /* filter remote-as (internal|external) */
10963 if (as_type != AS_UNSPECIFIED) {
10964 if (peer->as_type == AS_SPECIFIED) {
10965 if (as_type == AS_INTERNAL) {
10966 if (peer->as != peer->local_as)
10967 return true;
10968 } else if (peer->as == peer->local_as)
10969 return true;
10970 } else if (as_type != peer->as_type)
10971 return true;
10972 } else if (as && as != peer->as) /* filter remote-as XXX */
10973 return true;
10974
10975 return false;
10976}
10977
718e3744 10978/* Show BGP peer's summary information. */
d62a17ae 10979static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
8c1d4cd5 10980 struct peer *fpeer, int as_type, as_t as,
96c81f66 10981 uint16_t show_flags)
d62a17ae 10982{
10983 struct peer *peer;
10984 struct listnode *node, *nnode;
10985 unsigned int count = 0, dn_count = 0;
10986 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10987 char neighbor_buf[VTY_BUFSIZ];
10988 int neighbor_col_default_width = 16;
3577f1c5 10989 int len, failed_count = 0;
ce1944f0 10990 unsigned int filtered_count = 0;
d62a17ae 10991 int max_neighbor_width = 0;
10992 int pfx_rcd_safi;
3c13337d 10993 json_object *json = NULL;
d62a17ae 10994 json_object *json_peer = NULL;
10995 json_object *json_peers = NULL;
50e05855 10996 struct peer_af *paf;
d3ada366 10997 struct bgp_filter *filter;
85eeb029
DA
10998 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10999 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11000 bool show_established =
11001 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11002 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
96c81f66 11003 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
d62a17ae 11004
11005 /* labeled-unicast routes are installed in the unicast table so in order
11006 * to
11007 * display the correct PfxRcd value we must look at SAFI_UNICAST
11008 */
3577f1c5 11009
d62a17ae 11010 if (safi == SAFI_LABELED_UNICAST)
11011 pfx_rcd_safi = SAFI_UNICAST;
11012 else
11013 pfx_rcd_safi = safi;
11014
11015 if (use_json) {
3c13337d 11016 json = json_object_new_object();
d62a17ae 11017 json_peers = json_object_new_object();
3577f1c5 11018 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8c1d4cd5
LS
11019 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11020 as_type, as)) {
ce1944f0 11021 filtered_count++;
8c1d4cd5
LS
11022 count++;
11023 continue;
11024 }
11025
3577f1c5
DD
11026 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11027 continue;
11028
11029 if (peer->afc[afi][safi]) {
11030 /* See if we have at least a single failed peer */
11031 if (bgp_has_peer_failed(peer, afi, safi))
11032 failed_count++;
11033 count++;
11034 }
11035 if (peer_dynamic_neighbor(peer))
11036 dn_count++;
11037 }
c258527b 11038
d62a17ae 11039 } else {
11040 /* Loop over all neighbors that will be displayed to determine
11041 * how many
11042 * characters are needed for the Neighbor column
11043 */
11044 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8c1d4cd5
LS
11045 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11046 as_type, as)) {
ce1944f0 11047 filtered_count++;
8c1d4cd5
LS
11048 count++;
11049 continue;
11050 }
11051
d62a17ae 11052 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11053 continue;
11054
11055 if (peer->afc[afi][safi]) {
11056 memset(dn_flag, '\0', sizeof(dn_flag));
11057 if (peer_dynamic_neighbor(peer))
11058 dn_flag[0] = '*';
11059
11060 if (peer->hostname
892fedb6
DA
11061 && CHECK_FLAG(bgp->flags,
11062 BGP_FLAG_SHOW_HOSTNAME))
772270f3
QY
11063 snprintf(neighbor_buf,
11064 sizeof(neighbor_buf),
11065 "%s%s(%s) ", dn_flag,
11066 peer->hostname, peer->host);
d62a17ae 11067 else
772270f3
QY
11068 snprintf(neighbor_buf,
11069 sizeof(neighbor_buf), "%s%s ",
11070 dn_flag, peer->host);
d62a17ae 11071
11072 len = strlen(neighbor_buf);
11073
11074 if (len > max_neighbor_width)
11075 max_neighbor_width = len;
c258527b 11076
3577f1c5
DD
11077 /* See if we have at least a single failed peer */
11078 if (bgp_has_peer_failed(peer, afi, safi))
11079 failed_count++;
11080 count++;
d62a17ae 11081 }
11082 }
f933309e 11083
d62a17ae 11084 /* Originally we displayed the Neighbor column as 16
11085 * characters wide so make that the default
11086 */
11087 if (max_neighbor_width < neighbor_col_default_width)
11088 max_neighbor_width = neighbor_col_default_width;
11089 }
f933309e 11090
3577f1c5
DD
11091 if (show_failed && !failed_count) {
11092 if (use_json) {
11093 json_object_int_add(json, "failedPeersCount", 0);
11094 json_object_int_add(json, "dynamicPeers", dn_count);
c258527b 11095 json_object_int_add(json, "totalPeers", count);
3577f1c5
DD
11096
11097 vty_out(vty, "%s\n", json_object_to_json_string_ext(
11098 json, JSON_C_TO_STRING_PRETTY));
11099 json_object_free(json);
11100 } else {
11101 vty_out(vty, "%% No failed BGP neighbors found\n");
3577f1c5
DD
11102 }
11103 return CMD_SUCCESS;
11104 }
c258527b 11105
3577f1c5 11106 count = 0; /* Reset the value as its used again */
ce1944f0 11107 filtered_count = 0;
d62a17ae 11108 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
11109 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11110 continue;
11111
ea47320b
DL
11112 if (!peer->afc[afi][safi])
11113 continue;
d62a17ae 11114
ea47320b
DL
11115 if (!count) {
11116 unsigned long ents;
11117 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 11118 int64_t vrf_id_ui;
d62a17ae 11119
a4d82a8a
PZ
11120 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
11121 ? -1
11122 : (int64_t)bgp->vrf_id;
ea47320b
DL
11123
11124 /* Usage summary and header */
11125 if (use_json) {
23d0a753
DA
11126 char buf[BUFSIZ] = {0};
11127
ea47320b
DL
11128 json_object_string_add(
11129 json, "routerId",
23d0a753
DA
11130 inet_ntop(AF_INET, &bgp->router_id, buf,
11131 sizeof(buf)));
60466a63
QY
11132 json_object_int_add(json, "as", bgp->as);
11133 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
11134 json_object_string_add(
11135 json, "vrfName",
11136 (bgp->inst_type
11137 == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11138 ? VRF_DEFAULT_NAME
ea47320b
DL
11139 : bgp->name);
11140 } else {
11141 vty_out(vty,
23d0a753
DA
11142 "BGP router identifier %pI4, local AS number %u vrf-id %d",
11143 &bgp->router_id, bgp->as,
a4d82a8a
PZ
11144 bgp->vrf_id == VRF_UNKNOWN
11145 ? -1
11146 : (int)bgp->vrf_id);
ea47320b
DL
11147 vty_out(vty, "\n");
11148 }
d62a17ae 11149
ea47320b 11150 if (bgp_update_delay_configured(bgp)) {
d62a17ae 11151 if (use_json) {
ea47320b 11152 json_object_int_add(
60466a63 11153 json, "updateDelayLimit",
ea47320b 11154 bgp->v_update_delay);
d62a17ae 11155
ea47320b
DL
11156 if (bgp->v_update_delay
11157 != bgp->v_establish_wait)
d62a17ae 11158 json_object_int_add(
11159 json,
ea47320b
DL
11160 "updateDelayEstablishWait",
11161 bgp->v_establish_wait);
d62a17ae 11162
60466a63 11163 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
11164 json_object_string_add(
11165 json,
11166 "updateDelayFirstNeighbor",
11167 bgp->update_delay_begin_time);
11168 json_object_boolean_true_add(
11169 json,
11170 "updateDelayInProgress");
11171 } else {
11172 if (bgp->update_delay_over) {
d62a17ae 11173 json_object_string_add(
11174 json,
11175 "updateDelayFirstNeighbor",
11176 bgp->update_delay_begin_time);
ea47320b 11177 json_object_string_add(
d62a17ae 11178 json,
ea47320b
DL
11179 "updateDelayBestpathResumed",
11180 bgp->update_delay_end_time);
11181 json_object_string_add(
d62a17ae 11182 json,
ea47320b
DL
11183 "updateDelayZebraUpdateResume",
11184 bgp->update_delay_zebra_resume_time);
11185 json_object_string_add(
11186 json,
11187 "updateDelayPeerUpdateResume",
11188 bgp->update_delay_peers_resume_time);
d62a17ae 11189 }
ea47320b
DL
11190 }
11191 } else {
11192 vty_out(vty,
11193 "Read-only mode update-delay limit: %d seconds\n",
11194 bgp->v_update_delay);
11195 if (bgp->v_update_delay
11196 != bgp->v_establish_wait)
d62a17ae 11197 vty_out(vty,
ea47320b
DL
11198 " Establish wait: %d seconds\n",
11199 bgp->v_establish_wait);
d62a17ae 11200
60466a63 11201 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
11202 vty_out(vty,
11203 " First neighbor established: %s\n",
11204 bgp->update_delay_begin_time);
11205 vty_out(vty,
11206 " Delay in progress\n");
11207 } else {
11208 if (bgp->update_delay_over) {
d62a17ae 11209 vty_out(vty,
11210 " First neighbor established: %s\n",
11211 bgp->update_delay_begin_time);
11212 vty_out(vty,
ea47320b
DL
11213 " Best-paths resumed: %s\n",
11214 bgp->update_delay_end_time);
11215 vty_out(vty,
11216 " zebra update resumed: %s\n",
11217 bgp->update_delay_zebra_resume_time);
11218 vty_out(vty,
11219 " peers update resumed: %s\n",
11220 bgp->update_delay_peers_resume_time);
d62a17ae 11221 }
11222 }
11223 }
ea47320b 11224 }
d62a17ae 11225
ea47320b
DL
11226 if (use_json) {
11227 if (bgp_maxmed_onstartup_configured(bgp)
11228 && bgp->maxmed_active)
11229 json_object_boolean_true_add(
60466a63 11230 json, "maxMedOnStartup");
ea47320b
DL
11231 if (bgp->v_maxmed_admin)
11232 json_object_boolean_true_add(
60466a63 11233 json, "maxMedAdministrative");
d62a17ae 11234
ea47320b
DL
11235 json_object_int_add(
11236 json, "tableVersion",
60466a63 11237 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 11238
60466a63
QY
11239 ents = bgp_table_count(bgp->rib[afi][safi]);
11240 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
11241 json_object_int_add(
11242 json, "ribMemory",
9bcb3eef 11243 ents * sizeof(struct bgp_dest));
d62a17ae 11244
210ec2a0 11245 ents = bgp->af_peer_count[afi][safi];
60466a63
QY
11246 json_object_int_add(json, "peerCount", ents);
11247 json_object_int_add(json, "peerMemory",
11248 ents * sizeof(struct peer));
d62a17ae 11249
ea47320b
DL
11250 if ((ents = listcount(bgp->group))) {
11251 json_object_int_add(
60466a63 11252 json, "peerGroupCount", ents);
ea47320b
DL
11253 json_object_int_add(
11254 json, "peerGroupMemory",
996c9314
LB
11255 ents * sizeof(struct
11256 peer_group));
ea47320b 11257 }
d62a17ae 11258
ea47320b
DL
11259 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11260 BGP_CONFIG_DAMPENING))
11261 json_object_boolean_true_add(
60466a63 11262 json, "dampeningEnabled");
ea47320b 11263 } else {
96c81f66
LS
11264 if (!show_terse) {
11265 if (bgp_maxmed_onstartup_configured(bgp)
11266 && bgp->maxmed_active)
11267 vty_out(vty,
11268 "Max-med on-startup active\n");
11269 if (bgp->v_maxmed_admin)
11270 vty_out(vty,
11271 "Max-med administrative active\n");
d62a17ae 11272
96c81f66
LS
11273 vty_out(vty,
11274 "BGP table version %" PRIu64
11275 "\n",
11276 bgp_table_version(
11277 bgp->rib[afi][safi]));
ea47320b 11278
96c81f66
LS
11279 ents = bgp_table_count(
11280 bgp->rib[afi][safi]);
d62a17ae 11281 vty_out(vty,
96c81f66 11282 "RIB entries %ld, using %s of memory\n",
d62a17ae 11283 ents,
11284 mtype_memstr(
11285 memstrbuf,
11286 sizeof(memstrbuf),
96c81f66
LS
11287 ents
11288 * sizeof(
11289 struct
11290 bgp_dest)));
d62a17ae 11291
96c81f66
LS
11292 /* Peer related usage */
11293 ents = bgp->af_peer_count[afi][safi];
11294 vty_out(vty,
11295 "Peers %ld, using %s of memory\n",
11296 ents,
11297 mtype_memstr(
11298 memstrbuf,
11299 sizeof(memstrbuf),
11300 ents
11301 * sizeof(
11302 struct
11303 peer)));
d62a17ae 11304
96c81f66
LS
11305 if ((ents = listcount(bgp->group)))
11306 vty_out(vty,
11307 "Peer groups %ld, using %s of memory\n",
11308 ents,
11309 mtype_memstr(
11310 memstrbuf,
11311 sizeof(memstrbuf),
11312 ents
11313 * sizeof(
11314 struct
11315 peer_group)));
11316
11317 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11318 BGP_CONFIG_DAMPENING))
11319 vty_out(vty,
11320 "Dampening enabled.\n");
11321 }
11322 if (show_failed) {
11323 vty_out(vty, "\n");
11324
11325 /* Subtract 8 here because 'Neighbor' is
11326 * 8 characters */
11327 vty_out(vty, "Neighbor");
11328 vty_out(vty, "%*s",
11329 max_neighbor_width - 8, " ");
85eeb029
DA
11330 vty_out(vty,
11331 BGP_SHOW_SUMMARY_HEADER_FAILED);
96c81f66 11332 }
d62a17ae 11333 }
ea47320b 11334 }
d62a17ae 11335
d55811cc 11336 paf = peer_af_find(peer, afi, safi);
d3ada366 11337 filter = &peer->filter[afi][safi];
db92d226 11338
ea47320b 11339 count++;
3577f1c5
DD
11340 /* Works for both failed & successful cases */
11341 if (peer_dynamic_neighbor(peer))
11342 dn_count++;
d62a17ae 11343
ea47320b 11344 if (use_json) {
3577f1c5 11345 json_peer = NULL;
8c1d4cd5 11346 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
ce1944f0
LS
11347 as_type, as)) {
11348 filtered_count++;
8c1d4cd5 11349 continue;
ce1944f0 11350 }
3577f1c5
DD
11351 if (show_failed &&
11352 bgp_has_peer_failed(peer, afi, safi)) {
11353 json_peer = json_object_new_object();
11354 bgp_show_failed_summary(vty, bgp, peer,
11355 json_peer, 0, use_json);
11356 } else if (!show_failed) {
10b49f14 11357 if (show_established
ce1944f0
LS
11358 && bgp_has_peer_failed(peer, afi, safi)) {
11359 filtered_count++;
10b49f14 11360 continue;
ce1944f0 11361 }
10b49f14 11362
3577f1c5
DD
11363 json_peer = json_object_new_object();
11364 if (peer_dynamic_neighbor(peer)) {
11365 json_object_boolean_true_add(json_peer,
11366 "dynamicPeer");
11367 }
d62a17ae 11368
3577f1c5
DD
11369 if (peer->hostname)
11370 json_object_string_add(json_peer, "hostname",
11371 peer->hostname);
11372
11373 if (peer->domainname)
11374 json_object_string_add(json_peer, "domainname",
11375 peer->domainname);
11376
11377 json_object_int_add(json_peer, "remoteAs", peer->as);
c854765f
DA
11378 json_object_int_add(
11379 json_peer, "localAs",
11380 peer->change_local_as
11381 ? peer->change_local_as
11382 : peer->local_as);
3577f1c5
DD
11383 json_object_int_add(json_peer, "version", 4);
11384 json_object_int_add(json_peer, "msgRcvd",
11385 PEER_TOTAL_RX(peer));
11386 json_object_int_add(json_peer, "msgSent",
11387 PEER_TOTAL_TX(peer));
11388
43aa5965
QY
11389 atomic_size_t outq_count, inq_count;
11390 outq_count = atomic_load_explicit(
11391 &peer->obuf->count,
11392 memory_order_relaxed);
11393 inq_count = atomic_load_explicit(
11394 &peer->ibuf->count,
11395 memory_order_relaxed);
11396
3577f1c5
DD
11397 json_object_int_add(json_peer, "tableVersion",
11398 peer->version[afi][safi]);
11399 json_object_int_add(json_peer, "outq",
43aa5965
QY
11400 outq_count);
11401 json_object_int_add(json_peer, "inq",
11402 inq_count);
3577f1c5
DD
11403 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
11404 use_json, json_peer);
11405
3577f1c5
DD
11406 json_object_int_add(json_peer, "pfxRcd",
11407 peer->pcount[afi][pfx_rcd_safi]);
11408
3577f1c5 11409 if (paf && PAF_SUBGRP(paf))
a616dd1f
DA
11410 json_object_int_add(
11411 json_peer, "pfxSnt",
11412 (PAF_SUBGRP(paf))->scount);
11413 else
11414 json_object_int_add(json_peer, "pfxSnt",
11415 0);
0e1f8ab5
DA
11416
11417 /* BGP FSM state */
cb9196e7 11418 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
736b68f3
DS
11419 || CHECK_FLAG(peer->bgp->flags,
11420 BGP_FLAG_SHUTDOWN))
0e1f8ab5
DA
11421 json_object_string_add(json_peer,
11422 "state",
3577f1c5
DD
11423 "Idle (Admin)");
11424 else if (peer->afc_recv[afi][safi])
11425 json_object_string_add(
0e1f8ab5
DA
11426 json_peer, "state",
11427 lookup_msg(bgp_status_msg,
11428 peer->status, NULL));
11429 else if (CHECK_FLAG(
11430 peer->sflags,
11431 PEER_STATUS_PREFIX_OVERFLOW))
11432 json_object_string_add(json_peer,
11433 "state",
3577f1c5
DD
11434 "Idle (PfxCt)");
11435 else
11436 json_object_string_add(
0e1f8ab5
DA
11437 json_peer, "state",
11438 lookup_msg(bgp_status_msg,
11439 peer->status, NULL));
11440
11441 /* BGP peer state */
11442 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11443 || CHECK_FLAG(peer->bgp->flags,
11444 BGP_FLAG_SHUTDOWN))
11445 json_object_string_add(json_peer,
11446 "peerState",
11447 "Admin");
11448 else if (CHECK_FLAG(
11449 peer->sflags,
11450 PEER_STATUS_PREFIX_OVERFLOW))
11451 json_object_string_add(json_peer,
11452 "peerState",
11453 "PfxCt");
11454 else if (CHECK_FLAG(peer->flags,
11455 PEER_FLAG_PASSIVE))
11456 json_object_string_add(json_peer,
11457 "peerState",
11458 "Passive");
11459 else if (CHECK_FLAG(peer->sflags,
11460 PEER_STATUS_NSF_WAIT))
11461 json_object_string_add(json_peer,
11462 "peerState",
11463 "NSF passive");
11464 else if (CHECK_FLAG(
11465 peer->bgp->flags,
11466 BGP_FLAG_EBGP_REQUIRES_POLICY)
11467 && (!bgp_inbound_policy_exists(peer,
11468 filter)
11469 || !bgp_outbound_policy_exists(
11470 peer, filter)))
11471 json_object_string_add(json_peer,
11472 "peerState",
11473 "Policy");
11474 else
11475 json_object_string_add(
11476 json_peer, "peerState", "OK");
11477
200116db
DD
11478 json_object_int_add(json_peer, "connectionsEstablished",
11479 peer->established);
11480 json_object_int_add(json_peer, "connectionsDropped",
11481 peer->dropped);
aa72bd7e
PG
11482 if (peer->desc)
11483 json_object_string_add(
11484 json_peer, "desc", peer->desc);
b4e9dcba 11485 }
3577f1c5
DD
11486 /* Avoid creating empty peer dicts in JSON */
11487 if (json_peer == NULL)
11488 continue;
ea47320b
DL
11489
11490 if (peer->conf_if)
60466a63 11491 json_object_string_add(json_peer, "idType",
ea47320b
DL
11492 "interface");
11493 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
11494 json_object_string_add(json_peer, "idType",
11495 "ipv4");
ea47320b 11496 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
11497 json_object_string_add(json_peer, "idType",
11498 "ipv6");
ea47320b
DL
11499 json_object_object_add(json_peers, peer->host,
11500 json_peer);
11501 } else {
8c1d4cd5 11502 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
ce1944f0
LS
11503 as_type, as)) {
11504 filtered_count++;
8c1d4cd5 11505 continue;
ce1944f0 11506 }
3577f1c5
DD
11507 if (show_failed &&
11508 bgp_has_peer_failed(peer, afi, safi)) {
11509 bgp_show_failed_summary(vty, bgp, peer, NULL,
11510 max_neighbor_width,
11511 use_json);
11512 } else if (!show_failed) {
10b49f14 11513 if (show_established
ce1944f0
LS
11514 && bgp_has_peer_failed(peer, afi, safi)) {
11515 filtered_count++;
10b49f14 11516 continue;
ce1944f0 11517 }
96c81f66
LS
11518
11519 if ((count - filtered_count) == 1) {
11520 /* display headline before the first
11521 * neighbor line */
11522 vty_out(vty, "\n");
11523
11524 /* Subtract 8 here because 'Neighbor' is
11525 * 8 characters */
11526 vty_out(vty, "Neighbor");
11527 vty_out(vty, "%*s",
11528 max_neighbor_width - 8, " ");
11529 vty_out(vty,
11530 show_wide
11531 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
11532 : BGP_SHOW_SUMMARY_HEADER_ALL);
11533 }
11534
3577f1c5
DD
11535 memset(dn_flag, '\0', sizeof(dn_flag));
11536 if (peer_dynamic_neighbor(peer)) {
11537 dn_flag[0] = '*';
11538 }
d62a17ae 11539
3577f1c5 11540 if (peer->hostname
892fedb6
DA
11541 && CHECK_FLAG(bgp->flags,
11542 BGP_FLAG_SHOW_HOSTNAME))
3577f1c5 11543 len = vty_out(vty, "%s%s(%s)", dn_flag,
892fedb6
DA
11544 peer->hostname,
11545 peer->host);
d62a17ae 11546 else
3577f1c5
DD
11547 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11548
11549 /* pad the neighbor column with spaces */
11550 if (len < max_neighbor_width)
11551 vty_out(vty, "%*s", max_neighbor_width - len,
11552 " ");
11553
43aa5965
QY
11554 atomic_size_t outq_count, inq_count;
11555 outq_count = atomic_load_explicit(
11556 &peer->obuf->count,
11557 memory_order_relaxed);
11558 inq_count = atomic_load_explicit(
11559 &peer->ibuf->count,
11560 memory_order_relaxed);
11561
85eeb029
DA
11562 if (show_wide)
11563 vty_out(vty,
11564 "4 %10u %10u %9u %9u %8" PRIu64
11565 " %4zu %4zu %8s",
11566 peer->as,
11567 peer->change_local_as
11568 ? peer->change_local_as
11569 : peer->local_as,
11570 PEER_TOTAL_RX(peer),
11571 PEER_TOTAL_TX(peer),
11572 peer->version[afi][safi],
11573 inq_count, outq_count,
11574 peer_uptime(peer->uptime,
11575 timebuf,
11576 BGP_UPTIME_LEN, 0,
11577 NULL));
11578 else
11579 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
11580 " %4zu %4zu %8s",
11581 peer->as, PEER_TOTAL_RX(peer),
11582 PEER_TOTAL_TX(peer),
11583 peer->version[afi][safi],
11584 inq_count, outq_count,
11585 peer_uptime(peer->uptime,
11586 timebuf,
11587 BGP_UPTIME_LEN, 0,
11588 NULL));
3577f1c5 11589
feb17238 11590 if (peer_established(peer)) {
d3ada366
DA
11591 if (peer->afc_recv[afi][safi]) {
11592 if (CHECK_FLAG(
11593 bgp->flags,
11594 BGP_FLAG_EBGP_REQUIRES_POLICY)
11595 && !bgp_inbound_policy_exists(
11596 peer, filter))
11597 vty_out(vty, " %12s",
11598 "(Policy)");
11599 else
11600 vty_out(vty,
6cde4b45 11601 " %12u",
d3ada366
DA
11602 peer->pcount
11603 [afi]
11604 [pfx_rcd_safi]);
11605 } else {
749d0f27 11606 vty_out(vty, " NoNeg");
d3ada366 11607 }
db92d226 11608
d3ada366
DA
11609 if (paf && PAF_SUBGRP(paf)) {
11610 if (CHECK_FLAG(
11611 bgp->flags,
11612 BGP_FLAG_EBGP_REQUIRES_POLICY)
11613 && !bgp_outbound_policy_exists(
11614 peer, filter))
11615 vty_out(vty, " %8s",
11616 "(Policy)");
11617 else
11618 vty_out(vty,
6cde4b45 11619 " %8u",
d3ada366
DA
11620 (PAF_SUBGRP(
11621 paf))
11622 ->scount);
749d0f27
DA
11623 } else {
11624 vty_out(vty, " NoNeg");
d3ada366 11625 }
db92d226 11626 } else {
736b68f3
DS
11627 if (CHECK_FLAG(peer->flags,
11628 PEER_FLAG_SHUTDOWN)
11629 || CHECK_FLAG(peer->bgp->flags,
11630 BGP_FLAG_SHUTDOWN))
3577f1c5
DD
11631 vty_out(vty, " Idle (Admin)");
11632 else if (CHECK_FLAG(
11633 peer->sflags,
11634 PEER_STATUS_PREFIX_OVERFLOW))
11635 vty_out(vty, " Idle (PfxCt)");
11636 else
11637 vty_out(vty, " %12s",
11638 lookup_msg(bgp_status_msg,
11639 peer->status, NULL));
db92d226 11640
6cde4b45 11641 vty_out(vty, " %8u", 0);
3577f1c5 11642 }
aa72bd7e 11643 if (peer->desc)
cb75bb31
DA
11644 vty_out(vty, " %s",
11645 bgp_peer_description_stripped(
85eeb029
DA
11646 peer->desc,
11647 show_wide ? 64 : 20));
aa72bd7e
PG
11648 else
11649 vty_out(vty, " N/A");
3577f1c5 11650 vty_out(vty, "\n");
d62a17ae 11651 }
3577f1c5 11652
d62a17ae 11653 }
11654 }
f933309e 11655
d62a17ae 11656 if (use_json) {
11657 json_object_object_add(json, "peers", json_peers);
3577f1c5 11658 json_object_int_add(json, "failedPeers", failed_count);
ce1944f0
LS
11659 json_object_int_add(json, "displayedPeers",
11660 count - filtered_count);
d62a17ae 11661 json_object_int_add(json, "totalPeers", count);
11662 json_object_int_add(json, "dynamicPeers", dn_count);
11663
3577f1c5
DD
11664 if (!show_failed)
11665 bgp_show_bestpath_json(bgp, json);
57a9c8a8 11666
996c9314
LB
11667 vty_out(vty, "%s\n", json_object_to_json_string_ext(
11668 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 11669 json_object_free(json);
11670 } else {
ce1944f0 11671 if (count) {
96c81f66
LS
11672 if (filtered_count == count)
11673 vty_out(vty, "\n%% No matching neighbor\n");
11674 else {
11675 if (show_failed)
11676 vty_out(vty, "\nDisplayed neighbors %d",
11677 failed_count);
11678 else if (as_type != AS_UNSPECIFIED || as
11679 || fpeer || show_established)
ce1944f0
LS
11680 vty_out(vty, "\nDisplayed neighbors %d",
11681 count - filtered_count);
96c81f66
LS
11682
11683 vty_out(vty, "\nTotal number of neighbors %d\n",
11684 count);
ce1944f0 11685 }
ce1944f0 11686 } else {
d6ceaca3 11687 vty_out(vty, "No %s neighbor is configured\n",
5cb5f4d0 11688 get_afi_safi_str(afi, safi, false));
d62a17ae 11689 }
b05a1c8b 11690
d6ceaca3 11691 if (dn_count) {
d62a17ae 11692 vty_out(vty, "* - dynamic neighbor\n");
11693 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11694 dn_count, bgp->dynamic_neighbors_limit);
11695 }
11696 }
1ff9a340 11697
d62a17ae 11698 return CMD_SUCCESS;
718e3744 11699}
11700
d62a17ae 11701static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8c1d4cd5 11702 int safi, struct peer *fpeer, int as_type,
96c81f66 11703 as_t as, uint16_t show_flags)
d62a17ae 11704{
11705 int is_first = 1;
11706 int afi_wildcard = (afi == AFI_MAX);
11707 int safi_wildcard = (safi == SAFI_MAX);
11708 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 11709 bool nbr_output = false;
85eeb029 11710 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 11711
11712 if (use_json && is_wildcard)
11713 vty_out(vty, "{\n");
11714 if (afi_wildcard)
11715 afi = 1; /* AFI_IP */
11716 while (afi < AFI_MAX) {
11717 if (safi_wildcard)
11718 safi = 1; /* SAFI_UNICAST */
11719 while (safi < SAFI_MAX) {
318cac96 11720 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 11721 nbr_output = true;
f86897b9 11722
d62a17ae 11723 if (is_wildcard) {
11724 /*
11725 * So limit output to those afi/safi
11726 * pairs that
11727 * actualy have something interesting in
11728 * them
11729 */
11730 if (use_json) {
d62a17ae 11731 if (!is_first)
11732 vty_out(vty, ",\n");
11733 else
11734 is_first = 0;
11735
11736 vty_out(vty, "\"%s\":",
5cb5f4d0
DD
11737 get_afi_safi_str(afi,
11738 safi,
11739 true));
d62a17ae 11740 } else {
6cac2fcc
LS
11741 vty_out(vty,
11742 "\n%s Summary (%s):\n",
5cb5f4d0
DD
11743 get_afi_safi_str(afi,
11744 safi,
6cac2fcc
LS
11745 false),
11746 bgp->name_pretty);
d62a17ae 11747 }
11748 }
8c1d4cd5
LS
11749 bgp_show_summary(vty, bgp, afi, safi, fpeer,
11750 as_type, as, show_flags);
d62a17ae 11751 }
11752 safi++;
d62a17ae 11753 if (!safi_wildcard)
11754 safi = SAFI_MAX;
11755 }
11756 afi++;
ee851c8c 11757 if (!afi_wildcard)
d62a17ae 11758 afi = AFI_MAX;
11759 }
11760
11761 if (use_json && is_wildcard)
11762 vty_out(vty, "}\n");
ca61fd25
DS
11763 else if (!nbr_output) {
11764 if (use_json)
11765 vty_out(vty, "{}\n");
11766 else
6cac2fcc
LS
11767 vty_out(vty, "%% No BGP neighbors found in %s\n",
11768 bgp->name_pretty);
ca61fd25 11769 }
d62a17ae 11770}
11771
11772static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8c1d4cd5
LS
11773 safi_t safi,
11774 const char *neighbor,
11775 int as_type, as_t as,
96c81f66 11776 uint16_t show_flags)
d62a17ae 11777{
11778 struct listnode *node, *nnode;
11779 struct bgp *bgp;
8c1d4cd5 11780 struct peer *fpeer = NULL;
d62a17ae 11781 int is_first = 1;
9f049418 11782 bool nbr_output = false;
85eeb029 11783 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 11784
11785 if (use_json)
11786 vty_out(vty, "{\n");
11787
11788 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 11789 nbr_output = true;
d62a17ae 11790 if (use_json) {
d62a17ae 11791 if (!is_first)
11792 vty_out(vty, ",\n");
11793 else
11794 is_first = 0;
11795
11796 vty_out(vty, "\"%s\":",
11797 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11798 ? VRF_DEFAULT_NAME
d62a17ae 11799 : bgp->name);
d62a17ae 11800 }
8c1d4cd5
LS
11801 if (neighbor) {
11802 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11803 use_json);
11804 if (!fpeer)
11805 continue;
11806 }
11807 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11808 as, show_flags);
d62a17ae 11809 }
11810
11811 if (use_json)
11812 vty_out(vty, "}\n");
9f049418
DS
11813 else if (!nbr_output)
11814 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 11815}
11816
11817int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8c1d4cd5 11818 safi_t safi, const char *neighbor, int as_type,
96c81f66 11819 as_t as, uint16_t show_flags)
d62a17ae 11820{
11821 struct bgp *bgp;
85eeb029 11822 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
8c1d4cd5 11823 struct peer *fpeer = NULL;
d62a17ae 11824
11825 if (name) {
11826 if (strmatch(name, "all")) {
85eeb029 11827 bgp_show_all_instances_summary_vty(vty, afi, safi,
8c1d4cd5
LS
11828 neighbor, as_type,
11829 as, show_flags);
d62a17ae 11830 return CMD_SUCCESS;
11831 } else {
11832 bgp = bgp_lookup_by_name(name);
11833
11834 if (!bgp) {
11835 if (use_json)
11836 vty_out(vty, "{}\n");
11837 else
11838 vty_out(vty,
ca61fd25 11839 "%% BGP instance not found\n");
d62a17ae 11840 return CMD_WARNING;
11841 }
11842
8c1d4cd5
LS
11843 if (neighbor) {
11844 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11845 use_json);
11846 if (!fpeer)
11847 return CMD_WARNING;
11848 }
11849 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
11850 as_type, as, show_flags);
d62a17ae 11851 return CMD_SUCCESS;
11852 }
11853 }
11854
11855 bgp = bgp_get_default();
11856
8c1d4cd5
LS
11857 if (bgp) {
11858 if (neighbor) {
11859 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11860 use_json);
11861 if (!fpeer)
11862 return CMD_WARNING;
11863 }
11864 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11865 as, show_flags);
11866 } else {
ca61fd25
DS
11867 if (use_json)
11868 vty_out(vty, "{}\n");
11869 else
11870 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
11871 return CMD_WARNING;
11872 }
d62a17ae 11873
11874 return CMD_SUCCESS;
4fb25c53
DW
11875}
11876
716b2d8a 11877/* `show [ip] bgp summary' commands. */
8c1d4cd5
LS
11878DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
11879 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
11880 " [" BGP_SAFI_WITH_LABEL_CMD_STR
96c81f66 11881 "]] [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
11882 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11883 BGP_SAFI_WITH_LABEL_HELP_STR
11884 "Display the entries for all address families\n"
11885 "Summary of BGP neighbor status\n"
11886 "Show only sessions in Established state\n"
11887 "Show only sessions not in Established state\n"
11888 "Show only the specified neighbor session\n"
11889 "Neighbor to display information about\n"
11890 "Neighbor to display information about\n"
11891 "Neighbor on BGP configured interface\n"
11892 "Show only the specified remote AS sessions\n"
11893 "AS number\n"
11894 "Internal (iBGP) AS sessions\n"
11895 "External (eBGP) AS sessions\n"
96c81f66 11896 "Shorten the information on BGP instances\n"
8c1d4cd5 11897 "Increase table width for longer output\n" JSON_STR)
718e3744 11898{
d62a17ae 11899 char *vrf = NULL;
11900 afi_t afi = AFI_MAX;
11901 safi_t safi = SAFI_MAX;
8c1d4cd5
LS
11902 as_t as = 0; /* 0 means AS filter not set */
11903 int as_type = AS_UNSPECIFIED;
96c81f66 11904 uint16_t show_flags = 0;
d62a17ae 11905
11906 int idx = 0;
11907
11908 /* show [ip] bgp */
96f3485c 11909 if (!all && argv_find(argv, argc, "ip", &idx))
d62a17ae 11910 afi = AFI_IP;
9a8bdf1c
PG
11911 /* [<vrf> VIEWVRFNAME] */
11912 if (argv_find(argv, argc, "vrf", &idx)) {
11913 vrf = argv[idx + 1]->arg;
11914 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11915 vrf = NULL;
11916 } else if (argv_find(argv, argc, "view", &idx))
11917 /* [<view> VIEWVRFNAME] */
11918 vrf = argv[idx + 1]->arg;
d62a17ae 11919 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11920 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11921 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11922 }
11923
3577f1c5 11924 if (argv_find(argv, argc, "failed", &idx))
85eeb029
DA
11925 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11926
10b49f14 11927 if (argv_find(argv, argc, "established", &idx))
85eeb029
DA
11928 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11929
8c1d4cd5
LS
11930 if (argv_find(argv, argc, "remote-as", &idx)) {
11931 if (argv[idx + 1]->arg[0] == 'i')
11932 as_type = AS_INTERNAL;
11933 else if (argv[idx + 1]->arg[0] == 'e')
11934 as_type = AS_EXTERNAL;
11935 else
11936 as = (as_t)atoi(argv[idx + 1]->arg);
11937 }
11938
96c81f66
LS
11939 if (argv_find(argv, argc, "terse", &idx))
11940 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11941
85eeb029
DA
11942 if (argv_find(argv, argc, "wide", &idx))
11943 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11944
11945 if (argv_find(argv, argc, "json", &idx))
11946 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
3577f1c5 11947
8c1d4cd5
LS
11948 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
11949 show_flags);
d62a17ae 11950}
11951
5cb5f4d0 11952const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
d62a17ae 11953{
5cb5f4d0
DD
11954 if (for_json)
11955 return get_afi_safi_json_str(afi, safi);
d62a17ae 11956 else
5cb5f4d0 11957 return get_afi_safi_vty_str(afi, safi);
27162734
LB
11958}
11959
d62a17ae 11960
11961static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11962 afi_t afi, safi_t safi,
d7c0a89a
QY
11963 uint16_t adv_smcap, uint16_t adv_rmcap,
11964 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 11965 bool use_json, json_object *json_pref)
d62a17ae 11966{
11967 /* Send-Mode */
11968 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11969 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11970 if (use_json) {
11971 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11972 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11973 json_object_string_add(json_pref, "sendMode",
11974 "advertisedAndReceived");
11975 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11976 json_object_string_add(json_pref, "sendMode",
11977 "advertised");
11978 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11979 json_object_string_add(json_pref, "sendMode",
11980 "received");
11981 } else {
11982 vty_out(vty, " Send-mode: ");
11983 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11984 vty_out(vty, "advertised");
11985 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11986 vty_out(vty, "%sreceived",
11987 CHECK_FLAG(p->af_cap[afi][safi],
11988 adv_smcap)
11989 ? ", "
11990 : "");
11991 vty_out(vty, "\n");
11992 }
11993 }
11994
11995 /* Receive-Mode */
11996 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11997 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11998 if (use_json) {
11999 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
12000 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
12001 json_object_string_add(json_pref, "recvMode",
12002 "advertisedAndReceived");
12003 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
12004 json_object_string_add(json_pref, "recvMode",
12005 "advertised");
12006 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
12007 json_object_string_add(json_pref, "recvMode",
12008 "received");
12009 } else {
12010 vty_out(vty, " Receive-mode: ");
12011 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
12012 vty_out(vty, "advertised");
12013 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
12014 vty_out(vty, "%sreceived",
12015 CHECK_FLAG(p->af_cap[afi][safi],
12016 adv_rmcap)
12017 ? ", "
12018 : "");
12019 vty_out(vty, "\n");
12020 }
12021 }
12022}
12023
13909c4f
DS
12024static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty,
12025 struct peer *p,
12026 bool use_json,
12027 json_object *json)
2986cac2 12028{
08c2d52a 12029 bool rbit_status = false;
2986cac2 12030
12031 if (!use_json)
a53ca37b 12032 vty_out(vty, "\n R bit: ");
2986cac2 12033
13909c4f
DS
12034 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
12035 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
feb17238 12036 && (peer_established(p))) {
2986cac2 12037
12038 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV))
08c2d52a 12039 rbit_status = true;
2986cac2 12040 else
08c2d52a 12041 rbit_status = false;
2986cac2 12042 }
12043
12044 if (rbit_status) {
12045 if (use_json)
13909c4f 12046 json_object_boolean_true_add(json, "rBit");
2986cac2 12047 else
12048 vty_out(vty, "True\n");
12049 } else {
12050 if (use_json)
13909c4f 12051 json_object_boolean_false_add(json, "rBit");
2986cac2 12052 else
12053 vty_out(vty, "False\n");
12054 }
12055}
12056
13909c4f
DS
12057static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
12058 struct peer *peer,
12059 bool use_json,
12060 json_object *json)
2986cac2 12061{
2bb5d39b 12062 const char *mode = "NotApplicable";
2986cac2 12063
12064 if (!use_json)
a53ca37b 12065 vty_out(vty, "\n Remote GR Mode: ");
2986cac2 12066
13909c4f 12067 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
feb17238 12068 && (peer_established(peer))) {
2986cac2 12069
13909c4f
DS
12070 if ((peer->nsf_af_count == 0)
12071 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 12072
2986cac2 12073 mode = "Disable";
12074
13909c4f
DS
12075 } else if (peer->nsf_af_count == 0
12076 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 12077
2986cac2 12078 mode = "Helper";
12079
13909c4f
DS
12080 } else if (peer->nsf_af_count != 0
12081 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 12082
2986cac2 12083 mode = "Restart";
2986cac2 12084 }
12085 }
12086
12087 if (use_json) {
13909c4f 12088 json_object_string_add(json, "remoteGrMode", mode);
2986cac2 12089 } else
12090 vty_out(vty, mode, "\n");
12091}
12092
13909c4f
DS
12093static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
12094 struct peer *p,
12095 bool use_json,
12096 json_object *json)
2986cac2 12097{
12098 const char *mode = "Invalid";
12099
12100 if (!use_json)
a53ca37b 12101 vty_out(vty, " Local GR Mode: ");
2986cac2 12102
12103 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
12104 mode = "Helper";
12105 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
12106 mode = "Restart";
12107 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
12108 mode = "Disable";
2ba1fe69 12109 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
2986cac2 12110 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
12111 mode = "Helper*";
12112 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
12113 mode = "Restart*";
12114 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
12115 mode = "Disable*";
12116 else
12117 mode = "Invalid*";
2ba1fe69 12118 }
2986cac2 12119
12120 if (use_json) {
13909c4f 12121 json_object_string_add(json, "localGrMode", mode);
2986cac2 12122 } else {
12123 vty_out(vty, mode, "\n");
12124 }
12125}
12126
13909c4f
DS
12127static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
12128 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
2986cac2 12129{
2ba1fe69 12130 afi_t afi;
12131 safi_t safi;
2986cac2 12132 json_object *json_afi_safi = NULL;
12133 json_object *json_timer = NULL;
12134 json_object *json_endofrib_status = NULL;
9e3b51a7 12135 bool eor_flag = false;
2986cac2 12136
12137 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
12138 for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) {
13909c4f
DS
12139 if (!peer->afc[afi][safi])
12140 continue;
2986cac2 12141
13909c4f
DS
12142 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
12143 || !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
12144 continue;
9e3b51a7 12145
13909c4f
DS
12146 if (use_json) {
12147 json_afi_safi = json_object_new_object();
12148 json_endofrib_status = json_object_new_object();
12149 json_timer = json_object_new_object();
12150 }
2986cac2 12151
13909c4f
DS
12152 if (peer->eor_stime[afi][safi]
12153 >= peer->pkt_stime[afi][safi])
12154 eor_flag = true;
12155 else
12156 eor_flag = false;
2986cac2 12157
13909c4f 12158 if (!use_json) {
a53ca37b 12159 vty_out(vty, " %s:\n",
13909c4f 12160 get_afi_safi_str(afi, safi, false));
2986cac2 12161
a53ca37b 12162 vty_out(vty, " F bit: ");
698ba8d0 12163 }
2986cac2 12164
13909c4f
DS
12165 if (peer->nsf[afi][safi]
12166 && CHECK_FLAG(peer->af_cap[afi][safi],
12167 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
2986cac2 12168
13909c4f
DS
12169 if (use_json) {
12170 json_object_boolean_true_add(
2986cac2 12171 json_afi_safi, "fBit");
13909c4f
DS
12172 } else
12173 vty_out(vty, "True\n");
12174 } else {
12175 if (use_json)
12176 json_object_boolean_false_add(
12177 json_afi_safi, "fBit");
12178 else
12179 vty_out(vty, "False\n");
12180 }
2986cac2 12181
13909c4f 12182 if (!use_json)
a53ca37b 12183 vty_out(vty, " End-of-RIB sent: ");
2986cac2 12184
13909c4f
DS
12185 if (CHECK_FLAG(peer->af_sflags[afi][safi],
12186 PEER_STATUS_EOR_SEND)) {
12187 if (use_json) {
12188 json_object_boolean_true_add(
2986cac2 12189 json_endofrib_status,
13909c4f 12190 "endOfRibSend");
9e3b51a7 12191
13909c4f
DS
12192 PRINT_EOR_JSON(eor_flag);
12193 } else {
12194 vty_out(vty, "Yes\n");
12195 vty_out(vty,
a53ca37b 12196 " End-of-RIB sent after update: ");
2986cac2 12197
13909c4f
DS
12198 PRINT_EOR(eor_flag);
12199 }
12200 } else {
12201 if (use_json) {
12202 json_object_boolean_false_add(
2986cac2 12203 json_endofrib_status,
13909c4f
DS
12204 "endOfRibSend");
12205 json_object_boolean_false_add(
9e3b51a7 12206 json_endofrib_status,
13909c4f
DS
12207 "endOfRibSentAfterUpdate");
12208 } else {
12209 vty_out(vty, "No\n");
12210 vty_out(vty,
a53ca37b 12211 " End-of-RIB sent after update: ");
13909c4f 12212 vty_out(vty, "No\n");
2986cac2 12213 }
13909c4f 12214 }
2986cac2 12215
a53ca37b
DA
12216 if (!use_json)
12217 vty_out(vty, " End-of-RIB received: ");
12218
12219 if (CHECK_FLAG(peer->af_sflags[afi][safi],
12220 PEER_STATUS_EOR_RECEIVED)) {
12221 if (use_json)
12222 json_object_boolean_true_add(
12223 json_endofrib_status,
12224 "endOfRibRecv");
12225 else
12226 vty_out(vty, "Yes\n");
12227 } else {
12228 if (use_json)
12229 json_object_boolean_false_add(
12230 json_endofrib_status,
12231 "endOfRibRecv");
12232 else
12233 vty_out(vty, "No\n");
12234 }
12235
13909c4f
DS
12236 if (use_json) {
12237 json_object_int_add(json_timer,
12238 "stalePathTimer",
12239 peer->bgp->stalepath_time);
2986cac2 12240
13909c4f
DS
12241 if (peer->t_gr_stale != NULL) {
12242 json_object_int_add(
2986cac2 12243 json_timer,
12244 "stalePathTimerRemaining",
12245 thread_timer_remain_second(
13909c4f
DS
12246 peer->t_gr_stale));
12247 }
3a75afa4 12248
13909c4f
DS
12249 /* Display Configured Selection
12250 * Deferral only when when
12251 * Gr mode is enabled.
12252 */
12253 if (CHECK_FLAG(peer->flags,
12254 PEER_FLAG_GRACEFUL_RESTART)) {
12255 json_object_int_add(
3a75afa4 12256 json_timer,
2986cac2 12257 "selectionDeferralTimer",
12258 peer->bgp->stalepath_time);
13909c4f 12259 }
2986cac2 12260
13909c4f
DS
12261 if (peer->bgp->gr_info[afi][safi]
12262 .t_select_deferral
12263 != NULL) {
2986cac2 12264
13909c4f 12265 json_object_int_add(
2986cac2 12266 json_timer,
12267 "selectionDeferralTimerRemaining",
12268 thread_timer_remain_second(
13909c4f
DS
12269 peer->bgp
12270 ->gr_info[afi]
12271 [safi]
12272 .t_select_deferral));
12273 }
12274 } else {
a53ca37b 12275 vty_out(vty, " Timers:\n");
13909c4f 12276 vty_out(vty,
a53ca37b
DA
12277 " Configured Stale Path Time(sec): %u\n",
12278 peer->bgp->stalepath_time);
2986cac2 12279
a53ca37b 12280 if (peer->t_gr_stale != NULL)
2986cac2 12281 vty_out(vty,
a53ca37b 12282 " Stale Path Remaining(sec): %ld\n",
2986cac2 12283 thread_timer_remain_second(
13909c4f 12284 peer->t_gr_stale));
13909c4f
DS
12285 /* Display Configured Selection
12286 * Deferral only when when
12287 * Gr mode is enabled.
12288 */
12289 if (CHECK_FLAG(peer->flags,
a53ca37b 12290 PEER_FLAG_GRACEFUL_RESTART))
13909c4f 12291 vty_out(vty,
a53ca37b 12292 " Configured Selection Deferral Time(sec): %u\n",
3a75afa4 12293 peer->bgp->select_defer_time);
2986cac2 12294
13909c4f
DS
12295 if (peer->bgp->gr_info[afi][safi]
12296 .t_select_deferral
a53ca37b 12297 != NULL)
13909c4f 12298 vty_out(vty,
a53ca37b 12299 " Selection Deferral Time Remaining(sec): %ld\n",
2986cac2 12300 thread_timer_remain_second(
13909c4f
DS
12301 peer->bgp
12302 ->gr_info[afi]
12303 [safi]
12304 .t_select_deferral));
2986cac2 12305 }
13909c4f
DS
12306 if (use_json) {
12307 json_object_object_add(json_afi_safi,
12308 "endOfRibStatus",
12309 json_endofrib_status);
12310 json_object_object_add(json_afi_safi, "timers",
12311 json_timer);
12312 json_object_object_add(
12313 json, get_afi_safi_str(afi, safi, true),
12314 json_afi_safi);
12315 }
2986cac2 12316 }
12317 }
12318}
12319
36235319
QY
12320static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
12321 struct peer *p,
12322 bool use_json,
12323 json_object *json)
2986cac2 12324{
12325 if (use_json) {
12326 json_object *json_timer = NULL;
12327
12328 json_timer = json_object_new_object();
12329
13909c4f
DS
12330 json_object_int_add(json_timer, "configuredRestartTimer",
12331 p->bgp->restart_time);
2986cac2 12332
13909c4f
DS
12333 json_object_int_add(json_timer, "receivedRestartTimer",
12334 p->v_gr_restart);
2986cac2 12335
13909c4f
DS
12336 if (p->t_gr_restart != NULL)
12337 json_object_int_add(
12338 json_timer, "restartTimerRemaining",
12339 thread_timer_remain_second(p->t_gr_restart));
2986cac2 12340
12341 json_object_object_add(json, "timers", json_timer);
12342 } else {
12343
a53ca37b
DA
12344 vty_out(vty, " Timers:\n");
12345 vty_out(vty, " Configured Restart Time(sec): %u\n",
13909c4f 12346 p->bgp->restart_time);
2986cac2 12347
a53ca37b 12348 vty_out(vty, " Received Restart Time(sec): %u\n",
13909c4f
DS
12349 p->v_gr_restart);
12350 if (p->t_gr_restart != NULL)
a53ca37b 12351 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
13909c4f 12352 thread_timer_remain_second(p->t_gr_restart));
36235319 12353 if (p->t_gr_restart != NULL) {
a53ca37b 12354 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
36235319
QY
12355 thread_timer_remain_second(p->t_gr_restart));
12356 }
2986cac2 12357 }
12358}
12359
12360static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
36235319 12361 bool use_json, json_object *json)
2986cac2 12362{
12363 char buf[SU_ADDRSTRLEN] = {0};
12364 char dn_flag[2] = {0};
2b7165e7
QY
12365 /* '*' + v6 address of neighbor */
12366 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
2986cac2 12367
2986cac2 12368 if (!p->conf_if && peer_dynamic_neighbor(p))
12369 dn_flag[0] = '*';
12370
12371 if (p->conf_if) {
12372 if (use_json)
13909c4f
DS
12373 json_object_string_add(
12374 json, "neighborAddr",
2986cac2 12375 BGP_PEER_SU_UNSPEC(p)
13909c4f
DS
12376 ? "none"
12377 : sockunion2str(&p->su, buf,
12378 SU_ADDRSTRLEN));
2986cac2 12379 else
13909c4f 12380 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
2986cac2 12381 BGP_PEER_SU_UNSPEC(p)
12382 ? "none"
12383 : sockunion2str(&p->su, buf,
12384 SU_ADDRSTRLEN));
12385 } else {
772270f3
QY
12386 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
12387 p->host);
2986cac2 12388
12389 if (use_json)
36235319
QY
12390 json_object_string_add(json, "neighborAddr",
12391 neighborAddr);
2986cac2 12392 else
36235319 12393 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
2986cac2 12394 }
12395
12396 /* more gr info in new format */
12397 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
12398}
12399
d62a17ae 12400static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 12401 safi_t safi, bool use_json,
d62a17ae 12402 json_object *json_neigh)
12403{
0291c246
MK
12404 struct bgp_filter *filter;
12405 struct peer_af *paf;
12406 char orf_pfx_name[BUFSIZ];
12407 int orf_pfx_count;
12408 json_object *json_af = NULL;
12409 json_object *json_prefA = NULL;
12410 json_object *json_prefB = NULL;
12411 json_object *json_addr = NULL;
fa36596c 12412 json_object *json_advmap = NULL;
d62a17ae 12413
12414 if (use_json) {
12415 json_addr = json_object_new_object();
12416 json_af = json_object_new_object();
12417 filter = &p->filter[afi][safi];
12418
12419 if (peer_group_active(p))
12420 json_object_string_add(json_addr, "peerGroupMember",
12421 p->group->name);
12422
12423 paf = peer_af_find(p, afi, safi);
12424 if (paf && PAF_SUBGRP(paf)) {
12425 json_object_int_add(json_addr, "updateGroupId",
12426 PAF_UPDGRP(paf)->id);
12427 json_object_int_add(json_addr, "subGroupId",
12428 PAF_SUBGRP(paf)->id);
12429 json_object_int_add(json_addr, "packetQueueLength",
12430 bpacket_queue_virtual_length(paf));
12431 }
12432
12433 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12434 || CHECK_FLAG(p->af_cap[afi][safi],
12435 PEER_CAP_ORF_PREFIX_SM_RCV)
12436 || CHECK_FLAG(p->af_cap[afi][safi],
12437 PEER_CAP_ORF_PREFIX_RM_ADV)
12438 || CHECK_FLAG(p->af_cap[afi][safi],
12439 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12440 json_object_int_add(json_af, "orfType",
12441 ORF_TYPE_PREFIX);
12442 json_prefA = json_object_new_object();
12443 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
12444 PEER_CAP_ORF_PREFIX_SM_ADV,
12445 PEER_CAP_ORF_PREFIX_RM_ADV,
12446 PEER_CAP_ORF_PREFIX_SM_RCV,
12447 PEER_CAP_ORF_PREFIX_RM_RCV,
12448 use_json, json_prefA);
12449 json_object_object_add(json_af, "orfPrefixList",
12450 json_prefA);
12451 }
12452
12453 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12454 || CHECK_FLAG(p->af_cap[afi][safi],
12455 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12456 || CHECK_FLAG(p->af_cap[afi][safi],
12457 PEER_CAP_ORF_PREFIX_RM_ADV)
12458 || CHECK_FLAG(p->af_cap[afi][safi],
12459 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12460 json_object_int_add(json_af, "orfOldType",
12461 ORF_TYPE_PREFIX_OLD);
12462 json_prefB = json_object_new_object();
12463 bgp_show_peer_afi_orf_cap(
12464 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12465 PEER_CAP_ORF_PREFIX_RM_ADV,
12466 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12467 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
12468 json_prefB);
12469 json_object_object_add(json_af, "orfOldPrefixList",
12470 json_prefB);
12471 }
12472
12473 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12474 || CHECK_FLAG(p->af_cap[afi][safi],
12475 PEER_CAP_ORF_PREFIX_SM_RCV)
12476 || CHECK_FLAG(p->af_cap[afi][safi],
12477 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12478 || CHECK_FLAG(p->af_cap[afi][safi],
12479 PEER_CAP_ORF_PREFIX_RM_ADV)
12480 || CHECK_FLAG(p->af_cap[afi][safi],
12481 PEER_CAP_ORF_PREFIX_RM_RCV)
12482 || CHECK_FLAG(p->af_cap[afi][safi],
12483 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12484 json_object_object_add(json_addr, "afDependentCap",
12485 json_af);
12486 else
12487 json_object_free(json_af);
12488
772270f3
QY
12489 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12490 p->host, afi, safi);
d62a17ae 12491 orf_pfx_count = prefix_bgp_show_prefix_list(
12492 NULL, afi, orf_pfx_name, use_json);
12493
12494 if (CHECK_FLAG(p->af_sflags[afi][safi],
12495 PEER_STATUS_ORF_PREFIX_SEND)
12496 || orf_pfx_count) {
12497 if (CHECK_FLAG(p->af_sflags[afi][safi],
12498 PEER_STATUS_ORF_PREFIX_SEND))
12499 json_object_boolean_true_add(json_neigh,
12500 "orfSent");
12501 if (orf_pfx_count)
12502 json_object_int_add(json_addr, "orfRecvCounter",
12503 orf_pfx_count);
12504 }
12505 if (CHECK_FLAG(p->af_sflags[afi][safi],
12506 PEER_STATUS_ORF_WAIT_REFRESH))
12507 json_object_string_add(
12508 json_addr, "orfFirstUpdate",
12509 "deferredUntilORFOrRouteRefreshRecvd");
12510
12511 if (CHECK_FLAG(p->af_flags[afi][safi],
12512 PEER_FLAG_REFLECTOR_CLIENT))
12513 json_object_boolean_true_add(json_addr,
12514 "routeReflectorClient");
12515 if (CHECK_FLAG(p->af_flags[afi][safi],
12516 PEER_FLAG_RSERVER_CLIENT))
12517 json_object_boolean_true_add(json_addr,
12518 "routeServerClient");
12519 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12520 json_object_boolean_true_add(json_addr,
12521 "inboundSoftConfigPermit");
12522
12523 if (CHECK_FLAG(p->af_flags[afi][safi],
12524 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12525 json_object_boolean_true_add(
12526 json_addr,
12527 "privateAsNumsAllReplacedInUpdatesToNbr");
12528 else if (CHECK_FLAG(p->af_flags[afi][safi],
12529 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12530 json_object_boolean_true_add(
12531 json_addr,
12532 "privateAsNumsReplacedInUpdatesToNbr");
12533 else if (CHECK_FLAG(p->af_flags[afi][safi],
12534 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12535 json_object_boolean_true_add(
12536 json_addr,
12537 "privateAsNumsAllRemovedInUpdatesToNbr");
12538 else if (CHECK_FLAG(p->af_flags[afi][safi],
12539 PEER_FLAG_REMOVE_PRIVATE_AS))
12540 json_object_boolean_true_add(
12541 json_addr,
12542 "privateAsNumsRemovedInUpdatesToNbr");
12543
dcc68b5e
MS
12544 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12545 json_object_boolean_true_add(
12546 json_addr,
12547 bgp_addpath_names(p->addpath_type[afi][safi])
12548 ->type_json_name);
d62a17ae 12549
12550 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12551 json_object_string_add(json_addr,
12552 "overrideASNsInOutboundUpdates",
12553 "ifAspathEqualRemoteAs");
12554
12555 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12556 || CHECK_FLAG(p->af_flags[afi][safi],
12557 PEER_FLAG_FORCE_NEXTHOP_SELF))
12558 json_object_boolean_true_add(json_addr,
12559 "routerAlwaysNextHop");
12560 if (CHECK_FLAG(p->af_flags[afi][safi],
12561 PEER_FLAG_AS_PATH_UNCHANGED))
12562 json_object_boolean_true_add(
12563 json_addr, "unchangedAsPathPropogatedToNbr");
12564 if (CHECK_FLAG(p->af_flags[afi][safi],
12565 PEER_FLAG_NEXTHOP_UNCHANGED))
12566 json_object_boolean_true_add(
12567 json_addr, "unchangedNextHopPropogatedToNbr");
12568 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12569 json_object_boolean_true_add(
12570 json_addr, "unchangedMedPropogatedToNbr");
12571 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12572 || CHECK_FLAG(p->af_flags[afi][safi],
12573 PEER_FLAG_SEND_EXT_COMMUNITY)) {
12574 if (CHECK_FLAG(p->af_flags[afi][safi],
12575 PEER_FLAG_SEND_COMMUNITY)
12576 && CHECK_FLAG(p->af_flags[afi][safi],
12577 PEER_FLAG_SEND_EXT_COMMUNITY))
12578 json_object_string_add(json_addr,
12579 "commAttriSentToNbr",
12580 "extendedAndStandard");
12581 else if (CHECK_FLAG(p->af_flags[afi][safi],
12582 PEER_FLAG_SEND_EXT_COMMUNITY))
12583 json_object_string_add(json_addr,
12584 "commAttriSentToNbr",
12585 "extended");
12586 else
12587 json_object_string_add(json_addr,
12588 "commAttriSentToNbr",
12589 "standard");
12590 }
12591 if (CHECK_FLAG(p->af_flags[afi][safi],
12592 PEER_FLAG_DEFAULT_ORIGINATE)) {
12593 if (p->default_rmap[afi][safi].name)
12594 json_object_string_add(
12595 json_addr, "defaultRouteMap",
12596 p->default_rmap[afi][safi].name);
12597
12598 if (paf && PAF_SUBGRP(paf)
12599 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12600 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12601 json_object_boolean_true_add(json_addr,
12602 "defaultSent");
12603 else
12604 json_object_boolean_true_add(json_addr,
12605 "defaultNotSent");
12606 }
12607
dff8f48d 12608 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 12609 if (is_evpn_enabled())
60466a63
QY
12610 json_object_boolean_true_add(
12611 json_addr, "advertiseAllVnis");
dff8f48d
MK
12612 }
12613
d62a17ae 12614 if (filter->plist[FILTER_IN].name
12615 || filter->dlist[FILTER_IN].name
12616 || filter->aslist[FILTER_IN].name
12617 || filter->map[RMAP_IN].name)
12618 json_object_boolean_true_add(json_addr,
12619 "inboundPathPolicyConfig");
12620 if (filter->plist[FILTER_OUT].name
12621 || filter->dlist[FILTER_OUT].name
12622 || filter->aslist[FILTER_OUT].name
12623 || filter->map[RMAP_OUT].name || filter->usmap.name)
12624 json_object_boolean_true_add(
12625 json_addr, "outboundPathPolicyConfig");
12626
12627 /* prefix-list */
12628 if (filter->plist[FILTER_IN].name)
12629 json_object_string_add(json_addr,
12630 "incomingUpdatePrefixFilterList",
12631 filter->plist[FILTER_IN].name);
12632 if (filter->plist[FILTER_OUT].name)
12633 json_object_string_add(json_addr,
12634 "outgoingUpdatePrefixFilterList",
12635 filter->plist[FILTER_OUT].name);
12636
12637 /* distribute-list */
12638 if (filter->dlist[FILTER_IN].name)
12639 json_object_string_add(
12640 json_addr, "incomingUpdateNetworkFilterList",
12641 filter->dlist[FILTER_IN].name);
12642 if (filter->dlist[FILTER_OUT].name)
12643 json_object_string_add(
12644 json_addr, "outgoingUpdateNetworkFilterList",
12645 filter->dlist[FILTER_OUT].name);
12646
12647 /* filter-list. */
12648 if (filter->aslist[FILTER_IN].name)
12649 json_object_string_add(json_addr,
12650 "incomingUpdateAsPathFilterList",
12651 filter->aslist[FILTER_IN].name);
12652 if (filter->aslist[FILTER_OUT].name)
12653 json_object_string_add(json_addr,
12654 "outgoingUpdateAsPathFilterList",
12655 filter->aslist[FILTER_OUT].name);
12656
12657 /* route-map. */
12658 if (filter->map[RMAP_IN].name)
12659 json_object_string_add(
12660 json_addr, "routeMapForIncomingAdvertisements",
12661 filter->map[RMAP_IN].name);
12662 if (filter->map[RMAP_OUT].name)
12663 json_object_string_add(
12664 json_addr, "routeMapForOutgoingAdvertisements",
12665 filter->map[RMAP_OUT].name);
12666
9dac9fc8 12667 /* ebgp-requires-policy (inbound) */
1d3fdccf 12668 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12669 && !bgp_inbound_policy_exists(p, filter))
12670 json_object_string_add(
12671 json_addr, "inboundEbgpRequiresPolicy",
12672 "Inbound updates discarded due to missing policy");
12673
12674 /* ebgp-requires-policy (outbound) */
1d3fdccf 12675 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12676 && (!bgp_outbound_policy_exists(p, filter)))
12677 json_object_string_add(
12678 json_addr, "outboundEbgpRequiresPolicy",
12679 "Outbound updates discarded due to missing policy");
12680
d62a17ae 12681 /* unsuppress-map */
12682 if (filter->usmap.name)
12683 json_object_string_add(json_addr,
12684 "selectiveUnsuppressRouteMap",
12685 filter->usmap.name);
12686
fa36596c
MK
12687 /* advertise-map */
12688 if (filter->advmap.aname) {
12689 json_advmap = json_object_new_object();
12690 json_object_string_add(json_advmap, "condition",
12691 filter->advmap.condition
12692 ? "EXIST"
12693 : "NON_EXIST");
12694 json_object_string_add(json_advmap, "conditionMap",
12695 filter->advmap.cname);
12696 json_object_string_add(json_advmap, "advertiseMap",
12697 filter->advmap.aname);
12698 json_object_string_add(json_advmap, "advertiseStatus",
12699 filter->advmap.update_type
12700 == ADVERTISE
12701 ? "Advertise"
12702 : "Withdraw");
12703 json_object_object_add(json_addr, "advertiseMap",
12704 json_advmap);
12705 }
12706
d62a17ae 12707 /* Receive prefix count */
12708 json_object_int_add(json_addr, "acceptedPrefixCounter",
12709 p->pcount[afi][safi]);
50e05855
AD
12710 if (paf && PAF_SUBGRP(paf))
12711 json_object_int_add(json_addr, "sentPrefixCounter",
12712 (PAF_SUBGRP(paf))->scount);
d62a17ae 12713
fde246e8
DA
12714 /* Maximum prefix */
12715 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12716 json_object_int_add(json_addr, "prefixOutAllowedMax",
12717 p->pmax_out[afi][safi]);
12718
d62a17ae 12719 /* Maximum prefix */
12720 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12721 json_object_int_add(json_addr, "prefixAllowedMax",
12722 p->pmax[afi][safi]);
12723 if (CHECK_FLAG(p->af_flags[afi][safi],
12724 PEER_FLAG_MAX_PREFIX_WARNING))
12725 json_object_boolean_true_add(
12726 json_addr, "prefixAllowedMaxWarning");
12727 json_object_int_add(json_addr,
12728 "prefixAllowedWarningThresh",
12729 p->pmax_threshold[afi][safi]);
12730 if (p->pmax_restart[afi][safi])
12731 json_object_int_add(
12732 json_addr,
12733 "prefixAllowedRestartIntervalMsecs",
12734 p->pmax_restart[afi][safi] * 60000);
12735 }
2986cac2 12736 json_object_object_add(json_neigh,
36235319 12737 get_afi_safi_str(afi, safi, true),
d62a17ae 12738 json_addr);
12739
12740 } else {
12741 filter = &p->filter[afi][safi];
12742
12743 vty_out(vty, " For address family: %s\n",
5cb5f4d0 12744 get_afi_safi_str(afi, safi, false));
d62a17ae 12745
12746 if (peer_group_active(p))
12747 vty_out(vty, " %s peer-group member\n",
12748 p->group->name);
12749
12750 paf = peer_af_find(p, afi, safi);
12751 if (paf && PAF_SUBGRP(paf)) {
6cde4b45 12752 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
d62a17ae 12753 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12754 vty_out(vty, " Packet Queue length %d\n",
12755 bpacket_queue_virtual_length(paf));
12756 } else {
12757 vty_out(vty, " Not part of any update group\n");
12758 }
12759 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12760 || CHECK_FLAG(p->af_cap[afi][safi],
12761 PEER_CAP_ORF_PREFIX_SM_RCV)
12762 || CHECK_FLAG(p->af_cap[afi][safi],
12763 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12764 || CHECK_FLAG(p->af_cap[afi][safi],
12765 PEER_CAP_ORF_PREFIX_RM_ADV)
12766 || CHECK_FLAG(p->af_cap[afi][safi],
12767 PEER_CAP_ORF_PREFIX_RM_RCV)
12768 || CHECK_FLAG(p->af_cap[afi][safi],
12769 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12770 vty_out(vty, " AF-dependant capabilities:\n");
12771
12772 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12773 || CHECK_FLAG(p->af_cap[afi][safi],
12774 PEER_CAP_ORF_PREFIX_SM_RCV)
12775 || CHECK_FLAG(p->af_cap[afi][safi],
12776 PEER_CAP_ORF_PREFIX_RM_ADV)
12777 || CHECK_FLAG(p->af_cap[afi][safi],
12778 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12779 vty_out(vty,
12780 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12781 ORF_TYPE_PREFIX);
12782 bgp_show_peer_afi_orf_cap(
12783 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12784 PEER_CAP_ORF_PREFIX_RM_ADV,
12785 PEER_CAP_ORF_PREFIX_SM_RCV,
12786 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12787 }
12788 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12789 || CHECK_FLAG(p->af_cap[afi][safi],
12790 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12791 || CHECK_FLAG(p->af_cap[afi][safi],
12792 PEER_CAP_ORF_PREFIX_RM_ADV)
12793 || CHECK_FLAG(p->af_cap[afi][safi],
12794 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12795 vty_out(vty,
12796 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12797 ORF_TYPE_PREFIX_OLD);
12798 bgp_show_peer_afi_orf_cap(
12799 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12800 PEER_CAP_ORF_PREFIX_RM_ADV,
12801 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12802 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12803 }
12804
772270f3
QY
12805 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12806 p->host, afi, safi);
d62a17ae 12807 orf_pfx_count = prefix_bgp_show_prefix_list(
12808 NULL, afi, orf_pfx_name, use_json);
12809
12810 if (CHECK_FLAG(p->af_sflags[afi][safi],
12811 PEER_STATUS_ORF_PREFIX_SEND)
12812 || orf_pfx_count) {
12813 vty_out(vty, " Outbound Route Filter (ORF):");
12814 if (CHECK_FLAG(p->af_sflags[afi][safi],
12815 PEER_STATUS_ORF_PREFIX_SEND))
12816 vty_out(vty, " sent;");
12817 if (orf_pfx_count)
12818 vty_out(vty, " received (%d entries)",
12819 orf_pfx_count);
12820 vty_out(vty, "\n");
12821 }
12822 if (CHECK_FLAG(p->af_sflags[afi][safi],
12823 PEER_STATUS_ORF_WAIT_REFRESH))
12824 vty_out(vty,
12825 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12826
12827 if (CHECK_FLAG(p->af_flags[afi][safi],
12828 PEER_FLAG_REFLECTOR_CLIENT))
12829 vty_out(vty, " Route-Reflector Client\n");
12830 if (CHECK_FLAG(p->af_flags[afi][safi],
12831 PEER_FLAG_RSERVER_CLIENT))
12832 vty_out(vty, " Route-Server Client\n");
12833 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12834 vty_out(vty,
12835 " Inbound soft reconfiguration allowed\n");
12836
12837 if (CHECK_FLAG(p->af_flags[afi][safi],
12838 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12839 vty_out(vty,
12840 " Private AS numbers (all) replaced in updates to this neighbor\n");
12841 else if (CHECK_FLAG(p->af_flags[afi][safi],
12842 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12843 vty_out(vty,
12844 " Private AS numbers replaced in updates to this neighbor\n");
12845 else if (CHECK_FLAG(p->af_flags[afi][safi],
12846 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12847 vty_out(vty,
12848 " Private AS numbers (all) removed in updates to this neighbor\n");
12849 else if (CHECK_FLAG(p->af_flags[afi][safi],
12850 PEER_FLAG_REMOVE_PRIVATE_AS))
12851 vty_out(vty,
12852 " Private AS numbers removed in updates to this neighbor\n");
12853
dcc68b5e
MS
12854 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12855 vty_out(vty, " %s\n",
12856 bgp_addpath_names(p->addpath_type[afi][safi])
12857 ->human_description);
d62a17ae 12858
12859 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12860 vty_out(vty,
12861 " Override ASNs in outbound updates if aspath equals remote-as\n");
12862
12863 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12864 || CHECK_FLAG(p->af_flags[afi][safi],
12865 PEER_FLAG_FORCE_NEXTHOP_SELF))
12866 vty_out(vty, " NEXT_HOP is always this router\n");
12867 if (CHECK_FLAG(p->af_flags[afi][safi],
12868 PEER_FLAG_AS_PATH_UNCHANGED))
12869 vty_out(vty,
12870 " AS_PATH is propagated unchanged to this neighbor\n");
12871 if (CHECK_FLAG(p->af_flags[afi][safi],
12872 PEER_FLAG_NEXTHOP_UNCHANGED))
12873 vty_out(vty,
12874 " NEXT_HOP is propagated unchanged to this neighbor\n");
12875 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12876 vty_out(vty,
12877 " MED is propagated unchanged to this neighbor\n");
12878 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12879 || CHECK_FLAG(p->af_flags[afi][safi],
12880 PEER_FLAG_SEND_EXT_COMMUNITY)
12881 || CHECK_FLAG(p->af_flags[afi][safi],
12882 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12883 vty_out(vty,
12884 " Community attribute sent to this neighbor");
12885 if (CHECK_FLAG(p->af_flags[afi][safi],
12886 PEER_FLAG_SEND_COMMUNITY)
12887 && CHECK_FLAG(p->af_flags[afi][safi],
12888 PEER_FLAG_SEND_EXT_COMMUNITY)
12889 && CHECK_FLAG(p->af_flags[afi][safi],
12890 PEER_FLAG_SEND_LARGE_COMMUNITY))
12891 vty_out(vty, "(all)\n");
12892 else if (CHECK_FLAG(p->af_flags[afi][safi],
12893 PEER_FLAG_SEND_LARGE_COMMUNITY))
12894 vty_out(vty, "(large)\n");
12895 else if (CHECK_FLAG(p->af_flags[afi][safi],
12896 PEER_FLAG_SEND_EXT_COMMUNITY))
12897 vty_out(vty, "(extended)\n");
12898 else
12899 vty_out(vty, "(standard)\n");
12900 }
12901 if (CHECK_FLAG(p->af_flags[afi][safi],
12902 PEER_FLAG_DEFAULT_ORIGINATE)) {
12903 vty_out(vty, " Default information originate,");
12904
12905 if (p->default_rmap[afi][safi].name)
12906 vty_out(vty, " default route-map %s%s,",
12907 p->default_rmap[afi][safi].map ? "*"
12908 : "",
12909 p->default_rmap[afi][safi].name);
12910 if (paf && PAF_SUBGRP(paf)
12911 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12912 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12913 vty_out(vty, " default sent\n");
12914 else
12915 vty_out(vty, " default not sent\n");
12916 }
12917
dff8f48d
MK
12918 /* advertise-vni-all */
12919 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 12920 if (is_evpn_enabled())
dff8f48d
MK
12921 vty_out(vty, " advertise-all-vni\n");
12922 }
12923
d62a17ae 12924 if (filter->plist[FILTER_IN].name
12925 || filter->dlist[FILTER_IN].name
12926 || filter->aslist[FILTER_IN].name
12927 || filter->map[RMAP_IN].name)
12928 vty_out(vty, " Inbound path policy configured\n");
12929 if (filter->plist[FILTER_OUT].name
12930 || filter->dlist[FILTER_OUT].name
12931 || filter->aslist[FILTER_OUT].name
12932 || filter->map[RMAP_OUT].name || filter->usmap.name)
12933 vty_out(vty, " Outbound path policy configured\n");
12934
12935 /* prefix-list */
12936 if (filter->plist[FILTER_IN].name)
12937 vty_out(vty,
12938 " Incoming update prefix filter list is %s%s\n",
12939 filter->plist[FILTER_IN].plist ? "*" : "",
12940 filter->plist[FILTER_IN].name);
12941 if (filter->plist[FILTER_OUT].name)
12942 vty_out(vty,
12943 " Outgoing update prefix filter list is %s%s\n",
12944 filter->plist[FILTER_OUT].plist ? "*" : "",
12945 filter->plist[FILTER_OUT].name);
12946
12947 /* distribute-list */
12948 if (filter->dlist[FILTER_IN].name)
12949 vty_out(vty,
12950 " Incoming update network filter list is %s%s\n",
12951 filter->dlist[FILTER_IN].alist ? "*" : "",
12952 filter->dlist[FILTER_IN].name);
12953 if (filter->dlist[FILTER_OUT].name)
12954 vty_out(vty,
12955 " Outgoing update network filter list is %s%s\n",
12956 filter->dlist[FILTER_OUT].alist ? "*" : "",
12957 filter->dlist[FILTER_OUT].name);
12958
12959 /* filter-list. */
12960 if (filter->aslist[FILTER_IN].name)
12961 vty_out(vty,
12962 " Incoming update AS path filter list is %s%s\n",
12963 filter->aslist[FILTER_IN].aslist ? "*" : "",
12964 filter->aslist[FILTER_IN].name);
12965 if (filter->aslist[FILTER_OUT].name)
12966 vty_out(vty,
12967 " Outgoing update AS path filter list is %s%s\n",
12968 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12969 filter->aslist[FILTER_OUT].name);
12970
12971 /* route-map. */
12972 if (filter->map[RMAP_IN].name)
12973 vty_out(vty,
12974 " Route map for incoming advertisements is %s%s\n",
12975 filter->map[RMAP_IN].map ? "*" : "",
12976 filter->map[RMAP_IN].name);
12977 if (filter->map[RMAP_OUT].name)
12978 vty_out(vty,
12979 " Route map for outgoing advertisements is %s%s\n",
12980 filter->map[RMAP_OUT].map ? "*" : "",
12981 filter->map[RMAP_OUT].name);
12982
9dac9fc8 12983 /* ebgp-requires-policy (inbound) */
1d3fdccf 12984 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12985 && !bgp_inbound_policy_exists(p, filter))
12986 vty_out(vty,
12987 " Inbound updates discarded due to missing policy\n");
12988
12989 /* ebgp-requires-policy (outbound) */
1d3fdccf 12990 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12991 && !bgp_outbound_policy_exists(p, filter))
12992 vty_out(vty,
12993 " Outbound updates discarded due to missing policy\n");
12994
d62a17ae 12995 /* unsuppress-map */
12996 if (filter->usmap.name)
12997 vty_out(vty,
12998 " Route map for selective unsuppress is %s%s\n",
12999 filter->usmap.map ? "*" : "",
13000 filter->usmap.name);
13001
7f7940e6
MK
13002 /* advertise-map */
13003 if (filter->advmap.aname && filter->advmap.cname)
13004 vty_out(vty,
13005 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
13006 filter->advmap.condition ? "EXIST"
13007 : "NON_EXIST",
13008 filter->advmap.cmap ? "*" : "",
13009 filter->advmap.cname,
13010 filter->advmap.amap ? "*" : "",
13011 filter->advmap.aname,
fa36596c 13012 filter->advmap.update_type == ADVERTISE
c385f82a
MK
13013 ? "Advertise"
13014 : "Withdraw");
7f7940e6 13015
d62a17ae 13016 /* Receive prefix count */
6cde4b45 13017 vty_out(vty, " %u accepted prefixes\n",
a0a87037 13018 p->pcount[afi][safi]);
d62a17ae 13019
fde246e8
DA
13020 /* maximum-prefix-out */
13021 if (CHECK_FLAG(p->af_flags[afi][safi],
13022 PEER_FLAG_MAX_PREFIX_OUT))
13023 vty_out(vty,
6cde4b45 13024 " Maximum allowed prefixes sent %u\n",
fde246e8
DA
13025 p->pmax_out[afi][safi]);
13026
d62a17ae 13027 /* Maximum prefix */
13028 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
a0a87037 13029 vty_out(vty,
6cde4b45 13030 " Maximum prefixes allowed %u%s\n",
d62a17ae 13031 p->pmax[afi][safi],
13032 CHECK_FLAG(p->af_flags[afi][safi],
13033 PEER_FLAG_MAX_PREFIX_WARNING)
13034 ? " (warning-only)"
13035 : "");
13036 vty_out(vty, " Threshold for warning message %d%%",
13037 p->pmax_threshold[afi][safi]);
13038 if (p->pmax_restart[afi][safi])
13039 vty_out(vty, ", restart interval %d min",
13040 p->pmax_restart[afi][safi]);
13041 vty_out(vty, "\n");
13042 }
13043
13044 vty_out(vty, "\n");
13045 }
13046}
13047
9f049418 13048static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 13049 json_object *json)
718e3744 13050{
d62a17ae 13051 struct bgp *bgp;
13052 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
13053 char timebuf[BGP_UPTIME_LEN];
13054 char dn_flag[2];
d62a17ae 13055 afi_t afi;
13056 safi_t safi;
d7c0a89a
QY
13057 uint16_t i;
13058 uint8_t *msg;
d62a17ae 13059 json_object *json_neigh = NULL;
13060 time_t epoch_tbuf;
4ab46701 13061 uint32_t sync_tcp_mss;
718e3744 13062
d62a17ae 13063 bgp = p->bgp;
13064
13065 if (use_json)
13066 json_neigh = json_object_new_object();
13067
13068 memset(dn_flag, '\0', sizeof(dn_flag));
13069 if (!p->conf_if && peer_dynamic_neighbor(p))
13070 dn_flag[0] = '*';
13071
13072 if (!use_json) {
13073 if (p->conf_if) /* Configured interface name. */
13074 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
13075 BGP_PEER_SU_UNSPEC(p)
13076 ? "None"
13077 : sockunion2str(&p->su, buf,
13078 SU_ADDRSTRLEN));
13079 else /* Configured IP address. */
13080 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
13081 p->host);
13082 }
13083
13084 if (use_json) {
13085 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
13086 json_object_string_add(json_neigh, "bgpNeighborAddr",
13087 "none");
13088 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
13089 json_object_string_add(
13090 json_neigh, "bgpNeighborAddr",
13091 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
13092
13093 json_object_int_add(json_neigh, "remoteAs", p->as);
13094
13095 if (p->change_local_as)
13096 json_object_int_add(json_neigh, "localAs",
13097 p->change_local_as);
13098 else
13099 json_object_int_add(json_neigh, "localAs", p->local_as);
13100
13101 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
13102 json_object_boolean_true_add(json_neigh,
13103 "localAsNoPrepend");
13104
13105 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
13106 json_object_boolean_true_add(json_neigh,
13107 "localAsReplaceAs");
13108 } else {
13109 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
13110 || (p->as_type == AS_INTERNAL))
13111 vty_out(vty, "remote AS %u, ", p->as);
13112 else
13113 vty_out(vty, "remote AS Unspecified, ");
13114 vty_out(vty, "local AS %u%s%s, ",
13115 p->change_local_as ? p->change_local_as : p->local_as,
13116 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
13117 ? " no-prepend"
13118 : "",
13119 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
13120 ? " replace-as"
13121 : "");
13122 }
faa16034
DS
13123 /* peer type internal or confed-internal */
13124 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
d62a17ae 13125 if (use_json) {
13126 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13127 json_object_boolean_true_add(
13128 json_neigh, "nbrConfedInternalLink");
13129 else
13130 json_object_boolean_true_add(json_neigh,
13131 "nbrInternalLink");
13132 } else {
13133 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13134 vty_out(vty, "confed-internal link\n");
13135 else
13136 vty_out(vty, "internal link\n");
13137 }
faa16034
DS
13138 /* peer type external or confed-external */
13139 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
d62a17ae 13140 if (use_json) {
13141 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13142 json_object_boolean_true_add(
13143 json_neigh, "nbrConfedExternalLink");
13144 else
13145 json_object_boolean_true_add(json_neigh,
13146 "nbrExternalLink");
13147 } else {
13148 if (bgp_confederation_peers_check(bgp, p->as))
13149 vty_out(vty, "confed-external link\n");
13150 else
13151 vty_out(vty, "external link\n");
13152 }
faa16034
DS
13153 } else {
13154 if (use_json)
13155 json_object_boolean_true_add(json_neigh,
13156 "nbrUnspecifiedLink");
13157 else
13158 vty_out(vty, "unspecified link\n");
d62a17ae 13159 }
13160
13161 /* Description. */
13162 if (p->desc) {
13163 if (use_json)
13164 json_object_string_add(json_neigh, "nbrDesc", p->desc);
13165 else
13166 vty_out(vty, " Description: %s\n", p->desc);
13167 }
13168
13169 if (p->hostname) {
13170 if (use_json) {
13171 if (p->hostname)
13172 json_object_string_add(json_neigh, "hostname",
13173 p->hostname);
13174
13175 if (p->domainname)
13176 json_object_string_add(json_neigh, "domainname",
13177 p->domainname);
13178 } else {
13179 if (p->domainname && (p->domainname[0] != '\0'))
13180 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
13181 p->domainname);
13182 else
13183 vty_out(vty, "Hostname: %s\n", p->hostname);
13184 }
13185 }
13186
13187 /* Peer-group */
13188 if (p->group) {
13189 if (use_json) {
13190 json_object_string_add(json_neigh, "peerGroup",
13191 p->group->name);
13192
13193 if (dn_flag[0]) {
13194 struct prefix prefix, *range = NULL;
13195
0154d8ce
DS
13196 if (sockunion2hostprefix(&(p->su), &prefix))
13197 range = peer_group_lookup_dynamic_neighbor_range(
13198 p->group, &prefix);
d62a17ae 13199
13200 if (range) {
13201 prefix2str(range, buf1, sizeof(buf1));
13202 json_object_string_add(
13203 json_neigh,
13204 "peerSubnetRangeGroup", buf1);
13205 }
13206 }
13207 } else {
13208 vty_out(vty,
13209 " Member of peer-group %s for session parameters\n",
13210 p->group->name);
13211
13212 if (dn_flag[0]) {
13213 struct prefix prefix, *range = NULL;
13214
0154d8ce
DS
13215 if (sockunion2hostprefix(&(p->su), &prefix))
13216 range = peer_group_lookup_dynamic_neighbor_range(
13217 p->group, &prefix);
d62a17ae 13218
13219 if (range) {
d62a17ae 13220 vty_out(vty,
1b78780b
DL
13221 " Belongs to the subnet range group: %pFX\n",
13222 range);
d62a17ae 13223 }
13224 }
13225 }
13226 }
13227
13228 if (use_json) {
13229 /* Administrative shutdown. */
cb9196e7
DS
13230 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13231 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 13232 json_object_boolean_true_add(json_neigh,
13233 "adminShutDown");
13234
13235 /* BGP Version. */
13236 json_object_int_add(json_neigh, "bgpVersion", 4);
13237 json_object_string_add(
13238 json_neigh, "remoteRouterId",
13239 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
d0086e8e
AD
13240 json_object_string_add(
13241 json_neigh, "localRouterId",
13242 inet_ntop(AF_INET, &bgp->router_id, buf1,
13243 sizeof(buf1)));
d62a17ae 13244
13245 /* Confederation */
13246 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13247 && bgp_confederation_peers_check(bgp, p->as))
13248 json_object_boolean_true_add(json_neigh,
13249 "nbrCommonAdmin");
13250
13251 /* Status. */
13252 json_object_string_add(
13253 json_neigh, "bgpState",
13254 lookup_msg(bgp_status_msg, p->status, NULL));
13255
feb17238 13256 if (peer_established(p)) {
d62a17ae 13257 time_t uptime;
d62a17ae 13258
13259 uptime = bgp_clock();
13260 uptime -= p->uptime;
d62a17ae 13261 epoch_tbuf = time(NULL) - uptime;
13262
d3c7efed
DS
13263 json_object_int_add(json_neigh, "bgpTimerUpMsec",
13264 uptime * 1000);
d62a17ae 13265 json_object_string_add(json_neigh, "bgpTimerUpString",
13266 peer_uptime(p->uptime, timebuf,
13267 BGP_UPTIME_LEN, 0,
13268 NULL));
13269 json_object_int_add(json_neigh,
13270 "bgpTimerUpEstablishedEpoch",
13271 epoch_tbuf);
13272 }
13273
13274 else if (p->status == Active) {
13275 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13276 json_object_string_add(json_neigh, "bgpStateIs",
13277 "passive");
13278 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13279 json_object_string_add(json_neigh, "bgpStateIs",
13280 "passiveNSF");
13281 }
13282
13283 /* read timer */
13284 time_t uptime;
a2700b50 13285 struct tm tm;
d62a17ae 13286
13287 uptime = bgp_clock();
13288 uptime -= p->readtime;
a2700b50
MS
13289 gmtime_r(&uptime, &tm);
13290
d62a17ae 13291 json_object_int_add(json_neigh, "bgpTimerLastRead",
a2700b50
MS
13292 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13293 + (tm.tm_hour * 3600000));
d62a17ae 13294
13295 uptime = bgp_clock();
13296 uptime -= p->last_write;
a2700b50
MS
13297 gmtime_r(&uptime, &tm);
13298
d62a17ae 13299 json_object_int_add(json_neigh, "bgpTimerLastWrite",
a2700b50
MS
13300 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13301 + (tm.tm_hour * 3600000));
d62a17ae 13302
13303 uptime = bgp_clock();
13304 uptime -= p->update_time;
a2700b50
MS
13305 gmtime_r(&uptime, &tm);
13306
d62a17ae 13307 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
a2700b50
MS
13308 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13309 + (tm.tm_hour * 3600000));
d62a17ae 13310
13311 /* Configured timer values. */
13312 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
13313 p->v_holdtime * 1000);
13314 json_object_int_add(json_neigh,
13315 "bgpTimerKeepAliveIntervalMsecs",
13316 p->v_keepalive * 1000);
d43114f3
DS
13317 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
13318 json_object_int_add(json_neigh,
13319 "bgpTimerDelayOpenTimeMsecs",
13320 p->v_delayopen * 1000);
13321 }
13322
4ab46701
AR
13323 /* Configured and Synced tcp-mss value for peer */
13324 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13325 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13326 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
13327 p->tcp_mss);
13328 json_object_int_add(json_neigh, "bgpTcpMssSynced",
13329 sync_tcp_mss);
13330 }
13331
b90a8e13 13332 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 13333 json_object_int_add(json_neigh,
13334 "bgpTimerConfiguredHoldTimeMsecs",
13335 p->holdtime * 1000);
13336 json_object_int_add(
13337 json_neigh,
13338 "bgpTimerConfiguredKeepAliveIntervalMsecs",
13339 p->keepalive * 1000);
5d5393b9
DL
13340 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
13341 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
13342 json_object_int_add(json_neigh,
13343 "bgpTimerConfiguredHoldTimeMsecs",
13344 bgp->default_holdtime);
13345 json_object_int_add(
13346 json_neigh,
13347 "bgpTimerConfiguredKeepAliveIntervalMsecs",
13348 bgp->default_keepalive);
d62a17ae 13349 }
13350 } else {
13351 /* Administrative shutdown. */
cb9196e7
DS
13352 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13353 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 13354 vty_out(vty, " Administratively shut down\n");
13355
13356 /* BGP Version. */
13357 vty_out(vty, " BGP version 4");
0e38aeb4 13358 vty_out(vty, ", remote router ID %s",
d62a17ae 13359 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
0e38aeb4
AD
13360 vty_out(vty, ", local router ID %s\n",
13361 inet_ntop(AF_INET, &bgp->router_id, buf1,
13362 sizeof(buf1)));
d62a17ae 13363
13364 /* Confederation */
13365 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13366 && bgp_confederation_peers_check(bgp, p->as))
13367 vty_out(vty,
13368 " Neighbor under common administration\n");
13369
13370 /* Status. */
13371 vty_out(vty, " BGP state = %s",
13372 lookup_msg(bgp_status_msg, p->status, NULL));
13373
feb17238 13374 if (peer_established(p))
d62a17ae 13375 vty_out(vty, ", up for %8s",
13376 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
13377 0, NULL));
13378
13379 else if (p->status == Active) {
13380 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13381 vty_out(vty, " (passive)");
13382 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13383 vty_out(vty, " (NSF passive)");
13384 }
13385 vty_out(vty, "\n");
13386
13387 /* read timer */
13388 vty_out(vty, " Last read %s",
13389 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
13390 NULL));
13391 vty_out(vty, ", Last write %s\n",
13392 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
13393 NULL));
13394
13395 /* Configured timer values. */
13396 vty_out(vty,
13397 " Hold time is %d, keepalive interval is %d seconds\n",
13398 p->v_holdtime, p->v_keepalive);
b90a8e13 13399 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 13400 vty_out(vty, " Configured hold time is %d",
13401 p->holdtime);
13402 vty_out(vty, ", keepalive interval is %d seconds\n",
13403 p->keepalive);
5d5393b9
DL
13404 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
13405 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
13406 vty_out(vty, " Configured hold time is %d",
13407 bgp->default_holdtime);
13408 vty_out(vty, ", keepalive interval is %d seconds\n",
13409 bgp->default_keepalive);
d62a17ae 13410 }
d43114f3
DS
13411 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
13412 vty_out(vty,
13413 " Configured DelayOpenTime is %d seconds\n",
13414 p->delayopen);
4ab46701
AR
13415
13416 /* Configured and synced tcp-mss value for peer */
13417 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13418 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13419 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
13420 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
13421 }
d62a17ae 13422 }
13423 /* Capability. */
feb17238 13424 if (peer_established(p)) {
d62a17ae 13425 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
13426 || p->afc_recv[AFI_IP][SAFI_UNICAST]
13427 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
13428 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
13429 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
13430 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
13431 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
13432 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
13433 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
13434 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
13435 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
13436 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
7c40bf39 13437 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
13438 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
d62a17ae 13439 || p->afc_adv[AFI_IP][SAFI_ENCAP]
13440 || p->afc_recv[AFI_IP][SAFI_ENCAP]
7c40bf39 13441 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
13442 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
d62a17ae 13443 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
13444 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
13445 if (use_json) {
13446 json_object *json_cap = NULL;
13447
13448 json_cap = json_object_new_object();
13449
13450 /* AS4 */
13451 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
13452 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13453 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
13454 && CHECK_FLAG(p->cap,
13455 PEER_CAP_AS4_RCV))
13456 json_object_string_add(
13457 json_cap, "4byteAs",
13458 "advertisedAndReceived");
13459 else if (CHECK_FLAG(p->cap,
13460 PEER_CAP_AS4_ADV))
13461 json_object_string_add(
13462 json_cap, "4byteAs",
13463 "advertised");
13464 else if (CHECK_FLAG(p->cap,
13465 PEER_CAP_AS4_RCV))
13466 json_object_string_add(
13467 json_cap, "4byteAs",
13468 "received");
13469 }
13470
ef56aee4
DA
13471 /* Extended Message Support */
13472 if (CHECK_FLAG(p->cap,
13473 PEER_CAP_EXTENDED_MESSAGE_ADV)
13474 && CHECK_FLAG(
13475 p->cap,
13476 PEER_CAP_EXTENDED_MESSAGE_RCV))
13477 json_object_string_add(
13478 json_cap, "extendedMessage",
13479 "advertisedAndReceived");
13480 else if (CHECK_FLAG(
13481 p->cap,
13482 PEER_CAP_EXTENDED_MESSAGE_ADV))
13483 json_object_string_add(
13484 json_cap, "extendedMessage",
13485 "advertised");
13486 else if (CHECK_FLAG(
13487 p->cap,
13488 PEER_CAP_EXTENDED_MESSAGE_RCV))
13489 json_object_string_add(
13490 json_cap, "extendedMessage",
13491 "received");
13492
d62a17ae 13493 /* AddPath */
13494 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
13495 || CHECK_FLAG(p->cap,
13496 PEER_CAP_ADDPATH_ADV)) {
13497 json_object *json_add = NULL;
13498 const char *print_store;
13499
13500 json_add = json_object_new_object();
13501
05c7a1cc
QY
13502 FOREACH_AFI_SAFI (afi, safi) {
13503 json_object *json_sub = NULL;
13504 json_sub =
13505 json_object_new_object();
5cb5f4d0
DD
13506 print_store = get_afi_safi_str(
13507 afi, safi, true);
d62a17ae 13508
05c7a1cc
QY
13509 if (CHECK_FLAG(
13510 p->af_cap[afi]
13511 [safi],
13512 PEER_CAP_ADDPATH_AF_TX_ADV)
13513 || CHECK_FLAG(
13514 p->af_cap[afi]
13515 [safi],
13516 PEER_CAP_ADDPATH_AF_TX_RCV)) {
d62a17ae 13517 if (CHECK_FLAG(
13518 p->af_cap
13519 [afi]
13520 [safi],
13521 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 13522 && CHECK_FLAG(
d62a17ae 13523 p->af_cap
13524 [afi]
13525 [safi],
05c7a1cc
QY
13526 PEER_CAP_ADDPATH_AF_TX_RCV))
13527 json_object_boolean_true_add(
13528 json_sub,
13529 "txAdvertisedAndReceived");
13530 else if (
13531 CHECK_FLAG(
13532 p->af_cap
13533 [afi]
13534 [safi],
13535 PEER_CAP_ADDPATH_AF_TX_ADV))
13536 json_object_boolean_true_add(
13537 json_sub,
13538 "txAdvertised");
13539 else if (
13540 CHECK_FLAG(
13541 p->af_cap
13542 [afi]
13543 [safi],
13544 PEER_CAP_ADDPATH_AF_TX_RCV))
13545 json_object_boolean_true_add(
13546 json_sub,
13547 "txReceived");
13548 }
d62a17ae 13549
05c7a1cc
QY
13550 if (CHECK_FLAG(
13551 p->af_cap[afi]
13552 [safi],
13553 PEER_CAP_ADDPATH_AF_RX_ADV)
13554 || CHECK_FLAG(
13555 p->af_cap[afi]
13556 [safi],
13557 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 13558 if (CHECK_FLAG(
13559 p->af_cap
13560 [afi]
13561 [safi],
13562 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 13563 && CHECK_FLAG(
d62a17ae 13564 p->af_cap
13565 [afi]
13566 [safi],
13567 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
13568 json_object_boolean_true_add(
13569 json_sub,
13570 "rxAdvertisedAndReceived");
13571 else if (
13572 CHECK_FLAG(
13573 p->af_cap
13574 [afi]
13575 [safi],
13576 PEER_CAP_ADDPATH_AF_RX_ADV))
13577 json_object_boolean_true_add(
13578 json_sub,
13579 "rxAdvertised");
13580 else if (
13581 CHECK_FLAG(
13582 p->af_cap
13583 [afi]
13584 [safi],
13585 PEER_CAP_ADDPATH_AF_RX_RCV))
13586 json_object_boolean_true_add(
13587 json_sub,
13588 "rxReceived");
d62a17ae 13589 }
13590
05c7a1cc
QY
13591 if (CHECK_FLAG(
13592 p->af_cap[afi]
13593 [safi],
13594 PEER_CAP_ADDPATH_AF_TX_ADV)
13595 || CHECK_FLAG(
13596 p->af_cap[afi]
13597 [safi],
13598 PEER_CAP_ADDPATH_AF_TX_RCV)
13599 || CHECK_FLAG(
13600 p->af_cap[afi]
13601 [safi],
13602 PEER_CAP_ADDPATH_AF_RX_ADV)
13603 || CHECK_FLAG(
13604 p->af_cap[afi]
13605 [safi],
13606 PEER_CAP_ADDPATH_AF_RX_RCV))
13607 json_object_object_add(
13608 json_add,
13609 print_store,
13610 json_sub);
13611 else
13612 json_object_free(
13613 json_sub);
13614 }
13615
d62a17ae 13616 json_object_object_add(
13617 json_cap, "addPath", json_add);
13618 }
13619
13620 /* Dynamic */
13621 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
13622 || CHECK_FLAG(p->cap,
13623 PEER_CAP_DYNAMIC_ADV)) {
13624 if (CHECK_FLAG(p->cap,
13625 PEER_CAP_DYNAMIC_ADV)
13626 && CHECK_FLAG(p->cap,
13627 PEER_CAP_DYNAMIC_RCV))
13628 json_object_string_add(
13629 json_cap, "dynamic",
13630 "advertisedAndReceived");
13631 else if (CHECK_FLAG(
13632 p->cap,
13633 PEER_CAP_DYNAMIC_ADV))
13634 json_object_string_add(
13635 json_cap, "dynamic",
13636 "advertised");
13637 else if (CHECK_FLAG(
13638 p->cap,
13639 PEER_CAP_DYNAMIC_RCV))
13640 json_object_string_add(
13641 json_cap, "dynamic",
13642 "received");
13643 }
13644
13645 /* Extended nexthop */
13646 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
13647 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13648 json_object *json_nxt = NULL;
13649 const char *print_store;
13650
13651
13652 if (CHECK_FLAG(p->cap,
13653 PEER_CAP_ENHE_ADV)
13654 && CHECK_FLAG(p->cap,
13655 PEER_CAP_ENHE_RCV))
13656 json_object_string_add(
13657 json_cap,
13658 "extendedNexthop",
13659 "advertisedAndReceived");
13660 else if (CHECK_FLAG(p->cap,
13661 PEER_CAP_ENHE_ADV))
13662 json_object_string_add(
13663 json_cap,
13664 "extendedNexthop",
13665 "advertised");
13666 else if (CHECK_FLAG(p->cap,
13667 PEER_CAP_ENHE_RCV))
13668 json_object_string_add(
13669 json_cap,
13670 "extendedNexthop",
13671 "received");
13672
13673 if (CHECK_FLAG(p->cap,
13674 PEER_CAP_ENHE_RCV)) {
13675 json_nxt =
13676 json_object_new_object();
13677
13678 for (safi = SAFI_UNICAST;
13679 safi < SAFI_MAX; safi++) {
13680 if (CHECK_FLAG(
13681 p->af_cap
13682 [AFI_IP]
13683 [safi],
13684 PEER_CAP_ENHE_AF_RCV)) {
5cb5f4d0 13685 print_store = get_afi_safi_str(
d62a17ae 13686 AFI_IP,
5cb5f4d0 13687 safi, true);
d62a17ae 13688 json_object_string_add(
13689 json_nxt,
13690 print_store,
54f29523 13691 "recieved"); /* misspelled for compatibility */
d62a17ae 13692 }
13693 }
13694 json_object_object_add(
13695 json_cap,
13696 "extendedNexthopFamililesByPeer",
13697 json_nxt);
13698 }
13699 }
13700
13701 /* Route Refresh */
13702 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
13703 || CHECK_FLAG(p->cap,
13704 PEER_CAP_REFRESH_NEW_RCV)
13705 || CHECK_FLAG(p->cap,
13706 PEER_CAP_REFRESH_OLD_RCV)) {
13707 if (CHECK_FLAG(p->cap,
13708 PEER_CAP_REFRESH_ADV)
13709 && (CHECK_FLAG(
13710 p->cap,
13711 PEER_CAP_REFRESH_NEW_RCV)
13712 || CHECK_FLAG(
13713 p->cap,
13714 PEER_CAP_REFRESH_OLD_RCV))) {
13715 if (CHECK_FLAG(
13716 p->cap,
13717 PEER_CAP_REFRESH_OLD_RCV)
13718 && CHECK_FLAG(
13719 p->cap,
13720 PEER_CAP_REFRESH_NEW_RCV))
13721 json_object_string_add(
13722 json_cap,
13723 "routeRefresh",
13724 "advertisedAndReceivedOldNew");
13725 else {
13726 if (CHECK_FLAG(
13727 p->cap,
13728 PEER_CAP_REFRESH_OLD_RCV))
13729 json_object_string_add(
13730 json_cap,
13731 "routeRefresh",
13732 "advertisedAndReceivedOld");
13733 else
13734 json_object_string_add(
13735 json_cap,
13736 "routeRefresh",
13737 "advertisedAndReceivedNew");
13738 }
13739 } else if (
13740 CHECK_FLAG(
13741 p->cap,
13742 PEER_CAP_REFRESH_ADV))
13743 json_object_string_add(
13744 json_cap,
13745 "routeRefresh",
13746 "advertised");
13747 else if (
13748 CHECK_FLAG(
13749 p->cap,
13750 PEER_CAP_REFRESH_NEW_RCV)
13751 || CHECK_FLAG(
13752 p->cap,
13753 PEER_CAP_REFRESH_OLD_RCV))
13754 json_object_string_add(
13755 json_cap,
13756 "routeRefresh",
13757 "received");
13758 }
13759
9af52ccf
DA
13760 /* Enhanced Route Refresh */
13761 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV)
13762 || CHECK_FLAG(p->cap,
13763 PEER_CAP_ENHANCED_RR_RCV)) {
13764 if (CHECK_FLAG(p->cap,
13765 PEER_CAP_ENHANCED_RR_ADV)
13766 && CHECK_FLAG(
13767 p->cap,
13768 PEER_CAP_ENHANCED_RR_RCV))
13769 json_object_string_add(
13770 json_cap,
13771 "enhancedRouteRefresh",
13772 "advertisedAndReceived");
13773 else if (
13774 CHECK_FLAG(
13775 p->cap,
13776 PEER_CAP_ENHANCED_RR_ADV))
13777 json_object_string_add(
13778 json_cap,
13779 "enhancedRouteRefresh",
13780 "advertised");
13781 else if (
13782 CHECK_FLAG(
13783 p->cap,
13784 PEER_CAP_ENHANCED_RR_RCV))
13785 json_object_string_add(
13786 json_cap,
13787 "enhancedRouteRefresh",
13788 "received");
13789 }
13790
d62a17ae 13791 /* Multiprotocol Extensions */
13792 json_object *json_multi = NULL;
13793 json_multi = json_object_new_object();
13794
05c7a1cc
QY
13795 FOREACH_AFI_SAFI (afi, safi) {
13796 if (p->afc_adv[afi][safi]
13797 || p->afc_recv[afi][safi]) {
13798 json_object *json_exten = NULL;
13799 json_exten =
13800 json_object_new_object();
13801
d62a17ae 13802 if (p->afc_adv[afi][safi]
05c7a1cc
QY
13803 && p->afc_recv[afi][safi])
13804 json_object_boolean_true_add(
13805 json_exten,
13806 "advertisedAndReceived");
13807 else if (p->afc_adv[afi][safi])
13808 json_object_boolean_true_add(
13809 json_exten,
13810 "advertised");
13811 else if (p->afc_recv[afi][safi])
13812 json_object_boolean_true_add(
13813 json_exten,
13814 "received");
d62a17ae 13815
05c7a1cc
QY
13816 json_object_object_add(
13817 json_multi,
5cb5f4d0
DD
13818 get_afi_safi_str(afi,
13819 safi,
13820 true),
05c7a1cc 13821 json_exten);
d62a17ae 13822 }
13823 }
13824 json_object_object_add(
13825 json_cap, "multiprotocolExtensions",
13826 json_multi);
13827
d77114b7 13828 /* Hostname capabilities */
60466a63 13829 json_object *json_hname = NULL;
d77114b7
MK
13830
13831 json_hname = json_object_new_object();
13832
13833 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13834 json_object_string_add(
60466a63
QY
13835 json_hname, "advHostName",
13836 bgp->peer_self->hostname
13837 ? bgp->peer_self
13838 ->hostname
d77114b7
MK
13839 : "n/a");
13840 json_object_string_add(
60466a63
QY
13841 json_hname, "advDomainName",
13842 bgp->peer_self->domainname
13843 ? bgp->peer_self
13844 ->domainname
d77114b7
MK
13845 : "n/a");
13846 }
13847
13848
13849 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13850 json_object_string_add(
60466a63
QY
13851 json_hname, "rcvHostName",
13852 p->hostname ? p->hostname
13853 : "n/a");
d77114b7 13854 json_object_string_add(
60466a63
QY
13855 json_hname, "rcvDomainName",
13856 p->domainname ? p->domainname
13857 : "n/a");
d77114b7
MK
13858 }
13859
60466a63 13860 json_object_object_add(json_cap, "hostName",
d77114b7
MK
13861 json_hname);
13862
d62a17ae 13863 /* Gracefull Restart */
13864 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
13865 || CHECK_FLAG(p->cap,
13866 PEER_CAP_RESTART_ADV)) {
13867 if (CHECK_FLAG(p->cap,
13868 PEER_CAP_RESTART_ADV)
13869 && CHECK_FLAG(p->cap,
13870 PEER_CAP_RESTART_RCV))
13871 json_object_string_add(
13872 json_cap,
13873 "gracefulRestart",
13874 "advertisedAndReceived");
13875 else if (CHECK_FLAG(
13876 p->cap,
13877 PEER_CAP_RESTART_ADV))
13878 json_object_string_add(
13879 json_cap,
13880 "gracefulRestartCapability",
13881 "advertised");
13882 else if (CHECK_FLAG(
13883 p->cap,
13884 PEER_CAP_RESTART_RCV))
13885 json_object_string_add(
13886 json_cap,
13887 "gracefulRestartCapability",
13888 "received");
13889
13890 if (CHECK_FLAG(p->cap,
13891 PEER_CAP_RESTART_RCV)) {
13892 int restart_af_count = 0;
13893 json_object *json_restart =
13894 NULL;
13895 json_restart =
13896 json_object_new_object();
13897
13898 json_object_int_add(
13899 json_cap,
13900 "gracefulRestartRemoteTimerMsecs",
13901 p->v_gr_restart * 1000);
13902
05c7a1cc
QY
13903 FOREACH_AFI_SAFI (afi, safi) {
13904 if (CHECK_FLAG(
13905 p->af_cap
13906 [afi]
13907 [safi],
13908 PEER_CAP_RESTART_AF_RCV)) {
13909 json_object *
13910 json_sub =
13911 NULL;
13912 json_sub =
13913 json_object_new_object();
13914
d62a17ae 13915 if (CHECK_FLAG(
13916 p->af_cap
13917 [afi]
13918 [safi],
05c7a1cc
QY
13919 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13920 json_object_boolean_true_add(
13921 json_sub,
13922 "preserved");
13923 restart_af_count++;
13924 json_object_object_add(
13925 json_restart,
5cb5f4d0 13926 get_afi_safi_str(
05c7a1cc 13927 afi,
5cb5f4d0
DD
13928 safi,
13929 true),
05c7a1cc 13930 json_sub);
d62a17ae 13931 }
13932 }
13933 if (!restart_af_count) {
13934 json_object_string_add(
13935 json_cap,
13936 "addressFamiliesByPeer",
13937 "none");
13938 json_object_free(
13939 json_restart);
13940 } else
13941 json_object_object_add(
13942 json_cap,
13943 "addressFamiliesByPeer",
13944 json_restart);
13945 }
13946 }
13947 json_object_object_add(json_neigh,
13948 "neighborCapabilities",
13949 json_cap);
13950 } else {
13951 vty_out(vty, " Neighbor capabilities:\n");
13952
13953 /* AS4 */
13954 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
13955 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13956 vty_out(vty, " 4 Byte AS:");
13957 if (CHECK_FLAG(p->cap,
13958 PEER_CAP_AS4_ADV))
13959 vty_out(vty, " advertised");
13960 if (CHECK_FLAG(p->cap,
13961 PEER_CAP_AS4_RCV))
13962 vty_out(vty, " %sreceived",
13963 CHECK_FLAG(
13964 p->cap,
13965 PEER_CAP_AS4_ADV)
13966 ? "and "
13967 : "");
13968 vty_out(vty, "\n");
13969 }
13970
ef56aee4
DA
13971 /* Extended Message Support */
13972 if (CHECK_FLAG(p->cap,
13973 PEER_CAP_EXTENDED_MESSAGE_RCV)
13974 || CHECK_FLAG(
13975 p->cap,
13976 PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13977 vty_out(vty, " Extended Message:");
13978 if (CHECK_FLAG(
13979 p->cap,
13980 PEER_CAP_EXTENDED_MESSAGE_ADV))
13981 vty_out(vty, " advertised");
13982 if (CHECK_FLAG(
13983 p->cap,
13984 PEER_CAP_EXTENDED_MESSAGE_RCV))
13985 vty_out(vty, " %sreceived",
13986 CHECK_FLAG(
13987 p->cap,
13988 PEER_CAP_EXTENDED_MESSAGE_ADV)
13989 ? "and "
13990 : "");
13991 vty_out(vty, "\n");
13992 }
13993
d62a17ae 13994 /* AddPath */
13995 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
13996 || CHECK_FLAG(p->cap,
13997 PEER_CAP_ADDPATH_ADV)) {
13998 vty_out(vty, " AddPath:\n");
13999
05c7a1cc
QY
14000 FOREACH_AFI_SAFI (afi, safi) {
14001 if (CHECK_FLAG(
14002 p->af_cap[afi]
14003 [safi],
14004 PEER_CAP_ADDPATH_AF_TX_ADV)
14005 || CHECK_FLAG(
14006 p->af_cap[afi]
14007 [safi],
14008 PEER_CAP_ADDPATH_AF_TX_RCV)) {
14009 vty_out(vty,
14010 " %s: TX ",
5cb5f4d0 14011 get_afi_safi_str(
05c7a1cc 14012 afi,
5cb5f4d0
DD
14013 safi,
14014 false));
05c7a1cc 14015
d62a17ae 14016 if (CHECK_FLAG(
14017 p->af_cap
14018 [afi]
14019 [safi],
05c7a1cc 14020 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 14021 vty_out(vty,
05c7a1cc 14022 "advertised %s",
5cb5f4d0 14023 get_afi_safi_str(
d62a17ae 14024 afi,
5cb5f4d0
DD
14025 safi,
14026 false));
d62a17ae 14027
05c7a1cc
QY
14028 if (CHECK_FLAG(
14029 p->af_cap
14030 [afi]
14031 [safi],
14032 PEER_CAP_ADDPATH_AF_TX_RCV))
14033 vty_out(vty,
14034 "%sreceived",
14035 CHECK_FLAG(
14036 p->af_cap
14037 [afi]
14038 [safi],
14039 PEER_CAP_ADDPATH_AF_TX_ADV)
14040 ? " and "
14041 : "");
d62a17ae 14042
05c7a1cc
QY
14043 vty_out(vty, "\n");
14044 }
d62a17ae 14045
05c7a1cc
QY
14046 if (CHECK_FLAG(
14047 p->af_cap[afi]
14048 [safi],
14049 PEER_CAP_ADDPATH_AF_RX_ADV)
14050 || CHECK_FLAG(
14051 p->af_cap[afi]
14052 [safi],
14053 PEER_CAP_ADDPATH_AF_RX_RCV)) {
14054 vty_out(vty,
14055 " %s: RX ",
5cb5f4d0 14056 get_afi_safi_str(
05c7a1cc 14057 afi,
5cb5f4d0
DD
14058 safi,
14059 false));
d62a17ae 14060
14061 if (CHECK_FLAG(
14062 p->af_cap
14063 [afi]
14064 [safi],
05c7a1cc 14065 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 14066 vty_out(vty,
05c7a1cc 14067 "advertised %s",
5cb5f4d0 14068 get_afi_safi_str(
d62a17ae 14069 afi,
5cb5f4d0
DD
14070 safi,
14071 false));
d62a17ae 14072
05c7a1cc
QY
14073 if (CHECK_FLAG(
14074 p->af_cap
14075 [afi]
14076 [safi],
14077 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 14078 vty_out(vty,
05c7a1cc
QY
14079 "%sreceived",
14080 CHECK_FLAG(
14081 p->af_cap
14082 [afi]
14083 [safi],
14084 PEER_CAP_ADDPATH_AF_RX_ADV)
14085 ? " and "
14086 : "");
14087
14088 vty_out(vty, "\n");
d62a17ae 14089 }
05c7a1cc 14090 }
d62a17ae 14091 }
14092
14093 /* Dynamic */
14094 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
14095 || CHECK_FLAG(p->cap,
14096 PEER_CAP_DYNAMIC_ADV)) {
14097 vty_out(vty, " Dynamic:");
14098 if (CHECK_FLAG(p->cap,
14099 PEER_CAP_DYNAMIC_ADV))
14100 vty_out(vty, " advertised");
14101 if (CHECK_FLAG(p->cap,
14102 PEER_CAP_DYNAMIC_RCV))
14103 vty_out(vty, " %sreceived",
14104 CHECK_FLAG(
14105 p->cap,
14106 PEER_CAP_DYNAMIC_ADV)
14107 ? "and "
14108 : "");
14109 vty_out(vty, "\n");
14110 }
14111
14112 /* Extended nexthop */
14113 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
14114 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
14115 vty_out(vty, " Extended nexthop:");
14116 if (CHECK_FLAG(p->cap,
14117 PEER_CAP_ENHE_ADV))
14118 vty_out(vty, " advertised");
14119 if (CHECK_FLAG(p->cap,
14120 PEER_CAP_ENHE_RCV))
14121 vty_out(vty, " %sreceived",
14122 CHECK_FLAG(
14123 p->cap,
14124 PEER_CAP_ENHE_ADV)
14125 ? "and "
14126 : "");
14127 vty_out(vty, "\n");
14128
14129 if (CHECK_FLAG(p->cap,
14130 PEER_CAP_ENHE_RCV)) {
14131 vty_out(vty,
14132 " Address families by peer:\n ");
14133 for (safi = SAFI_UNICAST;
14134 safi < SAFI_MAX; safi++)
14135 if (CHECK_FLAG(
14136 p->af_cap
14137 [AFI_IP]
14138 [safi],
14139 PEER_CAP_ENHE_AF_RCV))
14140 vty_out(vty,
14141 " %s\n",
5cb5f4d0 14142 get_afi_safi_str(
d62a17ae 14143 AFI_IP,
5cb5f4d0
DD
14144 safi,
14145 false));
d62a17ae 14146 }
14147 }
14148
14149 /* Route Refresh */
14150 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
14151 || CHECK_FLAG(p->cap,
14152 PEER_CAP_REFRESH_NEW_RCV)
14153 || CHECK_FLAG(p->cap,
14154 PEER_CAP_REFRESH_OLD_RCV)) {
14155 vty_out(vty, " Route refresh:");
14156 if (CHECK_FLAG(p->cap,
14157 PEER_CAP_REFRESH_ADV))
14158 vty_out(vty, " advertised");
14159 if (CHECK_FLAG(p->cap,
14160 PEER_CAP_REFRESH_NEW_RCV)
14161 || CHECK_FLAG(
14162 p->cap,
14163 PEER_CAP_REFRESH_OLD_RCV))
14164 vty_out(vty, " %sreceived(%s)",
14165 CHECK_FLAG(
14166 p->cap,
14167 PEER_CAP_REFRESH_ADV)
14168 ? "and "
14169 : "",
14170 (CHECK_FLAG(
14171 p->cap,
14172 PEER_CAP_REFRESH_OLD_RCV)
14173 && CHECK_FLAG(
14174 p->cap,
14175 PEER_CAP_REFRESH_NEW_RCV))
14176 ? "old & new"
14177 : CHECK_FLAG(
14178 p->cap,
14179 PEER_CAP_REFRESH_OLD_RCV)
14180 ? "old"
14181 : "new");
14182
14183 vty_out(vty, "\n");
14184 }
14185
9af52ccf
DA
14186 /* Enhanced Route Refresh */
14187 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV)
14188 || CHECK_FLAG(p->cap,
14189 PEER_CAP_ENHANCED_RR_RCV)) {
14190 vty_out(vty,
14191 " Enhanced Route Refresh:");
14192 if (CHECK_FLAG(
14193 p->cap,
14194 PEER_CAP_ENHANCED_RR_ADV))
14195 vty_out(vty, " advertised");
14196 if (CHECK_FLAG(
14197 p->cap,
14198 PEER_CAP_ENHANCED_RR_RCV))
14199 vty_out(vty, " %sreceived",
14200 CHECK_FLAG(
14201 p->cap,
14202 PEER_CAP_REFRESH_ADV)
14203 ? "and "
14204 : "");
14205 vty_out(vty, "\n");
14206 }
14207
d62a17ae 14208 /* Multiprotocol Extensions */
05c7a1cc
QY
14209 FOREACH_AFI_SAFI (afi, safi)
14210 if (p->afc_adv[afi][safi]
14211 || p->afc_recv[afi][safi]) {
14212 vty_out(vty,
14213 " Address Family %s:",
5cb5f4d0
DD
14214 get_afi_safi_str(
14215 afi,
14216 safi,
14217 false));
05c7a1cc 14218 if (p->afc_adv[afi][safi])
d62a17ae 14219 vty_out(vty,
05c7a1cc
QY
14220 " advertised");
14221 if (p->afc_recv[afi][safi])
14222 vty_out(vty,
14223 " %sreceived",
14224 p->afc_adv[afi]
14225 [safi]
14226 ? "and "
14227 : "");
14228 vty_out(vty, "\n");
14229 }
d62a17ae 14230
14231 /* Hostname capability */
60466a63 14232 vty_out(vty, " Hostname Capability:");
d77114b7
MK
14233
14234 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
14235 vty_out(vty,
14236 " advertised (name: %s,domain name: %s)",
60466a63
QY
14237 bgp->peer_self->hostname
14238 ? bgp->peer_self
14239 ->hostname
d77114b7 14240 : "n/a",
60466a63
QY
14241 bgp->peer_self->domainname
14242 ? bgp->peer_self
14243 ->domainname
d77114b7
MK
14244 : "n/a");
14245 } else {
14246 vty_out(vty, " not advertised");
d62a17ae 14247 }
14248
d77114b7 14249 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
14250 vty_out(vty,
14251 " received (name: %s,domain name: %s)",
60466a63
QY
14252 p->hostname ? p->hostname
14253 : "n/a",
14254 p->domainname ? p->domainname
14255 : "n/a");
d77114b7
MK
14256 } else {
14257 vty_out(vty, " not received");
14258 }
14259
14260 vty_out(vty, "\n");
14261
61bfbd51 14262 /* Graceful Restart */
d62a17ae 14263 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
14264 || CHECK_FLAG(p->cap,
14265 PEER_CAP_RESTART_ADV)) {
14266 vty_out(vty,
61bfbd51 14267 " Graceful Restart Capability:");
d62a17ae 14268 if (CHECK_FLAG(p->cap,
14269 PEER_CAP_RESTART_ADV))
14270 vty_out(vty, " advertised");
14271 if (CHECK_FLAG(p->cap,
14272 PEER_CAP_RESTART_RCV))
14273 vty_out(vty, " %sreceived",
14274 CHECK_FLAG(
14275 p->cap,
14276 PEER_CAP_RESTART_ADV)
14277 ? "and "
14278 : "");
14279 vty_out(vty, "\n");
14280
14281 if (CHECK_FLAG(p->cap,
14282 PEER_CAP_RESTART_RCV)) {
14283 int restart_af_count = 0;
14284
14285 vty_out(vty,
14286 " Remote Restart timer is %d seconds\n",
14287 p->v_gr_restart);
14288 vty_out(vty,
14289 " Address families by peer:\n ");
14290
05c7a1cc
QY
14291 FOREACH_AFI_SAFI (afi, safi)
14292 if (CHECK_FLAG(
14293 p->af_cap
14294 [afi]
14295 [safi],
14296 PEER_CAP_RESTART_AF_RCV)) {
14297 vty_out(vty,
14298 "%s%s(%s)",
14299 restart_af_count
14300 ? ", "
14301 : "",
5cb5f4d0 14302 get_afi_safi_str(
05c7a1cc 14303 afi,
5cb5f4d0
DD
14304 safi,
14305 false),
05c7a1cc
QY
14306 CHECK_FLAG(
14307 p->af_cap
14308 [afi]
14309 [safi],
14310 PEER_CAP_RESTART_AF_PRESERVE_RCV)
14311 ? "preserved"
14312 : "not preserved");
14313 restart_af_count++;
14314 }
d62a17ae 14315 if (!restart_af_count)
14316 vty_out(vty, "none");
14317 vty_out(vty, "\n");
14318 }
2986cac2 14319 } /* Gracefull Restart */
d62a17ae 14320 }
14321 }
14322 }
14323
14324 /* graceful restart information */
d62a17ae 14325 json_object *json_grace = NULL;
14326 json_object *json_grace_send = NULL;
14327 json_object *json_grace_recv = NULL;
14328 int eor_send_af_count = 0;
14329 int eor_receive_af_count = 0;
14330
14331 if (use_json) {
14332 json_grace = json_object_new_object();
14333 json_grace_send = json_object_new_object();
14334 json_grace_recv = json_object_new_object();
14335
feb17238 14336 if ((peer_established(p))
36235319 14337 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
05c7a1cc
QY
14338 FOREACH_AFI_SAFI (afi, safi) {
14339 if (CHECK_FLAG(p->af_sflags[afi][safi],
36235319 14340 PEER_STATUS_EOR_SEND)) {
05c7a1cc
QY
14341 json_object_boolean_true_add(
14342 json_grace_send,
5cb5f4d0
DD
14343 get_afi_safi_str(afi,
14344 safi,
14345 true));
05c7a1cc 14346 eor_send_af_count++;
d62a17ae 14347 }
14348 }
05c7a1cc
QY
14349 FOREACH_AFI_SAFI (afi, safi) {
14350 if (CHECK_FLAG(
36235319
QY
14351 p->af_sflags[afi][safi],
14352 PEER_STATUS_EOR_RECEIVED)) {
05c7a1cc
QY
14353 json_object_boolean_true_add(
14354 json_grace_recv,
5cb5f4d0
DD
14355 get_afi_safi_str(afi,
14356 safi,
14357 true));
05c7a1cc 14358 eor_receive_af_count++;
d62a17ae 14359 }
14360 }
14361 }
36235319
QY
14362 json_object_object_add(json_grace, "endOfRibSend",
14363 json_grace_send);
14364 json_object_object_add(json_grace, "endOfRibRecv",
14365 json_grace_recv);
d62a17ae 14366
d62a17ae 14367
14368 if (p->t_gr_restart)
14369 json_object_int_add(json_grace,
14370 "gracefulRestartTimerMsecs",
14371 thread_timer_remain_second(
14372 p->t_gr_restart)
14373 * 1000);
14374
14375 if (p->t_gr_stale)
14376 json_object_int_add(
14377 json_grace,
14378 "gracefulStalepathTimerMsecs",
14379 thread_timer_remain_second(
14380 p->t_gr_stale)
14381 * 1000);
2986cac2 14382 /* more gr info in new format */
14383 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json,
36235319 14384 json_grace);
d62a17ae 14385 json_object_object_add(
14386 json_neigh, "gracefulRestartInfo", json_grace);
14387 } else {
2089dd80 14388 vty_out(vty, " Graceful restart information:\n");
feb17238 14389 if ((peer_established(p))
36235319 14390 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 14391
d62a17ae 14392 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
14393 FOREACH_AFI_SAFI (afi, safi) {
14394 if (CHECK_FLAG(p->af_sflags[afi][safi],
14395 PEER_STATUS_EOR_SEND)) {
14396 vty_out(vty, "%s%s",
14397 eor_send_af_count ? ", "
14398 : "",
36235319
QY
14399 get_afi_safi_str(
14400 afi, safi,
14401 false));
05c7a1cc 14402 eor_send_af_count++;
d62a17ae 14403 }
14404 }
14405 vty_out(vty, "\n");
14406 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
14407 FOREACH_AFI_SAFI (afi, safi) {
14408 if (CHECK_FLAG(
14409 p->af_sflags[afi][safi],
14410 PEER_STATUS_EOR_RECEIVED)) {
14411 vty_out(vty, "%s%s",
14412 eor_receive_af_count
14413 ? ", "
14414 : "",
5cb5f4d0
DD
14415 get_afi_safi_str(afi,
14416 safi,
14417 false));
05c7a1cc 14418 eor_receive_af_count++;
d62a17ae 14419 }
14420 }
14421 vty_out(vty, "\n");
14422 }
14423
14424 if (p->t_gr_restart)
14425 vty_out(vty,
14426 " The remaining time of restart timer is %ld\n",
14427 thread_timer_remain_second(
14428 p->t_gr_restart));
14429
14430 if (p->t_gr_stale)
14431 vty_out(vty,
14432 " The remaining time of stalepath timer is %ld\n",
14433 thread_timer_remain_second(
14434 p->t_gr_stale));
2986cac2 14435
14436 /* more gr info in new format */
14437 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
d62a17ae 14438 }
2986cac2 14439
d62a17ae 14440 if (use_json) {
14441 json_object *json_stat = NULL;
14442 json_stat = json_object_new_object();
14443 /* Packet counts. */
43aa5965
QY
14444
14445 atomic_size_t outq_count, inq_count;
14446 outq_count = atomic_load_explicit(&p->obuf->count,
14447 memory_order_relaxed);
14448 inq_count = atomic_load_explicit(&p->ibuf->count,
14449 memory_order_relaxed);
14450
14451 json_object_int_add(json_stat, "depthInq",
14452 (unsigned long)inq_count);
d62a17ae 14453 json_object_int_add(json_stat, "depthOutq",
43aa5965 14454 (unsigned long)outq_count);
0112e9e0
QY
14455 json_object_int_add(json_stat, "opensSent",
14456 atomic_load_explicit(&p->open_out,
14457 memory_order_relaxed));
14458 json_object_int_add(json_stat, "opensRecv",
14459 atomic_load_explicit(&p->open_in,
14460 memory_order_relaxed));
d62a17ae 14461 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
14462 atomic_load_explicit(&p->notify_out,
14463 memory_order_relaxed));
d62a17ae 14464 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
14465 atomic_load_explicit(&p->notify_in,
14466 memory_order_relaxed));
14467 json_object_int_add(json_stat, "updatesSent",
14468 atomic_load_explicit(&p->update_out,
14469 memory_order_relaxed));
14470 json_object_int_add(json_stat, "updatesRecv",
14471 atomic_load_explicit(&p->update_in,
14472 memory_order_relaxed));
d62a17ae 14473 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
14474 atomic_load_explicit(&p->keepalive_out,
14475 memory_order_relaxed));
d62a17ae 14476 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
14477 atomic_load_explicit(&p->keepalive_in,
14478 memory_order_relaxed));
d62a17ae 14479 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
14480 atomic_load_explicit(&p->refresh_out,
14481 memory_order_relaxed));
d62a17ae 14482 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
14483 atomic_load_explicit(&p->refresh_in,
14484 memory_order_relaxed));
d62a17ae 14485 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
14486 atomic_load_explicit(&p->dynamic_cap_out,
14487 memory_order_relaxed));
d62a17ae 14488 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
14489 atomic_load_explicit(&p->dynamic_cap_in,
14490 memory_order_relaxed));
14491 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
14492 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 14493 json_object_object_add(json_neigh, "messageStats", json_stat);
14494 } else {
43aa5965
QY
14495 atomic_size_t outq_count, inq_count;
14496 outq_count = atomic_load_explicit(&p->obuf->count,
14497 memory_order_relaxed);
14498 inq_count = atomic_load_explicit(&p->ibuf->count,
14499 memory_order_relaxed);
14500
d62a17ae 14501 /* Packet counts. */
14502 vty_out(vty, " Message statistics:\n");
43aa5965
QY
14503 vty_out(vty, " Inq depth is %zu\n", inq_count);
14504 vty_out(vty, " Outq depth is %zu\n", outq_count);
d62a17ae 14505 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
14506 vty_out(vty, " Opens: %10d %10d\n",
14507 atomic_load_explicit(&p->open_out,
14508 memory_order_relaxed),
14509 atomic_load_explicit(&p->open_in,
14510 memory_order_relaxed));
14511 vty_out(vty, " Notifications: %10d %10d\n",
14512 atomic_load_explicit(&p->notify_out,
14513 memory_order_relaxed),
14514 atomic_load_explicit(&p->notify_in,
14515 memory_order_relaxed));
14516 vty_out(vty, " Updates: %10d %10d\n",
14517 atomic_load_explicit(&p->update_out,
14518 memory_order_relaxed),
14519 atomic_load_explicit(&p->update_in,
14520 memory_order_relaxed));
14521 vty_out(vty, " Keepalives: %10d %10d\n",
14522 atomic_load_explicit(&p->keepalive_out,
14523 memory_order_relaxed),
14524 atomic_load_explicit(&p->keepalive_in,
14525 memory_order_relaxed));
14526 vty_out(vty, " Route Refresh: %10d %10d\n",
14527 atomic_load_explicit(&p->refresh_out,
14528 memory_order_relaxed),
14529 atomic_load_explicit(&p->refresh_in,
14530 memory_order_relaxed));
d62a17ae 14531 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
14532 atomic_load_explicit(&p->dynamic_cap_out,
14533 memory_order_relaxed),
14534 atomic_load_explicit(&p->dynamic_cap_in,
14535 memory_order_relaxed));
14536 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
14537 PEER_TOTAL_RX(p));
d62a17ae 14538 }
14539
14540 if (use_json) {
14541 /* advertisement-interval */
14542 json_object_int_add(json_neigh,
14543 "minBtwnAdvertisementRunsTimerMsecs",
14544 p->v_routeadv * 1000);
14545
14546 /* Update-source. */
14547 if (p->update_if || p->update_source) {
14548 if (p->update_if)
14549 json_object_string_add(json_neigh,
14550 "updateSource",
14551 p->update_if);
14552 else if (p->update_source)
14553 json_object_string_add(
14554 json_neigh, "updateSource",
14555 sockunion2str(p->update_source, buf1,
14556 SU_ADDRSTRLEN));
14557 }
14558 } else {
14559 /* advertisement-interval */
14560 vty_out(vty,
14561 " Minimum time between advertisement runs is %d seconds\n",
14562 p->v_routeadv);
14563
14564 /* Update-source. */
14565 if (p->update_if || p->update_source) {
14566 vty_out(vty, " Update source is ");
14567 if (p->update_if)
14568 vty_out(vty, "%s", p->update_if);
14569 else if (p->update_source)
14570 vty_out(vty, "%s",
14571 sockunion2str(p->update_source, buf1,
14572 SU_ADDRSTRLEN));
14573 vty_out(vty, "\n");
14574 }
14575
14576 vty_out(vty, "\n");
14577 }
14578
14579 /* Address Family Information */
14580 json_object *json_hold = NULL;
14581
14582 if (use_json)
14583 json_hold = json_object_new_object();
14584
05c7a1cc
QY
14585 FOREACH_AFI_SAFI (afi, safi)
14586 if (p->afc[afi][safi])
14587 bgp_show_peer_afi(vty, p, afi, safi, use_json,
14588 json_hold);
d62a17ae 14589
14590 if (use_json) {
14591 json_object_object_add(json_neigh, "addressFamilyInfo",
14592 json_hold);
14593 json_object_int_add(json_neigh, "connectionsEstablished",
14594 p->established);
14595 json_object_int_add(json_neigh, "connectionsDropped",
14596 p->dropped);
14597 } else
14598 vty_out(vty, " Connections established %d; dropped %d\n",
14599 p->established, p->dropped);
14600
14601 if (!p->last_reset) {
14602 if (use_json)
14603 json_object_string_add(json_neigh, "lastReset",
14604 "never");
14605 else
14606 vty_out(vty, " Last reset never\n");
14607 } else {
14608 if (use_json) {
14609 time_t uptime;
a2700b50 14610 struct tm tm;
d62a17ae 14611
14612 uptime = bgp_clock();
14613 uptime -= p->resettime;
a2700b50
MS
14614 gmtime_r(&uptime, &tm);
14615
d62a17ae 14616 json_object_int_add(json_neigh, "lastResetTimerMsecs",
a2700b50
MS
14617 (tm.tm_sec * 1000)
14618 + (tm.tm_min * 60000)
14619 + (tm.tm_hour * 3600000));
3577f1c5 14620 bgp_show_peer_reset(NULL, p, json_neigh, true);
d62a17ae 14621 } else {
14622 vty_out(vty, " Last reset %s, ",
14623 peer_uptime(p->resettime, timebuf,
14624 BGP_UPTIME_LEN, 0, NULL));
14625
3577f1c5 14626 bgp_show_peer_reset(vty, p, NULL, false);
d62a17ae 14627 if (p->last_reset_cause_size) {
14628 msg = p->last_reset_cause;
14629 vty_out(vty,
14630 " Message received that caused BGP to send a NOTIFICATION:\n ");
14631 for (i = 1; i <= p->last_reset_cause_size;
14632 i++) {
14633 vty_out(vty, "%02X", *msg++);
14634
14635 if (i != p->last_reset_cause_size) {
14636 if (i % 16 == 0) {
14637 vty_out(vty, "\n ");
14638 } else if (i % 4 == 0) {
14639 vty_out(vty, " ");
14640 }
14641 }
14642 }
14643 vty_out(vty, "\n");
14644 }
14645 }
14646 }
14647
14648 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
14649 if (use_json)
14650 json_object_boolean_true_add(json_neigh,
14651 "prefixesConfigExceedMax");
14652 else
14653 vty_out(vty,
14654 " Peer had exceeded the max. no. of prefixes configured.\n");
14655
14656 if (p->t_pmax_restart) {
14657 if (use_json) {
14658 json_object_boolean_true_add(
14659 json_neigh, "reducePrefixNumFrom");
14660 json_object_int_add(json_neigh,
14661 "restartInTimerMsec",
14662 thread_timer_remain_second(
14663 p->t_pmax_restart)
14664 * 1000);
14665 } else
14666 vty_out(vty,
14667 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
14668 p->host, thread_timer_remain_second(
14669 p->t_pmax_restart));
d62a17ae 14670 } else {
14671 if (use_json)
14672 json_object_boolean_true_add(
14673 json_neigh,
14674 "reducePrefixNumAndClearIpBgp");
14675 else
14676 vty_out(vty,
14677 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
14678 p->host);
14679 }
14680 }
14681
14682 /* EBGP Multihop and GTSM */
14683 if (p->sort != BGP_PEER_IBGP) {
14684 if (use_json) {
e2521429 14685 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14686 json_object_int_add(json_neigh,
14687 "externalBgpNbrMaxHopsAway",
14688 p->gtsm_hops);
c8d6f0d6 14689 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 14690 json_object_int_add(json_neigh,
14691 "externalBgpNbrMaxHopsAway",
14692 p->ttl);
14693 } else {
e2521429 14694 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14695 vty_out(vty,
14696 " External BGP neighbor may be up to %d hops away.\n",
14697 p->gtsm_hops);
c8d6f0d6 14698 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 14699 vty_out(vty,
14700 " External BGP neighbor may be up to %d hops away.\n",
14701 p->ttl);
14702 }
14703 } else {
e2521429 14704 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED) {
d62a17ae 14705 if (use_json)
14706 json_object_int_add(json_neigh,
14707 "internalBgpNbrMaxHopsAway",
14708 p->gtsm_hops);
14709 else
14710 vty_out(vty,
14711 " Internal BGP neighbor may be up to %d hops away.\n",
14712 p->gtsm_hops);
14713 }
14714 }
14715
14716 /* Local address. */
14717 if (p->su_local) {
14718 if (use_json) {
14719 json_object_string_add(json_neigh, "hostLocal",
14720 sockunion2str(p->su_local, buf1,
14721 SU_ADDRSTRLEN));
14722 json_object_int_add(json_neigh, "portLocal",
14723 ntohs(p->su_local->sin.sin_port));
14724 } else
14725 vty_out(vty, "Local host: %s, Local port: %d\n",
14726 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
14727 ntohs(p->su_local->sin.sin_port));
14728 }
14729
14730 /* Remote address. */
14731 if (p->su_remote) {
14732 if (use_json) {
14733 json_object_string_add(json_neigh, "hostForeign",
14734 sockunion2str(p->su_remote, buf1,
14735 SU_ADDRSTRLEN));
14736 json_object_int_add(json_neigh, "portForeign",
14737 ntohs(p->su_remote->sin.sin_port));
14738 } else
14739 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
14740 sockunion2str(p->su_remote, buf1,
14741 SU_ADDRSTRLEN),
14742 ntohs(p->su_remote->sin.sin_port));
14743 }
14744
14745 /* Nexthop display. */
14746 if (p->su_local) {
14747 if (use_json) {
14748 json_object_string_add(json_neigh, "nexthop",
14749 inet_ntop(AF_INET,
14750 &p->nexthop.v4, buf1,
14751 sizeof(buf1)));
14752 json_object_string_add(json_neigh, "nexthopGlobal",
14753 inet_ntop(AF_INET6,
14754 &p->nexthop.v6_global,
14755 buf1, sizeof(buf1)));
14756 json_object_string_add(json_neigh, "nexthopLocal",
14757 inet_ntop(AF_INET6,
14758 &p->nexthop.v6_local,
14759 buf1, sizeof(buf1)));
14760 if (p->shared_network)
14761 json_object_string_add(json_neigh,
14762 "bgpConnection",
14763 "sharedNetwork");
14764 else
14765 json_object_string_add(json_neigh,
14766 "bgpConnection",
14767 "nonSharedNetwork");
14768 } else {
14769 vty_out(vty, "Nexthop: %s\n",
14770 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
14771 sizeof(buf1)));
14772 vty_out(vty, "Nexthop global: %s\n",
14773 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
14774 sizeof(buf1)));
14775 vty_out(vty, "Nexthop local: %s\n",
14776 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
14777 sizeof(buf1)));
14778 vty_out(vty, "BGP connection: %s\n",
14779 p->shared_network ? "shared network"
14780 : "non shared network");
14781 }
14782 }
14783
14784 /* Timer information. */
14785 if (use_json) {
14786 json_object_int_add(json_neigh, "connectRetryTimer",
14787 p->v_connect);
feb17238 14788 if (peer_established(p) && p->rtt)
d62a17ae 14789 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14790 p->rtt);
14791 if (p->t_start)
14792 json_object_int_add(
14793 json_neigh, "nextStartTimerDueInMsecs",
14794 thread_timer_remain_second(p->t_start) * 1000);
14795 if (p->t_connect)
14796 json_object_int_add(
14797 json_neigh, "nextConnectTimerDueInMsecs",
14798 thread_timer_remain_second(p->t_connect)
14799 * 1000);
14800 if (p->t_routeadv) {
14801 json_object_int_add(json_neigh, "mraiInterval",
14802 p->v_routeadv);
14803 json_object_int_add(
14804 json_neigh, "mraiTimerExpireInMsecs",
14805 thread_timer_remain_second(p->t_routeadv)
14806 * 1000);
14807 }
14808 if (p->password)
14809 json_object_int_add(json_neigh, "authenticationEnabled",
14810 1);
14811
14812 if (p->t_read)
14813 json_object_string_add(json_neigh, "readThread", "on");
14814 else
14815 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
14816
14817 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 14818 json_object_string_add(json_neigh, "writeThread", "on");
14819 else
14820 json_object_string_add(json_neigh, "writeThread",
14821 "off");
14822 } else {
14823 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14824 p->v_connect);
feb17238 14825 if (peer_established(p) && p->rtt)
d62a17ae 14826 vty_out(vty, "Estimated round trip time: %d ms\n",
14827 p->rtt);
14828 if (p->t_start)
14829 vty_out(vty, "Next start timer due in %ld seconds\n",
14830 thread_timer_remain_second(p->t_start));
14831 if (p->t_connect)
14832 vty_out(vty, "Next connect timer due in %ld seconds\n",
14833 thread_timer_remain_second(p->t_connect));
14834 if (p->t_routeadv)
14835 vty_out(vty,
14836 "MRAI (interval %u) timer expires in %ld seconds\n",
14837 p->v_routeadv,
14838 thread_timer_remain_second(p->t_routeadv));
14839 if (p->password)
14840 vty_out(vty, "Peer Authentication Enabled\n");
14841
cac9e917 14842 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
49507a6f
QY
14843 p->t_read ? "on" : "off",
14844 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14845 ? "on"
cac9e917 14846 : "off", p->fd);
d62a17ae 14847 }
14848
14849 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14850 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14851 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14852
14853 if (!use_json)
14854 vty_out(vty, "\n");
14855
14856 /* BFD information. */
21bfce98
RZ
14857 if (p->bfd_config)
14858 bgp_bfd_show_info(vty, p, json_neigh);
d62a17ae 14859
14860 if (use_json) {
14861 if (p->conf_if) /* Configured interface name. */
14862 json_object_object_add(json, p->conf_if, json_neigh);
14863 else /* Configured IP address. */
14864 json_object_object_add(json, p->host, json_neigh);
14865 }
14866}
14867
36235319
QY
14868static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14869 enum show_type type,
14870 union sockunion *su,
14871 const char *conf_if, afi_t afi,
74a630b6 14872 bool use_json)
2986cac2 14873{
14874 struct listnode *node, *nnode;
14875 struct peer *peer;
14876 int find = 0;
14877 safi_t safi = SAFI_UNICAST;
74a630b6 14878 json_object *json = NULL;
2986cac2 14879 json_object *json_neighbor = NULL;
14880
74a630b6
NT
14881 if (use_json) {
14882 json = json_object_new_object();
14883 json_neighbor = json_object_new_object();
14884 }
14885
2986cac2 14886 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14887
14888 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14889 continue;
14890
14891 if ((peer->afc[afi][safi]) == 0)
14892 continue;
14893
2ba1fe69 14894 if (type == show_all) {
2986cac2 14895 bgp_show_peer_gr_status(vty, peer, use_json,
13909c4f 14896 json_neighbor);
2986cac2 14897
74a630b6 14898 if (use_json) {
13909c4f
DS
14899 json_object_object_add(json, peer->host,
14900 json_neighbor);
74a630b6
NT
14901 json_neighbor = NULL;
14902 }
2986cac2 14903
2ba1fe69 14904 } else if (type == show_peer) {
2986cac2 14905 if (conf_if) {
14906 if ((peer->conf_if
13909c4f
DS
14907 && !strcmp(peer->conf_if, conf_if))
14908 || (peer->hostname
2986cac2 14909 && !strcmp(peer->hostname, conf_if))) {
14910 find = 1;
13909c4f
DS
14911 bgp_show_peer_gr_status(vty, peer,
14912 use_json,
14913 json_neighbor);
2986cac2 14914 }
14915 } else {
14916 if (sockunion_same(&peer->su, su)) {
14917 find = 1;
13909c4f
DS
14918 bgp_show_peer_gr_status(vty, peer,
14919 use_json,
14920 json_neighbor);
2986cac2 14921 }
14922 }
13909c4f
DS
14923 if (use_json && find)
14924 json_object_object_add(json, peer->host,
14925 json_neighbor);
2986cac2 14926 }
14927
74a630b6
NT
14928 if (find) {
14929 json_neighbor = NULL;
2986cac2 14930 break;
74a630b6 14931 }
2986cac2 14932 }
14933
14934 if (type == show_peer && !find) {
14935 if (use_json)
13909c4f 14936 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
2986cac2 14937 else
14938 vty_out(vty, "%% No such neighbor\n");
14939 }
14940 if (use_json) {
13909c4f
DS
14941 vty_out(vty, "%s\n",
14942 json_object_to_json_string_ext(
14943 json, JSON_C_TO_STRING_PRETTY));
74a630b6
NT
14944
14945 if (json_neighbor)
14946 json_object_free(json_neighbor);
14947 json_object_free(json);
2986cac2 14948 } else {
14949 vty_out(vty, "\n");
14950 }
14951
14952 return CMD_SUCCESS;
14953}
14954
d62a17ae 14955static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14956 enum show_type type, union sockunion *su,
9f049418 14957 const char *conf_if, bool use_json,
d62a17ae 14958 json_object *json)
14959{
14960 struct listnode *node, *nnode;
14961 struct peer *peer;
14962 int find = 0;
9f049418 14963 bool nbr_output = false;
d1927ebe
AS
14964 afi_t afi = AFI_MAX;
14965 safi_t safi = SAFI_MAX;
14966
14967 if (type == show_ipv4_peer || type == show_ipv4_all) {
14968 afi = AFI_IP;
14969 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14970 afi = AFI_IP6;
14971 }
d62a17ae 14972
14973 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14974 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14975 continue;
14976
14977 switch (type) {
14978 case show_all:
14979 bgp_show_peer(vty, peer, use_json, json);
9f049418 14980 nbr_output = true;
d62a17ae 14981 break;
14982 case show_peer:
14983 if (conf_if) {
14984 if ((peer->conf_if
14985 && !strcmp(peer->conf_if, conf_if))
14986 || (peer->hostname
14987 && !strcmp(peer->hostname, conf_if))) {
14988 find = 1;
14989 bgp_show_peer(vty, peer, use_json,
14990 json);
14991 }
14992 } else {
14993 if (sockunion_same(&peer->su, su)) {
14994 find = 1;
14995 bgp_show_peer(vty, peer, use_json,
14996 json);
14997 }
14998 }
14999 break;
d1927ebe
AS
15000 case show_ipv4_peer:
15001 case show_ipv6_peer:
15002 FOREACH_SAFI (safi) {
15003 if (peer->afc[afi][safi]) {
15004 if (conf_if) {
15005 if ((peer->conf_if
15006 && !strcmp(peer->conf_if, conf_if))
15007 || (peer->hostname
15008 && !strcmp(peer->hostname, conf_if))) {
15009 find = 1;
15010 bgp_show_peer(vty, peer, use_json,
15011 json);
15012 break;
15013 }
15014 } else {
15015 if (sockunion_same(&peer->su, su)) {
15016 find = 1;
15017 bgp_show_peer(vty, peer, use_json,
15018 json);
15019 break;
15020 }
15021 }
15022 }
15023 }
15024 break;
15025 case show_ipv4_all:
15026 case show_ipv6_all:
15027 FOREACH_SAFI (safi) {
15028 if (peer->afc[afi][safi]) {
15029 bgp_show_peer(vty, peer, use_json, json);
15030 nbr_output = true;
15031 break;
15032 }
15033 }
15034 break;
d62a17ae 15035 }
15036 }
15037
d1927ebe
AS
15038 if ((type == show_peer || type == show_ipv4_peer ||
15039 type == show_ipv6_peer) && !find) {
d62a17ae 15040 if (use_json)
15041 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
15042 else
88b7d255 15043 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 15044 }
15045
d1927ebe
AS
15046 if (type != show_peer && type != show_ipv4_peer &&
15047 type != show_ipv6_peer && !nbr_output && !use_json)
94d4c685 15048 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 15049
d62a17ae 15050 if (use_json) {
996c9314
LB
15051 vty_out(vty, "%s\n", json_object_to_json_string_ext(
15052 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 15053 } else {
15054 vty_out(vty, "\n");
15055 }
15056
15057 return CMD_SUCCESS;
15058}
15059
36235319
QY
15060static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
15061 enum show_type type,
15062 const char *ip_str,
15063 afi_t afi, bool use_json)
2986cac2 15064{
15065
15066 int ret;
15067 struct bgp *bgp;
15068 union sockunion su;
2986cac2 15069
15070 bgp = bgp_get_default();
15071
13909c4f
DS
15072 if (!bgp)
15073 return;
2986cac2 15074
13909c4f
DS
15075 if (!use_json)
15076 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
15077 NULL);
2986cac2 15078
13909c4f
DS
15079 if (ip_str) {
15080 ret = str2sockunion(ip_str, &su);
15081 if (ret < 0)
13909c4f 15082 bgp_show_neighbor_graceful_restart(
74a630b6
NT
15083 vty, bgp, type, NULL, ip_str, afi, use_json);
15084 else
15085 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
15086 NULL, afi, use_json);
13909c4f
DS
15087 } else
15088 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
74a630b6 15089 afi, use_json);
2986cac2 15090}
15091
d62a17ae 15092static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
15093 enum show_type type,
15094 const char *ip_str,
9f049418 15095 bool use_json)
d62a17ae 15096{
0291c246
MK
15097 struct listnode *node, *nnode;
15098 struct bgp *bgp;
71aedaa3 15099 union sockunion su;
0291c246 15100 json_object *json = NULL;
71aedaa3 15101 int ret, is_first = 1;
9f049418 15102 bool nbr_output = false;
d62a17ae 15103
15104 if (use_json)
15105 vty_out(vty, "{\n");
15106
15107 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 15108 nbr_output = true;
d62a17ae 15109 if (use_json) {
15110 if (!(json = json_object_new_object())) {
af4c2728 15111 flog_err(
e50f7cfd 15112 EC_BGP_JSON_MEM_ERROR,
d62a17ae 15113 "Unable to allocate memory for JSON object");
15114 vty_out(vty,
15115 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
15116 return;
15117 }
15118
15119 json_object_int_add(json, "vrfId",
15120 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
15121 ? -1
15122 : (int64_t)bgp->vrf_id);
d62a17ae 15123 json_object_string_add(
15124 json, "vrfName",
15125 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 15126 ? VRF_DEFAULT_NAME
d62a17ae 15127 : bgp->name);
15128
15129 if (!is_first)
15130 vty_out(vty, ",\n");
15131 else
15132 is_first = 0;
15133
15134 vty_out(vty, "\"%s\":",
15135 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 15136 ? VRF_DEFAULT_NAME
d62a17ae 15137 : bgp->name);
15138 } else {
15139 vty_out(vty, "\nInstance %s:\n",
15140 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 15141 ? VRF_DEFAULT_NAME
d62a17ae 15142 : bgp->name);
15143 }
71aedaa3 15144
d1927ebe
AS
15145 if (type == show_peer || type == show_ipv4_peer ||
15146 type == show_ipv6_peer) {
71aedaa3
DS
15147 ret = str2sockunion(ip_str, &su);
15148 if (ret < 0)
15149 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
15150 use_json, json);
15151 else
15152 bgp_show_neighbor(vty, bgp, type, &su, NULL,
15153 use_json, json);
15154 } else {
d1927ebe 15155 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
71aedaa3
DS
15156 use_json, json);
15157 }
b77004d6 15158 json_object_free(json);
121067e9 15159 json = NULL;
d62a17ae 15160 }
15161
3e78a6ce 15162 if (use_json)
d62a17ae 15163 vty_out(vty, "}\n");
9f049418
DS
15164 else if (!nbr_output)
15165 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 15166}
15167
15168static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
15169 enum show_type type, const char *ip_str,
9f049418 15170 bool use_json)
d62a17ae 15171{
15172 int ret;
15173 struct bgp *bgp;
15174 union sockunion su;
15175 json_object *json = NULL;
15176
15177 if (name) {
15178 if (strmatch(name, "all")) {
71aedaa3
DS
15179 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
15180 use_json);
d62a17ae 15181 return CMD_SUCCESS;
15182 } else {
15183 bgp = bgp_lookup_by_name(name);
15184 if (!bgp) {
15185 if (use_json) {
15186 json = json_object_new_object();
d62a17ae 15187 vty_out(vty, "%s\n",
15188 json_object_to_json_string_ext(
15189 json,
15190 JSON_C_TO_STRING_PRETTY));
15191 json_object_free(json);
15192 } else
15193 vty_out(vty,
9f049418 15194 "%% BGP instance not found\n");
d62a17ae 15195
15196 return CMD_WARNING;
15197 }
15198 }
15199 } else {
15200 bgp = bgp_get_default();
15201 }
15202
15203 if (bgp) {
15204 json = json_object_new_object();
15205 if (ip_str) {
15206 ret = str2sockunion(ip_str, &su);
15207 if (ret < 0)
15208 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
15209 use_json, json);
15210 else
15211 bgp_show_neighbor(vty, bgp, type, &su, NULL,
15212 use_json, json);
15213 } else {
15214 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
15215 json);
15216 }
15217 json_object_free(json);
ca61fd25
DS
15218 } else {
15219 if (use_json)
15220 vty_out(vty, "{}\n");
15221 else
15222 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 15223 }
15224
15225 return CMD_SUCCESS;
4fb25c53
DW
15226}
15227
2986cac2 15228
15229
15230/* "show [ip] bgp neighbors graceful-restart" commands. */
15231DEFUN (show_ip_bgp_neighbors_gracrful_restart,
15232 show_ip_bgp_neighbors_graceful_restart_cmd,
15233 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
15234 SHOW_STR
15235 BGP_STR
15236 IP_STR
15237 IPV6_STR
15238 NEIGHBOR_STR
15239 "Neighbor to display information about\n"
15240 "Neighbor to display information about\n"
15241 "Neighbor on BGP configured interface\n"
15242 GR_SHOW
15243 JSON_STR)
15244{
15245 char *sh_arg = NULL;
15246 enum show_type sh_type;
15247 int idx = 0;
15248 afi_t afi = AFI_MAX;
2986cac2 15249 bool uj = use_json(argc, argv);
15250
36235319 15251 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
2986cac2 15252 afi = AFI_MAX;
15253
15254 idx++;
15255
15256 if (argv_find(argv, argc, "A.B.C.D", &idx)
15257 || argv_find(argv, argc, "X:X::X:X", &idx)
15258 || argv_find(argv, argc, "WORD", &idx)) {
15259 sh_type = show_peer;
15260 sh_arg = argv[idx]->arg;
15261 } else
15262 sh_type = show_all;
15263
15264 if (!argv_find(argv, argc, "graceful-restart", &idx))
15265 return CMD_SUCCESS;
15266
15267
36235319
QY
15268 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
15269 afi, uj);
2986cac2 15270}
15271
716b2d8a 15272/* "show [ip] bgp neighbors" commands. */
718e3744 15273DEFUN (show_ip_bgp_neighbors,
15274 show_ip_bgp_neighbors_cmd,
24345e82 15275 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 15276 SHOW_STR
15277 IP_STR
15278 BGP_STR
f2a8972b 15279 BGP_INSTANCE_HELP_STR
8c3deaae
QY
15280 "Address Family\n"
15281 "Address Family\n"
718e3744 15282 "Detailed information on TCP and BGP neighbor connections\n"
15283 "Neighbor to display information about\n"
a80beece 15284 "Neighbor to display information about\n"
91d37724 15285 "Neighbor on BGP configured interface\n"
9973d184 15286 JSON_STR)
718e3744 15287{
d62a17ae 15288 char *vrf = NULL;
15289 char *sh_arg = NULL;
15290 enum show_type sh_type;
d1927ebe 15291 afi_t afi = AFI_MAX;
718e3744 15292
9f049418 15293 bool uj = use_json(argc, argv);
718e3744 15294
d62a17ae 15295 int idx = 0;
718e3744 15296
9a8bdf1c
PG
15297 /* [<vrf> VIEWVRFNAME] */
15298 if (argv_find(argv, argc, "vrf", &idx)) {
15299 vrf = argv[idx + 1]->arg;
15300 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15301 vrf = NULL;
15302 } else if (argv_find(argv, argc, "view", &idx))
15303 /* [<view> VIEWVRFNAME] */
d62a17ae 15304 vrf = argv[idx + 1]->arg;
718e3744 15305
d62a17ae 15306 idx++;
d1927ebe
AS
15307
15308 if (argv_find(argv, argc, "ipv4", &idx)) {
15309 sh_type = show_ipv4_all;
15310 afi = AFI_IP;
15311 } else if (argv_find(argv, argc, "ipv6", &idx)) {
15312 sh_type = show_ipv6_all;
15313 afi = AFI_IP6;
15314 } else {
15315 sh_type = show_all;
15316 }
15317
d62a17ae 15318 if (argv_find(argv, argc, "A.B.C.D", &idx)
15319 || argv_find(argv, argc, "X:X::X:X", &idx)
15320 || argv_find(argv, argc, "WORD", &idx)) {
15321 sh_type = show_peer;
15322 sh_arg = argv[idx]->arg;
d1927ebe
AS
15323 }
15324
15325 if (sh_type == show_peer && afi == AFI_IP) {
15326 sh_type = show_ipv4_peer;
15327 } else if (sh_type == show_peer && afi == AFI_IP6) {
15328 sh_type = show_ipv6_peer;
15329 }
856ca177 15330
d62a17ae 15331 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 15332}
15333
716b2d8a 15334/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 15335 paths' and `show ip mbgp paths'. Those functions results are the
15336 same.*/
f412b39a 15337DEFUN (show_ip_bgp_paths,
718e3744 15338 show_ip_bgp_paths_cmd,
46f296b4 15339 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 15340 SHOW_STR
15341 IP_STR
15342 BGP_STR
46f296b4 15343 BGP_SAFI_HELP_STR
718e3744 15344 "Path information\n")
15345{
d62a17ae 15346 vty_out(vty, "Address Refcnt Path\n");
15347 aspath_print_all_vty(vty);
15348 return CMD_SUCCESS;
718e3744 15349}
15350
718e3744 15351#include "hash.h"
15352
e3b78da8 15353static void community_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 15354 struct vty *vty)
718e3744 15355{
d62a17ae 15356 struct community *com;
718e3744 15357
e3b78da8 15358 com = (struct community *)bucket->data;
3f65c5b1 15359 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 15360 community_str(com, false));
718e3744 15361}
15362
15363/* Show BGP's community internal data. */
f412b39a 15364DEFUN (show_ip_bgp_community_info,
718e3744 15365 show_ip_bgp_community_info_cmd,
bec37ba5 15366 "show [ip] bgp community-info",
718e3744 15367 SHOW_STR
15368 IP_STR
15369 BGP_STR
15370 "List all bgp community information\n")
15371{
d62a17ae 15372 vty_out(vty, "Address Refcnt Community\n");
718e3744 15373
d62a17ae 15374 hash_iterate(community_hash(),
e3b78da8 15375 (void (*)(struct hash_bucket *,
d62a17ae 15376 void *))community_show_all_iterator,
15377 vty);
718e3744 15378
d62a17ae 15379 return CMD_SUCCESS;
718e3744 15380}
15381
e3b78da8 15382static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 15383 struct vty *vty)
57d187bc 15384{
d62a17ae 15385 struct lcommunity *lcom;
57d187bc 15386
e3b78da8 15387 lcom = (struct lcommunity *)bucket->data;
3f65c5b1 15388 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 15389 lcommunity_str(lcom, false));
57d187bc
JS
15390}
15391
15392/* Show BGP's community internal data. */
15393DEFUN (show_ip_bgp_lcommunity_info,
15394 show_ip_bgp_lcommunity_info_cmd,
15395 "show ip bgp large-community-info",
15396 SHOW_STR
15397 IP_STR
15398 BGP_STR
15399 "List all bgp large-community information\n")
15400{
d62a17ae 15401 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 15402
d62a17ae 15403 hash_iterate(lcommunity_hash(),
e3b78da8 15404 (void (*)(struct hash_bucket *,
d62a17ae 15405 void *))lcommunity_show_all_iterator,
15406 vty);
57d187bc 15407
d62a17ae 15408 return CMD_SUCCESS;
57d187bc 15409}
2986cac2 15410/* Graceful Restart */
15411
15412static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
36235319
QY
15413 struct bgp *bgp,
15414 bool use_json,
15415 json_object *json)
2986cac2 15416{
57d187bc
JS
15417
15418
2986cac2 15419 vty_out(vty, "\n%s", SHOW_GR_HEADER);
15420
7318ae88 15421 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
2986cac2 15422
15423 switch (bgp_global_gr_mode) {
15424
15425 case GLOBAL_HELPER:
13909c4f 15426 vty_out(vty, "Global BGP GR Mode : Helper\n");
2986cac2 15427 break;
15428
15429 case GLOBAL_GR:
13909c4f 15430 vty_out(vty, "Global BGP GR Mode : Restart\n");
2986cac2 15431 break;
15432
15433 case GLOBAL_DISABLE:
13909c4f 15434 vty_out(vty, "Global BGP GR Mode : Disable\n");
2986cac2 15435 break;
15436
15437 case GLOBAL_INVALID:
2986cac2 15438 vty_out(vty,
2ba1fe69 15439 "Global BGP GR Mode Invalid\n");
2986cac2 15440 break;
15441 }
15442 vty_out(vty, "\n");
15443}
15444
36235319
QY
15445static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
15446 enum show_type type,
15447 const char *ip_str,
15448 afi_t afi, bool use_json)
2986cac2 15449{
15450 if ((afi == AFI_MAX) && (ip_str == NULL)) {
15451 afi = AFI_IP;
15452
15453 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
15454
36235319
QY
15455 bgp_show_neighbor_graceful_restart_vty(
15456 vty, type, ip_str, afi, use_json);
2986cac2 15457 afi++;
15458 }
15459 } else if (afi != AFI_MAX) {
36235319
QY
15460 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
15461 use_json);
2986cac2 15462 } else {
15463 return CMD_ERR_INCOMPLETE;
15464 }
15465
15466 return CMD_SUCCESS;
15467}
15468/* Graceful Restart */
15469
f412b39a 15470DEFUN (show_ip_bgp_attr_info,
718e3744 15471 show_ip_bgp_attr_info_cmd,
bec37ba5 15472 "show [ip] bgp attribute-info",
718e3744 15473 SHOW_STR
15474 IP_STR
15475 BGP_STR
15476 "List all bgp attribute information\n")
15477{
d62a17ae 15478 attr_show_all(vty);
15479 return CMD_SUCCESS;
718e3744 15480}
6b0655a2 15481
03915806
CS
15482static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
15483 afi_t afi, safi_t safi,
15484 bool use_json, json_object *json)
53089bec 15485{
15486 struct bgp *bgp;
15487 struct listnode *node;
15488 char *vname;
15489 char buf1[INET6_ADDRSTRLEN];
15490 char *ecom_str;
15491 vpn_policy_direction_t dir;
15492
03915806 15493 if (json) {
b46dfd20
DS
15494 json_object *json_import_vrfs = NULL;
15495 json_object *json_export_vrfs = NULL;
15496
b46dfd20
DS
15497 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15498
53089bec 15499 if (!bgp) {
b46dfd20
DS
15500 vty_out(vty, "%s\n",
15501 json_object_to_json_string_ext(
15502 json,
15503 JSON_C_TO_STRING_PRETTY));
15504 json_object_free(json);
15505
53089bec 15506 return CMD_WARNING;
15507 }
b46dfd20 15508
94d4c685
DS
15509 /* Provide context for the block */
15510 json_object_string_add(json, "vrf", name ? name : "default");
15511 json_object_string_add(json, "afiSafi",
5cb5f4d0 15512 get_afi_safi_str(afi, safi, true));
94d4c685 15513
b46dfd20
DS
15514 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15515 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
15516 json_object_string_add(json, "importFromVrfs", "none");
15517 json_object_string_add(json, "importRts", "none");
15518 } else {
6ce24e52
DS
15519 json_import_vrfs = json_object_new_array();
15520
b46dfd20
DS
15521 for (ALL_LIST_ELEMENTS_RO(
15522 bgp->vpn_policy[afi].import_vrf,
15523 node, vname))
15524 json_object_array_add(json_import_vrfs,
15525 json_object_new_string(vname));
15526
b20875ea
CS
15527 json_object_object_add(json, "importFromVrfs",
15528 json_import_vrfs);
b46dfd20 15529 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
15530 if (bgp->vpn_policy[afi].rtlist[dir]) {
15531 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15532 bgp->vpn_policy[afi].rtlist[dir],
15533 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
15534 json_object_string_add(json, "importRts",
15535 ecom_str);
15536 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15537 } else
15538 json_object_string_add(json, "importRts",
15539 "none");
b46dfd20
DS
15540 }
15541
15542 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15543 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
15544 json_object_string_add(json, "exportToVrfs", "none");
15545 json_object_string_add(json, "routeDistinguisher",
15546 "none");
15547 json_object_string_add(json, "exportRts", "none");
15548 } else {
6ce24e52
DS
15549 json_export_vrfs = json_object_new_array();
15550
b46dfd20
DS
15551 for (ALL_LIST_ELEMENTS_RO(
15552 bgp->vpn_policy[afi].export_vrf,
15553 node, vname))
15554 json_object_array_add(json_export_vrfs,
15555 json_object_new_string(vname));
15556 json_object_object_add(json, "exportToVrfs",
15557 json_export_vrfs);
15558 json_object_string_add(json, "routeDistinguisher",
15559 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
15560 buf1, RD_ADDRSTRLEN));
15561
15562 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
15563 if (bgp->vpn_policy[afi].rtlist[dir]) {
15564 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15565 bgp->vpn_policy[afi].rtlist[dir],
15566 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
15567 json_object_string_add(json, "exportRts",
15568 ecom_str);
15569 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15570 } else
15571 json_object_string_add(json, "exportRts",
15572 "none");
b46dfd20
DS
15573 }
15574
03915806
CS
15575 if (use_json) {
15576 vty_out(vty, "%s\n",
15577 json_object_to_json_string_ext(json,
b46dfd20 15578 JSON_C_TO_STRING_PRETTY));
03915806
CS
15579 json_object_free(json);
15580 }
53089bec 15581 } else {
b46dfd20
DS
15582 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15583
53089bec 15584 if (!bgp) {
b46dfd20 15585 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 15586 return CMD_WARNING;
15587 }
53089bec 15588
b46dfd20
DS
15589 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15590 BGP_CONFIG_VRF_TO_VRF_IMPORT))
15591 vty_out(vty,
15592 "This VRF is not importing %s routes from any other VRF\n",
5cb5f4d0 15593 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15594 else {
15595 vty_out(vty,
15596 "This VRF is importing %s routes from the following VRFs:\n",
5cb5f4d0 15597 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15598
15599 for (ALL_LIST_ELEMENTS_RO(
15600 bgp->vpn_policy[afi].import_vrf,
15601 node, vname))
15602 vty_out(vty, " %s\n", vname);
15603
15604 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
15605 ecom_str = NULL;
15606 if (bgp->vpn_policy[afi].rtlist[dir]) {
15607 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15608 bgp->vpn_policy[afi].rtlist[dir],
15609 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea 15610 vty_out(vty, "Import RT(s): %s\n", ecom_str);
b46dfd20 15611
b20875ea
CS
15612 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15613 } else
15614 vty_out(vty, "Import RT(s):\n");
53089bec 15615 }
53089bec 15616
b46dfd20
DS
15617 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15618 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15619 vty_out(vty,
15620 "This VRF is not exporting %s routes to any other VRF\n",
5cb5f4d0 15621 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15622 else {
15623 vty_out(vty,
04c9077f 15624 "This VRF is exporting %s routes to the following VRFs:\n",
5cb5f4d0 15625 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15626
15627 for (ALL_LIST_ELEMENTS_RO(
15628 bgp->vpn_policy[afi].export_vrf,
15629 node, vname))
15630 vty_out(vty, " %s\n", vname);
15631
15632 vty_out(vty, "RD: %s\n",
15633 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
15634 buf1, RD_ADDRSTRLEN));
15635
15636 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
15637 if (bgp->vpn_policy[afi].rtlist[dir]) {
15638 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15639 bgp->vpn_policy[afi].rtlist[dir],
15640 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
15641 vty_out(vty, "Export RT: %s\n", ecom_str);
15642 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15643 } else
15644 vty_out(vty, "Import RT(s):\n");
53089bec 15645 }
53089bec 15646 }
15647
15648 return CMD_SUCCESS;
15649}
15650
03915806
CS
15651static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
15652 safi_t safi, bool use_json)
15653{
15654 struct listnode *node, *nnode;
15655 struct bgp *bgp;
15656 char *vrf_name = NULL;
15657 json_object *json = NULL;
15658 json_object *json_vrf = NULL;
15659 json_object *json_vrfs = NULL;
15660
15661 if (use_json) {
15662 json = json_object_new_object();
15663 json_vrfs = json_object_new_object();
15664 }
15665
15666 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15667
15668 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
15669 vrf_name = bgp->name;
15670
15671 if (use_json) {
15672 json_vrf = json_object_new_object();
15673 } else {
15674 vty_out(vty, "\nInstance %s:\n",
15675 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15676 ? VRF_DEFAULT_NAME : bgp->name);
15677 }
15678 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
15679 if (use_json) {
15680 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15681 json_object_object_add(json_vrfs,
15682 VRF_DEFAULT_NAME, json_vrf);
15683 else
15684 json_object_object_add(json_vrfs, vrf_name,
15685 json_vrf);
15686 }
15687 }
15688
15689 if (use_json) {
15690 json_object_object_add(json, "vrfs", json_vrfs);
15691 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
15692 JSON_C_TO_STRING_PRETTY));
15693 json_object_free(json);
15694 }
15695
15696 return CMD_SUCCESS;
15697}
15698
53089bec 15699/* "show [ip] bgp route-leak" command. */
15700DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
15701 show_ip_bgp_route_leak_cmd,
15702 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
15703 SHOW_STR
15704 IP_STR
15705 BGP_STR
15706 BGP_INSTANCE_HELP_STR
15707 BGP_AFI_HELP_STR
15708 BGP_SAFI_HELP_STR
15709 "Route leaking information\n"
15710 JSON_STR)
53089bec 15711{
15712 char *vrf = NULL;
15713 afi_t afi = AFI_MAX;
15714 safi_t safi = SAFI_MAX;
15715
9f049418 15716 bool uj = use_json(argc, argv);
53089bec 15717 int idx = 0;
03915806 15718 json_object *json = NULL;
53089bec 15719
15720 /* show [ip] bgp */
15721 if (argv_find(argv, argc, "ip", &idx)) {
15722 afi = AFI_IP;
15723 safi = SAFI_UNICAST;
15724 }
15725 /* [vrf VIEWVRFNAME] */
15726 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
15727 vty_out(vty,
15728 "%% This command is not applicable to BGP views\n");
53089bec 15729 return CMD_WARNING;
15730 }
15731
9a8bdf1c
PG
15732 if (argv_find(argv, argc, "vrf", &idx)) {
15733 vrf = argv[idx + 1]->arg;
15734 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15735 vrf = NULL;
15736 }
53089bec 15737 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15738 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15739 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15740 }
15741
15742 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
15743 vty_out(vty,
15744 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 15745 return CMD_WARNING;
15746 }
15747
03915806
CS
15748 if (vrf && strmatch(vrf, "all"))
15749 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15750
15751 if (uj)
15752 json = json_object_new_object();
15753
15754 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
53089bec 15755}
15756
d62a17ae 15757static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
15758 safi_t safi)
f186de26 15759{
d62a17ae 15760 struct listnode *node, *nnode;
15761 struct bgp *bgp;
f186de26 15762
d62a17ae 15763 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15764 vty_out(vty, "\nInstance %s:\n",
15765 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 15766 ? VRF_DEFAULT_NAME
d62a17ae 15767 : bgp->name);
15768 update_group_show(bgp, afi, safi, vty, 0);
15769 }
f186de26 15770}
15771
d62a17ae 15772static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
15773 int safi, uint64_t subgrp_id)
4fb25c53 15774{
d62a17ae 15775 struct bgp *bgp;
4fb25c53 15776
d62a17ae 15777 if (name) {
15778 if (strmatch(name, "all")) {
15779 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
15780 return CMD_SUCCESS;
15781 } else {
15782 bgp = bgp_lookup_by_name(name);
15783 }
15784 } else {
15785 bgp = bgp_get_default();
15786 }
4fb25c53 15787
d62a17ae 15788 if (bgp)
15789 update_group_show(bgp, afi, safi, vty, subgrp_id);
15790 return CMD_SUCCESS;
4fb25c53
DW
15791}
15792
8fe8a7f6
DS
15793DEFUN (show_ip_bgp_updgrps,
15794 show_ip_bgp_updgrps_cmd,
c1a44e43 15795 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 15796 SHOW_STR
15797 IP_STR
15798 BGP_STR
15799 BGP_INSTANCE_HELP_STR
c9e571b4 15800 BGP_AFI_HELP_STR
9bedbb1e 15801 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
15802 "Detailed info about dynamic update groups\n"
15803 "Specific subgroup to display detailed info for\n")
8386ac43 15804{
d62a17ae 15805 char *vrf = NULL;
15806 afi_t afi = AFI_IP6;
15807 safi_t safi = SAFI_UNICAST;
15808 uint64_t subgrp_id = 0;
15809
15810 int idx = 0;
15811
15812 /* show [ip] bgp */
15813 if (argv_find(argv, argc, "ip", &idx))
15814 afi = AFI_IP;
9a8bdf1c
PG
15815 /* [<vrf> VIEWVRFNAME] */
15816 if (argv_find(argv, argc, "vrf", &idx)) {
15817 vrf = argv[idx + 1]->arg;
15818 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15819 vrf = NULL;
15820 } else if (argv_find(argv, argc, "view", &idx))
15821 /* [<view> VIEWVRFNAME] */
15822 vrf = argv[idx + 1]->arg;
d62a17ae 15823 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15824 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15825 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15826 }
5bf15956 15827
d62a17ae 15828 /* get subgroup id, if provided */
15829 idx = argc - 1;
15830 if (argv[idx]->type == VARIABLE_TKN)
15831 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 15832
d62a17ae 15833 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
15834}
15835
f186de26 15836DEFUN (show_bgp_instance_all_ipv6_updgrps,
15837 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 15838 "show [ip] bgp <view|vrf> all update-groups",
f186de26 15839 SHOW_STR
716b2d8a 15840 IP_STR
f186de26 15841 BGP_STR
15842 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 15843 "Detailed info about dynamic update groups\n")
f186de26 15844{
d62a17ae 15845 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
15846 return CMD_SUCCESS;
f186de26 15847}
15848
43d3f4fc
DS
15849DEFUN (show_bgp_l2vpn_evpn_updgrps,
15850 show_bgp_l2vpn_evpn_updgrps_cmd,
15851 "show [ip] bgp l2vpn evpn update-groups",
15852 SHOW_STR
15853 IP_STR
15854 BGP_STR
15855 "l2vpn address family\n"
15856 "evpn sub-address family\n"
15857 "Detailed info about dynamic update groups\n")
15858{
15859 char *vrf = NULL;
15860 uint64_t subgrp_id = 0;
15861
15862 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
15863 return CMD_SUCCESS;
15864}
15865
5bf15956
DW
15866DEFUN (show_bgp_updgrps_stats,
15867 show_bgp_updgrps_stats_cmd,
716b2d8a 15868 "show [ip] bgp update-groups statistics",
3f9c7369 15869 SHOW_STR
716b2d8a 15870 IP_STR
3f9c7369 15871 BGP_STR
0c7b1b01 15872 "Detailed info about dynamic update groups\n"
3f9c7369
DS
15873 "Statistics\n")
15874{
d62a17ae 15875 struct bgp *bgp;
3f9c7369 15876
d62a17ae 15877 bgp = bgp_get_default();
15878 if (bgp)
15879 update_group_show_stats(bgp, vty);
3f9c7369 15880
d62a17ae 15881 return CMD_SUCCESS;
3f9c7369
DS
15882}
15883
8386ac43 15884DEFUN (show_bgp_instance_updgrps_stats,
15885 show_bgp_instance_updgrps_stats_cmd,
18c57037 15886 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 15887 SHOW_STR
716b2d8a 15888 IP_STR
8386ac43 15889 BGP_STR
15890 BGP_INSTANCE_HELP_STR
0c7b1b01 15891 "Detailed info about dynamic update groups\n"
8386ac43 15892 "Statistics\n")
15893{
d62a17ae 15894 int idx_word = 3;
15895 struct bgp *bgp;
8386ac43 15896
d62a17ae 15897 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15898 if (bgp)
15899 update_group_show_stats(bgp, vty);
8386ac43 15900
d62a17ae 15901 return CMD_SUCCESS;
8386ac43 15902}
15903
d62a17ae 15904static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15905 afi_t afi, safi_t safi,
15906 const char *what, uint64_t subgrp_id)
3f9c7369 15907{
d62a17ae 15908 struct bgp *bgp;
8386ac43 15909
d62a17ae 15910 if (name)
15911 bgp = bgp_lookup_by_name(name);
15912 else
15913 bgp = bgp_get_default();
8386ac43 15914
d62a17ae 15915 if (bgp) {
15916 if (!strcmp(what, "advertise-queue"))
15917 update_group_show_adj_queue(bgp, afi, safi, vty,
15918 subgrp_id);
15919 else if (!strcmp(what, "advertised-routes"))
15920 update_group_show_advertised(bgp, afi, safi, vty,
15921 subgrp_id);
15922 else if (!strcmp(what, "packet-queue"))
15923 update_group_show_packet_queue(bgp, afi, safi, vty,
15924 subgrp_id);
15925 }
3f9c7369
DS
15926}
15927
dc64bdec
QY
15928DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15929 show_ip_bgp_instance_updgrps_adj_s_cmd,
15930 "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",
15931 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15932 BGP_SAFI_HELP_STR
15933 "Detailed info about dynamic update groups\n"
15934 "Specific subgroup to display info for\n"
15935 "Advertisement queue\n"
15936 "Announced routes\n"
15937 "Packet queue\n")
3f9c7369 15938{
dc64bdec
QY
15939 uint64_t subgrp_id = 0;
15940 afi_t afiz;
15941 safi_t safiz;
15942 if (sgid)
15943 subgrp_id = strtoull(sgid, NULL, 10);
15944
15945 if (!ip && !afi)
15946 afiz = AFI_IP6;
15947 if (!ip && afi)
15948 afiz = bgp_vty_afi_from_str(afi);
15949 if (ip && !afi)
15950 afiz = AFI_IP;
15951 if (ip && afi) {
15952 afiz = bgp_vty_afi_from_str(afi);
15953 if (afiz != AFI_IP)
15954 vty_out(vty,
15955 "%% Cannot specify both 'ip' and 'ipv6'\n");
15956 return CMD_WARNING;
15957 }
d62a17ae 15958
dc64bdec 15959 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 15960
dc64bdec 15961 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 15962 return CMD_SUCCESS;
15963}
15964
6f4eacf3
DA
15965static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
15966 json_object *json)
d62a17ae 15967{
15968 struct listnode *node, *nnode;
15969 struct prefix *range;
15970 struct peer *conf;
15971 struct peer *peer;
d62a17ae 15972 afi_t afi;
15973 safi_t safi;
15974 const char *peer_status;
d62a17ae 15975 int lr_count;
15976 int dynamic;
6f4eacf3
DA
15977 bool af_cfgd;
15978 json_object *json_peer_group = NULL;
15979 json_object *json_peer_group_afc = NULL;
15980 json_object *json_peer_group_members = NULL;
15981 json_object *json_peer_group_dynamic = NULL;
15982 json_object *json_peer_group_dynamic_af = NULL;
15983 json_object *json_peer_group_ranges = NULL;
d62a17ae 15984
15985 conf = group->conf;
15986
6f4eacf3
DA
15987 if (json) {
15988 json_peer_group = json_object_new_object();
15989 json_peer_group_afc = json_object_new_array();
15990 }
15991
d62a17ae 15992 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
6f4eacf3
DA
15993 if (json)
15994 json_object_int_add(json_peer_group, "remoteAs",
15995 conf->as);
15996 else
15997 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15998 group->name, conf->as);
d62a17ae 15999 } else if (conf->as_type == AS_INTERNAL) {
6f4eacf3
DA
16000 if (json)
16001 json_object_int_add(json_peer_group, "remoteAs",
16002 group->bgp->as);
16003 else
16004 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
16005 group->name, group->bgp->as);
d62a17ae 16006 } else {
6f4eacf3
DA
16007 if (!json)
16008 vty_out(vty, "\nBGP peer-group %s\n", group->name);
d62a17ae 16009 }
f14e6fdb 16010
6f4eacf3
DA
16011 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
16012 if (json)
16013 json_object_string_add(json_peer_group, "type",
16014 "internal");
16015 else
16016 vty_out(vty, " Peer-group type is internal\n");
16017 } else {
16018 if (json)
16019 json_object_string_add(json_peer_group, "type",
16020 "external");
16021 else
16022 vty_out(vty, " Peer-group type is external\n");
16023 }
d62a17ae 16024
16025 /* Display AFs configured. */
6f4eacf3
DA
16026 if (!json)
16027 vty_out(vty, " Configured address-families:");
16028
05c7a1cc
QY
16029 FOREACH_AFI_SAFI (afi, safi) {
16030 if (conf->afc[afi][safi]) {
6f4eacf3
DA
16031 af_cfgd = true;
16032 if (json)
16033 json_object_array_add(
16034 json_peer_group_afc,
16035 json_object_new_string(get_afi_safi_str(
16036 afi, safi, false)));
16037 else
16038 vty_out(vty, " %s;",
16039 get_afi_safi_str(afi, safi, false));
d62a17ae 16040 }
05c7a1cc 16041 }
6f4eacf3
DA
16042
16043 if (json) {
16044 json_object_object_add(json_peer_group,
16045 "addressFamiliesConfigured",
16046 json_peer_group_afc);
16047 } else {
16048 if (!af_cfgd)
16049 vty_out(vty, " none\n");
16050 else
16051 vty_out(vty, "\n");
16052 }
d62a17ae 16053
16054 /* Display listen ranges (for dynamic neighbors), if any */
16055 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
d62a17ae 16056 lr_count = listcount(group->listen_range[afi]);
16057 if (lr_count) {
6f4eacf3
DA
16058 if (json) {
16059 if (!json_peer_group_dynamic)
16060 json_peer_group_dynamic =
16061 json_object_new_object();
16062
16063 json_peer_group_dynamic_af =
16064 json_object_new_object();
16065 json_peer_group_ranges =
16066 json_object_new_array();
16067 json_object_int_add(json_peer_group_dynamic_af,
16068 "count", lr_count);
16069 } else {
16070 vty_out(vty, " %d %s listen range(s)\n",
16071 lr_count, afi2str(afi));
16072 }
d62a17ae 16073
16074 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
6f4eacf3
DA
16075 nnode, range)) {
16076 if (json) {
16077 char buf[BUFSIZ];
16078
16079 snprintfrr(buf, sizeof(buf), "%pFX",
16080 range);
16081
16082 json_object_array_add(
16083 json_peer_group_ranges,
16084 json_object_new_string(buf));
16085 } else {
16086 vty_out(vty, " %pFX\n", range);
16087 }
16088 }
16089
16090 if (json) {
16091 json_object_object_add(
16092 json_peer_group_dynamic_af, "ranges",
16093 json_peer_group_ranges);
16094
16095 json_object_object_add(
16096 json_peer_group_dynamic, afi2str(afi),
16097 json_peer_group_dynamic_af);
16098 }
d62a17ae 16099 }
16100 }
f14e6fdb 16101
6f4eacf3
DA
16102 if (json_peer_group_dynamic)
16103 json_object_object_add(json_peer_group, "dynamicRanges",
16104 json_peer_group_dynamic);
16105
d62a17ae 16106 /* Display group members and their status */
16107 if (listcount(group->peer)) {
6f4eacf3
DA
16108 if (json)
16109 json_peer_group_members = json_object_new_object();
16110 else
16111 vty_out(vty, " Peer-group members:\n");
d62a17ae 16112 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
cb9196e7
DS
16113 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
16114 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 16115 peer_status = "Idle (Admin)";
16116 else if (CHECK_FLAG(peer->sflags,
16117 PEER_STATUS_PREFIX_OVERFLOW))
16118 peer_status = "Idle (PfxCt)";
16119 else
16120 peer_status = lookup_msg(bgp_status_msg,
16121 peer->status, NULL);
16122
16123 dynamic = peer_dynamic_neighbor(peer);
6f4eacf3
DA
16124
16125 if (json) {
16126 json_object *json_peer_group_member =
16127 json_object_new_object();
16128
16129 json_object_string_add(json_peer_group_member,
16130 "status", peer_status);
16131
16132 if (dynamic)
16133 json_object_boolean_true_add(
16134 json_peer_group_member,
16135 "dynamic");
16136
16137 json_object_object_add(json_peer_group_members,
16138 peer->host,
16139 json_peer_group_member);
16140 } else {
16141 vty_out(vty, " %s %s %s \n", peer->host,
16142 dynamic ? "(dynamic)" : "",
16143 peer_status);
16144 }
d62a17ae 16145 }
6f4eacf3
DA
16146 if (json)
16147 json_object_object_add(json_peer_group, "members",
16148 json_peer_group_members);
d62a17ae 16149 }
f14e6fdb 16150
6f4eacf3
DA
16151 if (json)
16152 json_object_object_add(json, group->name, json_peer_group);
16153
d62a17ae 16154 return CMD_SUCCESS;
16155}
16156
ff9959b0 16157static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
6f4eacf3 16158 const char *group_name, bool uj)
d62a17ae 16159{
ff9959b0 16160 struct bgp *bgp;
d62a17ae 16161 struct listnode *node, *nnode;
16162 struct peer_group *group;
ff9959b0 16163 bool found = false;
6f4eacf3
DA
16164 json_object *json = NULL;
16165
16166 if (uj)
16167 json = json_object_new_object();
ff9959b0
QY
16168
16169 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
16170
16171 if (!bgp) {
6f4eacf3
DA
16172 if (uj) {
16173 vty_out(vty, "%s\n",
16174 json_object_to_json_string_ext(
16175 json, JSON_C_TO_STRING_PRETTY));
16176 json_object_free(json);
16177 } else {
16178 vty_out(vty, "%% BGP instance not found\n");
16179 }
16180
ff9959b0
QY
16181 return CMD_WARNING;
16182 }
d62a17ae 16183
16184 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
16185 if (group_name) {
16186 if (strmatch(group->name, group_name)) {
6f4eacf3 16187 bgp_show_one_peer_group(vty, group, json);
ff9959b0
QY
16188 found = true;
16189 break;
d62a17ae 16190 }
ff9959b0 16191 } else {
6f4eacf3 16192 bgp_show_one_peer_group(vty, group, json);
d62a17ae 16193 }
f14e6fdb 16194 }
f14e6fdb 16195
6f4eacf3 16196 if (group_name && !found && !uj)
d62a17ae 16197 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 16198
6f4eacf3
DA
16199 if (uj) {
16200 vty_out(vty, "%s\n",
16201 json_object_to_json_string_ext(
16202 json, JSON_C_TO_STRING_PRETTY));
16203 json_object_free(json);
16204 }
16205
d62a17ae 16206 return CMD_SUCCESS;
f14e6fdb
DS
16207}
16208
6f4eacf3
DA
16209DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
16210 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
16211 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
16212 "Detailed information on BGP peer groups\n"
16213 "Peer group name\n" JSON_STR)
f14e6fdb 16214{
d62a17ae 16215 char *vrf, *pg;
d62a17ae 16216 int idx = 0;
6f4eacf3 16217 bool uj = use_json(argc, argv);
f14e6fdb 16218
a4d82a8a
PZ
16219 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
16220 : NULL;
d62a17ae 16221 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 16222
6f4eacf3 16223 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
f14e6fdb 16224}
3f9c7369 16225
d6e3c605 16226
718e3744 16227/* Redistribute VTY commands. */
16228
37a87b8f
CS
16229DEFUN_YANG (bgp_redistribute_ipv4,
16230 bgp_redistribute_ipv4_cmd,
16231 "redistribute " FRR_IP_REDIST_STR_BGPD,
16232 "Redistribute information from another routing protocol\n"
16233 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 16234{
d62a17ae 16235 int idx_protocol = 1;
37a87b8f 16236 char base_xpath[XPATH_MAXLEN];
718e3744 16237
37a87b8f
CS
16238 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16239 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16240 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16241 argv[idx_protocol]->text, "0");
16242
16243 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
7f323236 16244
37a87b8f 16245 return nb_cli_apply_changes(vty, base_xpath);
718e3744 16246}
16247
d62a17ae 16248ALIAS_HIDDEN(
16249 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
16250 "redistribute " FRR_IP_REDIST_STR_BGPD,
16251 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 16252
37a87b8f
CS
16253DEFUN_YANG (bgp_redistribute_ipv4_rmap,
16254 bgp_redistribute_ipv4_rmap_cmd,
16255 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
16256 "Redistribute information from another routing protocol\n"
16257 FRR_IP_REDIST_HELP_STR_BGPD
16258 "Route map reference\n"
16259 "Pointer to route-map entries\n")
718e3744 16260{
d62a17ae 16261 int idx_protocol = 1;
16262 int idx_word = 3;
37a87b8f
CS
16263 char base_xpath[XPATH_MAXLEN];
16264
16265 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16266 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16267 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16268 argv[idx_protocol]->text, "0");
718e3744 16269
37a87b8f
CS
16270 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16271 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16272 argv[idx_word]->arg);
16273
16274 return nb_cli_apply_changes(vty, base_xpath);
718e3744 16275}
16276
d62a17ae 16277ALIAS_HIDDEN(
16278 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
16279 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
16280 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16281 "Route map reference\n"
16282 "Pointer to route-map entries\n")
596c17ba 16283
37a87b8f
CS
16284DEFUN_YANG (bgp_redistribute_ipv4_metric,
16285 bgp_redistribute_ipv4_metric_cmd,
16286 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
16287 "Redistribute information from another routing protocol\n"
16288 FRR_IP_REDIST_HELP_STR_BGPD
16289 "Metric for redistributed routes\n"
16290 "Default metric\n")
718e3744 16291{
d62a17ae 16292 int idx_protocol = 1;
16293 int idx_number = 3;
37a87b8f
CS
16294 char base_xpath[XPATH_MAXLEN];
16295
16296 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16297 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16298 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16299 argv[idx_protocol]->text, "0");
d62a17ae 16300
37a87b8f
CS
16301 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16302 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16303 argv[idx_number]->arg);
16304
16305 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 16306}
16307
16308ALIAS_HIDDEN(
16309 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
16310 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
16311 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16312 "Metric for redistributed routes\n"
16313 "Default metric\n")
596c17ba 16314
37a87b8f
CS
16315DEFUN_YANG(
16316 bgp_redistribute_ipv4_rmap_metric,
16317 bgp_redistribute_ipv4_rmap_metric_cmd,
16318 "redistribute " FRR_IP_REDIST_STR_BGPD
16319 " route-map WORD metric (0-4294967295)",
16320 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16321 "Route map reference\n"
16322 "Pointer to route-map entries\n"
16323 "Metric for redistributed routes\n"
16324 "Default metric\n")
718e3744 16325{
d62a17ae 16326 int idx_protocol = 1;
16327 int idx_word = 3;
16328 int idx_number = 5;
37a87b8f
CS
16329 char base_xpath[XPATH_MAXLEN];
16330
16331 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16332 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16333 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16334 argv[idx_protocol]->text, "0");
16335
16336 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16337 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16338 argv[idx_word]->arg);
16339 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16340 argv[idx_number]->arg);
d62a17ae 16341
37a87b8f 16342 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 16343}
16344
16345ALIAS_HIDDEN(
16346 bgp_redistribute_ipv4_rmap_metric,
16347 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
16348 "redistribute " FRR_IP_REDIST_STR_BGPD
16349 " route-map WORD metric (0-4294967295)",
16350 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16351 "Route map reference\n"
16352 "Pointer to route-map entries\n"
16353 "Metric for redistributed routes\n"
16354 "Default metric\n")
596c17ba 16355
37a87b8f
CS
16356DEFUN_YANG(
16357 bgp_redistribute_ipv4_metric_rmap,
16358 bgp_redistribute_ipv4_metric_rmap_cmd,
16359 "redistribute " FRR_IP_REDIST_STR_BGPD
16360 " metric (0-4294967295) route-map WORD",
16361 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16362 "Metric for redistributed routes\n"
16363 "Default metric\n"
16364 "Route map reference\n"
16365 "Pointer to route-map entries\n")
718e3744 16366{
d62a17ae 16367 int idx_protocol = 1;
d62a17ae 16368 int idx_word = 5;
37a87b8f
CS
16369 int idx_number = 3;
16370 char base_xpath[XPATH_MAXLEN];
16371
16372 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16373 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16374 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16375 argv[idx_protocol]->text, "0");
16376
16377 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16378 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16379 argv[idx_number]->arg);
16380 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16381 argv[idx_word]->arg);
d62a17ae 16382
37a87b8f 16383 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 16384}
16385
16386ALIAS_HIDDEN(
16387 bgp_redistribute_ipv4_metric_rmap,
16388 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
16389 "redistribute " FRR_IP_REDIST_STR_BGPD
16390 " metric (0-4294967295) route-map WORD",
16391 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16392 "Metric for redistributed routes\n"
16393 "Default metric\n"
16394 "Route map reference\n"
16395 "Pointer to route-map entries\n")
596c17ba 16396
37a87b8f
CS
16397DEFUN_YANG (bgp_redistribute_ipv4_ospf,
16398 bgp_redistribute_ipv4_ospf_cmd,
16399 "redistribute <ospf|table> (1-65535)",
16400 "Redistribute information from another routing protocol\n"
16401 "Open Shortest Path First (OSPFv2)\n"
16402 "Non-main Kernel Routing Table\n"
16403 "Instance ID/Table ID\n")
7c8ff89e 16404{
37a87b8f 16405 int idx_protocol = 1;
d62a17ae 16406 int idx_number = 2;
37a87b8f 16407 char base_xpath[XPATH_MAXLEN];
7c8ff89e 16408
37a87b8f
CS
16409 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16410 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16411 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16412 argv[idx_protocol]->text, argv[idx_number]->arg);
7a4bb9c5 16413
37a87b8f 16414 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
7a4bb9c5 16415
37a87b8f 16416 return nb_cli_apply_changes(vty, base_xpath);
7c8ff89e
DS
16417}
16418
d62a17ae 16419ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
16420 "redistribute <ospf|table> (1-65535)",
16421 "Redistribute information from another routing protocol\n"
16422 "Open Shortest Path First (OSPFv2)\n"
16423 "Non-main Kernel Routing Table\n"
16424 "Instance ID/Table ID\n")
596c17ba 16425
37a87b8f
CS
16426DEFUN_YANG (bgp_redistribute_ipv4_ospf_rmap,
16427 bgp_redistribute_ipv4_ospf_rmap_cmd,
16428 "redistribute <ospf|table> (1-65535) route-map WORD",
16429 "Redistribute information from another routing protocol\n"
16430 "Open Shortest Path First (OSPFv2)\n"
16431 "Non-main Kernel Routing Table\n"
16432 "Instance ID/Table ID\n"
16433 "Route map reference\n"
16434 "Pointer to route-map entries\n")
7c8ff89e 16435{
37a87b8f 16436 int idx_protocol = 1;
d62a17ae 16437 int idx_number = 2;
16438 int idx_word = 4;
37a87b8f
CS
16439 char base_xpath[XPATH_MAXLEN];
16440
16441 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16442 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16443 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16444 argv[idx_protocol]->text, argv[idx_number]->arg);
16445
16446 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16447
16448 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16449 argv[idx_word]->arg);
d62a17ae 16450
37a87b8f 16451 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 16452}
16453
16454ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
16455 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
16456 "redistribute <ospf|table> (1-65535) route-map WORD",
16457 "Redistribute information from another routing protocol\n"
16458 "Open Shortest Path First (OSPFv2)\n"
16459 "Non-main Kernel Routing Table\n"
16460 "Instance ID/Table ID\n"
16461 "Route map reference\n"
16462 "Pointer to route-map entries\n")
596c17ba 16463
37a87b8f
CS
16464DEFUN_YANG(bgp_redistribute_ipv4_ospf_metric,
16465 bgp_redistribute_ipv4_ospf_metric_cmd,
16466 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16467 "Redistribute information from another routing protocol\n"
16468 "Open Shortest Path First (OSPFv2)\n"
16469 "Non-main Kernel Routing Table\n"
16470 "Instance ID/Table ID\n"
16471 "Metric for redistributed routes\n"
16472 "Default metric\n")
7c8ff89e 16473{
37a87b8f 16474 int idx_protocol = 1;
d62a17ae 16475 int idx_number = 2;
16476 int idx_number_2 = 4;
37a87b8f
CS
16477 char base_xpath[XPATH_MAXLEN];
16478
16479 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16480 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16481 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16482 argv[idx_protocol]->text, argv[idx_number]->arg);
16483
16484 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 16485
37a87b8f
CS
16486 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16487 argv[idx_number_2]->arg);
d62a17ae 16488
37a87b8f 16489 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 16490}
16491
16492ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
16493 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
16494 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16495 "Redistribute information from another routing protocol\n"
16496 "Open Shortest Path First (OSPFv2)\n"
16497 "Non-main Kernel Routing Table\n"
16498 "Instance ID/Table ID\n"
16499 "Metric for redistributed routes\n"
16500 "Default metric\n")
596c17ba 16501
37a87b8f
CS
16502DEFUN_YANG(
16503 bgp_redistribute_ipv4_ospf_rmap_metric,
16504 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
16505 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
16506 "Redistribute information from another routing protocol\n"
16507 "Open Shortest Path First (OSPFv2)\n"
16508 "Non-main Kernel Routing Table\n"
16509 "Instance ID/Table ID\n"
16510 "Route map reference\n"
16511 "Pointer to route-map entries\n"
16512 "Metric for redistributed routes\n"
16513 "Default metric\n")
7c8ff89e 16514{
37a87b8f 16515 int idx_protocol = 1;
d62a17ae 16516 int idx_number = 2;
16517 int idx_word = 4;
16518 int idx_number_2 = 6;
37a87b8f
CS
16519 char base_xpath[XPATH_MAXLEN];
16520
16521 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16522 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16523 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16524 argv[idx_protocol]->text, argv[idx_number]->arg);
16525
16526 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 16527
37a87b8f
CS
16528 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16529 argv[idx_word]->arg);
16530 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16531 argv[idx_number_2]->arg);
d62a17ae 16532
37a87b8f 16533 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 16534}
16535
16536ALIAS_HIDDEN(
16537 bgp_redistribute_ipv4_ospf_rmap_metric,
16538 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
16539 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
16540 "Redistribute information from another routing protocol\n"
16541 "Open Shortest Path First (OSPFv2)\n"
16542 "Non-main Kernel Routing Table\n"
16543 "Instance ID/Table ID\n"
16544 "Route map reference\n"
16545 "Pointer to route-map entries\n"
16546 "Metric for redistributed routes\n"
16547 "Default metric\n")
596c17ba 16548
37a87b8f
CS
16549DEFUN_YANG(
16550 bgp_redistribute_ipv4_ospf_metric_rmap,
16551 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
16552 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
16553 "Redistribute information from another routing protocol\n"
16554 "Open Shortest Path First (OSPFv2)\n"
16555 "Non-main Kernel Routing Table\n"
16556 "Instance ID/Table ID\n"
16557 "Metric for redistributed routes\n"
16558 "Default metric\n"
16559 "Route map reference\n"
16560 "Pointer to route-map entries\n")
7c8ff89e 16561{
37a87b8f 16562 int idx_protocol = 1;
d62a17ae 16563 int idx_number = 2;
16564 int idx_number_2 = 4;
16565 int idx_word = 6;
37a87b8f
CS
16566 char base_xpath[XPATH_MAXLEN];
16567
16568 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16569 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16570 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16571 argv[idx_protocol]->text, argv[idx_number]->arg);
16572
16573 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 16574
37a87b8f
CS
16575 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16576 argv[idx_number_2]->arg);
16577 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16578 argv[idx_word]->arg);
d62a17ae 16579
37a87b8f 16580 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 16581}
16582
16583ALIAS_HIDDEN(
16584 bgp_redistribute_ipv4_ospf_metric_rmap,
16585 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
16586 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
16587 "Redistribute information from another routing protocol\n"
16588 "Open Shortest Path First (OSPFv2)\n"
16589 "Non-main Kernel Routing Table\n"
16590 "Instance ID/Table ID\n"
16591 "Metric for redistributed routes\n"
16592 "Default metric\n"
16593 "Route map reference\n"
16594 "Pointer to route-map entries\n")
596c17ba 16595
37a87b8f
CS
16596DEFUN_YANG (no_bgp_redistribute_ipv4_ospf,
16597 no_bgp_redistribute_ipv4_ospf_cmd,
16598 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
16599 NO_STR
16600 "Redistribute information from another routing protocol\n"
16601 "Open Shortest Path First (OSPFv2)\n"
16602 "Non-main Kernel Routing Table\n"
16603 "Instance ID/Table ID\n"
16604 "Metric for redistributed routes\n"
16605 "Default metric\n"
16606 "Route map reference\n"
16607 "Pointer to route-map entries\n")
7c8ff89e 16608{
37a87b8f 16609 int idx_protocol = 2;
d62a17ae 16610 int idx_number = 3;
37a87b8f 16611 char base_xpath[XPATH_MAXLEN];
d62a17ae 16612
37a87b8f
CS
16613 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16614 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16615 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16616 argv[idx_protocol]->text, argv[idx_number]->arg);
16617
16618 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
d62a17ae 16619
37a87b8f 16620 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 16621}
16622
16623ALIAS_HIDDEN(
16624 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
e27957c0 16625 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 16626 NO_STR
16627 "Redistribute information from another routing protocol\n"
16628 "Open Shortest Path First (OSPFv2)\n"
16629 "Non-main Kernel Routing Table\n"
16630 "Instance ID/Table ID\n"
16631 "Metric for redistributed routes\n"
16632 "Default metric\n"
16633 "Route map reference\n"
16634 "Pointer to route-map entries\n")
596c17ba 16635
37a87b8f
CS
16636DEFUN_YANG (no_bgp_redistribute_ipv4,
16637 no_bgp_redistribute_ipv4_cmd,
16638 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
16639 NO_STR
16640 "Redistribute information from another routing protocol\n"
16641 FRR_IP_REDIST_HELP_STR_BGPD
16642 "Metric for redistributed routes\n"
16643 "Default metric\n"
16644 "Route map reference\n"
16645 "Pointer to route-map entries\n")
718e3744 16646{
d62a17ae 16647 int idx_protocol = 2;
37a87b8f 16648 char base_xpath[XPATH_MAXLEN];
d62a17ae 16649
37a87b8f
CS
16650 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16651 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16652 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16653 argv[idx_protocol]->text, "0");
16654
16655 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
16656
16657 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 16658}
16659
16660ALIAS_HIDDEN(
16661 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
16662 "no redistribute " FRR_IP_REDIST_STR_BGPD
e27957c0 16663 " [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 16664 NO_STR
16665 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16666 "Metric for redistributed routes\n"
16667 "Default metric\n"
16668 "Route map reference\n"
16669 "Pointer to route-map entries\n")
596c17ba 16670
37a87b8f
CS
16671DEFUN_YANG (bgp_redistribute_ipv6,
16672 bgp_redistribute_ipv6_cmd,
16673 "redistribute " FRR_IP6_REDIST_STR_BGPD,
16674 "Redistribute information from another routing protocol\n"
16675 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 16676{
d62a17ae 16677 int idx_protocol = 1;
37a87b8f 16678 char base_xpath[XPATH_MAXLEN];
718e3744 16679
37a87b8f
CS
16680 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16681 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16682 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16683 argv[idx_protocol]->text, "0");
16684
16685 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
718e3744 16686
37a87b8f 16687 return nb_cli_apply_changes(vty, base_xpath);
718e3744 16688}
16689
37a87b8f
CS
16690DEFUN_YANG (bgp_redistribute_ipv6_rmap,
16691 bgp_redistribute_ipv6_rmap_cmd,
16692 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
16693 "Redistribute information from another routing protocol\n"
16694 FRR_IP6_REDIST_HELP_STR_BGPD
16695 "Route map reference\n"
16696 "Pointer to route-map entries\n")
718e3744 16697{
d62a17ae 16698 int idx_protocol = 1;
16699 int idx_word = 3;
37a87b8f
CS
16700 char base_xpath[XPATH_MAXLEN];
16701
16702 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16703 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16704 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16705 argv[idx_protocol]->text, "0");
718e3744 16706
37a87b8f
CS
16707 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16708 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16709 argv[idx_word]->arg);
16710
16711 return nb_cli_apply_changes(vty, base_xpath);
718e3744 16712}
16713
37a87b8f 16714DEFUN_YANG (bgp_redistribute_ipv6_metric,
718e3744 16715 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 16716 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 16717 "Redistribute information from another routing protocol\n"
ab0181ee 16718 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 16719 "Metric for redistributed routes\n"
16720 "Default metric\n")
16721{
d62a17ae 16722 int idx_protocol = 1;
16723 int idx_number = 3;
37a87b8f
CS
16724 char base_xpath[XPATH_MAXLEN];
16725
16726 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16727 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16728 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16729 argv[idx_protocol]->text, "0");
718e3744 16730
37a87b8f
CS
16731 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16732 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16733 argv[idx_number]->arg);
16734
16735 return nb_cli_apply_changes(vty, base_xpath);
718e3744 16736}
16737
37a87b8f
CS
16738DEFUN_YANG(
16739 bgp_redistribute_ipv6_rmap_metric,
16740 bgp_redistribute_ipv6_rmap_metric_cmd,
16741 "redistribute " FRR_IP6_REDIST_STR_BGPD
16742 " route-map WORD metric (0-4294967295)",
16743 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
16744 "Route map reference\n"
16745 "Pointer to route-map entries\n"
16746 "Metric for redistributed routes\n"
16747 "Default metric\n")
718e3744 16748{
d62a17ae 16749 int idx_protocol = 1;
16750 int idx_word = 3;
16751 int idx_number = 5;
37a87b8f
CS
16752 char base_xpath[XPATH_MAXLEN];
16753
16754 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16755 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16756 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16757 argv[idx_protocol]->text, "0");
718e3744 16758
37a87b8f
CS
16759 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16760 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16761 argv[idx_word]->arg);
16762 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16763 argv[idx_number]->arg);
16764
16765 return nb_cli_apply_changes(vty, base_xpath);
718e3744 16766}
16767
37a87b8f
CS
16768DEFUN_YANG(
16769 bgp_redistribute_ipv6_metric_rmap,
16770 bgp_redistribute_ipv6_metric_rmap_cmd,
16771 "redistribute " FRR_IP6_REDIST_STR_BGPD
16772 " metric (0-4294967295) route-map WORD",
16773 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
16774 "Metric for redistributed routes\n"
16775 "Default metric\n"
16776 "Route map reference\n"
16777 "Pointer to route-map entries\n")
718e3744 16778{
d62a17ae 16779 int idx_protocol = 1;
d62a17ae 16780 int idx_word = 5;
37a87b8f
CS
16781 int idx_number = 3;
16782 char base_xpath[XPATH_MAXLEN];
16783
16784 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16785 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16786 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16787 argv[idx_protocol]->text, "0");
718e3744 16788
37a87b8f
CS
16789 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16790 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16791 argv[idx_number]->arg);
16792 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16793 argv[idx_word]->arg);
16794
16795 return nb_cli_apply_changes(vty, base_xpath);
718e3744 16796}
16797
37a87b8f
CS
16798DEFUN_YANG(
16799 no_bgp_redistribute_ipv6,
16800 no_bgp_redistribute_ipv6_cmd,
16801 "no redistribute " FRR_IP6_REDIST_STR_BGPD
16802 " [{metric (0-4294967295)|route-map WORD}]",
16803 NO_STR
16804 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
16805 "Metric for redistributed routes\n"
16806 "Default metric\n"
16807 "Route map reference\n"
16808 "Pointer to route-map entries\n")
718e3744 16809{
d62a17ae 16810 int idx_protocol = 2;
37a87b8f 16811 char base_xpath[XPATH_MAXLEN];
718e3744 16812
37a87b8f
CS
16813 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16814 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16815 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16816 argv[idx_protocol]->text, "0");
16817
16818 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
16819
16820 return nb_cli_apply_changes(vty, base_xpath);
16821}
718e3744 16822
37a87b8f
CS
16823void cli_show_bgp_global_afi_safi_ip_unicast_redistribution_list(
16824 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
16825{
16826 uint32_t instance = 0;
16827
16828 vty_out(vty, " redistribute %s",
16829 yang_dnode_get_string(dnode, "./route-type"));
16830 if ((instance = yang_dnode_get_uint16(dnode, "./route-instance")))
16831 vty_out(vty, " %d", instance);
16832 if (yang_dnode_exists(dnode, "./metric"))
16833 vty_out(vty, " metric %u",
16834 yang_dnode_get_uint32(dnode, "./metric"));
16835 if (yang_dnode_exists(dnode, "./rmap-policy-import"))
16836 vty_out(vty, " route-map %s",
16837 yang_dnode_get_string(dnode, "./rmap-policy-import"));
16838 vty_out(vty, "\n");
d62a17ae 16839}
16840
4ab46701
AR
16841/* Neighbor update tcp-mss. */
16842static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
16843 const char *tcp_mss_str)
16844{
16845 struct peer *peer;
16846 uint32_t tcp_mss_val = 0;
16847
16848 peer = peer_and_group_lookup_vty(vty, peer_str);
16849 if (!peer)
16850 return CMD_WARNING_CONFIG_FAILED;
16851
16852 if (tcp_mss_str) {
16853 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
16854 peer_tcp_mss_set(peer, tcp_mss_val);
16855 } else {
16856 peer_tcp_mss_unset(peer);
16857 }
16858
16859 return CMD_SUCCESS;
16860}
16861
16862DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
16863 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
16864 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16865 "TCP max segment size\n"
16866 "TCP MSS value\n")
16867{
16868 int peer_index = 1;
16869 int mss_index = 3;
16870
16871 vty_out(vty,
16872 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16873 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
16874 argv[mss_index]->arg);
16875}
16876
16877DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
16878 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
16879 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16880 "TCP max segment size\n"
16881 "TCP MSS value\n")
16882{
16883 int peer_index = 2;
16884
16885 vty_out(vty,
16886 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16887 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
16888}
16889
dd65f45e
DL
16890static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16891 afi_t afi, safi_t safi)
d62a17ae 16892{
16893 int i;
16894
16895 /* Unicast redistribution only. */
16896 if (safi != SAFI_UNICAST)
2b791107 16897 return;
d62a17ae 16898
16899 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16900 /* Redistribute BGP does not make sense. */
16901 if (i != ZEBRA_ROUTE_BGP) {
16902 struct list *red_list;
16903 struct listnode *node;
16904 struct bgp_redist *red;
16905
16906 red_list = bgp->redist[afi][i];
16907 if (!red_list)
16908 continue;
16909
16910 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 16911 /* "redistribute" configuration. */
16912 vty_out(vty, " redistribute %s",
16913 zebra_route_string(i));
16914 if (red->instance)
16915 vty_out(vty, " %d", red->instance);
16916 if (red->redist_metric_flag)
16917 vty_out(vty, " metric %u",
16918 red->redist_metric);
16919 if (red->rmap.name)
16920 vty_out(vty, " route-map %s",
16921 red->rmap.name);
16922 vty_out(vty, "\n");
16923 }
16924 }
16925 }
718e3744 16926}
6b0655a2 16927
dd65f45e
DL
16928/* peer-group helpers for config-write */
16929
16930static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
16931{
16932 if (!peer_group_active(peer)) {
16933 if (CHECK_FLAG(peer->flags_invert, flag))
16934 return !CHECK_FLAG(peer->flags, flag);
16935 else
16936 return !!CHECK_FLAG(peer->flags, flag);
16937 }
16938
16939 return !!CHECK_FLAG(peer->flags_override, flag);
16940}
16941
16942static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16943 uint32_t flag)
16944{
16945 if (!peer_group_active(peer)) {
16946 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16947 return !peer_af_flag_check(peer, afi, safi, flag);
16948 else
16949 return !!peer_af_flag_check(peer, afi, safi, flag);
16950 }
16951
16952 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16953}
16954
16955static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16956 uint8_t type, int direct)
16957{
16958 struct bgp_filter *filter;
16959
16960 if (peer_group_active(peer))
16961 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16962 type);
16963
16964 filter = &peer->filter[afi][safi];
16965 switch (type) {
16966 case PEER_FT_DISTRIBUTE_LIST:
16967 return !!(filter->dlist[direct].name);
16968 case PEER_FT_FILTER_LIST:
16969 return !!(filter->aslist[direct].name);
16970 case PEER_FT_PREFIX_LIST:
16971 return !!(filter->plist[direct].name);
16972 case PEER_FT_ROUTE_MAP:
16973 return !!(filter->map[direct].name);
16974 case PEER_FT_UNSUPPRESS_MAP:
16975 return !!(filter->usmap.name);
7f7940e6
MK
16976 case PEER_FT_ADVERTISE_MAP:
16977 return !!(filter->advmap.aname
16978 && ((filter->advmap.condition == direct)
16979 && filter->advmap.cname));
dd65f45e
DL
16980 default:
16981 return false;
16982 }
16983}
16984
16985/* Return true if the addpath type is set for peer and different from
16986 * peer-group.
16987 */
3dc339cd
DA
16988static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16989 safi_t safi)
dd65f45e
DL
16990{
16991 enum bgp_addpath_strat type, g_type;
16992
16993 type = peer->addpath_type[afi][safi];
16994
16995 if (type != BGP_ADDPATH_NONE) {
16996 if (peer_group_active(peer)) {
16997 g_type = peer->group->conf->addpath_type[afi][safi];
16998
16999 if (type != g_type)
3dc339cd 17000 return true;
dd65f45e 17001 else
3dc339cd 17002 return false;
dd65f45e
DL
17003 }
17004
3dc339cd 17005 return true;
dd65f45e
DL
17006 }
17007
3dc339cd 17008 return false;
dd65f45e
DL
17009}
17010
b9c7bc5a 17011/* This is part of the address-family block (unicast only) */
dd65f45e 17012static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
17013 afi_t afi)
17014{
b9c7bc5a 17015 int indent = 2;
ddb5b488 17016
8a066a70 17017 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
ae6a6fb4
DS
17018 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
17019 BGP_CONFIG_VRF_TO_VRF_IMPORT))
8a066a70
PG
17020 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
17021 bgp->vpn_policy[afi]
bb4f6190 17022 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
17023 else
17024 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
17025 bgp->vpn_policy[afi]
17026 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
17027 }
12a844a5
DS
17028 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
17029 BGP_CONFIG_VRF_TO_VRF_IMPORT)
17030 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
17031 BGP_CONFIG_VRF_TO_VRF_EXPORT))
17032 return;
17033
e70e9f8e
PZ
17034 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17035 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
17036
17037 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
17038
17039 } else {
17040 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
17041 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
17042 bgp->vpn_policy[afi].tovpn_label);
17043 }
ddb5b488
PZ
17044 }
17045 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17046 BGP_VPN_POLICY_TOVPN_RD_SET)) {
17047 char buf[RD_ADDRSTRLEN];
b9c7bc5a 17048 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
17049 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
17050 sizeof(buf)));
17051 }
17052 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17053 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
17054
17055 char buf[PREFIX_STRLEN];
17056 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
17057 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
17058 sizeof(buf))) {
17059
b9c7bc5a
PZ
17060 vty_out(vty, "%*snexthop vpn export %s\n",
17061 indent, "", buf);
ddb5b488
PZ
17062 }
17063 }
17064 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
17065 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
17066 && ecommunity_cmp(
17067 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
17068 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
17069
17070 char *b = ecommunity_ecom2str(
17071 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
17072 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 17073 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
17074 XFREE(MTYPE_ECOMMUNITY_STR, b);
17075 } else {
17076 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
17077 char *b = ecommunity_ecom2str(
17078 bgp->vpn_policy[afi]
17079 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
17080 ECOMMUNITY_FORMAT_ROUTE_MAP,
17081 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 17082 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
17083 XFREE(MTYPE_ECOMMUNITY_STR, b);
17084 }
17085 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
17086 char *b = ecommunity_ecom2str(
17087 bgp->vpn_policy[afi]
17088 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
17089 ECOMMUNITY_FORMAT_ROUTE_MAP,
17090 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 17091 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
17092 XFREE(MTYPE_ECOMMUNITY_STR, b);
17093 }
17094 }
bb4f6190
DS
17095
17096 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 17097 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
17098 bgp->vpn_policy[afi]
17099 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 17100
301ad80a
PG
17101 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
17102 char *b = ecommunity_ecom2str(
17103 bgp->vpn_policy[afi]
17104 .import_redirect_rtlist,
17105 ECOMMUNITY_FORMAT_ROUTE_MAP,
17106 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 17107
9a659715
PG
17108 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
17109 != ECOMMUNITY_SIZE)
c6423c31 17110 vty_out(vty, "%*srt6 redirect import %s\n",
9a659715
PG
17111 indent, "", b);
17112 else
17113 vty_out(vty, "%*srt redirect import %s\n",
17114 indent, "", b);
301ad80a
PG
17115 XFREE(MTYPE_ECOMMUNITY_STR, b);
17116 }
ddb5b488
PZ
17117}
17118
dd65f45e
DL
17119static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
17120 afi_t afi, safi_t safi)
17121{
17122 struct bgp_filter *filter;
17123 char *addr;
17124
17125 addr = peer->host;
17126 filter = &peer->filter[afi][safi];
17127
17128 /* distribute-list. */
17129 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
17130 FILTER_IN))
17131 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
17132 filter->dlist[FILTER_IN].name);
17133
17134 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
17135 FILTER_OUT))
17136 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
17137 filter->dlist[FILTER_OUT].name);
17138
17139 /* prefix-list. */
17140 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
17141 FILTER_IN))
17142 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
17143 filter->plist[FILTER_IN].name);
17144
17145 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
17146 FILTER_OUT))
17147 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
17148 filter->plist[FILTER_OUT].name);
17149
17150 /* route-map. */
17151 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
17152 vty_out(vty, " neighbor %s route-map %s in\n", addr,
17153 filter->map[RMAP_IN].name);
17154
17155 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
17156 RMAP_OUT))
17157 vty_out(vty, " neighbor %s route-map %s out\n", addr,
17158 filter->map[RMAP_OUT].name);
17159
17160 /* unsuppress-map */
17161 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
17162 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
17163 filter->usmap.name);
17164
7f7940e6
MK
17165 /* advertise-map : always applied in OUT direction*/
17166 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
17167 CONDITION_NON_EXIST))
17168 vty_out(vty,
17169 " neighbor %s advertise-map %s non-exist-map %s\n",
17170 addr, filter->advmap.aname, filter->advmap.cname);
17171
17172 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
17173 CONDITION_EXIST))
17174 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
17175 addr, filter->advmap.aname, filter->advmap.cname);
17176
dd65f45e
DL
17177 /* filter-list. */
17178 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
17179 FILTER_IN))
17180 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
17181 filter->aslist[FILTER_IN].name);
17182
17183 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
17184 FILTER_OUT))
17185 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
17186 filter->aslist[FILTER_OUT].name);
17187}
17188
17189/* BGP peer configuration display function. */
17190static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
17191 struct peer *peer)
17192{
17193 struct peer *g_peer = NULL;
17194 char buf[SU_ADDRSTRLEN];
17195 char *addr;
17196 int if_pg_printed = false;
17197 int if_ras_printed = false;
17198
17199 /* Skip dynamic neighbors. */
17200 if (peer_dynamic_neighbor(peer))
17201 return;
17202
17203 if (peer->conf_if)
17204 addr = peer->conf_if;
17205 else
17206 addr = peer->host;
17207
17208 /************************************
17209 ****** Global to the neighbor ******
17210 ************************************/
17211 if (peer->conf_if) {
17212 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
17213 vty_out(vty, " neighbor %s interface v6only", addr);
17214 else
17215 vty_out(vty, " neighbor %s interface", addr);
17216
17217 if (peer_group_active(peer)) {
17218 vty_out(vty, " peer-group %s", peer->group->name);
17219 if_pg_printed = true;
17220 } else if (peer->as_type == AS_SPECIFIED) {
17221 vty_out(vty, " remote-as %u", peer->as);
17222 if_ras_printed = true;
17223 } else if (peer->as_type == AS_INTERNAL) {
17224 vty_out(vty, " remote-as internal");
17225 if_ras_printed = true;
17226 } else if (peer->as_type == AS_EXTERNAL) {
17227 vty_out(vty, " remote-as external");
17228 if_ras_printed = true;
17229 }
17230
17231 vty_out(vty, "\n");
17232 }
17233
17234 /* remote-as and peer-group */
17235 /* peer is a member of a peer-group */
17236 if (peer_group_active(peer)) {
17237 g_peer = peer->group->conf;
17238
17239 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
17240 if (peer->as_type == AS_SPECIFIED) {
17241 vty_out(vty, " neighbor %s remote-as %u\n",
17242 addr, peer->as);
17243 } else if (peer->as_type == AS_INTERNAL) {
17244 vty_out(vty,
17245 " neighbor %s remote-as internal\n",
17246 addr);
17247 } else if (peer->as_type == AS_EXTERNAL) {
17248 vty_out(vty,
17249 " neighbor %s remote-as external\n",
17250 addr);
17251 }
17252 }
17253
17254 /* For swpX peers we displayed the peer-group
17255 * via 'neighbor swpX interface peer-group PGNAME' */
17256 if (!if_pg_printed)
17257 vty_out(vty, " neighbor %s peer-group %s\n", addr,
17258 peer->group->name);
17259 }
17260
17261 /* peer is NOT a member of a peer-group */
17262 else {
17263 /* peer is a peer-group, declare the peer-group */
17264 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
17265 vty_out(vty, " neighbor %s peer-group\n", addr);
17266 }
17267
17268 if (!if_ras_printed) {
17269 if (peer->as_type == AS_SPECIFIED) {
17270 vty_out(vty, " neighbor %s remote-as %u\n",
17271 addr, peer->as);
17272 } else if (peer->as_type == AS_INTERNAL) {
17273 vty_out(vty,
17274 " neighbor %s remote-as internal\n",
17275 addr);
17276 } else if (peer->as_type == AS_EXTERNAL) {
17277 vty_out(vty,
17278 " neighbor %s remote-as external\n",
17279 addr);
17280 }
17281 }
17282 }
17283
17284 /* local-as */
17285 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
17286 vty_out(vty, " neighbor %s local-as %u", addr,
17287 peer->change_local_as);
17288 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
17289 vty_out(vty, " no-prepend");
17290 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
17291 vty_out(vty, " replace-as");
17292 vty_out(vty, "\n");
17293 }
17294
17295 /* description */
17296 if (peer->desc) {
17297 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
17298 }
17299
17300 /* shutdown */
17301 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
17302 if (peer->tx_shutdown_message)
17303 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
17304 peer->tx_shutdown_message);
17305 else
17306 vty_out(vty, " neighbor %s shutdown\n", addr);
17307 }
17308
8336c896
DA
17309 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
17310 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
17311 peer->rtt_expected, peer->rtt_keepalive_conf);
17312
dd65f45e 17313 /* bfd */
21bfce98
RZ
17314 if (peer->bfd_config)
17315 bgp_bfd_peer_config_write(vty, peer, addr);
dd65f45e
DL
17316
17317 /* password */
17318 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
17319 vty_out(vty, " neighbor %s password %s\n", addr,
17320 peer->password);
17321
17322 /* neighbor solo */
17323 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
17324 if (!peer_group_active(peer)) {
17325 vty_out(vty, " neighbor %s solo\n", addr);
17326 }
17327 }
17328
17329 /* BGP port */
17330 if (peer->port != BGP_PORT_DEFAULT) {
17331 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
17332 }
17333
17334 /* Local interface name */
17335 if (peer->ifname) {
17336 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
17337 }
17338
4ab46701
AR
17339 /* TCP max segment size */
17340 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
17341 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
17342
dd65f45e
DL
17343 /* passive */
17344 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
17345 vty_out(vty, " neighbor %s passive\n", addr);
17346
17347 /* ebgp-multihop */
17348 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
e2521429
DA
17349 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
17350 && peer->ttl == MAXTTL)) {
dd65f45e
DL
17351 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
17352 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
17353 peer->ttl);
17354 }
17355 }
17356
17357 /* ttl-security hops */
e2521429 17358 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
dd65f45e
DL
17359 if (!peer_group_active(peer)
17360 || g_peer->gtsm_hops != peer->gtsm_hops) {
17361 vty_out(vty, " neighbor %s ttl-security hops %d\n",
17362 addr, peer->gtsm_hops);
17363 }
17364 }
17365
17366 /* disable-connected-check */
17367 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
17368 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
17369
17370 /* enforce-first-as */
17371 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
17372 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
17373
17374 /* update-source */
17375 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
17376 if (peer->update_source)
17377 vty_out(vty, " neighbor %s update-source %s\n", addr,
17378 sockunion2str(peer->update_source, buf,
17379 SU_ADDRSTRLEN));
17380 else if (peer->update_if)
17381 vty_out(vty, " neighbor %s update-source %s\n", addr,
17382 peer->update_if);
17383 }
17384
17385 /* advertisement-interval */
17386 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
17387 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
17388 peer->routeadv);
17389
17390 /* timers */
17391 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
17392 vty_out(vty, " neighbor %s timers %u %u\n", addr,
17393 peer->keepalive, peer->holdtime);
17394
17395 /* timers connect */
17396 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
17397 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17398 peer->connect);
5d5393b9
DL
17399 /* need special-case handling for changed default values due to
17400 * config profile / version (because there is no "timers bgp connect"
17401 * command, we need to save this per-peer :/)
17402 */
17403 else if (!peer_group_active(peer) && !peer->connect &&
17404 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
17405 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17406 peer->bgp->default_connect_retry);
dd65f45e 17407
d43114f3
DS
17408 /* timers delayopen */
17409 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
17410 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17411 peer->delayopen);
17412 /* Save config even though flag is not set if default values have been
17413 * changed
17414 */
17415 else if (!peer_group_active(peer) && !peer->delayopen
17416 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
17417 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17418 peer->bgp->default_delayopen);
17419
dd65f45e
DL
17420 /* capability dynamic */
17421 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
17422 vty_out(vty, " neighbor %s capability dynamic\n", addr);
17423
17424 /* capability extended-nexthop */
17425 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
17426 if (!peer->conf_if) {
17427 if (CHECK_FLAG(peer->flags_invert,
17428 PEER_FLAG_CAPABILITY_ENHE))
17429 vty_out(vty,
17430 " no neighbor %s capability extended-nexthop\n",
17431 addr);
17432 else
17433 vty_out(vty,
17434 " neighbor %s capability extended-nexthop\n",
17435 addr);
17436 }
17437 }
17438
17439 /* dont-capability-negotiation */
17440 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
17441 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
17442
17443 /* override-capability */
17444 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
17445 vty_out(vty, " neighbor %s override-capability\n", addr);
17446
17447 /* strict-capability-match */
17448 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
17449 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
17450
17451 /* Sender side AS path loop detection. */
17452 if (peer->as_path_loop_detection)
17453 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
17454 addr);
cfd47646 17455
17456 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 17457 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
cfd47646 17458
17459 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 17460 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
cfd47646 17461 vty_out(vty,
17462 " neighbor %s graceful-restart-helper\n", addr);
13909c4f
DS
17463 } else if (CHECK_FLAG(
17464 peer->peer_gr_new_status_flag,
17465 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
cfd47646 17466 vty_out(vty,
17467 " neighbor %s graceful-restart\n", addr);
13909c4f
DS
17468 } else if (
17469 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
17470 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
17471 && !(CHECK_FLAG(
17472 peer->peer_gr_new_status_flag,
17473 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
17474 vty_out(vty, " neighbor %s graceful-restart-disable\n",
17475 addr);
cfd47646 17476 }
17477 }
dd65f45e
DL
17478}
17479
17480/* BGP peer configuration display function. */
17481static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
17482 struct peer *peer, afi_t afi, safi_t safi)
17483{
17484 struct peer *g_peer = NULL;
17485 char *addr;
17486 bool flag_scomm, flag_secomm, flag_slcomm;
17487
17488 /* Skip dynamic neighbors. */
17489 if (peer_dynamic_neighbor(peer))
17490 return;
17491
17492 if (peer->conf_if)
17493 addr = peer->conf_if;
17494 else
17495 addr = peer->host;
17496
17497 /************************************
17498 ****** Per AF to the neighbor ******
17499 ************************************/
17500 if (peer_group_active(peer)) {
17501 g_peer = peer->group->conf;
17502
17503 /* If the peer-group is active but peer is not, print a 'no
17504 * activate' */
17505 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
17506 vty_out(vty, " no neighbor %s activate\n", addr);
17507 }
17508
17509 /* If the peer-group is not active but peer is, print an
17510 'activate' */
17511 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
17512 vty_out(vty, " neighbor %s activate\n", addr);
17513 }
17514 } else {
17515 if (peer->afc[afi][safi]) {
38d11af5
TA
17516 if (safi == SAFI_ENCAP)
17517 vty_out(vty, " neighbor %s activate\n", addr);
17518 else if (!bgp->default_af[afi][safi])
dd65f45e
DL
17519 vty_out(vty, " neighbor %s activate\n", addr);
17520 } else {
38d11af5
TA
17521 if (bgp->default_af[afi][safi])
17522 vty_out(vty, " no neighbor %s activate\n",
17523 addr);
dd65f45e
DL
17524 }
17525 }
17526
17527 /* addpath TX knobs */
17528 if (peergroup_af_addpath_check(peer, afi, safi)) {
17529 switch (peer->addpath_type[afi][safi]) {
17530 case BGP_ADDPATH_ALL:
17531 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
17532 addr);
17533 break;
17534 case BGP_ADDPATH_BEST_PER_AS:
17535 vty_out(vty,
17536 " neighbor %s addpath-tx-bestpath-per-AS\n",
17537 addr);
17538 break;
17539 case BGP_ADDPATH_MAX:
17540 case BGP_ADDPATH_NONE:
17541 break;
17542 }
17543 }
17544
17545 /* ORF capability. */
17546 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
17547 || peergroup_af_flag_check(peer, afi, safi,
17548 PEER_FLAG_ORF_PREFIX_RM)) {
17549 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
17550
17551 if (peergroup_af_flag_check(peer, afi, safi,
17552 PEER_FLAG_ORF_PREFIX_SM)
17553 && peergroup_af_flag_check(peer, afi, safi,
17554 PEER_FLAG_ORF_PREFIX_RM))
17555 vty_out(vty, " both");
17556 else if (peergroup_af_flag_check(peer, afi, safi,
17557 PEER_FLAG_ORF_PREFIX_SM))
17558 vty_out(vty, " send");
17559 else
17560 vty_out(vty, " receive");
17561 vty_out(vty, "\n");
17562 }
17563
dd65f45e
DL
17564 /* Route reflector client. */
17565 if (peergroup_af_flag_check(peer, afi, safi,
17566 PEER_FLAG_REFLECTOR_CLIENT)) {
17567 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
17568 }
17569
17570 /* next-hop-self force */
17571 if (peergroup_af_flag_check(peer, afi, safi,
17572 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
17573 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
17574 }
17575
17576 /* next-hop-self */
17577 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
17578 vty_out(vty, " neighbor %s next-hop-self\n", addr);
17579 }
17580
17581 /* remove-private-AS */
17582 if (peergroup_af_flag_check(peer, afi, safi,
17583 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
17584 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
17585 addr);
17586 }
17587
17588 else if (peergroup_af_flag_check(peer, afi, safi,
17589 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
17590 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
17591 addr);
17592 }
17593
17594 else if (peergroup_af_flag_check(peer, afi, safi,
17595 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
17596 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
17597 }
17598
17599 else if (peergroup_af_flag_check(peer, afi, safi,
17600 PEER_FLAG_REMOVE_PRIVATE_AS)) {
17601 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
17602 }
17603
17604 /* as-override */
17605 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
17606 vty_out(vty, " neighbor %s as-override\n", addr);
17607 }
17608
17609 /* send-community print. */
17610 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
17611 PEER_FLAG_SEND_COMMUNITY);
17612 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
17613 PEER_FLAG_SEND_EXT_COMMUNITY);
17614 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
17615 PEER_FLAG_SEND_LARGE_COMMUNITY);
17616
17617 if (flag_scomm && flag_secomm && flag_slcomm) {
17618 vty_out(vty, " no neighbor %s send-community all\n", addr);
17619 } else {
17620 if (flag_scomm)
17621 vty_out(vty, " no neighbor %s send-community\n", addr);
17622 if (flag_secomm)
17623 vty_out(vty,
17624 " no neighbor %s send-community extended\n",
17625 addr);
17626
17627 if (flag_slcomm)
17628 vty_out(vty, " no neighbor %s send-community large\n",
17629 addr);
17630 }
17631
17632 /* Default information */
17633 if (peergroup_af_flag_check(peer, afi, safi,
17634 PEER_FLAG_DEFAULT_ORIGINATE)) {
17635 vty_out(vty, " neighbor %s default-originate", addr);
17636
17637 if (peer->default_rmap[afi][safi].name)
17638 vty_out(vty, " route-map %s",
17639 peer->default_rmap[afi][safi].name);
17640
17641 vty_out(vty, "\n");
17642 }
17643
17644 /* Soft reconfiguration inbound. */
17645 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
17646 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
17647 addr);
17648 }
17649
17650 /* maximum-prefix. */
17651 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
6cde4b45 17652 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
dd65f45e
DL
17653 peer->pmax[afi][safi]);
17654
17655 if (peer->pmax_threshold[afi][safi]
17656 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
17657 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
17658 if (peer_af_flag_check(peer, afi, safi,
17659 PEER_FLAG_MAX_PREFIX_WARNING))
17660 vty_out(vty, " warning-only");
17661 if (peer->pmax_restart[afi][safi])
17662 vty_out(vty, " restart %u",
17663 peer->pmax_restart[afi][safi]);
9cbd06e0
DA
17664 if (peer_af_flag_check(peer, afi, safi,
17665 PEER_FLAG_MAX_PREFIX_FORCE))
17666 vty_out(vty, " force");
dd65f45e
DL
17667
17668 vty_out(vty, "\n");
17669 }
17670
fde246e8
DA
17671 /* maximum-prefix-out */
17672 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
6cde4b45 17673 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
fde246e8
DA
17674 addr, peer->pmax_out[afi][safi]);
17675
dd65f45e
DL
17676 /* Route server client. */
17677 if (peergroup_af_flag_check(peer, afi, safi,
17678 PEER_FLAG_RSERVER_CLIENT)) {
17679 vty_out(vty, " neighbor %s route-server-client\n", addr);
17680 }
17681
17682 /* Nexthop-local unchanged. */
17683 if (peergroup_af_flag_check(peer, afi, safi,
17684 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
17685 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
17686 }
17687
17688 /* allowas-in <1-10> */
17689 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
17690 if (peer_af_flag_check(peer, afi, safi,
17691 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
17692 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
17693 } else if (peer->allowas_in[afi][safi] == 3) {
17694 vty_out(vty, " neighbor %s allowas-in\n", addr);
17695 } else {
17696 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
17697 peer->allowas_in[afi][safi]);
17698 }
17699 }
17700
17701 /* weight */
17702 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
17703 vty_out(vty, " neighbor %s weight %lu\n", addr,
17704 peer->weight[afi][safi]);
17705
17706 /* Filter. */
17707 bgp_config_write_filter(vty, peer, afi, safi);
17708
17709 /* atribute-unchanged. */
17710 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
17711 || (safi != SAFI_EVPN
17712 && peer_af_flag_check(peer, afi, safi,
17713 PEER_FLAG_NEXTHOP_UNCHANGED))
17714 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
17715
17716 if (!peer_group_active(peer)
17717 || peergroup_af_flag_check(peer, afi, safi,
17718 PEER_FLAG_AS_PATH_UNCHANGED)
17719 || peergroup_af_flag_check(peer, afi, safi,
17720 PEER_FLAG_NEXTHOP_UNCHANGED)
17721 || peergroup_af_flag_check(peer, afi, safi,
17722 PEER_FLAG_MED_UNCHANGED)) {
17723
17724 vty_out(vty,
17725 " neighbor %s attribute-unchanged%s%s%s\n",
17726 addr,
17727 peer_af_flag_check(peer, afi, safi,
17728 PEER_FLAG_AS_PATH_UNCHANGED)
17729 ? " as-path"
17730 : "",
17731 peer_af_flag_check(peer, afi, safi,
17732 PEER_FLAG_NEXTHOP_UNCHANGED)
17733 ? " next-hop"
17734 : "",
17735 peer_af_flag_check(peer, afi, safi,
17736 PEER_FLAG_MED_UNCHANGED)
17737 ? " med"
17738 : "");
17739 }
17740 }
39d8dd2d
DS
17741
17742 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_CONFIG_DAMPENING))
17743 bgp_config_write_peer_damp(vty, peer, afi, safi);
dd65f45e
DL
17744}
17745
17746/* Address family based peer configuration display. */
17747static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
17748 safi_t safi)
17749{
17750 struct peer *peer;
17751 struct peer_group *group;
17752 struct listnode *node, *nnode;
17753
17754
17755 vty_frame(vty, " !\n address-family ");
17756 if (afi == AFI_IP) {
17757 if (safi == SAFI_UNICAST)
17758 vty_frame(vty, "ipv4 unicast");
17759 else if (safi == SAFI_LABELED_UNICAST)
17760 vty_frame(vty, "ipv4 labeled-unicast");
17761 else if (safi == SAFI_MULTICAST)
17762 vty_frame(vty, "ipv4 multicast");
17763 else if (safi == SAFI_MPLS_VPN)
17764 vty_frame(vty, "ipv4 vpn");
17765 else if (safi == SAFI_ENCAP)
17766 vty_frame(vty, "ipv4 encap");
17767 else if (safi == SAFI_FLOWSPEC)
17768 vty_frame(vty, "ipv4 flowspec");
17769 } else if (afi == AFI_IP6) {
17770 if (safi == SAFI_UNICAST)
17771 vty_frame(vty, "ipv6 unicast");
17772 else if (safi == SAFI_LABELED_UNICAST)
17773 vty_frame(vty, "ipv6 labeled-unicast");
17774 else if (safi == SAFI_MULTICAST)
17775 vty_frame(vty, "ipv6 multicast");
17776 else if (safi == SAFI_MPLS_VPN)
17777 vty_frame(vty, "ipv6 vpn");
17778 else if (safi == SAFI_ENCAP)
17779 vty_frame(vty, "ipv6 encap");
17780 else if (safi == SAFI_FLOWSPEC)
17781 vty_frame(vty, "ipv6 flowspec");
17782 } else if (afi == AFI_L2VPN) {
17783 if (safi == SAFI_EVPN)
17784 vty_frame(vty, "l2vpn evpn");
17785 }
17786 vty_frame(vty, "\n");
17787
17788 bgp_config_write_distance(vty, bgp, afi, safi);
17789
17790 bgp_config_write_network(vty, bgp, afi, safi);
17791
17792 bgp_config_write_redistribute(vty, bgp, afi, safi);
17793
8a4e7fe6
DA
17794 /* BGP flag dampening. */
17795 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
0221327c 17796 bgp_config_write_damp(vty, bgp, afi, safi);
8a4e7fe6 17797
dd65f45e
DL
17798 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
17799 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
17800
17801 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dd65f45e
DL
17802 /* Do not display doppelganger peers */
17803 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17804 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
17805 }
17806
17807 bgp_config_write_maxpaths(vty, bgp, afi, safi);
17808 bgp_config_write_table_map(vty, bgp, afi, safi);
17809
17810 if (safi == SAFI_EVPN)
17811 bgp_config_write_evpn_info(vty, bgp, afi, safi);
17812
17813 if (safi == SAFI_FLOWSPEC)
17814 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
17815
17816 if (safi == SAFI_UNICAST) {
17817 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
17818 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17819 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
17820
17821 vty_out(vty, " export vpn\n");
17822 }
17823 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17824 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
17825
17826 vty_out(vty, " import vpn\n");
17827 }
17828 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17829 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
17830 char *name;
17831
17832 for (ALL_LIST_ELEMENTS_RO(
17833 bgp->vpn_policy[afi].import_vrf, node,
17834 name))
17835 vty_out(vty, " import vrf %s\n", name);
17836 }
17837 }
17838
17839 vty_endframe(vty, " exit-address-family\n");
17840}
17841
17842int bgp_config_write(struct vty *vty)
17843{
17844 struct bgp *bgp;
17845 struct peer_group *group;
17846 struct peer *peer;
17847 struct listnode *node, *nnode;
17848 struct listnode *mnode, *mnnode;
b16bcbba
TA
17849 afi_t afi;
17850 safi_t safi;
dd65f45e
DL
17851
17852 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
17853 vty_out(vty, "bgp route-map delay-timer %u\n",
17854 bm->rmap_update_timer);
17855
d70583f7
D
17856 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
17857 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17858 if (bm->v_update_delay != bm->v_establish_wait)
17859 vty_out(vty, " %d", bm->v_establish_wait);
17860 vty_out(vty, "\n");
17861 }
17862
9acb67cb
DS
17863 if (bm->wait_for_fib)
17864 vty_out(vty, "bgp suppress-fib-pending\n");
17865
05bd726c 17866 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17867 vty_out(vty, "bgp graceful-shutdown\n");
17868
c163f297
DS
17869 /* No-RIB (Zebra) option flag configuration */
17870 if (bgp_option_check(BGP_OPT_NO_FIB))
17871 vty_out(vty, "bgp no-rib\n");
17872
ec0acb80 17873 if (!CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
e46723a5
DS
17874 vty_out(vty, "no bgp send-extra-data zebra\n");
17875
dd65f45e
DL
17876 /* BGP configuration. */
17877 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17878
17879 /* skip all auto created vrf as they dont have user config */
17880 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17881 continue;
17882
17883 /* Router bgp ASN */
17884 vty_out(vty, "router bgp %u", bgp->as);
17885
17886 if (bgp->name)
17887 vty_out(vty, " %s %s",
17888 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17889 ? "view" : "vrf", bgp->name);
17890 vty_out(vty, "\n");
17891
17892 /* BGP fast-external-failover. */
17893 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17894 vty_out(vty, " no bgp fast-external-failover\n");
17895
17896 /* BGP router ID. */
3a6290bd 17897 if (bgp->router_id_static.s_addr != INADDR_ANY)
23d0a753
DA
17898 vty_out(vty, " bgp router-id %pI4\n",
17899 &bgp->router_id_static);
dd65f45e 17900
c208c586
S
17901 /* Suppress fib pending */
17902 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17903 vty_out(vty, " bgp suppress-fib-pending\n");
17904
dd65f45e 17905 /* BGP log-neighbor-changes. */
892fedb6 17906 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
5d5393b9 17907 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
dd65f45e 17908 vty_out(vty, " %sbgp log-neighbor-changes\n",
892fedb6
DA
17909 CHECK_FLAG(bgp->flags,
17910 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
dd65f45e
DL
17911 ? ""
17912 : "no ");
17913
17914 /* BGP configuration. */
892fedb6 17915 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
dd65f45e
DL
17916 vty_out(vty, " bgp always-compare-med\n");
17917
17918 /* RFC8212 default eBGP policy. */
1d3fdccf
DA
17919 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17920 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17921 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17922 CHECK_FLAG(bgp->flags,
17923 BGP_FLAG_EBGP_REQUIRES_POLICY)
17924 ? ""
17925 : "no ");
dd65f45e
DL
17926
17927 /* draft-ietf-idr-deprecate-as-set-confed-set */
7f972cd8 17928 if (bgp->reject_as_sets)
dd65f45e
DL
17929 vty_out(vty, " bgp reject-as-sets\n");
17930
2adac256
DA
17931 /* Suppress duplicate updates if the route actually not changed
17932 */
17933 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17934 != SAVE_BGP_SUPPRESS_DUPLICATES)
17935 vty_out(vty, " %sbgp suppress-duplicates\n",
17936 CHECK_FLAG(bgp->flags,
17937 BGP_FLAG_SUPPRESS_DUPLICATES)
17938 ? ""
17939 : "no ");
17940
b16bcbba
TA
17941 /* BGP default <afi>-<safi> */
17942 FOREACH_AFI_SAFI (afi, safi) {
17943 if (afi == AFI_IP && safi == SAFI_UNICAST) {
17944 if (!bgp->default_af[afi][safi])
17945 vty_out(vty, " no bgp default %s\n",
17946 get_bgp_default_af_flag(afi,
17947 safi));
17948 } else if (bgp->default_af[afi][safi])
17949 vty_out(vty, " bgp default %s\n",
17950 get_bgp_default_af_flag(afi, safi));
17951 }
e84c59af 17952
dd65f45e
DL
17953 /* BGP default local-preference. */
17954 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17955 vty_out(vty, " bgp default local-preference %u\n",
17956 bgp->default_local_pref);
17957
17958 /* BGP default show-hostname */
892fedb6 17959 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
5d5393b9 17960 != SAVE_BGP_SHOW_HOSTNAME)
dd65f45e 17961 vty_out(vty, " %sbgp default show-hostname\n",
892fedb6 17962 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
dd65f45e
DL
17963 ? ""
17964 : "no ");
17965
aef999a2
DA
17966 /* BGP default show-nexthop-hostname */
17967 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17968 != SAVE_BGP_SHOW_HOSTNAME)
17969 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17970 CHECK_FLAG(bgp->flags,
17971 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17972 ? ""
17973 : "no ");
17974
dd65f45e
DL
17975 /* BGP default subgroup-pkt-queue-max. */
17976 if (bgp->default_subgroup_pkt_queue_max
17977 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
17978 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
17979 bgp->default_subgroup_pkt_queue_max);
17980
17981 /* BGP client-to-client reflection. */
892fedb6 17982 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
dd65f45e
DL
17983 vty_out(vty, " no bgp client-to-client reflection\n");
17984
17985 /* BGP cluster ID. */
17986 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
23d0a753
DA
17987 vty_out(vty, " bgp cluster-id %pI4\n",
17988 &bgp->cluster_id);
dd65f45e
DL
17989
17990 /* Disable ebgp connected nexthop check */
892fedb6 17991 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
dd65f45e
DL
17992 vty_out(vty,
17993 " bgp disable-ebgp-connected-route-check\n");
17994
17995 /* Confederation identifier*/
17996 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
17997 vty_out(vty, " bgp confederation identifier %u\n",
17998 bgp->confed_id);
17999
18000 /* Confederation peer */
18001 if (bgp->confed_peers_cnt > 0) {
18002 int i;
18003
18004 vty_out(vty, " bgp confederation peers");
18005
18006 for (i = 0; i < bgp->confed_peers_cnt; i++)
18007 vty_out(vty, " %u", bgp->confed_peers[i]);
18008
18009 vty_out(vty, "\n");
18010 }
18011
18012 /* BGP deterministic-med. */
892fedb6 18013 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
5d5393b9 18014 != SAVE_BGP_DETERMINISTIC_MED)
dd65f45e 18015 vty_out(vty, " %sbgp deterministic-med\n",
892fedb6
DA
18016 CHECK_FLAG(bgp->flags,
18017 BGP_FLAG_DETERMINISTIC_MED)
dd65f45e
DL
18018 ? ""
18019 : "no ");
18020
18021 /* BGP update-delay. */
18022 bgp_config_write_update_delay(vty, bgp);
18023
18024 if (bgp->v_maxmed_onstartup
18025 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
18026 vty_out(vty, " bgp max-med on-startup %u",
18027 bgp->v_maxmed_onstartup);
18028 if (bgp->maxmed_onstartup_value
18029 != BGP_MAXMED_VALUE_DEFAULT)
18030 vty_out(vty, " %u",
18031 bgp->maxmed_onstartup_value);
18032 vty_out(vty, "\n");
18033 }
18034 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
18035 vty_out(vty, " bgp max-med administrative");
18036 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
18037 vty_out(vty, " %u", bgp->maxmed_admin_value);
18038 vty_out(vty, "\n");
18039 }
18040
18041 /* write quanta */
18042 bgp_config_write_wpkt_quanta(vty, bgp);
18043 /* read quanta */
18044 bgp_config_write_rpkt_quanta(vty, bgp);
18045
18046 /* coalesce time */
18047 bgp_config_write_coalesce_time(vty, bgp);
18048
05bd726c 18049 /* BGP per-instance graceful-shutdown */
18050 /* BGP-wide settings and per-instance settings are mutually
18051 * exclusive.
18052 */
18053 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
18054 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
18055 vty_out(vty, " bgp graceful-shutdown\n");
18056
dd65f45e
DL
18057 /* BGP graceful-restart. */
18058 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
18059 vty_out(vty,
18060 " bgp graceful-restart stalepath-time %u\n",
18061 bgp->stalepath_time);
cfd47646 18062
dd65f45e
DL
18063 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
18064 vty_out(vty, " bgp graceful-restart restart-time %u\n",
18065 bgp->restart_time);
cfd47646 18066
18067 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
18068 vty_out(vty,
18069 " bgp graceful-restart select-defer-time %u\n",
18070 bgp->select_defer_time);
18071
18072 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
dd65f45e
DL
18073 vty_out(vty, " bgp graceful-restart\n");
18074
cfd47646 18075 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
18076 vty_out(vty, " bgp graceful-restart-disable\n");
18077
dd65f45e 18078 /* BGP graceful-restart Preserve State F bit. */
892fedb6 18079 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
dd65f45e
DL
18080 vty_out(vty,
18081 " bgp graceful-restart preserve-fw-state\n");
18082
dc95985f 18083 /* Stale timer for RIB */
18084 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
18085 vty_out(vty,
18086 " bgp graceful-restart rib-stale-time %u\n",
18087 bgp->rib_stale_time);
18088
dd65f45e 18089 /* BGP bestpath method. */
892fedb6 18090 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
dd65f45e 18091 vty_out(vty, " bgp bestpath as-path ignore\n");
892fedb6 18092 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
dd65f45e
DL
18093 vty_out(vty, " bgp bestpath as-path confed\n");
18094
892fedb6
DA
18095 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
18096 if (CHECK_FLAG(bgp->flags,
18097 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
dd65f45e
DL
18098 vty_out(vty,
18099 " bgp bestpath as-path multipath-relax as-set\n");
18100 } else {
18101 vty_out(vty,
18102 " bgp bestpath as-path multipath-relax\n");
18103 }
18104 }
18105
892fedb6 18106 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
dd65f45e
DL
18107 vty_out(vty,
18108 " bgp route-reflector allow-outbound-policy\n");
18109 }
892fedb6 18110 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
dd65f45e 18111 vty_out(vty, " bgp bestpath compare-routerid\n");
892fedb6
DA
18112 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
18113 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
dd65f45e 18114 vty_out(vty, " bgp bestpath med");
892fedb6 18115 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
dd65f45e 18116 vty_out(vty, " confed");
892fedb6
DA
18117 if (CHECK_FLAG(bgp->flags,
18118 BGP_FLAG_MED_MISSING_AS_WORST))
dd65f45e
DL
18119 vty_out(vty, " missing-as-worst");
18120 vty_out(vty, "\n");
18121 }
18122
ee88563a
JM
18123 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
18124 vty_out(vty,
18125 " bgp bestpath peer-type multipath-relax\n");
18126
f7e1c681 18127 /* Link bandwidth handling. */
18128 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
18129 vty_out(vty, " bgp bestpath bandwidth ignore\n");
18130 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
18131 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
18132 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
18133 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
18134
dd65f45e 18135 /* BGP network import check. */
892fedb6 18136 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
5d5393b9 18137 != SAVE_BGP_IMPORT_CHECK)
dd65f45e 18138 vty_out(vty, " %sbgp network import-check\n",
892fedb6 18139 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
dd65f45e
DL
18140 ? ""
18141 : "no ");
18142
18143 /* BGP timers configuration. */
5d5393b9 18144 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
9800cfff 18145 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
dd65f45e
DL
18146 vty_out(vty, " timers bgp %u %u\n",
18147 bgp->default_keepalive, bgp->default_holdtime);
18148
18149 /* peer-group */
18150 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
18151 bgp_config_write_peer_global(vty, bgp, group->conf);
18152 }
18153
18154 /* Normal neighbor configuration. */
18155 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
18156 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
18157 bgp_config_write_peer_global(vty, bgp, peer);
18158 }
18159
18160 /* listen range and limit for dynamic BGP neighbors */
18161 bgp_config_write_listen(vty, bgp);
18162
18163 /*
18164 * BGP default autoshutdown neighbors
18165 *
18166 * This must be placed after any peer and peer-group
18167 * configuration, to avoid setting all peers to shutdown after
18168 * a daemon restart, which is undesired behavior. (see #2286)
18169 */
18170 if (bgp->autoshutdown)
18171 vty_out(vty, " bgp default shutdown\n");
18172
9cf59432
DS
18173 /* BGP instance administrative shutdown */
18174 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
18175 vty_out(vty, " bgp shutdown\n");
18176
a0281b2e
HS
18177 if (bgp->srv6_enabled) {
18178 vty_frame(vty, " !\n segment-routing srv6\n");
96db4340 18179 if (strlen(bgp->srv6_locator_name))
a0281b2e
HS
18180 vty_out(vty, " locator %s\n",
18181 bgp->srv6_locator_name);
18182 }
18183
18184
dd65f45e
DL
18185 /* IPv4 unicast configuration. */
18186 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
18187
18188 /* IPv4 multicast configuration. */
18189 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
18190
18191 /* IPv4 labeled-unicast configuration. */
18192 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
18193
18194 /* IPv4 VPN configuration. */
18195 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
18196
18197 /* ENCAPv4 configuration. */
18198 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
18199
18200 /* FLOWSPEC v4 configuration. */
18201 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
18202
18203 /* IPv6 unicast configuration. */
18204 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
18205
18206 /* IPv6 multicast configuration. */
18207 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
18208
18209 /* IPv6 labeled-unicast configuration. */
18210 bgp_config_write_family(vty, bgp, AFI_IP6,
18211 SAFI_LABELED_UNICAST);
18212
18213 /* IPv6 VPN configuration. */
18214 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
18215
18216 /* ENCAPv6 configuration. */
18217 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
18218
18219 /* FLOWSPEC v6 configuration. */
18220 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
18221
18222 /* EVPN configuration. */
18223 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
18224
18225 hook_call(bgp_inst_config_write, bgp, vty);
18226
49e5a4a0 18227#ifdef ENABLE_BGP_VNC
dd65f45e
DL
18228 bgp_rfapi_cfg_write(vty, bgp);
18229#endif
18230
18231 vty_out(vty, "!\n");
18232 }
18233 return 0;
18234}
18235
ddb5b488 18236
718e3744 18237/* BGP node structure. */
d62a17ae 18238static struct cmd_node bgp_node = {
f4b8291f 18239 .name = "bgp",
62b346ee 18240 .node = BGP_NODE,
24389580 18241 .parent_node = CONFIG_NODE,
62b346ee 18242 .prompt = "%s(config-router)# ",
612c2c15 18243 .config_write = bgp_config_write,
718e3744 18244};
18245
d62a17ae 18246static struct cmd_node bgp_ipv4_unicast_node = {
f4b8291f 18247 .name = "bgp ipv4 unicast",
62b346ee 18248 .node = BGP_IPV4_NODE,
24389580 18249 .parent_node = BGP_NODE,
62b346ee 18250 .prompt = "%s(config-router-af)# ",
718e3744 18251};
18252
d62a17ae 18253static struct cmd_node bgp_ipv4_multicast_node = {
f4b8291f 18254 .name = "bgp ipv4 multicast",
62b346ee 18255 .node = BGP_IPV4M_NODE,
24389580 18256 .parent_node = BGP_NODE,
62b346ee 18257 .prompt = "%s(config-router-af)# ",
718e3744 18258};
18259
d62a17ae 18260static struct cmd_node bgp_ipv4_labeled_unicast_node = {
f4b8291f 18261 .name = "bgp ipv4 labeled unicast",
62b346ee 18262 .node = BGP_IPV4L_NODE,
24389580 18263 .parent_node = BGP_NODE,
62b346ee 18264 .prompt = "%s(config-router-af)# ",
f51bae9c
DS
18265};
18266
d62a17ae 18267static struct cmd_node bgp_ipv6_unicast_node = {
f4b8291f 18268 .name = "bgp ipv6",
62b346ee 18269 .node = BGP_IPV6_NODE,
24389580 18270 .parent_node = BGP_NODE,
62b346ee 18271 .prompt = "%s(config-router-af)# ",
718e3744 18272};
18273
d62a17ae 18274static struct cmd_node bgp_ipv6_multicast_node = {
f4b8291f 18275 .name = "bgp ipv6 multicast",
62b346ee 18276 .node = BGP_IPV6M_NODE,
24389580 18277 .parent_node = BGP_NODE,
62b346ee 18278 .prompt = "%s(config-router-af)# ",
25ffbdc1 18279};
18280
d62a17ae 18281static struct cmd_node bgp_ipv6_labeled_unicast_node = {
f4b8291f 18282 .name = "bgp ipv6 labeled unicast",
62b346ee 18283 .node = BGP_IPV6L_NODE,
24389580 18284 .parent_node = BGP_NODE,
62b346ee 18285 .prompt = "%s(config-router-af)# ",
f51bae9c
DS
18286};
18287
62b346ee 18288static struct cmd_node bgp_vpnv4_node = {
f4b8291f 18289 .name = "bgp vpnv4",
62b346ee 18290 .node = BGP_VPNV4_NODE,
24389580 18291 .parent_node = BGP_NODE,
62b346ee 18292 .prompt = "%s(config-router-af)# ",
62b346ee 18293};
6b0655a2 18294
62b346ee 18295static struct cmd_node bgp_vpnv6_node = {
f4b8291f 18296 .name = "bgp vpnv6",
62b346ee 18297 .node = BGP_VPNV6_NODE,
24389580 18298 .parent_node = BGP_NODE,
62b346ee 18299 .prompt = "%s(config-router-af-vpnv6)# ",
62b346ee 18300};
8ecd3266 18301
62b346ee 18302static struct cmd_node bgp_evpn_node = {
f4b8291f 18303 .name = "bgp evpn",
62b346ee 18304 .node = BGP_EVPN_NODE,
24389580 18305 .parent_node = BGP_NODE,
62b346ee 18306 .prompt = "%s(config-router-evpn)# ",
62b346ee 18307};
4e0b7b6d 18308
62b346ee 18309static struct cmd_node bgp_evpn_vni_node = {
f4b8291f 18310 .name = "bgp evpn vni",
62b346ee 18311 .node = BGP_EVPN_VNI_NODE,
24389580 18312 .parent_node = BGP_EVPN_NODE,
62b346ee 18313 .prompt = "%s(config-router-af-vni)# ",
62b346ee 18314};
90e60aa7 18315
62b346ee 18316static struct cmd_node bgp_flowspecv4_node = {
f4b8291f 18317 .name = "bgp ipv4 flowspec",
62b346ee 18318 .node = BGP_FLOWSPECV4_NODE,
24389580 18319 .parent_node = BGP_NODE,
62b346ee 18320 .prompt = "%s(config-router-af)# ",
62b346ee 18321};
7c40bf39 18322
62b346ee 18323static struct cmd_node bgp_flowspecv6_node = {
f4b8291f 18324 .name = "bgp ipv6 flowspec",
62b346ee 18325 .node = BGP_FLOWSPECV6_NODE,
24389580 18326 .parent_node = BGP_NODE,
62b346ee 18327 .prompt = "%s(config-router-af-vpnv6)# ",
62b346ee 18328};
7c40bf39 18329
bfaab44d
HS
18330static struct cmd_node bgp_srv6_node = {
18331 .name = "bgp srv6",
18332 .node = BGP_SRV6_NODE,
18333 .parent_node = BGP_NODE,
18334 .prompt = "%s(config-router-srv6)# ",
18335};
18336
d62a17ae 18337static void community_list_vty(void);
1f8ae70b 18338
d62a17ae 18339static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 18340{
d62a17ae 18341 struct bgp *bgp;
18342 struct peer *peer;
d62a17ae 18343 struct listnode *lnbgp, *lnpeer;
b8a815e5 18344
d62a17ae 18345 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18346 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
18347 /* only provide suggestions on the appropriate input
18348 * token type,
18349 * they'll otherwise show up multiple times */
18350 enum cmd_token_type match_type;
18351 char *name = peer->host;
d48ed3e0 18352
d62a17ae 18353 if (peer->conf_if) {
18354 match_type = VARIABLE_TKN;
18355 name = peer->conf_if;
18356 } else if (strchr(peer->host, ':'))
18357 match_type = IPV6_TKN;
18358 else
18359 match_type = IPV4_TKN;
d48ed3e0 18360
d62a17ae 18361 if (token->type != match_type)
18362 continue;
d48ed3e0 18363
d62a17ae 18364 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
18365 }
d62a17ae 18366 }
b8a815e5
DL
18367}
18368
18369static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 18370 {.varname = "neighbor", .completions = bgp_ac_neighbor},
18371 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 18372 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 18373 {.completions = NULL}};
18374
47a306a0
DS
18375static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
18376{
18377 struct bgp *bgp;
18378 struct peer_group *group;
18379 struct listnode *lnbgp, *lnpeer;
18380
18381 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18382 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
18383 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
18384 group->name));
18385 }
18386}
18387
18388static const struct cmd_variable_handler bgp_var_peergroup[] = {
18389 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
18390 {.completions = NULL} };
18391
d62a17ae 18392void bgp_vty_init(void)
18393{
18394 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 18395 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 18396
18397 /* Install bgp top node. */
612c2c15
DL
18398 install_node(&bgp_node);
18399 install_node(&bgp_ipv4_unicast_node);
18400 install_node(&bgp_ipv4_multicast_node);
18401 install_node(&bgp_ipv4_labeled_unicast_node);
18402 install_node(&bgp_ipv6_unicast_node);
18403 install_node(&bgp_ipv6_multicast_node);
18404 install_node(&bgp_ipv6_labeled_unicast_node);
18405 install_node(&bgp_vpnv4_node);
18406 install_node(&bgp_vpnv6_node);
18407 install_node(&bgp_evpn_node);
18408 install_node(&bgp_evpn_vni_node);
18409 install_node(&bgp_flowspecv4_node);
18410 install_node(&bgp_flowspecv6_node);
bfaab44d 18411 install_node(&bgp_srv6_node);
d62a17ae 18412
18413 /* Install default VTY commands to new nodes. */
18414 install_default(BGP_NODE);
18415 install_default(BGP_IPV4_NODE);
18416 install_default(BGP_IPV4M_NODE);
18417 install_default(BGP_IPV4L_NODE);
18418 install_default(BGP_IPV6_NODE);
18419 install_default(BGP_IPV6M_NODE);
18420 install_default(BGP_IPV6L_NODE);
18421 install_default(BGP_VPNV4_NODE);
18422 install_default(BGP_VPNV6_NODE);
7c40bf39 18423 install_default(BGP_FLOWSPECV4_NODE);
18424 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 18425 install_default(BGP_EVPN_NODE);
18426 install_default(BGP_EVPN_VNI_NODE);
bfaab44d 18427 install_default(BGP_SRV6_NODE);
d62a17ae 18428
8029b216
AK
18429 /* "bgp local-mac" hidden commands. */
18430 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
18431 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
18432
9acb67cb
DS
18433 /* "bgp suppress-fib-pending" global */
18434 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
18435
d62a17ae 18436 /* bgp route-map delay-timer commands. */
18437 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
18438 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18439
d70583f7
D
18440 /* global bgp update-delay command */
18441 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
18442 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
18443
05bd726c 18444 /* global bgp graceful-shutdown command */
18445 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
18446 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
18447
d62a17ae 18448 /* Dummy commands (Currently not supported) */
18449 install_element(BGP_NODE, &no_synchronization_cmd);
18450 install_element(BGP_NODE, &no_auto_summary_cmd);
18451
18452 /* "router bgp" commands. */
18453 install_element(CONFIG_NODE, &router_bgp_cmd);
18454
18455 /* "no router bgp" commands. */
18456 install_element(CONFIG_NODE, &no_router_bgp_cmd);
18457
18458 /* "bgp router-id" commands. */
18459 install_element(BGP_NODE, &bgp_router_id_cmd);
18460 install_element(BGP_NODE, &no_bgp_router_id_cmd);
18461
c208c586
S
18462 /* "bgp suppress-fib-pending" command */
18463 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
18464
d62a17ae 18465 /* "bgp cluster-id" commands. */
18466 install_element(BGP_NODE, &bgp_cluster_id_cmd);
18467 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
18468
c163f297
DS
18469 /* "bgp no-rib" commands. */
18470 install_element(CONFIG_NODE, &bgp_norib_cmd);
18471 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
18472
e46723a5
DS
18473 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
18474
d62a17ae 18475 /* "bgp confederation" commands. */
18476 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
18477 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
18478
18479 /* "bgp confederation peers" commands. */
18480 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
18481 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
18482
18483 /* bgp max-med command */
18484 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
18485 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
18486 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
18487 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
18488 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
18489
18490 /* bgp disable-ebgp-connected-nh-check */
18491 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
18492 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
18493
18494 /* bgp update-delay command */
18495 install_element(BGP_NODE, &bgp_update_delay_cmd);
18496 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
d62a17ae 18497
18498 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
555e09d4 18499 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
d62a17ae 18500
18501 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
18502 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
18503
18504 /* "maximum-paths" commands. */
18505 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
18506 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
18507 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
18508 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
18509 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
18510 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
18511 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
18512 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
18513 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
18514 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
18515 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18516 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
18517 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
18518 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18519 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
18520
39edabac
PG
18521 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
18522 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
18523 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
18524 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18525 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
d62a17ae 18526 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
18527 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
18528 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
18529 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18530 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18531
18532 /* "timers bgp" commands. */
18533 install_element(BGP_NODE, &bgp_timers_cmd);
18534 install_element(BGP_NODE, &no_bgp_timers_cmd);
18535
18536 /* route-map delay-timer commands - per instance for backwards compat.
18537 */
18538 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
18539 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18540
18541 /* "bgp client-to-client reflection" commands */
18542 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
18543 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
18544
18545 /* "bgp always-compare-med" commands */
18546 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
18547 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
18548
9dac9fc8
DA
18549 /* bgp ebgp-requires-policy */
18550 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
18551 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
18552
2adac256
DA
18553 /* bgp suppress-duplicates */
18554 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
18555 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
18556
fb29348a
DA
18557 /* bgp reject-as-sets */
18558 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
18559 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
18560
d62a17ae 18561 /* "bgp deterministic-med" commands */
18562 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
18563 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
18564
055679e9 18565 /* "bgp graceful-restart" command */
36235319
QY
18566 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
18567 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
055679e9 18568
18569 /* "bgp graceful-restart-disable" command */
36235319
QY
18570 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
18571 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
055679e9 18572
18573 /* "neighbor a:b:c:d graceful-restart" command */
36235319
QY
18574 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
18575 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
055679e9 18576
18577 /* "neighbor a:b:c:d graceful-restart-disable" command */
18578 install_element(BGP_NODE,
18579 &bgp_neighbor_graceful_restart_disable_set_cmd);
18580 install_element(BGP_NODE,
18581 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
18582
18583 /* "neighbor a:b:c:d graceful-restart-helper" command */
18584 install_element(BGP_NODE,
18585 &bgp_neighbor_graceful_restart_helper_set_cmd);
18586 install_element(BGP_NODE,
18587 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
18588
d62a17ae 18589 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
18590 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
18591 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
18592 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
cfd47646 18593 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
f009ff26 18594 install_element(BGP_NODE,
18595 &no_bgp_graceful_restart_select_defer_time_cmd);
d62a17ae 18596 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
18597 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
18598
d6e3c15b 18599 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
18600 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
dc95985f 18601 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
18602 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
d6e3c15b 18603
7f323236
DW
18604 /* "bgp graceful-shutdown" commands */
18605 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
18606 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
18607
d62a17ae 18608 /* "bgp fast-external-failover" commands */
18609 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
18610 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
18611
d62a17ae 18612 /* "bgp bestpath compare-routerid" commands */
18613 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
18614 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
18615
18616 /* "bgp bestpath as-path ignore" commands */
18617 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
18618 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
18619
18620 /* "bgp bestpath as-path confed" commands */
18621 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
18622 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
18623
18624 /* "bgp bestpath as-path multipath-relax" commands */
18625 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
18626 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
18627
ee88563a
JM
18628 /* "bgp bestpath peer-type multipath-relax" commands */
18629 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
18630 install_element(BGP_NODE,
18631 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
18632
d62a17ae 18633 /* "bgp log-neighbor-changes" commands */
18634 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
18635 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
18636
18637 /* "bgp bestpath med" commands */
18638 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
18639 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
18640
f7e1c681 18641 /* "bgp bestpath bandwidth" commands */
18642 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
ad36d216 18643 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
f7e1c681 18644
b16bcbba
TA
18645 /* "no bgp default <afi>-<safi>" commands. */
18646 install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
e84c59af 18647
d62a17ae 18648 /* "bgp network import-check" commands. */
18649 install_element(BGP_NODE, &bgp_network_import_check_cmd);
18650 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
18651 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
18652
18653 /* "bgp default local-preference" commands. */
18654 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
18655 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
18656
18657 /* bgp default show-hostname */
18658 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
18659 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
18660
aef999a2
DA
18661 /* bgp default show-nexthop-hostname */
18662 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
18663 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
18664
d62a17ae 18665 /* "bgp default subgroup-pkt-queue-max" commands. */
18666 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
18667 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
18668
18669 /* bgp ibgp-allow-policy-mods command */
18670 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
18671 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
18672
18673 /* "bgp listen limit" commands. */
18674 install_element(BGP_NODE, &bgp_listen_limit_cmd);
18675 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
18676
18677 /* "bgp listen range" commands. */
18678 install_element(BGP_NODE, &bgp_listen_range_cmd);
18679 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
18680
8175f54a 18681 /* "bgp default shutdown" command */
f26845f9 18682 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
9cf59432
DS
18683
18684 /* "bgp shutdown" commands */
18685 install_element(BGP_NODE, &bgp_shutdown_cmd);
8389c83a 18686 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
9cf59432 18687 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
1b6e7a88 18688 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
f26845f9 18689
d62a17ae 18690 /* "neighbor remote-as" commands. */
18691 install_element(BGP_NODE, &neighbor_remote_as_cmd);
18692 install_element(BGP_NODE, &neighbor_interface_config_cmd);
18693 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
18694 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
18695 install_element(BGP_NODE,
18696 &neighbor_interface_v6only_config_remote_as_cmd);
18697 install_element(BGP_NODE, &no_neighbor_cmd);
18698 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
18699
18700 /* "neighbor peer-group" commands. */
18701 install_element(BGP_NODE, &neighbor_peer_group_cmd);
18702 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
18703 install_element(BGP_NODE,
18704 &no_neighbor_interface_peer_group_remote_as_cmd);
18705
18706 /* "neighbor local-as" commands. */
18707 install_element(BGP_NODE, &neighbor_local_as_cmd);
18708 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
18709 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
18710 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
18711
18712 /* "neighbor solo" commands. */
18713 install_element(BGP_NODE, &neighbor_solo_cmd);
18714 install_element(BGP_NODE, &no_neighbor_solo_cmd);
18715
18716 /* "neighbor password" commands. */
18717 install_element(BGP_NODE, &neighbor_password_cmd);
18718 install_element(BGP_NODE, &no_neighbor_password_cmd);
18719
18720 /* "neighbor activate" commands. */
18721 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
18722 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
18723 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
18724 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
18725 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
18726 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
18727 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
18728 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
18729 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 18730 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
18731 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 18732 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
18733
18734 /* "no neighbor activate" commands. */
18735 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
18736 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
18737 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
18738 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
18739 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
18740 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
18741 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
18742 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
18743 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 18744 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
18745 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 18746 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
18747
18748 /* "neighbor peer-group" set commands. */
18749 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
18750 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18751 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
18752 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18753 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
18754 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
18755 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18756 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 18757 install_element(BGP_FLOWSPECV4_NODE,
18758 &neighbor_set_peer_group_hidden_cmd);
18759 install_element(BGP_FLOWSPECV6_NODE,
18760 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 18761
18762 /* "no neighbor peer-group unset" commands. */
18763 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
18764 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18765 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18766 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18767 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18768 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18769 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18770 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 18771 install_element(BGP_FLOWSPECV4_NODE,
18772 &no_neighbor_set_peer_group_hidden_cmd);
18773 install_element(BGP_FLOWSPECV6_NODE,
18774 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 18775
18776 /* "neighbor softreconfiguration inbound" commands.*/
18777 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
18778 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
18779 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
18780 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18781 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
18782 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18783 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
18784 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18785 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
18786 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18787 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
18788 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18789 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
18790 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18791 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
18792 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18793 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
18794 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 18795 install_element(BGP_FLOWSPECV4_NODE,
18796 &neighbor_soft_reconfiguration_cmd);
18797 install_element(BGP_FLOWSPECV4_NODE,
18798 &no_neighbor_soft_reconfiguration_cmd);
18799 install_element(BGP_FLOWSPECV6_NODE,
18800 &neighbor_soft_reconfiguration_cmd);
18801 install_element(BGP_FLOWSPECV6_NODE,
18802 &no_neighbor_soft_reconfiguration_cmd);
616c6ee8
PG
18803 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
18804 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 18805
18806 /* "neighbor attribute-unchanged" commands. */
18807 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
18808 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
18809 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
18810 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
18811 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
18812 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
18813 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
18814 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
18815 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
18816 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
18817 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
18818 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
18819 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
18820 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
18821 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
18822 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
18823 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
18824 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
18825
18826 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
18827 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
18828
b8ad84d2
PG
18829 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
18830 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
18831 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
18832 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
18833
d62a17ae 18834 /* "nexthop-local unchanged" commands */
18835 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
18836 install_element(BGP_IPV6_NODE,
18837 &no_neighbor_nexthop_local_unchanged_cmd);
18838
18839 /* "neighbor next-hop-self" commands. */
18840 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
18841 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
18842 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
18843 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
18844 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
18845 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
18846 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
18847 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
18848 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
18849 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
18850 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
18851 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
18852 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
18853 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
18854 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
18855 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
18856 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
18857 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
18858 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
18859 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 18860
18861 /* "neighbor next-hop-self force" commands. */
18862 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
18863 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
1bc4e531
DA
18864 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18865 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18866 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
18867 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18868 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18869 install_element(BGP_IPV4_NODE,
18870 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18871 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
18872 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18873 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18874 install_element(BGP_IPV4M_NODE,
18875 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18876 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
18877 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18878 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18879 install_element(BGP_IPV4L_NODE,
18880 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18881 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
18882 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18883 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18884 install_element(BGP_IPV6_NODE,
18885 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18886 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
18887 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18888 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18889 install_element(BGP_IPV6M_NODE,
18890 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18891 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
18892 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18893 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18894 install_element(BGP_IPV6L_NODE,
18895 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18896 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
18897 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18898 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18899 install_element(BGP_VPNV4_NODE,
18900 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18901 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
18902 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18903 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18904 install_element(BGP_VPNV6_NODE,
18905 &no_neighbor_nexthop_self_all_hidden_cmd);
be7e1fa3
MS
18906 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
18907 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
d62a17ae 18908
18909 /* "neighbor as-override" commands. */
18910 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
18911 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
18912 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
18913 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
18914 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
18915 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
18916 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
18917 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
18918 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
18919 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
18920 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
18921 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
18922 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
18923 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
18924 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
18925 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
18926 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
18927 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
18928
18929 /* "neighbor remove-private-AS" commands. */
18930 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
18931 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
18932 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
18933 install_element(BGP_NODE,
18934 &no_neighbor_remove_private_as_all_hidden_cmd);
18935 install_element(BGP_NODE,
18936 &neighbor_remove_private_as_replace_as_hidden_cmd);
18937 install_element(BGP_NODE,
18938 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
18939 install_element(BGP_NODE,
18940 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
18941 install_element(
18942 BGP_NODE,
18943 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
18944 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
18945 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
18946 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
18947 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18948 install_element(BGP_IPV4_NODE,
18949 &neighbor_remove_private_as_replace_as_cmd);
18950 install_element(BGP_IPV4_NODE,
18951 &no_neighbor_remove_private_as_replace_as_cmd);
18952 install_element(BGP_IPV4_NODE,
18953 &neighbor_remove_private_as_all_replace_as_cmd);
18954 install_element(BGP_IPV4_NODE,
18955 &no_neighbor_remove_private_as_all_replace_as_cmd);
18956 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
18957 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
18958 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
18959 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
18960 install_element(BGP_IPV4M_NODE,
18961 &neighbor_remove_private_as_replace_as_cmd);
18962 install_element(BGP_IPV4M_NODE,
18963 &no_neighbor_remove_private_as_replace_as_cmd);
18964 install_element(BGP_IPV4M_NODE,
18965 &neighbor_remove_private_as_all_replace_as_cmd);
18966 install_element(BGP_IPV4M_NODE,
18967 &no_neighbor_remove_private_as_all_replace_as_cmd);
18968 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
18969 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
18970 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
18971 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
18972 install_element(BGP_IPV4L_NODE,
18973 &neighbor_remove_private_as_replace_as_cmd);
18974 install_element(BGP_IPV4L_NODE,
18975 &no_neighbor_remove_private_as_replace_as_cmd);
18976 install_element(BGP_IPV4L_NODE,
18977 &neighbor_remove_private_as_all_replace_as_cmd);
18978 install_element(BGP_IPV4L_NODE,
18979 &no_neighbor_remove_private_as_all_replace_as_cmd);
18980 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
18981 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
18982 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
18983 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18984 install_element(BGP_IPV6_NODE,
18985 &neighbor_remove_private_as_replace_as_cmd);
18986 install_element(BGP_IPV6_NODE,
18987 &no_neighbor_remove_private_as_replace_as_cmd);
18988 install_element(BGP_IPV6_NODE,
18989 &neighbor_remove_private_as_all_replace_as_cmd);
18990 install_element(BGP_IPV6_NODE,
18991 &no_neighbor_remove_private_as_all_replace_as_cmd);
18992 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
18993 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
18994 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
18995 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
18996 install_element(BGP_IPV6M_NODE,
18997 &neighbor_remove_private_as_replace_as_cmd);
18998 install_element(BGP_IPV6M_NODE,
18999 &no_neighbor_remove_private_as_replace_as_cmd);
19000 install_element(BGP_IPV6M_NODE,
19001 &neighbor_remove_private_as_all_replace_as_cmd);
19002 install_element(BGP_IPV6M_NODE,
19003 &no_neighbor_remove_private_as_all_replace_as_cmd);
19004 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
19005 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
19006 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
19007 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
19008 install_element(BGP_IPV6L_NODE,
19009 &neighbor_remove_private_as_replace_as_cmd);
19010 install_element(BGP_IPV6L_NODE,
19011 &no_neighbor_remove_private_as_replace_as_cmd);
19012 install_element(BGP_IPV6L_NODE,
19013 &neighbor_remove_private_as_all_replace_as_cmd);
19014 install_element(BGP_IPV6L_NODE,
19015 &no_neighbor_remove_private_as_all_replace_as_cmd);
19016 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
19017 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
19018 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
19019 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
19020 install_element(BGP_VPNV4_NODE,
19021 &neighbor_remove_private_as_replace_as_cmd);
19022 install_element(BGP_VPNV4_NODE,
19023 &no_neighbor_remove_private_as_replace_as_cmd);
19024 install_element(BGP_VPNV4_NODE,
19025 &neighbor_remove_private_as_all_replace_as_cmd);
19026 install_element(BGP_VPNV4_NODE,
19027 &no_neighbor_remove_private_as_all_replace_as_cmd);
19028 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
19029 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
19030 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
19031 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
19032 install_element(BGP_VPNV6_NODE,
19033 &neighbor_remove_private_as_replace_as_cmd);
19034 install_element(BGP_VPNV6_NODE,
19035 &no_neighbor_remove_private_as_replace_as_cmd);
19036 install_element(BGP_VPNV6_NODE,
19037 &neighbor_remove_private_as_all_replace_as_cmd);
19038 install_element(BGP_VPNV6_NODE,
19039 &no_neighbor_remove_private_as_all_replace_as_cmd);
19040
19041 /* "neighbor send-community" commands.*/
19042 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
19043 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
19044 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
19045 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
19046 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
19047 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
19048 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
19049 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
19050 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
19051 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
19052 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
19053 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
19054 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
19055 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
19056 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
19057 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
19058 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
19059 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
19060 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
19061 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
19062 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
19063 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
19064 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
19065 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
19066 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
19067 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
19068 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
19069 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
19070 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
19071 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
19072 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
19073 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
19074 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
19075 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
19076 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
19077 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
19078
19079 /* "neighbor route-reflector" commands.*/
19080 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
19081 install_element(BGP_NODE,
19082 &no_neighbor_route_reflector_client_hidden_cmd);
19083 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
19084 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
19085 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
19086 install_element(BGP_IPV4M_NODE,
19087 &no_neighbor_route_reflector_client_cmd);
19088 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
19089 install_element(BGP_IPV4L_NODE,
19090 &no_neighbor_route_reflector_client_cmd);
19091 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
19092 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
19093 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
19094 install_element(BGP_IPV6M_NODE,
19095 &no_neighbor_route_reflector_client_cmd);
19096 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
19097 install_element(BGP_IPV6L_NODE,
19098 &no_neighbor_route_reflector_client_cmd);
19099 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
19100 install_element(BGP_VPNV4_NODE,
19101 &no_neighbor_route_reflector_client_cmd);
19102 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
19103 install_element(BGP_VPNV6_NODE,
19104 &no_neighbor_route_reflector_client_cmd);
7c40bf39 19105 install_element(BGP_FLOWSPECV4_NODE,
19106 &neighbor_route_reflector_client_cmd);
19107 install_element(BGP_FLOWSPECV4_NODE,
19108 &no_neighbor_route_reflector_client_cmd);
19109 install_element(BGP_FLOWSPECV6_NODE,
19110 &neighbor_route_reflector_client_cmd);
19111 install_element(BGP_FLOWSPECV6_NODE,
19112 &no_neighbor_route_reflector_client_cmd);
d62a17ae 19113 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
19114 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
19115
19116 /* "neighbor route-server" commands.*/
19117 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
19118 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
19119 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
19120 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
19121 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
19122 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
19123 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
19124 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
19125 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
19126 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
19127 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
19128 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
19129 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
19130 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
19131 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
19132 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
19133 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
19134 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
19135 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
19136 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 19137 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
19138 install_element(BGP_FLOWSPECV4_NODE,
19139 &no_neighbor_route_server_client_cmd);
19140 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
19141 install_element(BGP_FLOWSPECV6_NODE,
19142 &no_neighbor_route_server_client_cmd);
d62a17ae 19143
19144 /* "neighbor addpath-tx-all-paths" commands.*/
19145 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
19146 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
19147 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19148 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19149 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19150 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19151 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19152 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19153 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19154 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19155 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19156 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19157 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19158 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19159 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19160 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19161 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19162 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19163
19164 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
19165 install_element(BGP_NODE,
19166 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19167 install_element(BGP_NODE,
19168 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19169 install_element(BGP_IPV4_NODE,
19170 &neighbor_addpath_tx_bestpath_per_as_cmd);
19171 install_element(BGP_IPV4_NODE,
19172 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19173 install_element(BGP_IPV4M_NODE,
19174 &neighbor_addpath_tx_bestpath_per_as_cmd);
19175 install_element(BGP_IPV4M_NODE,
19176 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19177 install_element(BGP_IPV4L_NODE,
19178 &neighbor_addpath_tx_bestpath_per_as_cmd);
19179 install_element(BGP_IPV4L_NODE,
19180 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19181 install_element(BGP_IPV6_NODE,
19182 &neighbor_addpath_tx_bestpath_per_as_cmd);
19183 install_element(BGP_IPV6_NODE,
19184 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19185 install_element(BGP_IPV6M_NODE,
19186 &neighbor_addpath_tx_bestpath_per_as_cmd);
19187 install_element(BGP_IPV6M_NODE,
19188 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19189 install_element(BGP_IPV6L_NODE,
19190 &neighbor_addpath_tx_bestpath_per_as_cmd);
19191 install_element(BGP_IPV6L_NODE,
19192 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19193 install_element(BGP_VPNV4_NODE,
19194 &neighbor_addpath_tx_bestpath_per_as_cmd);
19195 install_element(BGP_VPNV4_NODE,
19196 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19197 install_element(BGP_VPNV6_NODE,
19198 &neighbor_addpath_tx_bestpath_per_as_cmd);
19199 install_element(BGP_VPNV6_NODE,
19200 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19201
2b31007c
RZ
19202 /* "neighbor sender-as-path-loop-detection" commands. */
19203 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
19204 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
19205
d62a17ae 19206 /* "neighbor passive" commands. */
19207 install_element(BGP_NODE, &neighbor_passive_cmd);
19208 install_element(BGP_NODE, &no_neighbor_passive_cmd);
19209
19210
19211 /* "neighbor shutdown" commands. */
19212 install_element(BGP_NODE, &neighbor_shutdown_cmd);
19213 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
19214 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
19215 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
8336c896
DA
19216 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
19217 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
d62a17ae 19218
19219 /* "neighbor capability extended-nexthop" commands.*/
19220 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
19221 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
19222
19223 /* "neighbor capability orf prefix-list" commands.*/
19224 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
19225 install_element(BGP_NODE,
19226 &no_neighbor_capability_orf_prefix_hidden_cmd);
19227 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
19228 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
19229 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
19230 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19231 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
19232 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19233 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
19234 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
19235 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
19236 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19237 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
19238 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19239
19240 /* "neighbor capability dynamic" commands.*/
19241 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
19242 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
19243
19244 /* "neighbor dont-capability-negotiate" commands. */
19245 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
19246 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
19247
19248 /* "neighbor ebgp-multihop" commands. */
19249 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
19250 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
19251 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
19252
19253 /* "neighbor disable-connected-check" commands. */
19254 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
19255 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
19256
47cbc09b
PM
19257 /* "neighbor enforce-first-as" commands. */
19258 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
19259 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
19260
d62a17ae 19261 /* "neighbor description" commands. */
19262 install_element(BGP_NODE, &neighbor_description_cmd);
19263 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 19264 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 19265
19266 /* "neighbor update-source" commands. "*/
19267 install_element(BGP_NODE, &neighbor_update_source_cmd);
19268 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
19269
19270 /* "neighbor default-originate" commands. */
19271 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
19272 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
19273 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
19274 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
19275 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
19276 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
19277 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
19278 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
19279 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
19280 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
19281 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
19282 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
19283 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
19284 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
19285 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
19286 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
19287 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
19288 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
19289 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
19290 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
19291 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
19292
19293 /* "neighbor port" commands. */
19294 install_element(BGP_NODE, &neighbor_port_cmd);
19295 install_element(BGP_NODE, &no_neighbor_port_cmd);
19296
19297 /* "neighbor weight" commands. */
19298 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
19299 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
19300
19301 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
19302 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
19303 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
19304 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
19305 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
19306 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
19307 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
19308 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
19309 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
19310 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
19311 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
19312 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
19313 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
19314 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
19315 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
19316 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
19317
19318 /* "neighbor override-capability" commands. */
19319 install_element(BGP_NODE, &neighbor_override_capability_cmd);
19320 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
19321
19322 /* "neighbor strict-capability-match" commands. */
19323 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
19324 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
19325
19326 /* "neighbor timers" commands. */
19327 install_element(BGP_NODE, &neighbor_timers_cmd);
19328 install_element(BGP_NODE, &no_neighbor_timers_cmd);
19329
19330 /* "neighbor timers connect" commands. */
19331 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
19332 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
19333
d43114f3
DS
19334 /* "neighbor timers delayopen" commands. */
19335 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
19336 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
19337
d62a17ae 19338 /* "neighbor advertisement-interval" commands. */
19339 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
19340 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
19341
19342 /* "neighbor interface" commands. */
19343 install_element(BGP_NODE, &neighbor_interface_cmd);
19344 install_element(BGP_NODE, &no_neighbor_interface_cmd);
19345
19346 /* "neighbor distribute" commands. */
19347 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
19348 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
19349 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
19350 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
19351 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
19352 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
19353 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
19354 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
19355 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
19356 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
19357 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
19358 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
19359 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
19360 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
19361 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
19362 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
19363 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
19364 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
19365
19366 /* "neighbor prefix-list" commands. */
19367 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
d62a17ae 19368 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
d62a17ae 19369 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
d62a17ae 19370 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
d62a17ae 19371 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
d62a17ae 19372 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
d62a17ae 19373 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
d62a17ae 19374 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
d62a17ae 19375 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
7c40bf39 19376 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
7c40bf39 19377 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
d62a17ae 19378
19379 /* "neighbor filter-list" commands. */
19380 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
19381 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
19382 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
19383 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
19384 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
19385 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
19386 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
19387 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
19388 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
19389 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
19390 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
19391 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
19392 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
19393 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
19394 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
19395 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
19396 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
19397 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 19398 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
19399 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
19400 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
19401 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 19402
19403 /* "neighbor route-map" commands. */
d62a17ae 19404 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
d62a17ae 19405 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
d62a17ae 19406 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
d62a17ae 19407 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
d62a17ae 19408 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
d62a17ae 19409 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
d62a17ae 19410 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
d62a17ae 19411 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
7c40bf39 19412 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
7c40bf39 19413 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
d37ba549 19414 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
d62a17ae 19415
19416 /* "neighbor unsuppress-map" commands. */
19417 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
19418 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
19419 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
19420 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
19421 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
19422 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
19423 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
19424 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
19425 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
19426 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
19427 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
19428 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
19429 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
19430 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
19431 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
19432 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
19433 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
19434 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
19435
7f7940e6
MK
19436 /* "neighbor advertise-map" commands. */
19437 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
7f7940e6 19438 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19439 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19440 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19441 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19442 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19443 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19444 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19445 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19446
fde246e8
DA
19447 /* neighbor maximum-prefix-out commands. */
19448 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
19449 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
19450 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
19451 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19452 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
19453 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19454 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
19455 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19456 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
19457 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19458 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
19459 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19460 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
19461 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19462 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
19463 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19464 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
19465 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19466
d62a17ae 19467 /* "neighbor maximum-prefix" commands. */
19468 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
19469 install_element(BGP_NODE,
19470 &neighbor_maximum_prefix_threshold_hidden_cmd);
19471 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
19472 install_element(BGP_NODE,
19473 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
19474 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
19475 install_element(BGP_NODE,
19476 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
19477 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
19478 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
19479 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19480 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19481 install_element(BGP_IPV4_NODE,
19482 &neighbor_maximum_prefix_threshold_warning_cmd);
19483 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19484 install_element(BGP_IPV4_NODE,
19485 &neighbor_maximum_prefix_threshold_restart_cmd);
19486 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
19487 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
19488 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19489 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
19490 install_element(BGP_IPV4M_NODE,
19491 &neighbor_maximum_prefix_threshold_warning_cmd);
19492 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
19493 install_element(BGP_IPV4M_NODE,
19494 &neighbor_maximum_prefix_threshold_restart_cmd);
19495 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
19496 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
19497 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19498 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
19499 install_element(BGP_IPV4L_NODE,
19500 &neighbor_maximum_prefix_threshold_warning_cmd);
19501 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
19502 install_element(BGP_IPV4L_NODE,
19503 &neighbor_maximum_prefix_threshold_restart_cmd);
19504 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
19505 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
19506 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19507 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19508 install_element(BGP_IPV6_NODE,
19509 &neighbor_maximum_prefix_threshold_warning_cmd);
19510 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19511 install_element(BGP_IPV6_NODE,
19512 &neighbor_maximum_prefix_threshold_restart_cmd);
19513 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
19514 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
19515 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19516 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
19517 install_element(BGP_IPV6M_NODE,
19518 &neighbor_maximum_prefix_threshold_warning_cmd);
19519 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
19520 install_element(BGP_IPV6M_NODE,
19521 &neighbor_maximum_prefix_threshold_restart_cmd);
19522 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
19523 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
19524 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19525 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
19526 install_element(BGP_IPV6L_NODE,
19527 &neighbor_maximum_prefix_threshold_warning_cmd);
19528 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
19529 install_element(BGP_IPV6L_NODE,
19530 &neighbor_maximum_prefix_threshold_restart_cmd);
19531 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
19532 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
19533 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19534 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19535 install_element(BGP_VPNV4_NODE,
19536 &neighbor_maximum_prefix_threshold_warning_cmd);
19537 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19538 install_element(BGP_VPNV4_NODE,
19539 &neighbor_maximum_prefix_threshold_restart_cmd);
19540 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
19541 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
19542 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19543 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19544 install_element(BGP_VPNV6_NODE,
19545 &neighbor_maximum_prefix_threshold_warning_cmd);
19546 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19547 install_element(BGP_VPNV6_NODE,
19548 &neighbor_maximum_prefix_threshold_restart_cmd);
19549 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
19550
19551 /* "neighbor allowas-in" */
19552 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
19553 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
19554 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
19555 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
19556 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
19557 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
19558 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
19559 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
19560 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
19561 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
19562 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
19563 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
19564 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
19565 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
19566 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
19567 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
19568 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
19569 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
19570 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
19571 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
19572
0221327c
DS
19573 /* "neighbor dampening" commands. */
19574 install_element(BGP_NODE, &neighbor_damp_cmd);
19575 install_element(BGP_NODE, &no_neighbor_damp_cmd);
19576 install_element(BGP_IPV4_NODE, &neighbor_damp_cmd);
19577 install_element(BGP_IPV4_NODE, &no_neighbor_damp_cmd);
19578 install_element(BGP_IPV4M_NODE, &neighbor_damp_cmd);
19579 install_element(BGP_IPV4M_NODE, &no_neighbor_damp_cmd);
19580 install_element(BGP_IPV4L_NODE, &neighbor_damp_cmd);
19581 install_element(BGP_IPV4L_NODE, &no_neighbor_damp_cmd);
19582 install_element(BGP_IPV6_NODE, &neighbor_damp_cmd);
19583 install_element(BGP_IPV6_NODE, &no_neighbor_damp_cmd);
19584 install_element(BGP_IPV6M_NODE, &neighbor_damp_cmd);
19585 install_element(BGP_IPV6M_NODE, &no_neighbor_damp_cmd);
19586 install_element(BGP_IPV6L_NODE, &neighbor_damp_cmd);
19587 install_element(BGP_IPV6L_NODE, &no_neighbor_damp_cmd);
19588 install_element(VIEW_NODE, &show_ip_bgp_neighbor_damp_param_cmd);
19589
d62a17ae 19590 /* address-family commands. */
19591 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
19592 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 19593#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 19594 install_element(BGP_NODE, &address_family_vpnv4_cmd);
19595 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 19596#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 19597
d62a17ae 19598 install_element(BGP_NODE, &address_family_evpn_cmd);
19599
19600 /* "exit-address-family" command. */
19601 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
19602 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
19603 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
19604 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
19605 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
19606 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
19607 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
19608 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 19609 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
19610 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 19611 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
19612
19613 /* "clear ip bgp commands" */
19614 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
19615
19616 /* clear ip bgp prefix */
19617 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
19618 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
19619 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
19620
19621 /* "show [ip] bgp summary" commands. */
19622 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 19623 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 19624 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 19625 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 19626 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
19627 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 19628 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
19629
19630 /* "show [ip] bgp neighbors" commands. */
19631 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
19632
36235319 19633 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
2986cac2 19634
d62a17ae 19635 /* "show [ip] bgp peer-group" commands. */
19636 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
19637
19638 /* "show [ip] bgp paths" commands. */
19639 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
19640
19641 /* "show [ip] bgp community" commands. */
19642 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
19643
19644 /* "show ip bgp large-community" commands. */
19645 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
19646 /* "show [ip] bgp attribute-info" commands. */
19647 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 19648 /* "show [ip] bgp route-leak" command */
19649 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 19650
19651 /* "redistribute" commands. */
19652 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
19653 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
19654 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
19655 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
19656 install_element(BGP_NODE,
19657 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
19658 install_element(BGP_NODE,
19659 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
19660 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
19661 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
19662 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
19663 install_element(BGP_NODE,
19664 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
19665 install_element(BGP_NODE,
19666 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
19667 install_element(BGP_NODE,
19668 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
19669 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
19670 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
19671 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
19672 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
19673 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
19674 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
19675 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
19676 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
19677 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
19678 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
19679 install_element(BGP_IPV4_NODE,
19680 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
19681 install_element(BGP_IPV4_NODE,
19682 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
19683 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
19684 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
19685 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
19686 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
19687 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
19688 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
19689
b9c7bc5a
PZ
19690 /* import|export vpn [route-map WORD] */
19691 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
19692 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 19693
12a844a5
DS
19694 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
19695 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
19696
d62a17ae 19697 /* ttl_security commands */
19698 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
19699 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
19700
19701 /* "show [ip] bgp memory" commands. */
19702 install_element(VIEW_NODE, &show_bgp_memory_cmd);
19703
acf71666
MK
19704 /* "show bgp martian next-hop" */
19705 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
19706
48ecf8f5
DS
19707 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
19708
d62a17ae 19709 /* "show [ip] bgp views" commands. */
19710 install_element(VIEW_NODE, &show_bgp_views_cmd);
19711
19712 /* "show [ip] bgp vrfs" commands. */
19713 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
19714
19715 /* Community-list. */
19716 community_list_vty();
ddb5b488 19717
ed0e57e3
DA
19718 community_alias_vty();
19719
ddb5b488 19720 /* vpn-policy commands */
b9c7bc5a
PZ
19721 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
19722 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
19723 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
19724 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
19725 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
19726 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
19727 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
19728 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
19729 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
19730 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
19731 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
19732 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 19733
301ad80a
PG
19734 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
19735 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
19736
b9c7bc5a
PZ
19737 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
19738 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
19739 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
19740 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
b9c7bc5a
PZ
19741 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
19742 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
19743 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
19744 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
19745 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
19746 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
4ab46701
AR
19747
19748 /* tcp-mss command */
19749 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
19750 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
bfaab44d
HS
19751
19752 /* srv6 commands */
ea372e81 19753 install_element(VIEW_NODE, &show_bgp_srv6_cmd);
bfaab44d 19754 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
a0281b2e 19755 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
b72c9e14
HS
19756 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
19757 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
718e3744 19758}
6b0655a2 19759
718e3744 19760#include "memory.h"
19761#include "bgp_regex.h"
19762#include "bgp_clist.h"
19763#include "bgp_ecommunity.h"
19764
19765/* VTY functions. */
19766
19767/* Direction value to string conversion. */
d62a17ae 19768static const char *community_direct_str(int direct)
19769{
19770 switch (direct) {
19771 case COMMUNITY_DENY:
19772 return "deny";
19773 case COMMUNITY_PERMIT:
19774 return "permit";
19775 default:
19776 return "unknown";
19777 }
718e3744 19778}
19779
19780/* Display error string. */
d62a17ae 19781static void community_list_perror(struct vty *vty, int ret)
19782{
19783 switch (ret) {
19784 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
19785 vty_out(vty, "%% Can't find community-list\n");
19786 break;
19787 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
19788 vty_out(vty, "%% Malformed community-list value\n");
19789 break;
19790 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
19791 vty_out(vty,
19792 "%% Community name conflict, previously defined as standard community\n");
19793 break;
19794 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
19795 vty_out(vty,
19796 "%% Community name conflict, previously defined as expanded community\n");
19797 break;
19798 }
718e3744 19799}
19800
5bf15956
DW
19801/* "community-list" keyword help string. */
19802#define COMMUNITY_LIST_STR "Add a community list entry\n"
19803
7336e101
SP
19804/*community-list standard */
19805DEFUN (community_list_standard,
19806 bgp_community_list_standard_cmd,
a08032fe 19807 "bgp community-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 19808 BGP_STR
718e3744 19809 COMMUNITY_LIST_STR
19810 "Community list number (standard)\n"
5bf15956 19811 "Add an standard community-list entry\n"
718e3744 19812 "Community list name\n"
2f8cc0e5
DA
19813 "Sequence number of an entry\n"
19814 "Sequence number\n"
718e3744 19815 "Specify community to reject\n"
19816 "Specify community to accept\n"
19817 COMMUNITY_VAL_STR)
19818{
d62a17ae 19819 char *cl_name_or_number = NULL;
2f8cc0e5 19820 char *seq = NULL;
d62a17ae 19821 int direct = 0;
19822 int style = COMMUNITY_LIST_STANDARD;
d62a17ae 19823 int idx = 0;
7336e101 19824
a08032fe 19825 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19826 if (idx)
19827 seq = argv[idx]->arg;
19828
19829 idx = 0;
d62a17ae 19830 argv_find(argv, argc, "(1-99)", &idx);
19831 argv_find(argv, argc, "WORD", &idx);
19832 cl_name_or_number = argv[idx]->arg;
19833 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19834 : COMMUNITY_DENY;
19835 argv_find(argv, argc, "AA:NN", &idx);
19836 char *str = argv_concat(argv, argc, idx);
42f914d4 19837
2f8cc0e5
DA
19838 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19839 direct, style);
42f914d4 19840
d62a17ae 19841 XFREE(MTYPE_TMP, str);
42f914d4 19842
d62a17ae 19843 if (ret < 0) {
19844 /* Display error string. */
19845 community_list_perror(vty, ret);
19846 return CMD_WARNING_CONFIG_FAILED;
19847 }
42f914d4 19848
d62a17ae 19849 return CMD_SUCCESS;
718e3744 19850}
19851
7336e101
SP
19852DEFUN (no_community_list_standard_all,
19853 no_bgp_community_list_standard_all_cmd,
a08032fe 19854 "no bgp community-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19855 NO_STR
19856 BGP_STR
19857 COMMUNITY_LIST_STR
19858 "Community list number (standard)\n"
19859 "Add an standard community-list entry\n"
19860 "Community list name\n"
2f8cc0e5
DA
19861 "Sequence number of an entry\n"
19862 "Sequence number\n"
7336e101
SP
19863 "Specify community to reject\n"
19864 "Specify community to accept\n"
19865 COMMUNITY_VAL_STR)
718e3744 19866{
d62a17ae 19867 char *cl_name_or_number = NULL;
174b5cb9 19868 char *str = NULL;
d62a17ae 19869 int direct = 0;
19870 int style = COMMUNITY_LIST_STANDARD;
2f8cc0e5 19871 char *seq = NULL;
d62a17ae 19872 int idx = 0;
7336e101 19873
a08032fe 19874 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19875 if (idx)
19876 seq = argv[idx]->arg;
19877
19878 idx = 0;
174b5cb9
DA
19879 argv_find(argv, argc, "permit", &idx);
19880 argv_find(argv, argc, "deny", &idx);
19881
19882 if (idx) {
19883 direct = argv_find(argv, argc, "permit", &idx)
19884 ? COMMUNITY_PERMIT
19885 : COMMUNITY_DENY;
19886
19887 idx = 0;
19888 argv_find(argv, argc, "AA:NN", &idx);
19889 str = argv_concat(argv, argc, idx);
19890 }
19891
19892 idx = 0;
d62a17ae 19893 argv_find(argv, argc, "(1-99)", &idx);
19894 argv_find(argv, argc, "WORD", &idx);
19895 cl_name_or_number = argv[idx]->arg;
42f914d4 19896
2f8cc0e5 19897 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 19898 direct, style);
42f914d4 19899
d62a17ae 19900 XFREE(MTYPE_TMP, str);
daf9ddbb 19901
d62a17ae 19902 if (ret < 0) {
19903 community_list_perror(vty, ret);
19904 return CMD_WARNING_CONFIG_FAILED;
19905 }
42f914d4 19906
d62a17ae 19907 return CMD_SUCCESS;
718e3744 19908}
7336e101 19909
174b5cb9
DA
19910ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
19911 "no bgp community-list <(1-99)|standard WORD>",
19912 NO_STR BGP_STR COMMUNITY_LIST_STR
19913 "Community list number (standard)\n"
19914 "Add an standard community-list entry\n"
19915 "Community list name\n")
19916
7336e101
SP
19917/*community-list expanded */
19918DEFUN (community_list_expanded_all,
19919 bgp_community_list_expanded_all_cmd,
a08032fe 19920 "bgp community-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19921 BGP_STR
19922 COMMUNITY_LIST_STR
718e3744 19923 "Community list number (expanded)\n"
5bf15956 19924 "Add an expanded community-list entry\n"
718e3744 19925 "Community list name\n"
2f8cc0e5
DA
19926 "Sequence number of an entry\n"
19927 "Sequence number\n"
718e3744 19928 "Specify community to reject\n"
19929 "Specify community to accept\n"
19930 COMMUNITY_VAL_STR)
19931{
d62a17ae 19932 char *cl_name_or_number = NULL;
2f8cc0e5 19933 char *seq = NULL;
d62a17ae 19934 int direct = 0;
19935 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 19936 int idx = 0;
7b9a4750 19937
a08032fe 19938 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19939 if (idx)
19940 seq = argv[idx]->arg;
19941
19942 idx = 0;
19943
d62a17ae 19944 argv_find(argv, argc, "(100-500)", &idx);
19945 argv_find(argv, argc, "WORD", &idx);
19946 cl_name_or_number = argv[idx]->arg;
19947 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19948 : COMMUNITY_DENY;
19949 argv_find(argv, argc, "AA:NN", &idx);
19950 char *str = argv_concat(argv, argc, idx);
42f914d4 19951
2f8cc0e5
DA
19952 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19953 direct, style);
42f914d4 19954
d62a17ae 19955 XFREE(MTYPE_TMP, str);
42f914d4 19956
d62a17ae 19957 if (ret < 0) {
19958 /* Display error string. */
19959 community_list_perror(vty, ret);
19960 return CMD_WARNING_CONFIG_FAILED;
19961 }
42f914d4 19962
d62a17ae 19963 return CMD_SUCCESS;
718e3744 19964}
19965
7336e101
SP
19966DEFUN (no_community_list_expanded_all,
19967 no_bgp_community_list_expanded_all_cmd,
a08032fe 19968 "no bgp community-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19969 NO_STR
19970 BGP_STR
19971 COMMUNITY_LIST_STR
19972 "Community list number (expanded)\n"
19973 "Add an expanded community-list entry\n"
19974 "Community list name\n"
2f8cc0e5
DA
19975 "Sequence number of an entry\n"
19976 "Sequence number\n"
7336e101
SP
19977 "Specify community to reject\n"
19978 "Specify community to accept\n"
19979 COMMUNITY_VAL_STR)
718e3744 19980{
d62a17ae 19981 char *cl_name_or_number = NULL;
2f8cc0e5 19982 char *seq = NULL;
174b5cb9 19983 char *str = NULL;
d62a17ae 19984 int direct = 0;
19985 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 19986 int idx = 0;
174b5cb9 19987
a08032fe 19988 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19989 if (idx)
19990 seq = argv[idx]->arg;
19991
19992 idx = 0;
174b5cb9
DA
19993 argv_find(argv, argc, "permit", &idx);
19994 argv_find(argv, argc, "deny", &idx);
19995
19996 if (idx) {
19997 direct = argv_find(argv, argc, "permit", &idx)
19998 ? COMMUNITY_PERMIT
19999 : COMMUNITY_DENY;
20000
20001 idx = 0;
20002 argv_find(argv, argc, "AA:NN", &idx);
20003 str = argv_concat(argv, argc, idx);
7336e101 20004 }
174b5cb9
DA
20005
20006 idx = 0;
d62a17ae 20007 argv_find(argv, argc, "(100-500)", &idx);
20008 argv_find(argv, argc, "WORD", &idx);
20009 cl_name_or_number = argv[idx]->arg;
42f914d4 20010
2f8cc0e5 20011 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 20012 direct, style);
42f914d4 20013
d62a17ae 20014 XFREE(MTYPE_TMP, str);
daf9ddbb 20015
d62a17ae 20016 if (ret < 0) {
20017 community_list_perror(vty, ret);
20018 return CMD_WARNING_CONFIG_FAILED;
20019 }
42f914d4 20020
d62a17ae 20021 return CMD_SUCCESS;
718e3744 20022}
20023
36d4bb44
EB
20024ALIAS(no_community_list_expanded_all,
20025 no_bgp_community_list_expanded_all_list_cmd,
174b5cb9 20026 "no bgp community-list <(100-500)|expanded WORD>",
36d4bb44 20027 NO_STR BGP_STR COMMUNITY_LIST_STR
174b5cb9
DA
20028 "Community list number (expanded)\n"
20029 "Add an expanded community-list entry\n"
20030 "Community list name\n")
20031
8d9b8ed9
PM
20032/* Return configuration string of community-list entry. */
20033static const char *community_list_config_str(struct community_entry *entry)
20034{
20035 const char *str;
20036
20037 if (entry->any)
20038 str = "";
20039 else {
20040 if (entry->style == COMMUNITY_LIST_STANDARD)
20041 str = community_str(entry->u.com, false);
20042 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
20043 str = lcommunity_str(entry->u.lcom, false);
20044 else
20045 str = entry->config;
20046 }
20047 return str;
20048}
20049
d62a17ae 20050static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 20051{
d62a17ae 20052 struct community_entry *entry;
718e3744 20053
d62a17ae 20054 for (entry = list->head; entry; entry = entry->next) {
20055 if (entry == list->head) {
20056 if (all_digit(list->name))
20057 vty_out(vty, "Community %s list %s\n",
20058 entry->style == COMMUNITY_LIST_STANDARD
20059 ? "standard"
20060 : "(expanded) access",
20061 list->name);
20062 else
20063 vty_out(vty, "Named Community %s list %s\n",
20064 entry->style == COMMUNITY_LIST_STANDARD
20065 ? "standard"
20066 : "expanded",
20067 list->name);
20068 }
20069 if (entry->any)
20070 vty_out(vty, " %s\n",
20071 community_direct_str(entry->direct));
20072 else
20073 vty_out(vty, " %s %s\n",
20074 community_direct_str(entry->direct),
8d9b8ed9 20075 community_list_config_str(entry));
d62a17ae 20076 }
718e3744 20077}
20078
7336e101
SP
20079DEFUN (show_community_list,
20080 show_bgp_community_list_cmd,
20081 "show bgp community-list",
718e3744 20082 SHOW_STR
7336e101 20083 BGP_STR
718e3744 20084 "List community-list\n")
20085{
d62a17ae 20086 struct community_list *list;
20087 struct community_list_master *cm;
718e3744 20088
d62a17ae 20089 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20090 if (!cm)
20091 return CMD_SUCCESS;
718e3744 20092
d62a17ae 20093 for (list = cm->num.head; list; list = list->next)
20094 community_list_show(vty, list);
718e3744 20095
d62a17ae 20096 for (list = cm->str.head; list; list = list->next)
20097 community_list_show(vty, list);
718e3744 20098
d62a17ae 20099 return CMD_SUCCESS;
718e3744 20100}
20101
7336e101
SP
20102DEFUN (show_community_list_arg,
20103 show_bgp_community_list_arg_cmd,
960b69b9 20104 "show bgp community-list <(1-500)|WORD> detail",
7336e101
SP
20105 SHOW_STR
20106 BGP_STR
718e3744 20107 "List community-list\n"
20108 "Community-list number\n"
960b69b9 20109 "Community-list name\n"
20110 "Detailed information on community-list\n")
718e3744 20111{
d62a17ae 20112 int idx_comm_list = 3;
20113 struct community_list *list;
718e3744 20114
e237b0d2 20115 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 20116 COMMUNITY_LIST_MASTER);
20117 if (!list) {
20118 vty_out(vty, "%% Can't find community-list\n");
20119 return CMD_WARNING;
20120 }
718e3744 20121
d62a17ae 20122 community_list_show(vty, list);
718e3744 20123
d62a17ae 20124 return CMD_SUCCESS;
718e3744 20125}
6b0655a2 20126
57d187bc
JS
20127/*
20128 * Large Community code.
20129 */
d62a17ae 20130static int lcommunity_list_set_vty(struct vty *vty, int argc,
20131 struct cmd_token **argv, int style,
20132 int reject_all_digit_name)
20133{
20134 int ret;
20135 int direct;
20136 char *str;
20137 int idx = 0;
20138 char *cl_name;
2f8cc0e5
DA
20139 char *seq = NULL;
20140
a08032fe 20141 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 20142 seq = argv[idx]->arg;
d62a17ae 20143
2f8cc0e5 20144 idx = 0;
d62a17ae 20145 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20146 : COMMUNITY_DENY;
20147
20148 /* All digit name check. */
20149 idx = 0;
20150 argv_find(argv, argc, "WORD", &idx);
20151 argv_find(argv, argc, "(1-99)", &idx);
20152 argv_find(argv, argc, "(100-500)", &idx);
20153 cl_name = argv[idx]->arg;
20154 if (reject_all_digit_name && all_digit(cl_name)) {
20155 vty_out(vty, "%% Community name cannot have all digits\n");
20156 return CMD_WARNING_CONFIG_FAILED;
20157 }
20158
20159 idx = 0;
20160 argv_find(argv, argc, "AA:BB:CC", &idx);
20161 argv_find(argv, argc, "LINE", &idx);
20162 /* Concat community string argument. */
20163 if (idx)
20164 str = argv_concat(argv, argc, idx);
20165 else
20166 str = NULL;
20167
2f8cc0e5 20168 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
d62a17ae 20169
20170 /* Free temporary community list string allocated by
20171 argv_concat(). */
0a22ddfb 20172 XFREE(MTYPE_TMP, str);
d62a17ae 20173
20174 if (ret < 0) {
20175 community_list_perror(vty, ret);
20176 return CMD_WARNING_CONFIG_FAILED;
20177 }
20178 return CMD_SUCCESS;
20179}
20180
20181static int lcommunity_list_unset_vty(struct vty *vty, int argc,
20182 struct cmd_token **argv, int style)
20183{
20184 int ret;
20185 int direct = 0;
20186 char *str = NULL;
20187 int idx = 0;
2f8cc0e5 20188 char *seq = NULL;
d62a17ae 20189
a08032fe 20190 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 20191 seq = argv[idx]->arg;
d62a17ae 20192
2f8cc0e5 20193 idx = 0;
d62a17ae 20194 argv_find(argv, argc, "permit", &idx);
20195 argv_find(argv, argc, "deny", &idx);
20196
20197 if (idx) {
20198 /* Check the list direct. */
20199 if (strncmp(argv[idx]->arg, "p", 1) == 0)
20200 direct = COMMUNITY_PERMIT;
20201 else
20202 direct = COMMUNITY_DENY;
20203
20204 idx = 0;
20205 argv_find(argv, argc, "LINE", &idx);
20206 argv_find(argv, argc, "AA:AA:NN", &idx);
20207 /* Concat community string argument. */
20208 str = argv_concat(argv, argc, idx);
20209 }
20210
20211 idx = 0;
20212 argv_find(argv, argc, "(1-99)", &idx);
20213 argv_find(argv, argc, "(100-500)", &idx);
20214 argv_find(argv, argc, "WORD", &idx);
20215
20216 /* Unset community list. */
2f8cc0e5 20217 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
d62a17ae 20218 style);
20219
20220 /* Free temporary community list string allocated by
20221 argv_concat(). */
0a22ddfb 20222 XFREE(MTYPE_TMP, str);
d62a17ae 20223
20224 if (ret < 0) {
20225 community_list_perror(vty, ret);
20226 return CMD_WARNING_CONFIG_FAILED;
20227 }
20228
20229 return CMD_SUCCESS;
57d187bc
JS
20230}
20231
20232/* "large-community-list" keyword help string. */
20233#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
20234#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
20235
7336e101
SP
20236DEFUN (lcommunity_list_standard,
20237 bgp_lcommunity_list_standard_cmd,
a08032fe 20238 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
20239 BGP_STR
20240 LCOMMUNITY_LIST_STR
20241 "Large Community list number (standard)\n"
2f8cc0e5
DA
20242 "Sequence number of an entry\n"
20243 "Sequence number\n"
7336e101
SP
20244 "Specify large community to reject\n"
20245 "Specify large community to accept\n"
20246 LCOMMUNITY_VAL_STR)
52951b63 20247{
d62a17ae 20248 return lcommunity_list_set_vty(vty, argc, argv,
20249 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
20250}
20251
7336e101
SP
20252DEFUN (lcommunity_list_expanded,
20253 bgp_lcommunity_list_expanded_cmd,
a08032fe 20254 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20255 BGP_STR
20256 LCOMMUNITY_LIST_STR
20257 "Large Community list number (expanded)\n"
2f8cc0e5
DA
20258 "Sequence number of an entry\n"
20259 "Sequence number\n"
7336e101
SP
20260 "Specify large community to reject\n"
20261 "Specify large community to accept\n"
20262 "An ordered list as a regular-expression\n")
57d187bc 20263{
d62a17ae 20264 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 20265 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
20266}
20267
7336e101
SP
20268DEFUN (lcommunity_list_name_standard,
20269 bgp_lcommunity_list_name_standard_cmd,
a08032fe 20270 "bgp large-community-list standard WORD [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
20271 BGP_STR
20272 LCOMMUNITY_LIST_STR
20273 "Specify standard large-community-list\n"
20274 "Large Community list name\n"
2f8cc0e5
DA
20275 "Sequence number of an entry\n"
20276 "Sequence number\n"
7336e101
SP
20277 "Specify large community to reject\n"
20278 "Specify large community to accept\n"
20279 LCOMMUNITY_VAL_STR)
52951b63 20280{
d62a17ae 20281 return lcommunity_list_set_vty(vty, argc, argv,
20282 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
20283}
20284
7336e101
SP
20285DEFUN (lcommunity_list_name_expanded,
20286 bgp_lcommunity_list_name_expanded_cmd,
a08032fe 20287 "bgp large-community-list expanded WORD [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20288 BGP_STR
20289 LCOMMUNITY_LIST_STR
20290 "Specify expanded large-community-list\n"
20291 "Large Community list name\n"
2f8cc0e5
DA
20292 "Sequence number of an entry\n"
20293 "Sequence number\n"
7336e101
SP
20294 "Specify large community to reject\n"
20295 "Specify large community to accept\n"
20296 "An ordered list as a regular-expression\n")
57d187bc 20297{
d62a17ae 20298 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 20299 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
20300}
20301
4378f57c
DA
20302DEFUN (no_lcommunity_list_all,
20303 no_bgp_lcommunity_list_all_cmd,
7336e101
SP
20304 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
20305 NO_STR
20306 BGP_STR
20307 LCOMMUNITY_LIST_STR
20308 "Large Community list number (standard)\n"
20309 "Large Community list number (expanded)\n"
20310 "Large Community list name\n")
57d187bc 20311{
7336e101
SP
20312 return lcommunity_list_unset_vty(vty, argc, argv,
20313 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
20314}
20315
4378f57c
DA
20316DEFUN (no_lcommunity_list_name_standard_all,
20317 no_bgp_lcommunity_list_name_standard_all_cmd,
20318 "no bgp large-community-list standard WORD",
20319 NO_STR
20320 BGP_STR
20321 LCOMMUNITY_LIST_STR
20322 "Specify standard large-community-list\n"
20323 "Large Community list name\n")
20324{
20325 return lcommunity_list_unset_vty(vty, argc, argv,
20326 LARGE_COMMUNITY_LIST_STANDARD);
20327}
20328
7336e101
SP
20329DEFUN (no_lcommunity_list_name_expanded_all,
20330 no_bgp_lcommunity_list_name_expanded_all_cmd,
20331 "no bgp large-community-list expanded WORD",
20332 NO_STR
20333 BGP_STR
20334 LCOMMUNITY_LIST_STR
20335 "Specify expanded large-community-list\n"
20336 "Large Community list name\n")
57d187bc 20337{
d62a17ae 20338 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 20339 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
20340}
20341
7336e101
SP
20342DEFUN (no_lcommunity_list_standard,
20343 no_bgp_lcommunity_list_standard_cmd,
a08032fe 20344 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
20345 NO_STR
20346 BGP_STR
20347 LCOMMUNITY_LIST_STR
20348 "Large Community list number (standard)\n"
2f8cc0e5
DA
20349 "Sequence number of an entry\n"
20350 "Sequence number\n"
7336e101
SP
20351 "Specify large community to reject\n"
20352 "Specify large community to accept\n"
20353 LCOMMUNITY_VAL_STR)
57d187bc 20354{
d62a17ae 20355 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 20356 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
20357}
20358
7336e101
SP
20359DEFUN (no_lcommunity_list_expanded,
20360 no_bgp_lcommunity_list_expanded_cmd,
a08032fe 20361 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20362 NO_STR
20363 BGP_STR
20364 LCOMMUNITY_LIST_STR
20365 "Large Community list number (expanded)\n"
2f8cc0e5
DA
20366 "Sequence number of an entry\n"
20367 "Sequence number\n"
7336e101
SP
20368 "Specify large community to reject\n"
20369 "Specify large community to accept\n"
20370 "An ordered list as a regular-expression\n")
57d187bc 20371{
d62a17ae 20372 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 20373 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
20374}
20375
7336e101
SP
20376DEFUN (no_lcommunity_list_name_standard,
20377 no_bgp_lcommunity_list_name_standard_cmd,
a08032fe 20378 "no bgp large-community-list standard WORD [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
20379 NO_STR
20380 BGP_STR
20381 LCOMMUNITY_LIST_STR
20382 "Specify standard large-community-list\n"
20383 "Large Community list name\n"
2f8cc0e5
DA
20384 "Sequence number of an entry\n"
20385 "Sequence number\n"
7336e101
SP
20386 "Specify large community to reject\n"
20387 "Specify large community to accept\n"
20388 LCOMMUNITY_VAL_STR)
57d187bc 20389{
d62a17ae 20390 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 20391 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
20392}
20393
7336e101
SP
20394DEFUN (no_lcommunity_list_name_expanded,
20395 no_bgp_lcommunity_list_name_expanded_cmd,
a08032fe 20396 "no bgp large-community-list expanded WORD [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20397 NO_STR
20398 BGP_STR
20399 LCOMMUNITY_LIST_STR
20400 "Specify expanded large-community-list\n"
20401 "Large community list name\n"
2f8cc0e5
DA
20402 "Sequence number of an entry\n"
20403 "Sequence number\n"
7336e101
SP
20404 "Specify large community to reject\n"
20405 "Specify large community to accept\n"
20406 "An ordered list as a regular-expression\n")
57d187bc 20407{
d62a17ae 20408 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 20409 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
20410}
20411
d62a17ae 20412static void lcommunity_list_show(struct vty *vty, struct community_list *list)
20413{
20414 struct community_entry *entry;
20415
20416 for (entry = list->head; entry; entry = entry->next) {
20417 if (entry == list->head) {
20418 if (all_digit(list->name))
20419 vty_out(vty, "Large community %s list %s\n",
169b72c8 20420 entry->style ==
20421 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 20422 ? "standard"
20423 : "(expanded) access",
20424 list->name);
20425 else
20426 vty_out(vty,
20427 "Named large community %s list %s\n",
169b72c8 20428 entry->style ==
20429 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 20430 ? "standard"
20431 : "expanded",
20432 list->name);
20433 }
20434 if (entry->any)
20435 vty_out(vty, " %s\n",
20436 community_direct_str(entry->direct));
20437 else
20438 vty_out(vty, " %s %s\n",
20439 community_direct_str(entry->direct),
8d9b8ed9 20440 community_list_config_str(entry));
d62a17ae 20441 }
57d187bc
JS
20442}
20443
7336e101
SP
20444DEFUN (show_lcommunity_list,
20445 show_bgp_lcommunity_list_cmd,
20446 "show bgp large-community-list",
57d187bc 20447 SHOW_STR
7336e101 20448 BGP_STR
57d187bc
JS
20449 "List large-community list\n")
20450{
d62a17ae 20451 struct community_list *list;
20452 struct community_list_master *cm;
57d187bc 20453
d62a17ae 20454 cm = community_list_master_lookup(bgp_clist,
20455 LARGE_COMMUNITY_LIST_MASTER);
20456 if (!cm)
20457 return CMD_SUCCESS;
57d187bc 20458
d62a17ae 20459 for (list = cm->num.head; list; list = list->next)
20460 lcommunity_list_show(vty, list);
57d187bc 20461
d62a17ae 20462 for (list = cm->str.head; list; list = list->next)
20463 lcommunity_list_show(vty, list);
57d187bc 20464
d62a17ae 20465 return CMD_SUCCESS;
57d187bc
JS
20466}
20467
7336e101
SP
20468DEFUN (show_lcommunity_list_arg,
20469 show_bgp_lcommunity_list_arg_cmd,
960b69b9 20470 "show bgp large-community-list <(1-500)|WORD> detail",
7336e101
SP
20471 SHOW_STR
20472 BGP_STR
57d187bc 20473 "List large-community list\n"
960b69b9 20474 "Large-community-list number\n"
20475 "Large-community-list name\n"
20476 "Detailed information on large-community-list\n")
57d187bc 20477{
d62a17ae 20478 struct community_list *list;
57d187bc 20479
e237b0d2 20480 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
d62a17ae 20481 LARGE_COMMUNITY_LIST_MASTER);
20482 if (!list) {
960b69b9 20483 vty_out(vty, "%% Can't find large-community-list\n");
d62a17ae 20484 return CMD_WARNING;
20485 }
57d187bc 20486
d62a17ae 20487 lcommunity_list_show(vty, list);
57d187bc 20488
d62a17ae 20489 return CMD_SUCCESS;
57d187bc
JS
20490}
20491
718e3744 20492/* "extcommunity-list" keyword help string. */
20493#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
20494#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
20495
7336e101
SP
20496DEFUN (extcommunity_list_standard,
20497 bgp_extcommunity_list_standard_cmd,
a08032fe 20498 "bgp extcommunity-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 20499 BGP_STR
718e3744 20500 EXTCOMMUNITY_LIST_STR
20501 "Extended Community list number (standard)\n"
718e3744 20502 "Specify standard extcommunity-list\n"
5bf15956 20503 "Community list name\n"
2f8cc0e5
DA
20504 "Sequence number of an entry\n"
20505 "Sequence number\n"
718e3744 20506 "Specify community to reject\n"
20507 "Specify community to accept\n"
20508 EXTCOMMUNITY_VAL_STR)
20509{
d62a17ae 20510 int style = EXTCOMMUNITY_LIST_STANDARD;
20511 int direct = 0;
20512 char *cl_number_or_name = NULL;
2f8cc0e5 20513 char *seq = NULL;
42f914d4 20514
d62a17ae 20515 int idx = 0;
7b9a4750 20516
d62a17ae 20517 argv_find(argv, argc, "(1-99)", &idx);
20518 argv_find(argv, argc, "WORD", &idx);
20519 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 20520
a08032fe 20521 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20522 seq = argv[idx]->arg;
20523
d62a17ae 20524 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20525 : COMMUNITY_DENY;
20526 argv_find(argv, argc, "AA:NN", &idx);
20527 char *str = argv_concat(argv, argc, idx);
42f914d4 20528
2f8cc0e5 20529 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 20530 direct, style);
42f914d4 20531
d62a17ae 20532 XFREE(MTYPE_TMP, str);
42f914d4 20533
d62a17ae 20534 if (ret < 0) {
20535 community_list_perror(vty, ret);
20536 return CMD_WARNING_CONFIG_FAILED;
20537 }
42f914d4 20538
d62a17ae 20539 return CMD_SUCCESS;
718e3744 20540}
20541
7336e101
SP
20542DEFUN (extcommunity_list_name_expanded,
20543 bgp_extcommunity_list_name_expanded_cmd,
a08032fe 20544 "bgp extcommunity-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20545 BGP_STR
20546 EXTCOMMUNITY_LIST_STR
5bf15956 20547 "Extended Community list number (expanded)\n"
718e3744 20548 "Specify expanded extcommunity-list\n"
20549 "Extended Community list name\n"
2f8cc0e5
DA
20550 "Sequence number of an entry\n"
20551 "Sequence number\n"
718e3744 20552 "Specify community to reject\n"
20553 "Specify community to accept\n"
20554 "An ordered list as a regular-expression\n")
20555{
d62a17ae 20556 int style = EXTCOMMUNITY_LIST_EXPANDED;
20557 int direct = 0;
20558 char *cl_number_or_name = NULL;
2f8cc0e5 20559 char *seq = NULL;
d62a17ae 20560 int idx = 0;
7336e101 20561
d62a17ae 20562 argv_find(argv, argc, "(100-500)", &idx);
20563 argv_find(argv, argc, "WORD", &idx);
20564 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 20565
a08032fe 20566 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20567 seq = argv[idx]->arg;
20568
d62a17ae 20569 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20570 : COMMUNITY_DENY;
20571 argv_find(argv, argc, "LINE", &idx);
20572 char *str = argv_concat(argv, argc, idx);
42f914d4 20573
2f8cc0e5 20574 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 20575 direct, style);
42f914d4 20576
d62a17ae 20577 XFREE(MTYPE_TMP, str);
42f914d4 20578
d62a17ae 20579 if (ret < 0) {
20580 community_list_perror(vty, ret);
20581 return CMD_WARNING_CONFIG_FAILED;
20582 }
42f914d4 20583
d62a17ae 20584 return CMD_SUCCESS;
718e3744 20585}
20586
7336e101
SP
20587DEFUN (no_extcommunity_list_standard_all,
20588 no_bgp_extcommunity_list_standard_all_cmd,
a08032fe 20589 "no bgp extcommunity-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
20590 NO_STR
20591 BGP_STR
20592 EXTCOMMUNITY_LIST_STR
813d4307 20593 "Extended Community list number (standard)\n"
718e3744 20594 "Specify standard extcommunity-list\n"
5bf15956 20595 "Community list name\n"
2f8cc0e5
DA
20596 "Sequence number of an entry\n"
20597 "Sequence number\n"
718e3744 20598 "Specify community to reject\n"
20599 "Specify community to accept\n"
20600 EXTCOMMUNITY_VAL_STR)
20601{
d62a17ae 20602 int style = EXTCOMMUNITY_LIST_STANDARD;
20603 int direct = 0;
20604 char *cl_number_or_name = NULL;
d4455c89 20605 char *str = NULL;
2f8cc0e5 20606 char *seq = NULL;
d62a17ae 20607 int idx = 0;
d4455c89 20608
a08032fe 20609 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20610 seq = argv[idx]->arg;
20611
20612 idx = 0;
d4455c89
DA
20613 argv_find(argv, argc, "permit", &idx);
20614 argv_find(argv, argc, "deny", &idx);
d4455c89
DA
20615 if (idx) {
20616 direct = argv_find(argv, argc, "permit", &idx)
20617 ? COMMUNITY_PERMIT
20618 : COMMUNITY_DENY;
20619
20620 idx = 0;
20621 argv_find(argv, argc, "AA:NN", &idx);
20622 str = argv_concat(argv, argc, idx);
20623 }
20624
20625 idx = 0;
d62a17ae 20626 argv_find(argv, argc, "(1-99)", &idx);
20627 argv_find(argv, argc, "WORD", &idx);
20628 cl_number_or_name = argv[idx]->arg;
42f914d4 20629
d62a17ae 20630 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 20631 seq, direct, style);
42f914d4 20632
d62a17ae 20633 XFREE(MTYPE_TMP, str);
42f914d4 20634
d62a17ae 20635 if (ret < 0) {
20636 community_list_perror(vty, ret);
20637 return CMD_WARNING_CONFIG_FAILED;
20638 }
42f914d4 20639
d62a17ae 20640 return CMD_SUCCESS;
718e3744 20641}
20642
d4455c89
DA
20643ALIAS(no_extcommunity_list_standard_all,
20644 no_bgp_extcommunity_list_standard_all_list_cmd,
20645 "no bgp extcommunity-list <(1-99)|standard WORD>",
36d4bb44 20646 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
20647 "Extended Community list number (standard)\n"
20648 "Specify standard extcommunity-list\n"
20649 "Community list name\n")
20650
7336e101
SP
20651DEFUN (no_extcommunity_list_expanded_all,
20652 no_bgp_extcommunity_list_expanded_all_cmd,
a08032fe 20653 "no bgp extcommunity-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20654 NO_STR
20655 BGP_STR
20656 EXTCOMMUNITY_LIST_STR
718e3744 20657 "Extended Community list number (expanded)\n"
718e3744 20658 "Specify expanded extcommunity-list\n"
5bf15956 20659 "Extended Community list name\n"
2f8cc0e5
DA
20660 "Sequence number of an entry\n"
20661 "Sequence number\n"
718e3744 20662 "Specify community to reject\n"
20663 "Specify community to accept\n"
20664 "An ordered list as a regular-expression\n")
20665{
d62a17ae 20666 int style = EXTCOMMUNITY_LIST_EXPANDED;
20667 int direct = 0;
20668 char *cl_number_or_name = NULL;
d4455c89 20669 char *str = NULL;
2f8cc0e5 20670 char *seq = NULL;
d62a17ae 20671 int idx = 0;
d4455c89 20672
a08032fe 20673 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20674 seq = argv[idx]->arg;
20675
20676 idx = 0;
d4455c89
DA
20677 argv_find(argv, argc, "permit", &idx);
20678 argv_find(argv, argc, "deny", &idx);
20679
20680 if (idx) {
20681 direct = argv_find(argv, argc, "permit", &idx)
20682 ? COMMUNITY_PERMIT
20683 : COMMUNITY_DENY;
20684
20685 idx = 0;
20686 argv_find(argv, argc, "LINE", &idx);
20687 str = argv_concat(argv, argc, idx);
20688 }
20689
20690 idx = 0;
d62a17ae 20691 argv_find(argv, argc, "(100-500)", &idx);
20692 argv_find(argv, argc, "WORD", &idx);
20693 cl_number_or_name = argv[idx]->arg;
42f914d4 20694
d62a17ae 20695 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 20696 seq, direct, style);
42f914d4 20697
d62a17ae 20698 XFREE(MTYPE_TMP, str);
42f914d4 20699
d62a17ae 20700 if (ret < 0) {
20701 community_list_perror(vty, ret);
20702 return CMD_WARNING_CONFIG_FAILED;
20703 }
42f914d4 20704
d62a17ae 20705 return CMD_SUCCESS;
718e3744 20706}
20707
d4455c89
DA
20708ALIAS(no_extcommunity_list_expanded_all,
20709 no_bgp_extcommunity_list_expanded_all_list_cmd,
20710 "no bgp extcommunity-list <(100-500)|expanded WORD>",
36d4bb44 20711 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
20712 "Extended Community list number (expanded)\n"
20713 "Specify expanded extcommunity-list\n"
20714 "Extended Community list name\n")
20715
d62a17ae 20716static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 20717{
d62a17ae 20718 struct community_entry *entry;
718e3744 20719
d62a17ae 20720 for (entry = list->head; entry; entry = entry->next) {
20721 if (entry == list->head) {
20722 if (all_digit(list->name))
20723 vty_out(vty, "Extended community %s list %s\n",
20724 entry->style == EXTCOMMUNITY_LIST_STANDARD
20725 ? "standard"
20726 : "(expanded) access",
20727 list->name);
20728 else
20729 vty_out(vty,
20730 "Named extended community %s list %s\n",
20731 entry->style == EXTCOMMUNITY_LIST_STANDARD
20732 ? "standard"
20733 : "expanded",
20734 list->name);
20735 }
20736 if (entry->any)
20737 vty_out(vty, " %s\n",
20738 community_direct_str(entry->direct));
20739 else
20740 vty_out(vty, " %s %s\n",
20741 community_direct_str(entry->direct),
8d9b8ed9 20742 community_list_config_str(entry));
d62a17ae 20743 }
718e3744 20744}
20745
7336e101
SP
20746DEFUN (show_extcommunity_list,
20747 show_bgp_extcommunity_list_cmd,
20748 "show bgp extcommunity-list",
718e3744 20749 SHOW_STR
7336e101 20750 BGP_STR
718e3744 20751 "List extended-community list\n")
20752{
d62a17ae 20753 struct community_list *list;
20754 struct community_list_master *cm;
718e3744 20755
d62a17ae 20756 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20757 if (!cm)
20758 return CMD_SUCCESS;
718e3744 20759
d62a17ae 20760 for (list = cm->num.head; list; list = list->next)
20761 extcommunity_list_show(vty, list);
718e3744 20762
d62a17ae 20763 for (list = cm->str.head; list; list = list->next)
20764 extcommunity_list_show(vty, list);
718e3744 20765
d62a17ae 20766 return CMD_SUCCESS;
718e3744 20767}
20768
7336e101
SP
20769DEFUN (show_extcommunity_list_arg,
20770 show_bgp_extcommunity_list_arg_cmd,
960b69b9 20771 "show bgp extcommunity-list <(1-500)|WORD> detail",
7336e101
SP
20772 SHOW_STR
20773 BGP_STR
718e3744 20774 "List extended-community list\n"
20775 "Extcommunity-list number\n"
960b69b9 20776 "Extcommunity-list name\n"
20777 "Detailed information on extcommunity-list\n")
718e3744 20778{
d62a17ae 20779 int idx_comm_list = 3;
20780 struct community_list *list;
718e3744 20781
e237b0d2 20782 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 20783 EXTCOMMUNITY_LIST_MASTER);
20784 if (!list) {
20785 vty_out(vty, "%% Can't find extcommunity-list\n");
20786 return CMD_WARNING;
20787 }
718e3744 20788
d62a17ae 20789 extcommunity_list_show(vty, list);
718e3744 20790
d62a17ae 20791 return CMD_SUCCESS;
718e3744 20792}
6b0655a2 20793
718e3744 20794/* Display community-list and extcommunity-list configuration. */
d62a17ae 20795static int community_list_config_write(struct vty *vty)
20796{
20797 struct community_list *list;
20798 struct community_entry *entry;
20799 struct community_list_master *cm;
20800 int write = 0;
20801
20802 /* Community-list. */
20803 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20804
20805 for (list = cm->num.head; list; list = list->next)
20806 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20807 vty_out(vty,
20808 "bgp community-list %s seq %" PRId64 " %s %s\n",
20809 list->name, entry->seq,
d62a17ae 20810 community_direct_str(entry->direct),
20811 community_list_config_str(entry));
20812 write++;
20813 }
20814 for (list = cm->str.head; list; list = list->next)
20815 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20816 vty_out(vty,
20817 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
d62a17ae 20818 entry->style == COMMUNITY_LIST_STANDARD
20819 ? "standard"
20820 : "expanded",
2f8cc0e5
DA
20821 list->name, entry->seq,
20822 community_direct_str(entry->direct),
d62a17ae 20823 community_list_config_str(entry));
20824 write++;
20825 }
20826
20827 /* Extcommunity-list. */
20828 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20829
20830 for (list = cm->num.head; list; list = list->next)
20831 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20832 vty_out(vty,
20833 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
20834 list->name, entry->seq,
20835 community_direct_str(entry->direct),
d62a17ae 20836 community_list_config_str(entry));
20837 write++;
20838 }
20839 for (list = cm->str.head; list; list = list->next)
20840 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20841 vty_out(vty,
6cde4b45 20842 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
d62a17ae 20843 entry->style == EXTCOMMUNITY_LIST_STANDARD
20844 ? "standard"
20845 : "expanded",
2f8cc0e5
DA
20846 list->name, entry->seq,
20847 community_direct_str(entry->direct),
d62a17ae 20848 community_list_config_str(entry));
20849 write++;
20850 }
20851
20852
20853 /* lcommunity-list. */
20854 cm = community_list_master_lookup(bgp_clist,
20855 LARGE_COMMUNITY_LIST_MASTER);
20856
20857 for (list = cm->num.head; list; list = list->next)
20858 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20859 vty_out(vty,
6cde4b45 20860 "bgp large-community-list %s seq %" PRId64" %s %s\n",
2f8cc0e5
DA
20861 list->name, entry->seq,
20862 community_direct_str(entry->direct),
d62a17ae 20863 community_list_config_str(entry));
20864 write++;
20865 }
20866 for (list = cm->str.head; list; list = list->next)
20867 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20868 vty_out(vty,
6cde4b45 20869 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
2f8cc0e5 20870
d62a17ae 20871 entry->style == LARGE_COMMUNITY_LIST_STANDARD
20872 ? "standard"
20873 : "expanded",
2f8cc0e5 20874 list->name, entry->seq, community_direct_str(entry->direct),
d62a17ae 20875 community_list_config_str(entry));
20876 write++;
20877 }
20878
20879 return write;
20880}
20881
612c2c15 20882static int community_list_config_write(struct vty *vty);
d62a17ae 20883static struct cmd_node community_list_node = {
f4b8291f 20884 .name = "community list",
62b346ee
DL
20885 .node = COMMUNITY_LIST_NODE,
20886 .prompt = "",
612c2c15 20887 .config_write = community_list_config_write,
718e3744 20888};
20889
d62a17ae 20890static void community_list_vty(void)
20891{
612c2c15 20892 install_node(&community_list_node);
d62a17ae 20893
20894 /* Community-list. */
7336e101
SP
20895 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
20896 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
20897 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 20898 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 20899 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 20900 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
20901 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
20902 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 20903
20904 /* Extcommunity-list. */
7336e101
SP
20905 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
20906 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
20907 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
d4455c89
DA
20908 install_element(CONFIG_NODE,
20909 &no_bgp_extcommunity_list_standard_all_list_cmd);
7336e101 20910 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
d4455c89
DA
20911 install_element(CONFIG_NODE,
20912 &no_bgp_extcommunity_list_expanded_all_list_cmd);
7336e101
SP
20913 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
20914 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 20915
20916 /* Large Community List */
7336e101 20917 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
7336e101
SP
20918 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
20919 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
7336e101 20920 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
4378f57c
DA
20921 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
20922 install_element(CONFIG_NODE,
20923 &no_bgp_lcommunity_list_name_standard_all_cmd);
7336e101
SP
20924 install_element(CONFIG_NODE,
20925 &no_bgp_lcommunity_list_name_expanded_all_cmd);
20926 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
20927 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
20928 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
20929 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
20930 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
20931 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
5bf15956 20932}
ed0e57e3
DA
20933
20934static struct cmd_node community_alias_node = {
20935 .name = "community alias",
20936 .node = COMMUNITY_ALIAS_NODE,
20937 .prompt = "",
20938 .config_write = bgp_community_alias_write,
20939};
20940
20941void community_alias_vty(void)
20942{
20943 install_node(&community_alias_node);
20944
20945 /* Community-list. */
20946 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
20947}