]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
doc: Add `show bgp summary wide` short description
[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"
5cb5f4d0 25#include "lib_errors.h"
ec0ab544 26#include "lib/zclient.h"
718e3744 27#include "prefix.h"
28#include "plist.h"
29#include "buffer.h"
30#include "linklist.h"
31#include "stream.h"
32#include "thread.h"
33#include "log.h"
3b8b1855 34#include "memory.h"
1c0d8808 35#include "lib_vty.h"
4bf6a362 36#include "hash.h"
3f9c7369 37#include "queue.h"
039f3a34 38#include "filter.h"
5d5ba018 39#include "frrstr.h"
718e3744 40
41#include "bgpd/bgpd.h"
48ecf8f5 42#include "bgpd/bgp_attr_evpn.h"
4bf6a362 43#include "bgpd/bgp_advertise.h"
718e3744 44#include "bgpd/bgp_attr.h"
45#include "bgpd/bgp_aspath.h"
46#include "bgpd/bgp_community.h"
4bf6a362 47#include "bgpd/bgp_ecommunity.h"
57d187bc 48#include "bgpd/bgp_lcommunity.h"
4bf6a362 49#include "bgpd/bgp_damp.h"
718e3744 50#include "bgpd/bgp_debug.h"
14454c9f 51#include "bgpd/bgp_errors.h"
e0701b79 52#include "bgpd/bgp_fsm.h"
4bf6a362 53#include "bgpd/bgp_nexthop.h"
718e3744 54#include "bgpd/bgp_open.h"
4bf6a362 55#include "bgpd/bgp_regex.h"
718e3744 56#include "bgpd/bgp_route.h"
c016b6c7 57#include "bgpd/bgp_mplsvpn.h"
718e3744 58#include "bgpd/bgp_zebra.h"
fee0f4c6 59#include "bgpd/bgp_table.h"
94f2b392 60#include "bgpd/bgp_vty.h"
165b5fff 61#include "bgpd/bgp_mpath.h"
cb1faec9 62#include "bgpd/bgp_packet.h"
3f9c7369 63#include "bgpd/bgp_updgrp.h"
c43ed2e4 64#include "bgpd/bgp_bfd.h"
555e09d4 65#include "bgpd/bgp_io.h"
94c2f693 66#include "bgpd/bgp_evpn.h"
dd65f45e 67#include "bgpd/bgp_evpn_vty.h"
b5e140c8 68#include "bgpd/bgp_evpn_mh.h"
dcc68b5e 69#include "bgpd/bgp_addpath.h"
48ecf8f5 70#include "bgpd/bgp_mac.h"
dd65f45e 71#include "bgpd/bgp_flowspec.h"
49e5a4a0 72#ifdef ENABLE_BGP_VNC
dd65f45e
DL
73#include "bgpd/rfapi/bgp_rfapi_cfg.h"
74#endif
75
ff8a8a7a
CS
76#include "northbound.h"
77#include "northbound_cli.h"
78#include "bgpd/bgp_nb.h"
79
80
5d5393b9 81FRR_CFG_DEFAULT_BOOL(BGP_IMPORT_CHECK,
62282e83
DS
82 {
83 .val_bool = false,
84 .match_profile = "traditional",
85 .match_version = "< 7.4",
86 },
87 { .val_bool = true },
5d5393b9
DL
88)
89FRR_CFG_DEFAULT_BOOL(BGP_SHOW_HOSTNAME,
4c1458b5
DL
90 { .val_bool = true, .match_profile = "datacenter", },
91 { .val_bool = false },
5d5393b9 92)
aef999a2
DA
93FRR_CFG_DEFAULT_BOOL(BGP_SHOW_NEXTHOP_HOSTNAME,
94 { .val_bool = true, .match_profile = "datacenter", },
95 { .val_bool = false },
96)
5d5393b9 97FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
4c1458b5
DL
98 { .val_bool = true, .match_profile = "datacenter", },
99 { .val_bool = false },
5d5393b9
DL
100)
101FRR_CFG_DEFAULT_BOOL(BGP_DETERMINISTIC_MED,
4c1458b5
DL
102 { .val_bool = true, .match_profile = "datacenter", },
103 { .val_bool = false },
5d5393b9
DL
104)
105FRR_CFG_DEFAULT_ULONG(BGP_CONNECT_RETRY,
106 { .val_ulong = 10, .match_profile = "datacenter", },
107 { .val_ulong = 120 },
108)
109FRR_CFG_DEFAULT_ULONG(BGP_HOLDTIME,
110 { .val_ulong = 9, .match_profile = "datacenter", },
111 { .val_ulong = 180 },
112)
113FRR_CFG_DEFAULT_ULONG(BGP_KEEPALIVE,
114 { .val_ulong = 3, .match_profile = "datacenter", },
115 { .val_ulong = 60 },
116)
1d3fdccf
DA
117FRR_CFG_DEFAULT_BOOL(BGP_EBGP_REQUIRES_POLICY,
118 { .val_bool = false, .match_profile = "datacenter", },
119 { .val_bool = false, .match_version = "< 7.4", },
120 { .val_bool = true },
121)
2adac256
DA
122FRR_CFG_DEFAULT_BOOL(BGP_SUPPRESS_DUPLICATES,
123 { .val_bool = false, .match_version = "< 7.6", },
124 { .val_bool = true },
125)
5d5393b9 126
dd65f45e
DL
127DEFINE_HOOK(bgp_inst_config_write,
128 (struct bgp *bgp, struct vty *vty),
129 (bgp, vty))
718e3744 130
36235319
QY
131#define GR_NO_OPER \
132 "The Graceful Restart No Operation was executed as cmd same as previous one."
133#define GR_INVALID \
134 "The Graceful Restart command used is not valid at this moment."
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
5d5393b9
DL
473int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
474 enum bgp_instance_type inst_type)
475{
476 int ret = bgp_get(bgp, as, name, inst_type);
477
478 if (ret == BGP_CREATED) {
479 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
d43114f3 480 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
5d5393b9
DL
481
482 if (DFLT_BGP_IMPORT_CHECK)
892fedb6 483 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
5d5393b9 484 if (DFLT_BGP_SHOW_HOSTNAME)
892fedb6 485 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
aef999a2
DA
486 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
487 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
5d5393b9 488 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
892fedb6 489 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
5d5393b9 490 if (DFLT_BGP_DETERMINISTIC_MED)
892fedb6 491 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
1d3fdccf
DA
492 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
493 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2adac256
DA
494 if (DFLT_BGP_SUPPRESS_DUPLICATES)
495 SET_FLAG((*bgp)->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
5d5393b9
DL
496
497 ret = BGP_SUCCESS;
498 }
499 return ret;
500}
501
7eeee51e 502/*
f212a857 503 * bgp_vty_find_and_parse_afi_safi_bgp
7eeee51e 504 *
f212a857
DS
505 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
506 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
7eeee51e
DS
507 * to appropriate values for the calling function. This is to allow the
508 * calling function to make decisions appropriate for the show command
509 * that is being parsed.
510 *
511 * The show commands are generally of the form:
d62a17ae 512 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
513 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
7eeee51e
DS
514 *
515 * Since we use argv_find if the show command in particular doesn't have:
516 * [ip]
18c57037 517 * [<view|vrf> VIEWVRFNAME]
375a2e67 518 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
7eeee51e
DS
519 * The command parsing should still be ok.
520 *
521 * vty -> The vty for the command so we can output some useful data in
522 * the event of a parse error in the vrf.
523 * argv -> The command tokens
524 * argc -> How many command tokens we have
d62a17ae 525 * idx -> The current place in the command, generally should be 0 for this
526 * function
7eeee51e
DS
527 * afi -> The parsed afi if it was included in the show command, returned here
528 * safi -> The parsed safi if it was included in the show command, returned here
f212a857 529 * bgp -> Pointer to the bgp data structure we need to fill in.
52e5b8c4 530 * use_json -> json is configured or not
7eeee51e
DS
531 *
532 * The function returns the correct location in the parse tree for the
533 * last token found.
0e37c258
DS
534 *
535 * Returns 0 for failure to parse correctly, else the idx position of where
536 * it found the last token.
7eeee51e 537 */
d62a17ae 538int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
539 struct cmd_token **argv, int argc,
540 int *idx, afi_t *afi, safi_t *safi,
9f049418 541 struct bgp **bgp, bool use_json)
d62a17ae 542{
543 char *vrf_name = NULL;
544
545 assert(afi);
546 assert(safi);
547 assert(bgp);
548
549 if (argv_find(argv, argc, "ip", idx))
550 *afi = AFI_IP;
551
9a8bdf1c 552 if (argv_find(argv, argc, "view", idx))
d62a17ae 553 vrf_name = argv[*idx + 1]->arg;
9a8bdf1c
PG
554 else if (argv_find(argv, argc, "vrf", idx)) {
555 vrf_name = argv[*idx + 1]->arg;
556 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
557 vrf_name = NULL;
558 }
559 if (vrf_name) {
d62a17ae 560 if (strmatch(vrf_name, "all"))
561 *bgp = NULL;
562 else {
563 *bgp = bgp_lookup_by_name(vrf_name);
564 if (!*bgp) {
52e5b8c4
SP
565 if (use_json) {
566 json_object *json = NULL;
567 json = json_object_new_object();
568 json_object_string_add(
569 json, "warning",
570 "View/Vrf is unknown");
571 vty_out(vty, "%s\n",
572 json_object_to_json_string_ext(json,
573 JSON_C_TO_STRING_PRETTY));
574 json_object_free(json);
575 }
ca61fd25
DS
576 else
577 vty_out(vty, "View/Vrf %s is unknown\n",
578 vrf_name);
d62a17ae 579 *idx = 0;
580 return 0;
581 }
582 }
583 } else {
584 *bgp = bgp_get_default();
585 if (!*bgp) {
52e5b8c4
SP
586 if (use_json) {
587 json_object *json = NULL;
588 json = json_object_new_object();
589 json_object_string_add(
590 json, "warning",
591 "Default BGP instance not found");
592 vty_out(vty, "%s\n",
593 json_object_to_json_string_ext(json,
594 JSON_C_TO_STRING_PRETTY));
595 json_object_free(json);
596 }
ca61fd25
DS
597 else
598 vty_out(vty,
599 "Default BGP instance not found\n");
d62a17ae 600 *idx = 0;
601 return 0;
602 }
603 }
604
605 if (argv_find_and_parse_afi(argv, argc, idx, afi))
606 argv_find_and_parse_safi(argv, argc, idx, safi);
607
608 *idx += 1;
609 return *idx;
610}
611
f4b8ec07 612bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
d62a17ae 613{
614 struct interface *ifp = NULL;
615
616 if (su->sa.sa_family == AF_INET)
617 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
618 else if (su->sa.sa_family == AF_INET6)
619 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
620 su->sin6.sin6_scope_id,
621 bgp->vrf_id);
622
623 if (ifp)
3dc339cd 624 return true;
d62a17ae 625
3dc339cd 626 return false;
718e3744 627}
628
718e3744 629/* Utility function for looking up peer or peer group. */
f14e6fdb
DS
630/* This is used only for configuration, so disallow if attempted on
631 * a dynamic neighbor.
632 */
d62a17ae 633struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
634{
635 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
636 int ret;
637 union sockunion su;
638 struct peer *peer = NULL;
639 struct peer_group *group = NULL;
640
641 if (!bgp) {
642 return NULL;
643 }
644
645 ret = str2sockunion(peer_str, &su);
646 if (ret == 0) {
647 /* IP address, locate peer. */
648 peer = peer_lookup(bgp, &su);
649 } else {
650 /* Not IP, could match either peer configured on interface or a
651 * group. */
652 peer = peer_lookup_by_conf_if(bgp, peer_str);
653 if (!peer)
654 group = peer_group_lookup(bgp, peer_str);
655 }
656
657 if (peer) {
658 if (peer_dynamic_neighbor(peer)) {
659 vty_out(vty,
660 "%% Operation not allowed on a dynamic neighbor\n");
661 return NULL;
662 }
663
664 return peer;
665 }
666
667 if (group)
668 return group->conf;
669
670 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
671
672 return NULL;
673}
674
f4b8ec07
CS
675int bgp_nb_errmsg_return(char *errmsg, size_t errmsg_len, int ret)
676{
677 const char *str = NULL;
678
679 switch (ret) {
680 case BGP_ERR_INVALID_VALUE:
681 str = "Invalid value";
682 break;
683 case BGP_ERR_INVALID_FLAG:
684 str = "Invalid flag";
685 break;
686 case BGP_ERR_PEER_GROUP_SHUTDOWN:
687 str = "Peer-group has been shutdown. Activate the peer-group first";
688 break;
689 case BGP_ERR_PEER_FLAG_CONFLICT:
690 str = "Can't set override-capability and strict-capability-match at the same time";
691 break;
692 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
693 str = "Specify remote-as or peer-group remote AS first";
694 break;
695 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
696 str = "Cannot change the peer-group. Deconfigure first";
697 break;
698 case BGP_ERR_PEER_GROUP_MISMATCH:
699 str = "Peer is not a member of this peer-group";
700 break;
701 case BGP_ERR_PEER_FILTER_CONFLICT:
702 str = "Prefix/distribute list can not co-exist";
703 break;
704 case BGP_ERR_NOT_INTERNAL_PEER:
705 str = "Invalid command. Not an internal neighbor";
706 break;
707 case BGP_ERR_REMOVE_PRIVATE_AS:
708 str = "remove-private-AS cannot be configured for IBGP peers";
709 break;
710 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
711 str = "Local-AS allowed only for EBGP peers";
712 break;
713 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
714 str = "Cannot have local-as same as BGP AS number";
715 break;
716 case BGP_ERR_TCPSIG_FAILED:
717 str = "Error while applying TCP-Sig to session(s)";
718 break;
719 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
720 str = "ebgp-multihop and ttl-security cannot be configured together";
721 break;
722 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
723 str = "ttl-security only allowed for EBGP peers";
724 break;
725 case BGP_ERR_AS_OVERRIDE:
726 str = "as-override cannot be configured for IBGP peers";
727 break;
728 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
729 str = "Invalid limit for number of dynamic neighbors";
730 break;
731 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
732 str = "Dynamic neighbor listen range already exists";
733 break;
734 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
735 str = "Operation not allowed on a dynamic neighbor";
736 break;
737 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
738 str = "Operation not allowed on a directly connected neighbor";
739 break;
740 case BGP_ERR_PEER_SAFI_CONFLICT:
741 str = GR_INVALID;
742 break;
743 case BGP_ERR_GR_INVALID_CMD:
744 str = "The Graceful Restart command used is not valid at this moment.";
745 break;
746 case BGP_ERR_GR_OPERATION_FAILED:
747 str = "The Graceful Restart Operation failed due to an err.";
748 break;
749 case BGP_GR_NO_OPERATION:
750 str = GR_NO_OPER;
751 break;
752 case BGP_ERR_PEER_GROUP_MEMBER:
753 str = "Peer-group member cannot override remote-as of peer-group";
754 break;
755 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
756 str = "Peer-group members must be all internal or all external";
757 break;
758 }
759 if (str) {
760 snprintf(errmsg, errmsg_len, "%s", str);
761 return -1;
762 }
763
764 return 0;
765}
766
d62a17ae 767int bgp_vty_return(struct vty *vty, int ret)
768{
769 const char *str = NULL;
770
771 switch (ret) {
772 case BGP_ERR_INVALID_VALUE:
773 str = "Invalid value";
774 break;
775 case BGP_ERR_INVALID_FLAG:
776 str = "Invalid flag";
777 break;
778 case BGP_ERR_PEER_GROUP_SHUTDOWN:
779 str = "Peer-group has been shutdown. Activate the peer-group first";
780 break;
781 case BGP_ERR_PEER_FLAG_CONFLICT:
782 str = "Can't set override-capability and strict-capability-match at the same time";
783 break;
784 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
785 str = "Specify remote-as or peer-group remote AS first";
786 break;
787 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
788 str = "Cannot change the peer-group. Deconfigure first";
789 break;
790 case BGP_ERR_PEER_GROUP_MISMATCH:
791 str = "Peer is not a member of this peer-group";
792 break;
793 case BGP_ERR_PEER_FILTER_CONFLICT:
794 str = "Prefix/distribute list can not co-exist";
795 break;
796 case BGP_ERR_NOT_INTERNAL_PEER:
797 str = "Invalid command. Not an internal neighbor";
798 break;
799 case BGP_ERR_REMOVE_PRIVATE_AS:
800 str = "remove-private-AS cannot be configured for IBGP peers";
801 break;
802 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
803 str = "Local-AS allowed only for EBGP peers";
804 break;
805 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
806 str = "Cannot have local-as same as BGP AS number";
807 break;
808 case BGP_ERR_TCPSIG_FAILED:
809 str = "Error while applying TCP-Sig to session(s)";
810 break;
811 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
812 str = "ebgp-multihop and ttl-security cannot be configured together";
813 break;
814 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
815 str = "ttl-security only allowed for EBGP peers";
816 break;
817 case BGP_ERR_AS_OVERRIDE:
818 str = "as-override cannot be configured for IBGP peers";
819 break;
820 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
821 str = "Invalid limit for number of dynamic neighbors";
822 break;
823 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
824 str = "Dynamic neighbor listen range already exists";
825 break;
826 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
827 str = "Operation not allowed on a dynamic neighbor";
828 break;
829 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
830 str = "Operation not allowed on a directly connected neighbor";
831 break;
832 case BGP_ERR_PEER_SAFI_CONFLICT:
055679e9 833 str = GR_INVALID;
834 break;
835 case BGP_ERR_GR_INVALID_CMD:
836 str = "The Graceful Restart command used is not valid at this moment.";
837 break;
838 case BGP_ERR_GR_OPERATION_FAILED:
839 str = "The Graceful Restart Operation failed due to an err.";
840 break;
841 case BGP_GR_NO_OPERATION:
842 str = GR_NO_OPER;
d62a17ae 843 break;
844 }
845 if (str) {
846 vty_out(vty, "%% %s\n", str);
847 return CMD_WARNING_CONFIG_FAILED;
848 }
849 return CMD_SUCCESS;
718e3744 850}
851
7aafcaca 852/* BGP clear sort. */
d62a17ae 853enum clear_sort {
854 clear_all,
855 clear_peer,
856 clear_group,
857 clear_external,
858 clear_as
7aafcaca
DS
859};
860
ff8a8a7a
CS
861static void bgp_clear_vty_error(struct peer *peer, afi_t afi, safi_t safi,
862 int error, char *errmsg, size_t errmsg_len)
d62a17ae 863{
864 switch (error) {
865 case BGP_ERR_AF_UNCONFIGURED:
ff8a8a7a
CS
866 snprintf(errmsg, errmsg_len,
867 "%%BGP: Enable %s address family for the neighbor %s",
868 get_afi_safi_str(afi, safi, false), peer->host);
d62a17ae 869 break;
870 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
ff8a8a7a
CS
871 snprintf(
872 errmsg, errmsg_len,
873 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig",
d62a17ae 874 peer->host);
875 break;
876 default:
877 break;
878 }
7aafcaca
DS
879}
880
dc912615 881static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
c368171c 882 struct listnode **nnode, enum bgp_clear_type stype)
dc912615
DS
883{
884 int ret = 0;
2adac256 885 struct peer_af *paf;
dc912615
DS
886
887 /* if afi/.safi not specified, spin thru all of them */
888 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
889 afi_t tmp_afi;
890 safi_t tmp_safi;
891
892 FOREACH_AFI_SAFI (tmp_afi, tmp_safi) {
2adac256
DA
893 paf = peer_af_find(peer, tmp_afi, tmp_safi);
894 if (paf && paf->subgroup)
895 SET_FLAG(paf->subgroup->sflags,
896 SUBGRP_STATUS_FORCE_UPDATES);
897
dc912615
DS
898 if (!peer->afc[tmp_afi][tmp_safi])
899 continue;
900
901 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 902 ret = peer_clear(peer, nnode);
dc912615
DS
903 else
904 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
905 stype);
906 }
907 /* if afi specified and safi not, spin thru safis on this afi */
908 } else if (safi == SAFI_UNSPEC) {
909 safi_t tmp_safi;
910
911 for (tmp_safi = SAFI_UNICAST;
912 tmp_safi < SAFI_MAX; tmp_safi++) {
913 if (!peer->afc[afi][tmp_safi])
914 continue;
915
2adac256
DA
916 paf = peer_af_find(peer, afi, tmp_safi);
917 if (paf && paf->subgroup)
918 SET_FLAG(paf->subgroup->sflags,
919 SUBGRP_STATUS_FORCE_UPDATES);
920
dc912615 921 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 922 ret = peer_clear(peer, nnode);
dc912615
DS
923 else
924 ret = peer_clear_soft(peer, afi,
925 tmp_safi, stype);
926 }
927 /* both afi/safi specified, let the caller know if not defined */
928 } else {
929 if (!peer->afc[afi][safi])
930 return 1;
931
2adac256
DA
932 paf = peer_af_find(peer, afi, safi);
933 if (paf && paf->subgroup)
934 SET_FLAG(paf->subgroup->sflags,
935 SUBGRP_STATUS_FORCE_UPDATES);
936
dc912615 937 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 938 ret = peer_clear(peer, nnode);
dc912615
DS
939 else
940 ret = peer_clear_soft(peer, afi, safi, stype);
941 }
942
943 return ret;
944}
945
7aafcaca 946/* `clear ip bgp' functions. */
ff8a8a7a 947static int bgp_clear(struct bgp *bgp, afi_t afi, safi_t safi,
d62a17ae 948 enum clear_sort sort, enum bgp_clear_type stype,
ff8a8a7a 949 const char *arg, char *errmsg, size_t errmsg_len)
d62a17ae 950{
dc912615 951 int ret = 0;
3ae8bfa5 952 bool found = false;
d62a17ae 953 struct peer *peer;
dc95985f 954
955 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
d62a17ae 956
957 /* Clear all neighbors. */
958 /*
959 * Pass along pointer to next node to peer_clear() when walking all
3ae8bfa5
PM
960 * nodes on the BGP instance as that may get freed if it is a
961 * doppelganger
d62a17ae 962 */
963 if (sort == clear_all) {
964 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dc95985f 965
966 bgp_peer_gr_flags_update(peer);
967
36235319 968 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
dc95985f 969 gr_router_detected = true;
970
c368171c 971 ret = bgp_peer_clear(peer, afi, safi, &nnode,
dc912615 972 stype);
d62a17ae 973
974 if (ret < 0)
ff8a8a7a
CS
975 bgp_clear_vty_error(peer, afi, safi, ret,
976 errmsg, errmsg_len);
dc95985f 977 }
978
36235319
QY
979 if (gr_router_detected
980 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 981 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
982 } else if (!gr_router_detected
983 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 984 bgp_zebra_send_capabilities(bgp, true);
04b6bdc0 985 }
d62a17ae 986
987 /* This is to apply read-only mode on this clear. */
988 if (stype == BGP_CLEAR_SOFT_NONE)
989 bgp->update_delay_over = 0;
990
991 return CMD_SUCCESS;
7aafcaca
DS
992 }
993
3ae8bfa5 994 /* Clear specified neighbor. */
d62a17ae 995 if (sort == clear_peer) {
996 union sockunion su;
d62a17ae 997
998 /* Make sockunion for lookup. */
999 ret = str2sockunion(arg, &su);
1000 if (ret < 0) {
1001 peer = peer_lookup_by_conf_if(bgp, arg);
1002 if (!peer) {
1003 peer = peer_lookup_by_hostname(bgp, arg);
1004 if (!peer) {
ff8a8a7a
CS
1005 snprintf(
1006 errmsg, errmsg_len,
1007 "Malformed address or name: %s",
d62a17ae 1008 arg);
1009 return CMD_WARNING;
1010 }
1011 }
1012 } else {
1013 peer = peer_lookup(bgp, &su);
1014 if (!peer) {
ff8a8a7a
CS
1015 snprintf(errmsg, errmsg_len,
1016 "%%BGP: Unknown neighbor - \"%s\"",
1017 arg);
d62a17ae 1018 return CMD_WARNING;
1019 }
1020 }
7aafcaca 1021
dc95985f 1022 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1023 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1024
dc912615
DS
1025 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1026
1027 /* if afi/safi not defined for this peer, let caller know */
1028 if (ret == 1)
3ae8bfa5 1029 ret = BGP_ERR_AF_UNCONFIGURED;
7aafcaca 1030
d62a17ae 1031 if (ret < 0)
ff8a8a7a
CS
1032 bgp_clear_vty_error(peer, afi, safi, ret, errmsg,
1033 errmsg_len);
7aafcaca 1034
d62a17ae 1035 return CMD_SUCCESS;
7aafcaca 1036 }
7aafcaca 1037
3ae8bfa5 1038 /* Clear all neighbors belonging to a specific peer-group. */
d62a17ae 1039 if (sort == clear_group) {
1040 struct peer_group *group;
7aafcaca 1041
d62a17ae 1042 group = peer_group_lookup(bgp, arg);
1043 if (!group) {
ff8a8a7a
CS
1044 snprintf(errmsg, errmsg_len,
1045 "%%BGP: No such peer-group %s", arg);
d62a17ae 1046 return CMD_WARNING;
1047 }
1048
1049 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
c368171c 1050 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 1051
d62a17ae 1052 if (ret < 0)
ff8a8a7a
CS
1053 bgp_clear_vty_error(peer, afi, safi, ret,
1054 errmsg, errmsg_len);
3ae8bfa5
PM
1055 else
1056 found = true;
d62a17ae 1057 }
3ae8bfa5
PM
1058
1059 if (!found)
ff8a8a7a
CS
1060 snprintf(
1061 errmsg, errmsg_len,
1062 "%%BGP: No %s peer belonging to peer-group %s is configured",
5cb5f4d0 1063 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1064
d62a17ae 1065 return CMD_SUCCESS;
7aafcaca 1066 }
7aafcaca 1067
3ae8bfa5 1068 /* Clear all external (eBGP) neighbors. */
d62a17ae 1069 if (sort == clear_external) {
1070 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1071 if (peer->sort == BGP_PEER_IBGP)
1072 continue;
7aafcaca 1073
dc95985f 1074 bgp_peer_gr_flags_update(peer);
1075
36235319 1076 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 1077 gr_router_detected = true;
dc95985f 1078
c368171c 1079 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 1080
d62a17ae 1081 if (ret < 0)
ff8a8a7a
CS
1082 bgp_clear_vty_error(peer, afi, safi, ret,
1083 errmsg, errmsg_len);
3ae8bfa5
PM
1084 else
1085 found = true;
d62a17ae 1086 }
3ae8bfa5 1087
36235319
QY
1088 if (gr_router_detected
1089 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1090 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1091 } else if (!gr_router_detected
1092 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1093 bgp_zebra_send_capabilities(bgp, true);
1094 }
1095
3ae8bfa5 1096 if (!found)
ff8a8a7a
CS
1097 snprintf(errmsg, errmsg_len,
1098 "%%BGP: No external %s peer is configured",
1099 get_afi_safi_str(afi, safi, false));
3ae8bfa5 1100
d62a17ae 1101 return CMD_SUCCESS;
1102 }
1103
3ae8bfa5 1104 /* Clear all neighbors belonging to a specific AS. */
d62a17ae 1105 if (sort == clear_as) {
3ae8bfa5 1106 as_t as = strtoul(arg, NULL, 10);
d62a17ae 1107
1108 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1109 if (peer->as != as)
1110 continue;
1111
dc95985f 1112 bgp_peer_gr_flags_update(peer);
1113
36235319 1114 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 1115 gr_router_detected = true;
dc95985f 1116
c368171c 1117 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
d62a17ae 1118
1119 if (ret < 0)
ff8a8a7a
CS
1120 bgp_clear_vty_error(peer, afi, safi, ret,
1121 errmsg, errmsg_len);
3ae8bfa5
PM
1122 else
1123 found = true;
d62a17ae 1124 }
3ae8bfa5 1125
36235319
QY
1126 if (gr_router_detected
1127 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1128 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1129 } else if (!gr_router_detected
1130 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1131 bgp_zebra_send_capabilities(bgp, true);
1132 }
1133
3ae8bfa5 1134 if (!found)
ff8a8a7a
CS
1135 snprintf(errmsg, errmsg_len,
1136 "%%BGP: No %s peer is configured with AS %s",
1137 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1138
d62a17ae 1139 return CMD_SUCCESS;
1140 }
1141
1142 return CMD_SUCCESS;
1143}
1144
ff8a8a7a
CS
1145static int bgp_clear_vty(const char *name, afi_t afi, safi_t safi,
1146 enum clear_sort sort, enum bgp_clear_type stype,
1147 const char *arg, char *errmsg, size_t errmsg_len)
d62a17ae 1148{
1149 struct bgp *bgp;
1150
1151 /* BGP structure lookup. */
1152 if (name) {
1153 bgp = bgp_lookup_by_name(name);
1154 if (bgp == NULL) {
ff8a8a7a
CS
1155 snprintf(errmsg, errmsg_len,
1156 "Can't find BGP instance %s", name);
d62a17ae 1157 return CMD_WARNING;
1158 }
1159 } else {
1160 bgp = bgp_get_default();
1161 if (bgp == NULL) {
ff8a8a7a
CS
1162 snprintf(errmsg, errmsg_len,
1163 "No BGP process is configured");
d62a17ae 1164 return CMD_WARNING;
1165 }
1166 }
1167
ff8a8a7a 1168 return bgp_clear(bgp, afi, safi, sort, stype, arg, errmsg, errmsg_len);
7aafcaca
DS
1169}
1170
1171/* clear soft inbound */
ff8a8a7a 1172int bgp_clear_star_soft_in(const char *name, char *errmsg, size_t errmsg_len)
7aafcaca 1173{
99b3ebd3
NS
1174 afi_t afi;
1175 safi_t safi;
ff8a8a7a
CS
1176 int ret;
1177
1178 FOREACH_AFI_SAFI (afi, safi) {
1179 ret = bgp_clear_vty(name, afi, safi, clear_all,
1180 BGP_CLEAR_SOFT_IN, NULL, errmsg,
1181 errmsg_len);
1182 if (ret != CMD_SUCCESS)
1183 return -1;
1184 }
99b3ebd3 1185
ff8a8a7a 1186 return 0;
7aafcaca
DS
1187}
1188
1189/* clear soft outbound */
ff8a8a7a 1190int bgp_clear_star_soft_out(const char *name, char *errmsg, size_t errmsg_len)
7aafcaca 1191{
99b3ebd3
NS
1192 afi_t afi;
1193 safi_t safi;
ff8a8a7a 1194 int ret;
99b3ebd3 1195
ff8a8a7a
CS
1196 FOREACH_AFI_SAFI (afi, safi) {
1197 ret = bgp_clear_vty(name, afi, safi, clear_all,
1198 BGP_CLEAR_SOFT_OUT, NULL, errmsg,
1199 errmsg_len);
1200 if (ret != CMD_SUCCESS)
1201 return -1;
1202 }
1203
1204 return 0;
7aafcaca
DS
1205}
1206
1207
f787d7a0 1208#ifndef VTYSH_EXTRACT_PL
2e4c2296 1209#include "bgpd/bgp_vty_clippy.c"
f787d7a0
DL
1210#endif
1211
8029b216
AK
1212DEFUN_HIDDEN (bgp_local_mac,
1213 bgp_local_mac_cmd,
093e3f23 1214 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
8029b216
AK
1215 BGP_STR
1216 "Local MAC config\n"
1217 "VxLAN Network Identifier\n"
1218 "VNI number\n"
1219 "local mac\n"
1220 "mac address\n"
1221 "mac-mobility sequence\n"
1222 "seq number\n")
1223{
1224 int rv;
1225 vni_t vni;
1226 struct ethaddr mac;
1227 struct ipaddr ip;
1228 uint32_t seq;
1229 struct bgp *bgp;
1230
1231 vni = strtoul(argv[3]->arg, NULL, 10);
1232 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1233 vty_out(vty, "%% Malformed MAC address\n");
1234 return CMD_WARNING;
1235 }
1236 memset(&ip, 0, sizeof(ip));
1237 seq = strtoul(argv[7]->arg, NULL, 10);
1238
1239 bgp = bgp_get_default();
1240 if (!bgp) {
1241 vty_out(vty, "Default BGP instance is not there\n");
1242 return CMD_WARNING;
1243 }
1244
b5e140c8
AK
1245 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1246 zero_esi);
8029b216
AK
1247 if (rv < 0) {
1248 vty_out(vty, "Internal error\n");
1249 return CMD_WARNING;
1250 }
1251
1252 return CMD_SUCCESS;
1253}
1254
1255DEFUN_HIDDEN (no_bgp_local_mac,
1256 no_bgp_local_mac_cmd,
093e3f23 1257 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
8029b216
AK
1258 NO_STR
1259 BGP_STR
1260 "Local MAC config\n"
1261 "VxLAN Network Identifier\n"
1262 "VNI number\n"
1263 "local mac\n"
1264 "mac address\n")
1265{
1266 int rv;
1267 vni_t vni;
1268 struct ethaddr mac;
1269 struct ipaddr ip;
1270 struct bgp *bgp;
1271
1272 vni = strtoul(argv[4]->arg, NULL, 10);
1273 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1274 vty_out(vty, "%% Malformed MAC address\n");
1275 return CMD_WARNING;
1276 }
1277 memset(&ip, 0, sizeof(ip));
1278
1279 bgp = bgp_get_default();
1280 if (!bgp) {
1281 vty_out(vty, "Default BGP instance is not there\n");
1282 return CMD_WARNING;
1283 }
1284
ec0ab544 1285 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
8029b216
AK
1286 if (rv < 0) {
1287 vty_out(vty, "Internal error\n");
1288 return CMD_WARNING;
1289 }
1290
1291 return CMD_SUCCESS;
1292}
1293
718e3744 1294DEFUN (no_synchronization,
1295 no_synchronization_cmd,
1296 "no synchronization",
1297 NO_STR
1298 "Perform IGP synchronization\n")
1299{
d62a17ae 1300 return CMD_SUCCESS;
718e3744 1301}
1302
1303DEFUN (no_auto_summary,
1304 no_auto_summary_cmd,
1305 "no auto-summary",
1306 NO_STR
1307 "Enable automatic network number summarization\n")
1308{
d62a17ae 1309 return CMD_SUCCESS;
718e3744 1310}
3d515fd9 1311
718e3744 1312/* "router bgp" commands. */
ff8a8a7a
CS
1313DEFUN_YANG_NOSH(router_bgp,
1314 router_bgp_cmd,
1315 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1316 ROUTER_STR BGP_STR AS_STR BGP_INSTANCE_HELP_STR)
718e3744 1317{
d62a17ae 1318 int idx_asn = 2;
1319 int idx_view_vrf = 3;
1320 int idx_vrf = 4;
ff8a8a7a 1321 int ret = CMD_SUCCESS;
d62a17ae 1322 as_t as;
1323 struct bgp *bgp;
1324 const char *name = NULL;
ff8a8a7a 1325 char as_str[12] = {'\0'};
d62a17ae 1326 enum bgp_instance_type inst_type;
ff8a8a7a 1327 char base_xpath[XPATH_MAXLEN];
d62a17ae 1328
1329 // "router bgp" without an ASN
1330 if (argc == 2) {
1331 // Pending: Make VRF option available for ASN less config
1332 bgp = bgp_get_default();
1333
1334 if (bgp == NULL) {
1335 vty_out(vty, "%% No BGP process is configured\n");
1336 return CMD_WARNING_CONFIG_FAILED;
1337 }
1338
1339 if (listcount(bm->bgp) > 1) {
996c9314 1340 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1341 return CMD_WARNING_CONFIG_FAILED;
1342 }
ff8a8a7a
CS
1343
1344 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
5ce106b7 1345 "frr-bgp:bgp", "bgp", VRF_DEFAULT_NAME);
ff8a8a7a
CS
1346
1347 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
1348 snprintf(as_str, 12, "%d", bgp->as);
87ce2564
CS
1349 nb_cli_enqueue_change(vty, "./global/local-as", NB_OP_MODIFY,
1350 as_str);
ff8a8a7a 1351 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW) {
87ce2564
CS
1352 nb_cli_enqueue_change(vty,
1353 "./global/instance-type-view",
ff8a8a7a
CS
1354 NB_OP_MODIFY, "true");
1355 }
1356
a5ab756f 1357 nb_cli_pending_commit_check(vty);
ff8a8a7a
CS
1358 ret = nb_cli_apply_changes(vty, base_xpath);
1359 if (ret == CMD_SUCCESS) {
1360 VTY_PUSH_XPATH(BGP_NODE, base_xpath);
1361
1362 /*
1363 * For backward compatibility with old commands we still
1364 * need to use the qobj infrastructure.
1365 */
1366 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1367 }
1368 return ret;
d62a17ae 1369 }
1370
1371 // "router bgp X"
1372 else {
d62a17ae 1373
ff8a8a7a 1374 as = strtoul(argv[idx_asn]->arg, NULL, 10);
d62a17ae 1375 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1376 if (argc > 3) {
1377 name = argv[idx_vrf]->arg;
1378
9a8bdf1c
PG
1379 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1380 if (strmatch(name, VRF_DEFAULT_NAME))
1381 name = NULL;
1382 else
1383 inst_type = BGP_INSTANCE_TYPE_VRF;
ff8a8a7a 1384 } else if (!strcmp(argv[idx_view_vrf]->text, "view")) {
d62a17ae 1385 inst_type = BGP_INSTANCE_TYPE_VIEW;
ff8a8a7a 1386 }
d62a17ae 1387 }
ff8a8a7a
CS
1388 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1389 "frr-bgp:bgp", "bgp", name ? name : VRF_DEFAULT_NAME);
1390
1391 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
87ce2564 1392 nb_cli_enqueue_change(vty, "./global/local-as", NB_OP_MODIFY,
ff8a8a7a
CS
1393 argv[idx_asn]->arg);
1394 if (inst_type == BGP_INSTANCE_TYPE_VIEW) {
87ce2564
CS
1395 nb_cli_enqueue_change(vty,
1396 "./global/instance-type-view",
ff8a8a7a 1397 NB_OP_MODIFY, "true");
d62a17ae 1398 }
1399
ff8a8a7a
CS
1400 nb_cli_pending_commit_check(vty);
1401 ret = nb_cli_apply_changes(vty, base_xpath);
1402 if (ret == CMD_SUCCESS) {
1403 VTY_PUSH_XPATH(BGP_NODE, base_xpath);
3bd70bf8 1404
ff8a8a7a
CS
1405 /*
1406 * For backward compatibility with old commands we still
1407 * need to use the qobj infrastructure.
1408 */
1409 bgp = bgp_lookup(as, name);
1410 if (bgp)
1411 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1412 }
d62a17ae 1413 }
1414
ff8a8a7a 1415 return ret;
718e3744 1416}
1417
718e3744 1418/* "no router bgp" commands. */
ff8a8a7a
CS
1419DEFUN_YANG(no_router_bgp,
1420 no_router_bgp_cmd,
1421 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1422 NO_STR ROUTER_STR BGP_STR AS_STR BGP_INSTANCE_HELP_STR)
718e3744 1423{
d62a17ae 1424 int idx_asn = 3;
1425 int idx_vrf = 5;
ff8a8a7a 1426 as_t as = 0;
d62a17ae 1427 struct bgp *bgp;
1428 const char *name = NULL;
ff8a8a7a 1429 char base_xpath[XPATH_MAXLEN];
4b63e358 1430 const struct lyd_node *bgp_glb_dnode;
718e3744 1431
d62a17ae 1432 // "no router bgp" without an ASN
1433 if (argc == 3) {
1434 // Pending: Make VRF option available for ASN less config
4b63e358
CS
1435 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1436 "frr-bgp:bgp", "bgp", VRF_DEFAULT_NAME);
718e3744 1437
4b63e358
CS
1438 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
1439 base_xpath);
1440 if (!bgp_glb_dnode) {
d62a17ae 1441 vty_out(vty, "%% No BGP process is configured\n");
1442 return CMD_WARNING_CONFIG_FAILED;
1443 }
7fb21a9f 1444
d62a17ae 1445 if (listcount(bm->bgp) > 1) {
996c9314 1446 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1447 return CMD_WARNING_CONFIG_FAILED;
1448 }
0b5131c9 1449
4b63e358
CS
1450 /* tcli mode bgp would not be set until apply stage. */
1451 bgp = nb_running_get_entry(bgp_glb_dnode, NULL, false);
1452 if (!bgp)
1453 return CMD_SUCCESS;
1454
0b5131c9
MK
1455 if (bgp->l3vni) {
1456 vty_out(vty, "%% Please unconfigure l3vni %u",
1457 bgp->l3vni);
1458 return CMD_WARNING_CONFIG_FAILED;
1459 }
d62a17ae 1460 } else {
1461 as = strtoul(argv[idx_asn]->arg, NULL, 10);
7fb21a9f 1462
d62a17ae 1463 if (argc > 4)
1464 name = argv[idx_vrf]->arg;
7fb21a9f 1465
d62a17ae 1466 /* Lookup bgp structure. */
1467 bgp = bgp_lookup(as, name);
1468 if (!bgp) {
1469 vty_out(vty, "%% Can't find BGP instance\n");
1470 return CMD_WARNING_CONFIG_FAILED;
1471 }
0b5131c9
MK
1472
1473 if (bgp->l3vni) {
dd5868c2 1474 vty_out(vty, "%% Please unconfigure l3vni %u\n",
0b5131c9
MK
1475 bgp->l3vni);
1476 return CMD_WARNING_CONFIG_FAILED;
1477 }
dd5868c2
DS
1478
1479 /* Cannot delete default instance if vrf instances exist */
1480 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1481 struct listnode *node;
1482 struct bgp *tmp_bgp;
1483
1484 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1485 if (tmp_bgp->inst_type
1486 == BGP_INSTANCE_TYPE_VRF) {
1487 vty_out(vty,
1488 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1489 return CMD_WARNING_CONFIG_FAILED;
1490 }
1491 }
1492 }
d62a17ae 1493 }
ff8a8a7a
CS
1494 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1495 "frr-bgp:bgp", "bgp",
1496 bgp->name ? bgp->name : VRF_DEFAULT_NAME);
718e3744 1497
ff8a8a7a 1498 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
718e3744 1499
ff8a8a7a 1500 return nb_cli_apply_changes(vty, base_xpath);
718e3744 1501}
1502
ff8a8a7a
CS
1503void cli_show_router_bgp(struct vty *vty, struct lyd_node *dnode,
1504 bool show_defaults)
1505{
1506 const struct lyd_node *vrf_dnode;
1507 const char *vrf_name;
1508 as_t as;
6b0655a2 1509
ff8a8a7a
CS
1510 vrf_dnode = yang_dnode_get_parent(dnode, "control-plane-protocol");
1511 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
5e42cb2f 1512 as = yang_dnode_get_uint32(dnode, "./global/local-as");
718e3744 1513
ff8a8a7a
CS
1514 vty_out(vty, "!\n");
1515 vty_out(vty, "router bgp %u", as);
1516 if (!strmatch(vrf_name, VRF_DEFAULT_NAME))
1517 vty_out(vty, " vrf %s", vrf_name);
1518 vty_out(vty, "\n");
718e3744 1519}
1520
ff8a8a7a
CS
1521/* BGP router-id. */
1522
1523DEFPY_YANG(bgp_router_id, bgp_router_id_cmd, "bgp router-id A.B.C.D",
1524 BGP_STR
1525 "Override configured router identifier\n"
1526 "Manually configured router identifier\n")
718e3744 1527{
87ce2564
CS
1528 nb_cli_enqueue_change(vty, "./global/router-id", NB_OP_MODIFY,
1529 router_id_str);
718e3744 1530
ff8a8a7a
CS
1531 return nb_cli_apply_changes(vty, NULL);
1532}
718e3744 1533
ff8a8a7a
CS
1534DEFPY_YANG(no_bgp_router_id, no_bgp_router_id_cmd, "no bgp router-id [A.B.C.D]",
1535 NO_STR BGP_STR
1536 "Override configured router identifier\n"
1537 "Manually configured router identifier\n")
1538{
87ce2564 1539 nb_cli_enqueue_change(vty, "./global/router-id", NB_OP_DESTROY,
ff8a8a7a 1540 router_id_str ? router_id_str : NULL);
718e3744 1541
ff8a8a7a 1542 return nb_cli_apply_changes(vty, NULL);
718e3744 1543}
1544
ff8a8a7a
CS
1545void cli_show_router_bgp_router_id(struct vty *vty, struct lyd_node *dnode,
1546 bool show_defaults)
1547{
1548 vty_out(vty, " bgp router-id %s\n", yang_dnode_get_string(dnode, NULL));
1549}
6b0655a2 1550
9acb67cb
DS
1551DEFPY (bgp_global_suppress_fib_pending,
1552 bgp_global_suppress_fib_pending_cmd,
1553 "[no] bgp suppress-fib-pending",
1554 NO_STR
1555 BGP_STR
1556 "Advertise only routes that are programmed in kernel to peers globally\n")
1557{
1558 bm_wait_for_fib_set(!no);
1559
1560 return CMD_SUCCESS;
1561}
1562
c208c586
S
1563DEFPY (bgp_suppress_fib_pending,
1564 bgp_suppress_fib_pending_cmd,
1565 "[no] bgp suppress-fib-pending",
1566 NO_STR
1567 BGP_STR
1568 "Advertise only routes that are programmed in kernel to peers\n")
1569{
1570 VTY_DECLVAR_CONTEXT(bgp, bgp);
1571
1572 bgp_suppress_fib_pending_set(bgp, !no);
1573 return CMD_SUCCESS;
1574}
1575
1576
718e3744 1577/* BGP Cluster ID. */
ff8a8a7a
CS
1578DEFUN_YANG(bgp_cluster_id,
1579 bgp_cluster_id_cmd,
1580 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1581 BGP_STR
1582 "Configure Route-Reflector Cluster-id\n"
1583 "Route-Reflector Cluster-id in IP address format\n"
1584 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1585{
d62a17ae 1586 int idx_ipv4 = 2;
718e3744 1587
87ce2564
CS
1588 nb_cli_enqueue_change(
1589 vty, "./global/route-reflector/route-reflector-cluster-id",
1590 NB_OP_MODIFY, argv[idx_ipv4]->arg);
718e3744 1591
ff8a8a7a 1592 return nb_cli_apply_changes(vty, NULL);
718e3744 1593}
1594
ff8a8a7a
CS
1595DEFUN_YANG(no_bgp_cluster_id,
1596 no_bgp_cluster_id_cmd,
1597 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1598 NO_STR BGP_STR
1599 "Configure Route-Reflector Cluster-id\n"
1600 "Route-Reflector Cluster-id in IP address format\n"
1601 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1602{
87ce2564
CS
1603 nb_cli_enqueue_change(
1604 vty, "./global/route-reflector/route-reflector-cluster-id",
1605 NB_OP_DESTROY, NULL);
718e3744 1606
ff8a8a7a 1607 return nb_cli_apply_changes(vty, NULL);
718e3744 1608}
1609
c163f297
DS
1610DEFPY (bgp_norib,
1611 bgp_norib_cmd,
1612 "bgp no-rib",
1613 BGP_STR
1614 "Disable BGP route installation to RIB (Zebra)\n")
1615{
1616 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1617 vty_out(vty,
1618 "%% No-RIB option is already set, nothing to do here.\n");
1619 return CMD_SUCCESS;
1620 }
1621
1622 bgp_option_norib_set_runtime();
1623
1624 return CMD_SUCCESS;
1625}
1626
1627DEFPY (no_bgp_norib,
1628 no_bgp_norib_cmd,
1629 "no bgp no-rib",
1630 NO_STR
1631 BGP_STR
1632 "Disable BGP route installation to RIB (Zebra)\n")
1633{
1634 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1635 vty_out(vty,
1636 "%% No-RIB option is not set, nothing to do here.\n");
1637 return CMD_SUCCESS;
1638 }
1639
1640 bgp_option_norib_unset_runtime();
1641
1642 return CMD_SUCCESS;
1643}
1644
e46723a5
DS
1645DEFPY (no_bgp_send_extra_data,
1646 no_bgp_send_extra_data_cmd,
1647 "[no] bgp send-extra-data zebra",
1648 NO_STR
1649 BGP_STR
1650 "Extra data to Zebra for display/use\n"
1651 "To zebra\n")
1652{
ec0acb80
DA
1653 if (no)
1654 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1655 else
1656 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
e46723a5
DS
1657
1658 return CMD_SUCCESS;
1659}
1660
ff8a8a7a
CS
1661DEFUN_YANG(bgp_confederation_identifier,
1662 bgp_confederation_identifier_cmd,
1663 "bgp confederation identifier (1-4294967295)",
1664 "BGP specific commands\n"
1665 "AS confederation parameters\n"
1666 "AS number\n"
1667 "Set routing domain confederation AS\n")
718e3744 1668{
d62a17ae 1669 int idx_number = 3;
718e3744 1670
87ce2564
CS
1671 nb_cli_enqueue_change(vty, "./global/confederation/identifier",
1672 NB_OP_MODIFY, argv[idx_number]->arg);
718e3744 1673
ff8a8a7a 1674 return nb_cli_apply_changes(vty, NULL);
718e3744 1675}
1676
ff8a8a7a
CS
1677DEFUN_YANG(no_bgp_confederation_identifier,
1678 no_bgp_confederation_identifier_cmd,
1679 "no bgp confederation identifier [(1-4294967295)]",
1680 NO_STR
1681 "BGP specific commands\n"
1682 "AS confederation parameters\n"
1683 "AS number\n"
1684 "Set routing domain confederation AS\n")
718e3744 1685{
87ce2564
CS
1686 nb_cli_enqueue_change(vty, "./global/confederation/identifier",
1687 NB_OP_DESTROY, NULL);
718e3744 1688
ff8a8a7a 1689 return nb_cli_apply_changes(vty, NULL);
718e3744 1690}
1691
ff8a8a7a
CS
1692void cli_show_router_bgp_confederation_identifier(struct vty *vty,
1693 struct lyd_node *dnode,
1694 bool show_defaults)
1695{
1696 vty_out(vty, " bgp confederation identifier %u\n",
1697 yang_dnode_get_uint32(dnode, NULL));
1698}
1699
1700DEFUN_YANG(bgp_confederation_peers,
1701 bgp_confederation_peers_cmd,
1702 "bgp confederation peers (1-4294967295)...",
1703 "BGP specific commands\n"
1704 "AS confederation parameters\n"
1705 "Peer ASs in BGP confederation\n" AS_STR)
718e3744 1706{
d62a17ae 1707 int idx_asn = 3;
d62a17ae 1708 int i;
718e3744 1709
ff8a8a7a 1710 for (i = idx_asn; i < argc; i++)
87ce2564 1711 nb_cli_enqueue_change(vty, "./global/confederation/member-as",
ff8a8a7a 1712 NB_OP_CREATE, argv[i]->arg);
718e3744 1713
ff8a8a7a 1714 return nb_cli_apply_changes(vty, NULL);
718e3744 1715}
1716
ff8a8a7a
CS
1717DEFUN_YANG(no_bgp_confederation_peers,
1718 no_bgp_confederation_peers_cmd,
1719 "no bgp confederation peers (1-4294967295)...",
1720 NO_STR
1721 "BGP specific commands\n"
1722 "AS confederation parameters\n"
1723 "Peer ASs in BGP confederation\n" AS_STR)
718e3744 1724{
d62a17ae 1725 int idx_asn = 4;
d62a17ae 1726 int i;
718e3744 1727
ff8a8a7a 1728 for (i = idx_asn; i < argc; i++)
87ce2564 1729 nb_cli_enqueue_change(vty, "./global/confederation/member-as",
ff8a8a7a 1730 NB_OP_DESTROY, argv[i]->arg);
0b2aa3a0 1731
ff8a8a7a
CS
1732 return nb_cli_apply_changes(vty, NULL);
1733}
1734
1735void cli_show_router_bgp_confederation_member_as(struct vty *vty,
1736 struct lyd_node *dnode,
1737 bool show_defaults)
1738{
1739 vty_out(vty, " bgp confederation peers %u \n",
1740 yang_dnode_get_uint32(dnode, NULL));
718e3744 1741}
6b0655a2 1742
5e242b0d
DS
1743/**
1744 * Central routine for maximum-paths configuration.
1745 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1746 * @set: 1 for setting values, 0 for removing the max-paths config.
1747 */
37a87b8f
CS
1748int bgp_maxpaths_config_vty(struct bgp *bgp, afi_t afi, safi_t safi,
1749 int peer_type, uint16_t maxpaths, uint16_t options,
1750 int set, char *errmsg, size_t errmsg_len)
d62a17ae 1751{
d62a17ae 1752 int ret;
d62a17ae 1753
1754 if (set) {
d62a17ae 1755 if (maxpaths > multipath_num) {
37a87b8f
CS
1756 snprintf(
1757 errmsg, errmsg_len,
d62a17ae 1758 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1759 maxpaths, multipath_num);
1760 return CMD_WARNING_CONFIG_FAILED;
1761 }
1762 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1763 options);
1764 } else
1765 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1766
1767 if (ret < 0) {
37a87b8f
CS
1768 snprintf(
1769 errmsg, errmsg_len,
d62a17ae 1770 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1771 (set == 1) ? "" : "un",
1772 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1773 maxpaths, afi, safi);
1774 return CMD_WARNING_CONFIG_FAILED;
1775 }
1776
1777 bgp_recalculate_all_bestpaths(bgp);
1778
1779 return CMD_SUCCESS;
165b5fff
JB
1780}
1781
ff8a8a7a
CS
1782void cli_show_router_bgp_med_config(struct vty *vty, struct lyd_node *dnode,
1783 bool show_defaults)
abc920f8 1784{
ff8a8a7a
CS
1785 if (yang_dnode_get_bool(dnode, "./enable-med-admin")) {
1786 uint32_t med_admin_val;
abc920f8 1787
ff8a8a7a
CS
1788 vty_out(vty, " bgp max-med administrative");
1789 if ((med_admin_val =
1790 yang_dnode_get_uint32(dnode, "./max-med-admin"))
1791 != BGP_MAXMED_VALUE_DEFAULT)
1792 vty_out(vty, " %u", med_admin_val);
1793 vty_out(vty, "\n");
1794 }
abc920f8 1795
ff8a8a7a
CS
1796 if (yang_dnode_exists(dnode, "./max-med-onstart-up-time")) {
1797 uint32_t onstartup_val;
abc920f8 1798
ff8a8a7a
CS
1799 vty_out(vty, " bgp max-med on-startup %u",
1800 yang_dnode_get_uint32(dnode,
1801 "./max-med-onstart-up-time"));
1802 onstartup_val = yang_dnode_get_uint32(
1803 dnode, "./max-med-onstart-up-value");
1804 if (onstartup_val != BGP_MAXMED_VALUE_DEFAULT)
1805 vty_out(vty, " %u", onstartup_val);
1806
1807 vty_out(vty, "\n");
1808 }
abc920f8
DS
1809}
1810
ff8a8a7a
CS
1811DEFUN_YANG(bgp_maxmed_admin,
1812 bgp_maxmed_admin_cmd,
1813 "bgp max-med administrative ",
1814 BGP_STR
1815 "Advertise routes with max-med\n"
1816 "Administratively applied, for an indefinite period\n")
1817{
87ce2564 1818 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
ff8a8a7a
CS
1819 NB_OP_MODIFY, "true");
1820
1821 return nb_cli_apply_changes(vty, NULL);
1822}
1823
1824DEFUN_YANG(bgp_maxmed_admin_medv,
1825 bgp_maxmed_admin_medv_cmd,
1826 "bgp max-med administrative (0-4294967295)",
1827 BGP_STR
1828 "Advertise routes with max-med\n"
1829 "Administratively applied, for an indefinite period\n"
1830 "Max MED value to be used\n")
abc920f8 1831{
d62a17ae 1832 int idx_number = 3;
abc920f8 1833
87ce2564 1834 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
ff8a8a7a 1835 NB_OP_MODIFY, "true");
abc920f8 1836
87ce2564
CS
1837 nb_cli_enqueue_change(vty, "./global/med-config/max-med-admin",
1838 NB_OP_MODIFY, argv[idx_number]->arg);
abc920f8 1839
ff8a8a7a 1840 return nb_cli_apply_changes(vty, NULL);
abc920f8
DS
1841}
1842
ff8a8a7a
CS
1843DEFUN_YANG(no_bgp_maxmed_admin,
1844 no_bgp_maxmed_admin_cmd,
1845 "no bgp max-med administrative [(0-4294967295)]",
1846 NO_STR BGP_STR
1847 "Advertise routes with max-med\n"
1848 "Administratively applied, for an indefinite period\n"
1849 "Max MED value to be used\n")
abc920f8 1850{
87ce2564 1851 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
ff8a8a7a 1852 NB_OP_MODIFY, "false");
abc920f8 1853
87ce2564
CS
1854 nb_cli_enqueue_change(vty, "./global/med-config/max-med-admin",
1855 NB_OP_MODIFY, NULL);
ff8a8a7a
CS
1856
1857 return nb_cli_apply_changes(vty, NULL);
abc920f8
DS
1858}
1859
37a87b8f
CS
1860DEFUN_YANG (bgp_maxmed_onstartup,
1861 bgp_maxmed_onstartup_cmd,
1862 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1863 BGP_STR
1864 "Advertise routes with max-med\n"
1865 "Effective on a startup\n"
1866 "Time (seconds) period for max-med\n"
1867 "Max MED value to be used\n")
abc920f8 1868{
d62a17ae 1869 int idx = 0;
4668a151 1870
d62a17ae 1871 argv_find(argv, argc, "(5-86400)", &idx);
87ce2564
CS
1872 nb_cli_enqueue_change(vty,
1873 "./global/med-config/max-med-onstart-up-time",
ff8a8a7a
CS
1874 NB_OP_MODIFY, argv[idx]->arg);
1875
d62a17ae 1876 if (argv_find(argv, argc, "(0-4294967295)", &idx))
87ce2564
CS
1877 nb_cli_enqueue_change(
1878 vty, "./global/med-config/max-med-onstart-up-value",
1879 NB_OP_MODIFY, argv[idx]->arg);
d62a17ae 1880 else
87ce2564
CS
1881 nb_cli_enqueue_change(
1882 vty, "./global/med-config/max-med-onstart-up-value",
1883 NB_OP_MODIFY, NULL);
abc920f8 1884
ff8a8a7a 1885 return nb_cli_apply_changes(vty, NULL);
abc920f8
DS
1886}
1887
37a87b8f
CS
1888DEFUN_YANG (no_bgp_maxmed_onstartup,
1889 no_bgp_maxmed_onstartup_cmd,
1890 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1891 NO_STR BGP_STR
1892 "Advertise routes with max-med\n"
1893 "Effective on a startup\n"
1894 "Time (seconds) period for max-med\n"
1895 "Max MED value to be used\n")
abc920f8 1896{
87ce2564
CS
1897 nb_cli_enqueue_change(vty,
1898 "./global/med-config/max-med-onstart-up-time",
ff8a8a7a 1899 NB_OP_DESTROY, NULL);
abc920f8 1900
87ce2564
CS
1901 nb_cli_enqueue_change(vty,
1902 "./global/med-config/max-med-onstart-up-value",
ff8a8a7a 1903 NB_OP_MODIFY, NULL);
abc920f8 1904
ff8a8a7a 1905 return nb_cli_apply_changes(vty, NULL);
abc920f8
DS
1906}
1907
d70583f7
D
1908static int bgp_global_update_delay_config_vty(struct vty *vty,
1909 uint16_t update_delay,
1910 uint16_t establish_wait)
1911{
1912 struct listnode *node, *nnode;
1913 struct bgp *bgp;
1914 bool vrf_cfg = false;
1915
1916 /*
1917 * See if update-delay is set per-vrf and warn user to delete it
1918 * Note that we only need to check this if this is the first time
1919 * setting the global config.
1920 */
1921 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
1922 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1923 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1924 vty_out(vty,
1925 "%% update-delay configuration found in vrf %s\n",
1926 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
1927 ? VRF_DEFAULT_NAME
1928 : bgp->name);
1929 vrf_cfg = true;
1930 }
1931 }
1932 }
1933
1934 if (vrf_cfg) {
1935 vty_out(vty,
1936 "%%Failed: global update-delay config not permitted\n");
1937 return CMD_WARNING;
1938 }
1939
1940 if (!establish_wait) { /* update-delay <delay> */
1941 bm->v_update_delay = update_delay;
1942 bm->v_establish_wait = bm->v_update_delay;
1943 } else {
1944 /* update-delay <delay> <establish-wait> */
1945 if (update_delay < establish_wait) {
1946 vty_out(vty,
1947 "%%Failed: update-delay less than the establish-wait!\n");
1948 return CMD_WARNING_CONFIG_FAILED;
1949 }
1950
1951 bm->v_update_delay = update_delay;
1952 bm->v_establish_wait = establish_wait;
1953 }
1954
1955 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1956 bgp->v_update_delay = bm->v_update_delay;
1957 bgp->v_establish_wait = bm->v_establish_wait;
1958 }
1959
1960 return CMD_SUCCESS;
1961}
1962
1963static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
1964{
1965 struct listnode *node, *nnode;
1966 struct bgp *bgp;
1967
1968 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
1969 bm->v_establish_wait = bm->v_update_delay;
1970
1971 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1972 bgp->v_update_delay = bm->v_update_delay;
1973 bgp->v_establish_wait = bm->v_establish_wait;
1974 }
1975
1976 return CMD_SUCCESS;
1977}
1978
1979static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
1980 uint16_t establish_wait)
f188f2c4 1981{
d62a17ae 1982 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 1983
d70583f7
D
1984 /* if configured globally, per-instance config is not allowed */
1985 if (bm->v_update_delay) {
1986 vty_out(vty,
1987 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
1988 return CMD_WARNING_CONFIG_FAILED;
1989 }
1990
f188f2c4 1991
d70583f7 1992 if (!establish_wait) /* update-delay <delay> */
d62a17ae 1993 {
1994 bgp->v_update_delay = update_delay;
1995 bgp->v_establish_wait = bgp->v_update_delay;
1996 return CMD_SUCCESS;
1997 }
f188f2c4 1998
d62a17ae 1999 /* update-delay <delay> <establish-wait> */
d62a17ae 2000 if (update_delay < establish_wait) {
2001 vty_out(vty,
2002 "%%Failed: update-delay less than the establish-wait!\n");
2003 return CMD_WARNING_CONFIG_FAILED;
2004 }
f188f2c4 2005
d62a17ae 2006 bgp->v_update_delay = update_delay;
2007 bgp->v_establish_wait = establish_wait;
f188f2c4 2008
d62a17ae 2009 return CMD_SUCCESS;
f188f2c4
DS
2010}
2011
d62a17ae 2012static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 2013{
d62a17ae 2014 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 2015
d70583f7
D
2016 /* If configured globally, cannot remove from one bgp instance */
2017 if (bm->v_update_delay) {
2018 vty_out(vty,
2019 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2020 return CMD_WARNING_CONFIG_FAILED;
2021 }
d62a17ae 2022 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2023 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 2024
d62a17ae 2025 return CMD_SUCCESS;
f188f2c4
DS
2026}
2027
2b791107 2028void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 2029{
d70583f7
D
2030 /* If configured globally, no need to display per-instance value */
2031 if (bgp->v_update_delay != bm->v_update_delay) {
d62a17ae 2032 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2033 if (bgp->v_update_delay != bgp->v_establish_wait)
2034 vty_out(vty, " %d", bgp->v_establish_wait);
2035 vty_out(vty, "\n");
2036 }
f188f2c4
DS
2037}
2038
d70583f7
D
2039/* Global update-delay configuration */
2040DEFPY (bgp_global_update_delay,
2041 bgp_global_update_delay_cmd,
2042 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2043 BGP_STR
2044 "Force initial delay for best-path and updates for all bgp instances\n"
2045 "Max delay in seconds\n"
2046 "Establish wait in seconds\n")
2047{
2048 return bgp_global_update_delay_config_vty(vty, delay, wait);
2049}
f188f2c4 2050
d70583f7
D
2051/* Global update-delay deconfiguration */
2052DEFPY (no_bgp_global_update_delay,
2053 no_bgp_global_update_delay_cmd,
2054 "no bgp update-delay [(0-3600) [(1-3600)]]",
2055 NO_STR
2056 BGP_STR
f188f2c4 2057 "Force initial delay for best-path and updates\n"
d70583f7
D
2058 "Max delay in seconds\n"
2059 "Establish wait in seconds\n")
f188f2c4 2060{
d70583f7 2061 return bgp_global_update_delay_deconfig_vty(vty);
f188f2c4
DS
2062}
2063
d70583f7
D
2064/* Update-delay configuration */
2065
2066DEFPY (bgp_update_delay,
2067 bgp_update_delay_cmd,
2068 "update-delay (0-3600)$delay [(1-3600)$wait]",
f188f2c4 2069 "Force initial delay for best-path and updates\n"
d70583f7
D
2070 "Max delay in seconds\n"
2071 "Establish wait in seconds\n")
f188f2c4 2072{
d70583f7 2073 return bgp_update_delay_config_vty(vty, delay, wait);
f188f2c4
DS
2074}
2075
2076/* Update-delay deconfiguration */
d70583f7 2077DEFPY (no_bgp_update_delay,
f188f2c4 2078 no_bgp_update_delay_cmd,
838758ac
DW
2079 "no update-delay [(0-3600) [(1-3600)]]",
2080 NO_STR
f188f2c4 2081 "Force initial delay for best-path and updates\n"
d70583f7
D
2082 "Max delay in seconds\n"
2083 "Establish wait in seconds\n")
f188f2c4 2084{
d62a17ae 2085 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
2086}
2087
5e242b0d 2088
ff8a8a7a 2089int bgp_wpkt_quanta_config_vty(struct bgp *bgp, uint32_t quanta, bool set)
cb1faec9 2090{
8fa7732f
QY
2091 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2092 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
555e09d4
QY
2093
2094 return CMD_SUCCESS;
2095}
2096
ff8a8a7a 2097int bgp_rpkt_quanta_config_vty(struct bgp *bgp, uint32_t quanta, bool set)
555e09d4 2098{
8fa7732f
QY
2099 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2100 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
cb1faec9 2101
d62a17ae 2102 return CMD_SUCCESS;
cb1faec9
DS
2103}
2104
2b791107 2105void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 2106{
555e09d4
QY
2107 uint32_t quanta =
2108 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2109 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 2110 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
2111}
2112
555e09d4
QY
2113void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2114{
2115 uint32_t quanta =
2116 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2117 if (quanta != BGP_READ_PACKET_MAX)
152456fe 2118 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 2119}
cb1faec9 2120
8fa7732f
QY
2121/* Packet quanta configuration
2122 *
2123 * XXX: The value set here controls the size of a stack buffer in the IO
2124 * thread. When changing these limits be careful to prevent stack overflow.
2125 *
2126 * Furthermore, the maximums used here should correspond to
2127 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2128 */
37a87b8f
CS
2129DEFPY_YANG (bgp_wpkt_quanta,
2130 bgp_wpkt_quanta_cmd,
2131 "[no] write-quanta (1-64)$quanta",
2132 NO_STR
2133 "How many packets to write to peer socket per run\n"
2134 "Number of packets\n")
ff8a8a7a
CS
2135{
2136 if (!no)
2137 nb_cli_enqueue_change(
2138 vty,
87ce2564 2139 "./global/global-neighbor-config/packet-quanta-config/wpkt-quanta",
ff8a8a7a
CS
2140 NB_OP_MODIFY, quanta_str);
2141 else
2142 nb_cli_enqueue_change(
2143 vty,
87ce2564 2144 "./global/global-neighbor-config/packet-quanta-config/wpkt-quanta",
ff8a8a7a
CS
2145 NB_OP_MODIFY, NULL);
2146
2147 return nb_cli_apply_changes(vty, NULL);
2148}
2149
37a87b8f
CS
2150DEFPY_YANG (bgp_rpkt_quanta,
2151 bgp_rpkt_quanta_cmd,
2152 "[no] read-quanta (1-10)$quanta",
2153 NO_STR
2154 "How many packets to read from peer socket per I/O cycle\n"
2155 "Number of packets\n")
ff8a8a7a
CS
2156{
2157 if (!no)
2158 nb_cli_enqueue_change(
2159 vty,
87ce2564 2160 "./global/global-neighbor-config/packet-quanta-config/rpkt-quanta",
ff8a8a7a
CS
2161 NB_OP_MODIFY, quanta_str);
2162 else
2163 nb_cli_enqueue_change(
2164 vty,
87ce2564 2165 "./global/global-neighbor-config/packet-quanta-config/rpkt-quanta",
ff8a8a7a 2166 NB_OP_MODIFY, NULL);
cb1faec9 2167
ff8a8a7a 2168 return nb_cli_apply_changes(vty, NULL);
555e09d4
QY
2169}
2170
2b791107 2171void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 2172{
37a333fe 2173 if (!bgp->heuristic_coalesce)
d62a17ae 2174 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
2175}
2176
ff8a8a7a
CS
2177void cli_show_router_global_update_group_config_coalesce_time(
2178 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
3f9c7369 2179{
ff8a8a7a
CS
2180 vty_out(vty, " coalesce-time %u\n", yang_dnode_get_uint32(dnode, NULL));
2181}
2182
4668a151 2183
37a87b8f
CS
2184DEFUN_YANG (bgp_coalesce_time,
2185 bgp_coalesce_time_cmd,
2186 "coalesce-time (0-4294967295)",
2187 "Subgroup coalesce timer\n"
2188 "Subgroup coalesce timer value (in ms)\n")
ff8a8a7a 2189{
d62a17ae 2190 int idx = 0;
ff8a8a7a 2191
d62a17ae 2192 argv_find(argv, argc, "(0-4294967295)", &idx);
87ce2564
CS
2193 nb_cli_enqueue_change(
2194 vty, "./global/global-update-group-config/coalesce-time",
2195 NB_OP_MODIFY, argv[idx]->arg);
ff8a8a7a
CS
2196
2197 return nb_cli_apply_changes(vty, NULL);
3f9c7369
DS
2198}
2199
ff8a8a7a
CS
2200DEFUN_YANG(no_bgp_coalesce_time,
2201 no_bgp_coalesce_time_cmd,
2202 "no coalesce-time (0-4294967295)",
2203 NO_STR
2204 "Subgroup coalesce timer\n"
2205 "Subgroup coalesce timer value (in ms)\n")
3f9c7369 2206{
87ce2564
CS
2207 nb_cli_enqueue_change(
2208 vty, "./global/global-update-group-config/coalesce-time",
2209 NB_OP_MODIFY, NULL);
4668a151 2210
ff8a8a7a 2211 return nb_cli_apply_changes(vty, NULL);
3f9c7369
DS
2212}
2213
5e242b0d 2214/* Maximum-paths configuration */
37a87b8f
CS
2215DEFUN_YANG (bgp_maxpaths,
2216 bgp_maxpaths_cmd,
2217 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2218 "Forward packets over multiple paths\n"
2219 "Number of paths\n")
5e242b0d 2220{
d62a17ae 2221 int idx_number = 1;
37a87b8f
CS
2222 char base_xpath[XPATH_MAXLEN];
2223 afi_t afi;
2224 safi_t safi;
2225
2226 afi = bgp_node_afi(vty);
2227 safi = bgp_node_safi(vty);
2228
2229 snprintf(
2230 base_xpath, sizeof(base_xpath),
2231 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ebgp/maximum-paths",
2232 yang_afi_safi_value2identity(afi, safi),
2233 bgp_afi_safi_get_container_str(afi, safi));
2234
2235 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2236 argv[idx_number]->arg);
2237
2238 return nb_cli_apply_changes(vty, NULL);
2239}
2240
2241void cli_show_bgp_global_afi_safi_unicast_use_multiple_paths_ebgp_maximum_paths(
2242 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
2243{
2244 vty_out(vty, " maximum-paths %d\n",
2245 yang_dnode_get_uint16(dnode, NULL));
5e242b0d
DS
2246}
2247
d62a17ae 2248ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2249 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2250 "Forward packets over multiple paths\n"
2251 "Number of paths\n")
596c17ba 2252
37a87b8f
CS
2253DEFUN_YANG (bgp_maxpaths_ibgp,
2254 bgp_maxpaths_ibgp_cmd,
2255 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2256 "Forward packets over multiple paths\n"
2257 "iBGP-multipath\n"
2258 "Number of paths\n")
165b5fff 2259{
d62a17ae 2260 int idx_number = 2;
37a87b8f
CS
2261 char base_xpath[XPATH_MAXLEN];
2262 afi_t afi;
2263 safi_t safi;
2264
2265 afi = bgp_node_afi(vty);
2266 safi = bgp_node_safi(vty);
2267
2268 snprintf(
2269 base_xpath, sizeof(base_xpath),
2270 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2271 yang_afi_safi_value2identity(afi, safi),
2272 bgp_afi_safi_get_container_str(afi, safi));
2273
2274 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2275 argv[idx_number]->arg);
2276
2277 return nb_cli_apply_changes(vty, NULL);
5e242b0d 2278}
165b5fff 2279
d62a17ae 2280ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2281 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2282 "Forward packets over multiple paths\n"
2283 "iBGP-multipath\n"
2284 "Number of paths\n")
596c17ba 2285
37a87b8f
CS
2286DEFUN_YANG (bgp_maxpaths_ibgp_cluster,
2287 bgp_maxpaths_ibgp_cluster_cmd,
2288 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2289 "Forward packets over multiple paths\n"
2290 "iBGP-multipath\n"
2291 "Number of paths\n"
2292 "Match the cluster length\n")
5e242b0d 2293{
d62a17ae 2294 int idx_number = 2;
37a87b8f
CS
2295 char base_xpath[XPATH_MAXLEN];
2296 afi_t afi;
2297 safi_t safi;
2298
2299 afi = bgp_node_afi(vty);
2300 safi = bgp_node_safi(vty);
2301
2302 snprintf(
2303 base_xpath, sizeof(base_xpath),
2304 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2305 yang_afi_safi_value2identity(afi, safi),
2306 bgp_afi_safi_get_container_str(afi, safi));
2307
2308 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2309 argv[idx_number]->arg);
2310
2311 snprintf(
2312 base_xpath, sizeof(base_xpath),
2313 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/cluster-length-list",
2314 yang_afi_safi_value2identity(afi, safi),
2315 bgp_afi_safi_get_container_str(afi, safi));
2316
2317 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, "true");
2318
2319 return nb_cli_apply_changes(vty, NULL);
2320}
2321
2322void cli_show_bgp_global_afi_safi_ip_unicast_use_multiple_paths_ibgp_maximum_paths(
2323 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
2324{
2325 vty_out(vty, " maximum-paths ibgp %d",
2326 yang_dnode_get_uint16(dnode, "./maximum-paths"));
2327 if (yang_dnode_get_bool(dnode, "./cluster-length-list"))
2328 vty_out(vty, " equal-cluster-length");
2329 vty_out(vty, "\n");
165b5fff
JB
2330}
2331
d62a17ae 2332ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2333 "maximum-paths ibgp " CMD_RANGE_STR(
2334 1, MULTIPATH_NUM) " equal-cluster-length",
2335 "Forward packets over multiple paths\n"
2336 "iBGP-multipath\n"
2337 "Number of paths\n"
2338 "Match the cluster length\n")
596c17ba 2339
37a87b8f
CS
2340DEFUN_YANG (no_bgp_maxpaths,
2341 no_bgp_maxpaths_cmd,
2342 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2343 NO_STR
2344 "Forward packets over multiple paths\n"
2345 "Number of paths\n")
165b5fff 2346{
37a87b8f
CS
2347 char base_xpath[XPATH_MAXLEN];
2348 afi_t afi;
2349 safi_t safi;
2350
2351 afi = bgp_node_afi(vty);
2352 safi = bgp_node_safi(vty);
2353
2354 snprintf(
2355 base_xpath, sizeof(base_xpath),
2356 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ebgp/maximum-paths",
2357 yang_afi_safi_value2identity(afi, safi),
2358 bgp_afi_safi_get_container_str(afi, safi));
2359
2360 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, NULL);
2361
2362 return nb_cli_apply_changes(vty, NULL);
165b5fff
JB
2363}
2364
d62a17ae 2365ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 2366 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 2367 "Forward packets over multiple paths\n"
2368 "Number of paths\n")
596c17ba 2369
37a87b8f
CS
2370DEFUN_YANG (no_bgp_maxpaths_ibgp,
2371 no_bgp_maxpaths_ibgp_cmd,
2372 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2373 NO_STR
2374 "Forward packets over multiple paths\n"
2375 "iBGP-multipath\n"
2376 "Number of paths\n"
2377 "Match the cluster length\n")
165b5fff 2378{
37a87b8f
CS
2379 char base_xpath[XPATH_MAXLEN];
2380 afi_t afi;
2381 safi_t safi;
2382
2383 afi = bgp_node_afi(vty);
2384 safi = bgp_node_safi(vty);
2385
2386 snprintf(
2387 base_xpath, sizeof(base_xpath),
2388 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2389 yang_afi_safi_value2identity(afi, safi),
2390 bgp_afi_safi_get_container_str(afi, safi));
2391
2392 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, NULL);
2393
2394 snprintf(
2395 base_xpath, sizeof(base_xpath),
2396 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/cluster-length-list",
2397 yang_afi_safi_value2identity(afi, safi),
2398 bgp_afi_safi_get_container_str(afi, safi));
2399
2400 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, "false");
2401
2402 return nb_cli_apply_changes(vty, NULL);
165b5fff
JB
2403}
2404
d62a17ae 2405ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2406 "no maximum-paths ibgp [" CMD_RANGE_STR(
2407 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2408 NO_STR
2409 "Forward packets over multiple paths\n"
2410 "iBGP-multipath\n"
2411 "Number of paths\n"
2412 "Match the cluster length\n")
596c17ba 2413
dd65f45e
DL
2414static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2415 afi_t afi, safi_t safi)
165b5fff 2416{
00908b7a 2417 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
d62a17ae 2418 vty_out(vty, " maximum-paths %d\n",
2419 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2420 }
165b5fff 2421
00908b7a 2422 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
d62a17ae 2423 vty_out(vty, " maximum-paths ibgp %d",
2424 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2425 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
2426 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
2427 vty_out(vty, " equal-cluster-length");
2428 vty_out(vty, "\n");
2429 }
165b5fff 2430}
6b0655a2 2431
718e3744 2432/* BGP timers. */
2433
37a87b8f
CS
2434DEFUN_YANG (bgp_timers,
2435 bgp_timers_cmd,
2436 "timers bgp (0-65535) (0-65535)",
2437 "Adjust routing timers\n"
2438 "BGP timers\n"
2439 "Keepalive interval\n"
2440 "Holdtime\n")
718e3744 2441{
d62a17ae 2442 int idx_number = 2;
2443 int idx_number_2 = 3;
718e3744 2444
87ce2564 2445 nb_cli_enqueue_change(vty, "./global/global-config-timers/keepalive",
ff8a8a7a 2446 NB_OP_MODIFY, argv[idx_number]->arg);
87ce2564 2447 nb_cli_enqueue_change(vty, "./global/global-config-timers/hold-time",
ff8a8a7a 2448 NB_OP_MODIFY, argv[idx_number_2]->arg);
718e3744 2449
ff8a8a7a
CS
2450 return nb_cli_apply_changes(vty, NULL);
2451}
718e3744 2452
37a87b8f
CS
2453DEFUN_YANG (no_bgp_timers,
2454 no_bgp_timers_cmd,
2455 "no timers bgp [(0-65535) (0-65535)]",
2456 NO_STR
2457 "Adjust routing timers\n"
2458 "BGP timers\n"
2459 "Keepalive interval\n"
2460 "Holdtime\n")
ff8a8a7a 2461{
87ce2564 2462 nb_cli_enqueue_change(vty, "./global/global-config-timers/keepalive",
ff8a8a7a 2463 NB_OP_DESTROY, NULL);
87ce2564 2464 nb_cli_enqueue_change(vty, "./global/global-config-timers/hold-time",
ff8a8a7a 2465 NB_OP_DESTROY, NULL);
718e3744 2466
ff8a8a7a 2467 return nb_cli_apply_changes(vty, NULL);
718e3744 2468}
2469
ff8a8a7a
CS
2470void cli_show_router_bgp_route_reflector(struct vty *vty,
2471 struct lyd_node *dnode,
2472 bool show_defaults)
718e3744 2473{
ff8a8a7a
CS
2474 if (yang_dnode_get_bool(dnode, "./no-client-reflect"))
2475 vty_out(vty, " no bgp client-to-client reflection\n");
718e3744 2476
ff8a8a7a
CS
2477 if (yang_dnode_get_bool(dnode, "./allow-outbound-policy"))
2478 vty_out(vty, " bgp route-reflector allow-outbound-policy\n");
2479
2480 if (yang_dnode_exists(dnode, "./route-reflector-cluster-id"))
2481 vty_out(vty, " bgp cluster-id %s\n",
2482 yang_dnode_get_string(dnode,
2483 "./route-reflector-cluster-id"));
718e3744 2484}
2485
ff8a8a7a
CS
2486DEFUN_YANG(bgp_client_to_client_reflection,
2487 bgp_client_to_client_reflection_cmd,
2488 "bgp client-to-client reflection",
2489 "BGP specific commands\n"
2490 "Configure client to client route reflection\n"
2491 "reflection of routes allowed\n")
2492{
87ce2564 2493 nb_cli_enqueue_change(vty, "./global/route-reflector/no-client-reflect",
ff8a8a7a 2494 NB_OP_MODIFY, "false");
6b0655a2 2495
ff8a8a7a
CS
2496 return nb_cli_apply_changes(vty, NULL);
2497}
2498
2499DEFUN_YANG(no_bgp_client_to_client_reflection,
2500 no_bgp_client_to_client_reflection_cmd,
2501 "no bgp client-to-client reflection",
2502 NO_STR
2503 "BGP specific commands\n"
2504 "Configure client to client route reflection\n"
2505 "reflection of routes allowed\n")
718e3744 2506{
87ce2564 2507 nb_cli_enqueue_change(vty, "./global/route-reflector/no-client-reflect",
ff8a8a7a 2508 NB_OP_MODIFY, "true");
7aafcaca 2509
ff8a8a7a 2510 return nb_cli_apply_changes(vty, NULL);
718e3744 2511}
2512
ff8a8a7a
CS
2513void cli_show_router_bgp_route_selection(struct vty *vty,
2514 struct lyd_node *dnode,
2515 bool show_defaults)
718e3744 2516{
7aafcaca 2517
ff8a8a7a
CS
2518 if (yang_dnode_get_bool(dnode, "./always-compare-med"))
2519 vty_out(vty, " bgp always-compare-med\n");
2520
2521 if (yang_dnode_get_bool(dnode, "./ignore-as-path-length"))
2522 vty_out(vty, " bgp bestpath as-path ignore\n");
2523
2524 if (yang_dnode_get_bool(dnode, "./aspath-confed"))
2525 vty_out(vty, " bgp bestpath as-path confed\n");
2526
2527 if (yang_dnode_get_bool(dnode, "./external-compare-router-id"))
2528 vty_out(vty, " bgp bestpath compare-routerid\n");
2529
2530 if (yang_dnode_get_bool(dnode, "./allow-multiple-as")) {
2531 if (yang_dnode_get_bool(dnode, "./multi-path-as-set"))
2532 vty_out(vty,
2533 " bgp bestpath as-path multipath-relax as-set\n");
2534 else
2535 vty_out(vty, " bgp bestpath as-path multipath-relax\n");
2536 }
2537
2538 if (yang_dnode_get_bool(dnode, "./deterministic-med"))
2539 vty_out(vty, " bgp deterministic-med\n");
2540
2541 if (yang_dnode_get_bool(dnode, "./confed-med")
2542 || yang_dnode_get_bool(dnode, "./missing-as-worst-med")) {
2543 vty_out(vty, " bgp bestpath med");
2544 if (yang_dnode_get_bool(dnode, "./confed-med"))
2545 vty_out(vty, " confed");
2546 if (yang_dnode_get_bool(dnode, "./missing-as-worst-med"))
2547 vty_out(vty, " missing-as-worst");
2548 vty_out(vty, "\n");
2549 }
718e3744 2550}
2551
2552/* "bgp always-compare-med" configuration. */
ff8a8a7a
CS
2553DEFUN_YANG(bgp_always_compare_med,
2554 bgp_always_compare_med_cmd,
2555 "bgp always-compare-med",
2556 "BGP specific commands\n"
2557 "Allow comparing MED from different neighbors\n")
718e3744 2558{
87ce2564
CS
2559 nb_cli_enqueue_change(
2560 vty, "./global/route-selection-options/always-compare-med",
2561 NB_OP_MODIFY, "true");
7aafcaca 2562
ff8a8a7a 2563 return nb_cli_apply_changes(vty, NULL);
718e3744 2564}
2565
ff8a8a7a
CS
2566DEFUN_YANG(no_bgp_always_compare_med,
2567 no_bgp_always_compare_med_cmd,
2568 "no bgp always-compare-med",
2569 NO_STR
2570 "BGP specific commands\n"
2571 "Allow comparing MED from different neighbors\n")
718e3744 2572{
87ce2564
CS
2573 nb_cli_enqueue_change(
2574 vty, "./global/route-selection-options/always-compare-med",
2575 NB_OP_MODIFY, "false");
7aafcaca 2576
ff8a8a7a 2577 return nb_cli_apply_changes(vty, NULL);
718e3744 2578}
6b0655a2 2579
2adac256
DA
2580DEFUN_YANG(bgp_suppress_duplicates,
2581 bgp_suppress_duplicates_cmd,
2582 "bgp suppress-duplicates",
2583 "BGP specific commands\n"
2584 "Suppress duplicate updates if the route actually not changed\n")
2585{
2586 nb_cli_enqueue_change(vty, "./global/suppress-duplicates",
2587 NB_OP_MODIFY, "true");
2588 return nb_cli_apply_changes(vty, NULL);
2589}
2590
2591DEFUN_YANG(no_bgp_suppress_duplicates,
2592 no_bgp_suppress_duplicates_cmd,
2593 "no bgp suppress-duplicates",
2594 NO_STR
2595 "BGP specific commands\n"
2596 "Suppress duplicate updates if the route actually not changed\n")
2597{
2598 nb_cli_enqueue_change(vty, "./global/suppress-duplicates",
2599 NB_OP_MODIFY, "false");
2600 return nb_cli_apply_changes(vty, NULL);
2601}
2602
2603void cli_show_router_bgp_suppress_duplicates(struct vty *vty,
2604 struct lyd_node *dnode,
2605 bool show_defaults)
2606{
2607 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SUPPRESS_DUPLICATES)
2608 vty_out(vty, " bgp suppress-duplicates\n");
2609}
2610
ff8a8a7a
CS
2611DEFUN_YANG(bgp_ebgp_requires_policy,
2612 bgp_ebgp_requires_policy_cmd,
2613 "bgp ebgp-requires-policy",
2614 "BGP specific commands\n"
2615 "Require in and out policy for eBGP peers (RFC8212)\n")
2616{
87ce2564
CS
2617 nb_cli_enqueue_change(vty, "./global/ebgp-requires-policy",
2618 NB_OP_MODIFY, "true");
ff8a8a7a
CS
2619 return nb_cli_apply_changes(vty, NULL);
2620}
9dac9fc8 2621
ff8a8a7a
CS
2622DEFUN_YANG(no_bgp_ebgp_requires_policy,
2623 no_bgp_ebgp_requires_policy_cmd,
2624 "no bgp ebgp-requires-policy",
2625 NO_STR
2626 "BGP specific commands\n"
2627 "Require in and out policy for eBGP peers (RFC8212)\n")
9dac9fc8 2628{
87ce2564
CS
2629 nb_cli_enqueue_change(vty, "./global/ebgp-requires-policy",
2630 NB_OP_MODIFY, "false");
ff8a8a7a 2631 return nb_cli_apply_changes(vty, NULL);
9dac9fc8
DA
2632}
2633
ff8a8a7a
CS
2634void cli_show_router_bgp_ebgp_requires_policy(struct vty *vty,
2635 struct lyd_node *dnode,
2636 bool show_defaults)
9dac9fc8 2637{
ff8a8a7a
CS
2638 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_EBGP_REQUIRES_POLICY)
2639 vty_out(vty, " bgp ebgp-requires-policy\n");
9dac9fc8
DA
2640}
2641
fb29348a
DA
2642DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2643 "bgp reject-as-sets",
2644 "BGP specific commands\n"
2645 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2646{
2647 VTY_DECLVAR_CONTEXT(bgp, bgp);
2648 struct listnode *node, *nnode;
2649 struct peer *peer;
2650
7f972cd8 2651 bgp->reject_as_sets = true;
fb29348a
DA
2652
2653 /* Reset existing BGP sessions to reject routes
2654 * with aspath containing AS_SET or AS_CONFED_SET.
2655 */
2656 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2657 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2658 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2659 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2660 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2661 }
2662 }
2663
2664 return CMD_SUCCESS;
2665}
2666
2667DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2668 "no bgp reject-as-sets",
2669 NO_STR
2670 "BGP specific commands\n"
2671 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2672{
2673 VTY_DECLVAR_CONTEXT(bgp, bgp);
2674 struct listnode *node, *nnode;
2675 struct peer *peer;
2676
7f972cd8 2677 bgp->reject_as_sets = false;
fb29348a
DA
2678
2679 /* Reset existing BGP sessions to reject routes
2680 * with aspath containing AS_SET or AS_CONFED_SET.
2681 */
2682 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2683 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2684 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2685 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2686 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2687 }
2688 }
2689
2690 return CMD_SUCCESS;
2691}
9dac9fc8 2692
718e3744 2693/* "bgp deterministic-med" configuration. */
ff8a8a7a 2694DEFUN_YANG (bgp_deterministic_med,
718e3744 2695 bgp_deterministic_med_cmd,
2696 "bgp deterministic-med",
2697 "BGP specific commands\n"
2698 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2699{
87ce2564
CS
2700 nb_cli_enqueue_change(
2701 vty, "./global/route-selection-options/deterministic-med",
2702 NB_OP_MODIFY, "true");
7aafcaca 2703
ff8a8a7a 2704 return nb_cli_apply_changes(vty, NULL);
718e3744 2705}
2706
ff8a8a7a 2707DEFUN_YANG (no_bgp_deterministic_med,
718e3744 2708 no_bgp_deterministic_med_cmd,
2709 "no bgp deterministic-med",
2710 NO_STR
2711 "BGP specific commands\n"
2712 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2713{
87ce2564
CS
2714 nb_cli_enqueue_change(
2715 vty, "./global/route-selection-options/deterministic-med",
2716 NB_OP_MODIFY, "false");
d62a17ae 2717
ff8a8a7a 2718 return nb_cli_apply_changes(vty, NULL);
718e3744 2719}
538621f2 2720
055679e9 2721/* "bgp graceful-restart mode" configuration. */
538621f2 2722DEFUN (bgp_graceful_restart,
2ba1fe69 2723 bgp_graceful_restart_cmd,
2724 "bgp graceful-restart",
2725 "BGP specific commands\n"
2726 GR_CMD
055679e9 2727 )
538621f2 2728{
055679e9 2729 int ret = BGP_GR_FAILURE;
2730
2731 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2732 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
dc95985f 2733
d62a17ae 2734 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2735
2736 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2737
36235319
QY
2738 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2739 ret);
5cce3f05 2740
055679e9 2741 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2742 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
dc95985f 2743 vty_out(vty,
2744 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2745 return bgp_vty_return(vty, ret);
538621f2 2746}
2747
2748DEFUN (no_bgp_graceful_restart,
2ba1fe69 2749 no_bgp_graceful_restart_cmd,
2750 "no bgp graceful-restart",
2751 NO_STR
2752 "BGP specific commands\n"
2753 NO_GR_CMD
055679e9 2754 )
538621f2 2755{
d62a17ae 2756 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2757
2758 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2759 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
055679e9 2760
2761 int ret = BGP_GR_FAILURE;
2762
2763 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2764
36235319
QY
2765 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2766 ret);
5cce3f05 2767
055679e9 2768 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2769 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
dc95985f 2770 vty_out(vty,
2771 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2772
2773 return bgp_vty_return(vty, ret);
538621f2 2774}
2775
93406d87 2776DEFUN (bgp_graceful_restart_stalepath_time,
2ba1fe69 2777 bgp_graceful_restart_stalepath_time_cmd,
2778 "bgp graceful-restart stalepath-time (1-4095)",
2779 "BGP specific commands\n"
2780 "Graceful restart capability parameters\n"
2781 "Set the max time to hold onto restarting peer's stale paths\n"
2782 "Delay value (seconds)\n")
93406d87 2783{
d62a17ae 2784 VTY_DECLVAR_CONTEXT(bgp, bgp);
2785 int idx_number = 3;
d7c0a89a 2786 uint32_t stalepath;
93406d87 2787
d62a17ae 2788 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2789 bgp->stalepath_time = stalepath;
2790 return CMD_SUCCESS;
93406d87 2791}
2792
eb6f1b41 2793DEFUN (bgp_graceful_restart_restart_time,
2ba1fe69 2794 bgp_graceful_restart_restart_time_cmd,
2795 "bgp graceful-restart restart-time (1-4095)",
2796 "BGP specific commands\n"
2797 "Graceful restart capability parameters\n"
2798 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2799 "Delay value (seconds)\n")
eb6f1b41 2800{
d62a17ae 2801 VTY_DECLVAR_CONTEXT(bgp, bgp);
2802 int idx_number = 3;
d7c0a89a 2803 uint32_t restart;
eb6f1b41 2804
d62a17ae 2805 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2806 bgp->restart_time = restart;
2807 return CMD_SUCCESS;
eb6f1b41
PG
2808}
2809
cfd47646 2810DEFUN (bgp_graceful_restart_select_defer_time,
2811 bgp_graceful_restart_select_defer_time_cmd,
2812 "bgp graceful-restart select-defer-time (0-3600)",
2813 "BGP specific commands\n"
2814 "Graceful restart capability parameters\n"
2815 "Set the time to defer the BGP route selection after restart\n"
2816 "Delay value (seconds, 0 - disable)\n")
2817{
2818 VTY_DECLVAR_CONTEXT(bgp, bgp);
2819 int idx_number = 3;
2820 uint32_t defer_time;
2821
2822 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2823 bgp->select_defer_time = defer_time;
2824 if (defer_time == 0)
892fedb6 2825 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2826 else
892fedb6 2827 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2828
2829 return CMD_SUCCESS;
2830}
2831
93406d87 2832DEFUN (no_bgp_graceful_restart_stalepath_time,
2ba1fe69 2833 no_bgp_graceful_restart_stalepath_time_cmd,
2834 "no bgp graceful-restart stalepath-time [(1-4095)]",
2835 NO_STR
2836 "BGP specific commands\n"
2837 "Graceful restart capability parameters\n"
2838 "Set the max time to hold onto restarting peer's stale paths\n"
2839 "Delay value (seconds)\n")
93406d87 2840{
d62a17ae 2841 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 2842
d62a17ae 2843 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2844 return CMD_SUCCESS;
93406d87 2845}
2846
eb6f1b41 2847DEFUN (no_bgp_graceful_restart_restart_time,
2ba1fe69 2848 no_bgp_graceful_restart_restart_time_cmd,
2849 "no bgp graceful-restart restart-time [(1-4095)]",
2850 NO_STR
2851 "BGP specific commands\n"
2852 "Graceful restart capability parameters\n"
2853 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2854 "Delay value (seconds)\n")
eb6f1b41 2855{
d62a17ae 2856 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 2857
d62a17ae 2858 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2859 return CMD_SUCCESS;
eb6f1b41
PG
2860}
2861
cfd47646 2862DEFUN (no_bgp_graceful_restart_select_defer_time,
2863 no_bgp_graceful_restart_select_defer_time_cmd,
2864 "no bgp graceful-restart select-defer-time [(0-3600)]",
2865 NO_STR
2866 "BGP specific commands\n"
2867 "Graceful restart capability parameters\n"
2868 "Set the time to defer the BGP route selection after restart\n"
2869 "Delay value (seconds)\n")
2870{
2871 VTY_DECLVAR_CONTEXT(bgp, bgp);
2872
2873 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
892fedb6 2874 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2875
2876 return CMD_SUCCESS;
2877}
2878
43fc21b3 2879DEFUN (bgp_graceful_restart_preserve_fw,
2ba1fe69 2880 bgp_graceful_restart_preserve_fw_cmd,
2881 "bgp graceful-restart preserve-fw-state",
2882 "BGP specific commands\n"
2883 "Graceful restart capability parameters\n"
2884 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2885{
d62a17ae 2886 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2887 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2888 return CMD_SUCCESS;
43fc21b3
JC
2889}
2890
2891DEFUN (no_bgp_graceful_restart_preserve_fw,
2ba1fe69 2892 no_bgp_graceful_restart_preserve_fw_cmd,
2893 "no bgp graceful-restart preserve-fw-state",
2894 NO_STR
2895 "BGP specific commands\n"
2896 "Graceful restart capability parameters\n"
2897 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2898{
d62a17ae 2899 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2900 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2901 return CMD_SUCCESS;
43fc21b3
JC
2902}
2903
055679e9 2904DEFUN (bgp_graceful_restart_disable,
2ba1fe69 2905 bgp_graceful_restart_disable_cmd,
2906 "bgp graceful-restart-disable",
2907 "BGP specific commands\n"
2908 GR_DISABLE)
055679e9 2909{
2910 int ret = BGP_GR_FAILURE;
2911
2912 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2913 zlog_debug(
2ba1fe69 2914 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
dc95985f 2915
055679e9 2916 VTY_DECLVAR_CONTEXT(bgp, bgp);
2917
2918 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
2919
dc95985f 2920 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2921 bgp->peer, ret);
5cce3f05 2922
055679e9 2923 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2924 zlog_debug(
2ba1fe69 2925 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
dc95985f 2926 vty_out(vty,
2927 "Graceful restart configuration changed, reset all peers to take effect\n");
2928
055679e9 2929 return bgp_vty_return(vty, ret);
2930}
2931
2932DEFUN (no_bgp_graceful_restart_disable,
2ba1fe69 2933 no_bgp_graceful_restart_disable_cmd,
2934 "no bgp graceful-restart-disable",
2935 NO_STR
2936 "BGP specific commands\n"
2937 NO_GR_DISABLE
055679e9 2938 )
2939{
2940 VTY_DECLVAR_CONTEXT(bgp, bgp);
2941
2942 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2943 zlog_debug(
2ba1fe69 2944 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
055679e9 2945
2946 int ret = BGP_GR_FAILURE;
2947
2948 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
2949
36235319
QY
2950 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2951 ret);
5cce3f05 2952
055679e9 2953 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2954 zlog_debug(
2ba1fe69 2955 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
dc95985f 2956 vty_out(vty,
2957 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2958
2959 return bgp_vty_return(vty, ret);
2960}
2961
2962DEFUN (bgp_neighbor_graceful_restart_set,
2ba1fe69 2963 bgp_neighbor_graceful_restart_set_cmd,
2964 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2965 NEIGHBOR_STR
2966 NEIGHBOR_ADDR_STR2
2967 GR_NEIGHBOR_CMD
055679e9 2968 )
2969{
2970 int idx_peer = 1;
2971 struct peer *peer;
2972 int ret = BGP_GR_FAILURE;
2973
dc95985f 2974 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2975
055679e9 2976 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2977 zlog_debug(
2ba1fe69 2978 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
dc95985f 2979
055679e9 2980 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2981 if (!peer)
2982 return CMD_WARNING_CONFIG_FAILED;
2983
2984 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
2985
dc95985f 2986 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2987 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2988
2989 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2990 zlog_debug(
2ba1fe69 2991 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 2992 vty_out(vty,
2993 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2994
2995 return bgp_vty_return(vty, ret);
2996}
2997
2998DEFUN (no_bgp_neighbor_graceful_restart,
2ba1fe69 2999 no_bgp_neighbor_graceful_restart_set_cmd,
3000 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3001 NO_STR
3002 NEIGHBOR_STR
3003 NEIGHBOR_ADDR_STR2
3004 NO_GR_NEIGHBOR_CMD
055679e9 3005 )
3006{
3007 int idx_peer = 2;
3008 int ret = BGP_GR_FAILURE;
3009 struct peer *peer;
3010
dc95985f 3011 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3012
055679e9 3013 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3014 if (!peer)
3015 return CMD_WARNING_CONFIG_FAILED;
3016
3017 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3018 zlog_debug(
2ba1fe69 3019 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
055679e9 3020
3021 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
3022
dc95985f 3023 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3024 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3025
3026 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3027 zlog_debug(
2ba1fe69 3028 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 3029 vty_out(vty,
3030 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3031
3032 return bgp_vty_return(vty, ret);
3033}
3034
3035DEFUN (bgp_neighbor_graceful_restart_helper_set,
2ba1fe69 3036 bgp_neighbor_graceful_restart_helper_set_cmd,
3037 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3038 NEIGHBOR_STR
3039 NEIGHBOR_ADDR_STR2
3040 GR_NEIGHBOR_HELPER_CMD
055679e9 3041 )
3042{
3043 int idx_peer = 1;
3044 struct peer *peer;
3045 int ret = BGP_GR_FAILURE;
3046
dc95985f 3047 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3048
055679e9 3049 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3050 zlog_debug(
2ba1fe69 3051 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
dc95985f 3052
055679e9 3053 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3054
055679e9 3055 if (!peer)
3056 return CMD_WARNING_CONFIG_FAILED;
3057
3058
3059 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
5cce3f05 3060
dc95985f 3061 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3062 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
5cce3f05 3063
055679e9 3064 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3065 zlog_debug(
2ba1fe69 3066 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 3067 vty_out(vty,
3068 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3069
3070 return bgp_vty_return(vty, ret);
3071}
3072
3073DEFUN (no_bgp_neighbor_graceful_restart_helper,
2ba1fe69 3074 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3075 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3076 NO_STR
3077 NEIGHBOR_STR
3078 NEIGHBOR_ADDR_STR2
3079 NO_GR_NEIGHBOR_HELPER_CMD
055679e9 3080 )
3081{
3082 int idx_peer = 2;
3083 int ret = BGP_GR_FAILURE;
3084 struct peer *peer;
3085
dc95985f 3086 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3087
055679e9 3088 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3089 if (!peer)
3090 return CMD_WARNING_CONFIG_FAILED;
3091
3092 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3093 zlog_debug(
2ba1fe69 3094 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
055679e9 3095
36235319 3096 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
055679e9 3097
dc95985f 3098 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3099 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3100
3101 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3102 zlog_debug(
2ba1fe69 3103 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 3104 vty_out(vty,
3105 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3106
3107 return bgp_vty_return(vty, ret);
3108}
3109
3110DEFUN (bgp_neighbor_graceful_restart_disable_set,
2ba1fe69 3111 bgp_neighbor_graceful_restart_disable_set_cmd,
3112 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3113 NEIGHBOR_STR
3114 NEIGHBOR_ADDR_STR2
3115 GR_NEIGHBOR_DISABLE_CMD
055679e9 3116 )
3117{
3118 int idx_peer = 1;
3119 struct peer *peer;
3120 int ret = BGP_GR_FAILURE;
3121
dc95985f 3122 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3123
055679e9 3124 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3125 zlog_debug(
2ba1fe69 3126 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 3127
3128 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3129 if (!peer)
3130 return CMD_WARNING_CONFIG_FAILED;
3131
36235319 3132 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
055679e9 3133
3134 if (peer->bgp->t_startup)
3135 bgp_peer_gr_flags_update(peer);
3136
dc95985f 3137 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3138 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3139
055679e9 3140 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3141 zlog_debug(
2ba1fe69 3142 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3143 vty_out(vty,
3144 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3145
3146 return bgp_vty_return(vty, ret);
3147}
3148
3149DEFUN (no_bgp_neighbor_graceful_restart_disable,
2ba1fe69 3150 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3151 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3152 NO_STR
3153 NEIGHBOR_STR
3154 NEIGHBOR_ADDR_STR2
3155 NO_GR_NEIGHBOR_DISABLE_CMD
055679e9 3156 )
3157{
3158 int idx_peer = 2;
3159 int ret = BGP_GR_FAILURE;
3160 struct peer *peer;
3161
dc95985f 3162 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3163
055679e9 3164 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3165 if (!peer)
3166 return CMD_WARNING_CONFIG_FAILED;
3167
3168 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3169 zlog_debug(
2ba1fe69 3170 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 3171
3172 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3173
dc95985f 3174 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3175 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3176
3177 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3178 zlog_debug(
2ba1fe69 3179 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3180 vty_out(vty,
3181 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3182
3183 return bgp_vty_return(vty, ret);
3184}
3185
d6e3c15b 3186DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3187 bgp_graceful_restart_disable_eor_cmd,
3188 "bgp graceful-restart disable-eor",
3189 "BGP specific commands\n"
3190 "Graceful restart configuration parameters\n"
3191 "Disable EOR Check\n")
3192{
3193 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3194 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3195
d6e3c15b 3196 return CMD_SUCCESS;
3197}
3198
3199DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3200 no_bgp_graceful_restart_disable_eor_cmd,
3201 "no bgp graceful-restart disable-eor",
3202 NO_STR
3203 "BGP specific commands\n"
3204 "Graceful restart configuration parameters\n"
3205 "Disable EOR Check\n")
3206{
3207 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3208 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3209
3210 return CMD_SUCCESS;
3211}
3212
3213DEFUN (bgp_graceful_restart_rib_stale_time,
3214 bgp_graceful_restart_rib_stale_time_cmd,
3215 "bgp graceful-restart rib-stale-time (1-3600)",
3216 "BGP specific commands\n"
3217 "Graceful restart configuration parameters\n"
3218 "Specify the stale route removal timer in rib\n"
3219 "Delay value (seconds)\n")
3220{
3221 VTY_DECLVAR_CONTEXT(bgp, bgp);
3222 int idx_number = 3;
3223 uint32_t stale_time;
3224
3225 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3226 bgp->rib_stale_time = stale_time;
3227 /* Send the stale timer update message to RIB */
3228 if (bgp_zebra_stale_timer_update(bgp))
3229 return CMD_WARNING;
3230
3231 return CMD_SUCCESS;
3232}
3233
3234DEFUN (no_bgp_graceful_restart_rib_stale_time,
3235 no_bgp_graceful_restart_rib_stale_time_cmd,
3236 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3237 NO_STR
3238 "BGP specific commands\n"
3239 "Graceful restart configuration parameters\n"
3240 "Specify the stale route removal timer in rib\n"
3241 "Delay value (seconds)\n")
3242{
3243 VTY_DECLVAR_CONTEXT(bgp, bgp);
3244
3245 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3246 /* Send the stale timer update message to RIB */
3247 if (bgp_zebra_stale_timer_update(bgp))
3248 return CMD_WARNING;
3249
d6e3c15b 3250 return CMD_SUCCESS;
3251}
3252
ff8a8a7a
CS
3253static inline int bgp_initiate_graceful_shut_unshut(struct bgp *bgp,
3254 char *errmsg,
3255 size_t errmsg_len)
05bd726c 3256{
3257 bgp_static_redo_import_check(bgp);
3258 bgp_redistribute_redo(bgp);
ff8a8a7a
CS
3259 if (bgp_clear_star_soft_out(bgp->name, errmsg, errmsg_len) < 0)
3260 return -1;
3261 if (bgp_clear_star_soft_in(bgp->name, errmsg, errmsg_len) < 0)
3262 return -1;
3263
3264 return 0;
05bd726c 3265}
3266
3267static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3268{
3269 struct listnode *node, *nnode;
3270 struct bgp *bgp;
3271 bool vrf_cfg = false;
ff8a8a7a 3272 char errmsg[BUFSIZ] = {'\0'};
05bd726c 3273
3274 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3275 return CMD_SUCCESS;
3276
3277 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3278 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3279 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3280 vty_out(vty,
3281 "%% graceful-shutdown configuration found in vrf %s\n",
3282 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3283 VRF_DEFAULT_NAME : bgp->name);
3284 vrf_cfg = true;
3285 }
3286 }
3287
3288 if (vrf_cfg) {
3289 vty_out(vty,
3290 "%%Failed: global graceful-shutdown not permitted\n");
3291 return CMD_WARNING;
3292 }
3293
3294 /* Set flag globally */
3295 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3296
3297 /* Initiate processing for all BGP instances. */
ff8a8a7a
CS
3298 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3299 if (bgp_initiate_graceful_shut_unshut(bgp, errmsg,
3300 sizeof(errmsg))
3301 < 0)
3302 if (strlen(errmsg))
3303 vty_out(vty, "%s\n", errmsg);
3304 }
05bd726c 3305
3306 return CMD_SUCCESS;
3307}
3308
3309static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3310{
3311 struct listnode *node, *nnode;
3312 struct bgp *bgp;
ff8a8a7a 3313 char errmsg[BUFSIZ] = {'\0'};
05bd726c 3314
3315 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3316 return CMD_SUCCESS;
3317
3318 /* Unset flag globally */
3319 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3320
3321 /* Initiate processing for all BGP instances. */
ff8a8a7a
CS
3322 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3323 if (bgp_initiate_graceful_shut_unshut(bgp, errmsg,
3324 sizeof(errmsg))
3325 < 0)
3326 if (strlen(errmsg))
3327 vty_out(vty, "%s\n", errmsg);
3328 }
05bd726c 3329
3330 return CMD_SUCCESS;
3331}
3332
7f323236
DW
3333/* "bgp graceful-shutdown" configuration */
3334DEFUN (bgp_graceful_shutdown,
3335 bgp_graceful_shutdown_cmd,
3336 "bgp graceful-shutdown",
3337 BGP_STR
3338 "Graceful shutdown parameters\n")
3339{
05bd726c 3340 if (vty->node == CONFIG_NODE)
3341 return bgp_global_graceful_shutdown_config_vty(vty);
3342
87ce2564
CS
3343 nb_cli_enqueue_change(vty, "./global/graceful-shutdown/enable",
3344 NB_OP_MODIFY, "true");
7f323236 3345
ff8a8a7a 3346 return nb_cli_apply_changes(vty, NULL);
7f323236
DW
3347}
3348
ff8a8a7a 3349DEFUN_YANG (no_bgp_graceful_shutdown,
7f323236
DW
3350 no_bgp_graceful_shutdown_cmd,
3351 "no bgp graceful-shutdown",
3352 NO_STR
3353 BGP_STR
3354 "Graceful shutdown parameters\n")
3355{
05bd726c 3356 if (vty->node == CONFIG_NODE)
3357 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3358
87ce2564
CS
3359 nb_cli_enqueue_change(vty, "./global/graceful-shutdown/enable",
3360 NB_OP_MODIFY, "false");
05bd726c 3361
ff8a8a7a
CS
3362 return nb_cli_apply_changes(vty, NULL);
3363}
7f323236 3364
ff8a8a7a
CS
3365void cli_show_router_bgp_graceful_shutdown(struct vty *vty,
3366 struct lyd_node *dnode,
3367 bool show_defaults)
3368{
3369 if (yang_dnode_get_bool(dnode, NULL))
3370 vty_out(vty, " bgp graceful-shutdown\n");
7f323236
DW
3371}
3372
718e3744 3373/* "bgp fast-external-failover" configuration. */
ff8a8a7a 3374DEFUN_YANG (bgp_fast_external_failover,
718e3744 3375 bgp_fast_external_failover_cmd,
3376 "bgp fast-external-failover",
3377 BGP_STR
3378 "Immediately reset session if a link to a directly connected external peer goes down\n")
3379{
87ce2564
CS
3380 nb_cli_enqueue_change(vty, "./global/fast-external-failover",
3381 NB_OP_MODIFY, "false");
ff8a8a7a
CS
3382
3383 return nb_cli_apply_changes(vty, NULL);
718e3744 3384}
3385
ff8a8a7a 3386DEFUN_YANG (no_bgp_fast_external_failover,
718e3744 3387 no_bgp_fast_external_failover_cmd,
3388 "no bgp fast-external-failover",
3389 NO_STR
3390 BGP_STR
3391 "Immediately reset session if a link to a directly connected external peer goes down\n")
3392{
87ce2564
CS
3393 nb_cli_enqueue_change(vty, "./global/fast-external-failover",
3394 NB_OP_MODIFY, "true");
ff8a8a7a
CS
3395
3396 return nb_cli_apply_changes(vty, NULL);
3397}
3398
3399void cli_show_router_bgp_fast_external_failover(struct vty *vty,
3400 struct lyd_node *dnode,
3401 bool show_defaults)
3402{
3403 if (!yang_dnode_get_bool(dnode, NULL))
3404 vty_out(vty, " no bgp fast-external-failover\n");
718e3744 3405}
6b0655a2 3406
718e3744 3407/* "bgp bestpath compare-routerid" configuration. */
ff8a8a7a
CS
3408DEFUN_YANG(bgp_bestpath_compare_router_id,
3409 bgp_bestpath_compare_router_id_cmd,
3410 "bgp bestpath compare-routerid",
3411 "BGP specific commands\n"
3412 "Change the default bestpath selection\n"
3413 "Compare router-id for identical EBGP paths\n")
718e3744 3414{
ff8a8a7a 3415 nb_cli_enqueue_change(
87ce2564
CS
3416 vty,
3417 "./global/route-selection-options/external-compare-router-id",
ff8a8a7a 3418 NB_OP_MODIFY, "true");
7aafcaca 3419
ff8a8a7a 3420 return nb_cli_apply_changes(vty, NULL);
718e3744 3421}
3422
ff8a8a7a
CS
3423DEFUN_YANG(no_bgp_bestpath_compare_router_id,
3424 no_bgp_bestpath_compare_router_id_cmd,
3425 "no bgp bestpath compare-routerid",
3426 NO_STR
3427 "BGP specific commands\n"
3428 "Change the default bestpath selection\n"
3429 "Compare router-id for identical EBGP paths\n")
718e3744 3430{
ff8a8a7a 3431 nb_cli_enqueue_change(
87ce2564
CS
3432 vty,
3433 "./global/route-selection-options/external-compare-router-id",
ff8a8a7a 3434 NB_OP_MODIFY, "false");
7aafcaca 3435
ff8a8a7a 3436 return nb_cli_apply_changes(vty, NULL);
718e3744 3437}
6b0655a2 3438
718e3744 3439/* "bgp bestpath as-path ignore" configuration. */
ff8a8a7a
CS
3440DEFUN_YANG(bgp_bestpath_aspath_ignore,
3441 bgp_bestpath_aspath_ignore_cmd,
3442 "bgp bestpath as-path ignore",
3443 "BGP specific commands\n"
3444 "Change the default bestpath selection\n"
3445 "AS-path attribute\n"
3446 "Ignore as-path length in selecting a route\n")
718e3744 3447{
87ce2564
CS
3448 nb_cli_enqueue_change(
3449 vty, "./global/route-selection-options/ignore-as-path-length",
3450 NB_OP_MODIFY, "true");
7aafcaca 3451
ff8a8a7a 3452 return nb_cli_apply_changes(vty, NULL);
718e3744 3453}
3454
ff8a8a7a
CS
3455DEFUN_YANG(no_bgp_bestpath_aspath_ignore,
3456 no_bgp_bestpath_aspath_ignore_cmd,
3457 "no bgp bestpath as-path ignore",
3458 NO_STR
3459 "BGP specific commands\n"
3460 "Change the default bestpath selection\n"
3461 "AS-path attribute\n"
3462 "Ignore as-path length in selecting a route\n")
718e3744 3463{
87ce2564
CS
3464 nb_cli_enqueue_change(
3465 vty, "./global/route-selection-options/ignore-as-path-length",
3466 NB_OP_MODIFY, "false");
7aafcaca 3467
ff8a8a7a 3468 return nb_cli_apply_changes(vty, NULL);
718e3744 3469}
6b0655a2 3470
6811845b 3471/* "bgp bestpath as-path confed" configuration. */
ff8a8a7a 3472DEFUN_YANG (bgp_bestpath_aspath_confed,
6811845b 3473 bgp_bestpath_aspath_confed_cmd,
3474 "bgp bestpath as-path confed",
3475 "BGP specific commands\n"
3476 "Change the default bestpath selection\n"
3477 "AS-path attribute\n"
3478 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3479{
87ce2564
CS
3480 nb_cli_enqueue_change(vty,
3481 "./global/route-selection-options/aspath-confed",
ff8a8a7a 3482 NB_OP_MODIFY, "true");
7aafcaca 3483
ff8a8a7a 3484 return nb_cli_apply_changes(vty, NULL);
6811845b 3485}
3486
ff8a8a7a 3487DEFUN_YANG (no_bgp_bestpath_aspath_confed,
6811845b 3488 no_bgp_bestpath_aspath_confed_cmd,
3489 "no bgp bestpath as-path confed",
3490 NO_STR
3491 "BGP specific commands\n"
3492 "Change the default bestpath selection\n"
3493 "AS-path attribute\n"
3494 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3495{
87ce2564
CS
3496 nb_cli_enqueue_change(vty,
3497 "./global/route-selection-options/aspath-confed",
ff8a8a7a 3498 NB_OP_MODIFY, "false");
7aafcaca 3499
ff8a8a7a 3500 return nb_cli_apply_changes(vty, NULL);
6811845b 3501}
6b0655a2 3502
2fdd455c 3503/* "bgp bestpath as-path multipath-relax" configuration. */
ff8a8a7a 3504DEFUN_YANG (bgp_bestpath_aspath_multipath_relax,
2fdd455c 3505 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3506 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
3507 "BGP specific commands\n"
3508 "Change the default bestpath selection\n"
3509 "AS-path attribute\n"
3510 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3511 "Generate an AS_SET\n"
16fc1eec
DS
3512 "Do not generate an AS_SET\n")
3513{
d62a17ae 3514 int idx = 0;
219178b6 3515
87ce2564
CS
3516 nb_cli_enqueue_change(
3517 vty, "./global/route-selection-options/allow-multiple-as",
3518 NB_OP_MODIFY, "true");
d62a17ae 3519 if (argv_find(argv, argc, "as-set", &idx))
ff8a8a7a 3520 nb_cli_enqueue_change(
87ce2564
CS
3521 vty,
3522 "./global/route-selection-options/multi-path-as-set",
ff8a8a7a 3523 NB_OP_MODIFY, "true");
d62a17ae 3524 else
ff8a8a7a 3525 nb_cli_enqueue_change(
87ce2564
CS
3526 vty,
3527 "./global/route-selection-options/multi-path-as-set",
ff8a8a7a 3528 NB_OP_MODIFY, "false");
7aafcaca 3529
ff8a8a7a 3530 return nb_cli_apply_changes(vty, NULL);
16fc1eec
DS
3531}
3532
ff8a8a7a 3533DEFUN_YANG (no_bgp_bestpath_aspath_multipath_relax,
219178b6 3534 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3535 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
3536 NO_STR
3537 "BGP specific commands\n"
3538 "Change the default bestpath selection\n"
3539 "AS-path attribute\n"
3540 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3541 "Generate an AS_SET\n"
16fc1eec
DS
3542 "Do not generate an AS_SET\n")
3543{
87ce2564
CS
3544 nb_cli_enqueue_change(
3545 vty, "./global/route-selection-options/allow-multiple-as",
3546 NB_OP_MODIFY, "false");
3547 nb_cli_enqueue_change(
3548 vty, "./global/route-selection-options/multi-path-as-set",
3549 NB_OP_MODIFY, "false");
7aafcaca 3550
ff8a8a7a 3551 return nb_cli_apply_changes(vty, NULL);
2fdd455c 3552}
6b0655a2 3553
848973c7 3554/* "bgp log-neighbor-changes" configuration. */
ff8a8a7a
CS
3555DEFUN_YANG(bgp_log_neighbor_changes,
3556 bgp_log_neighbor_changes_cmd,
3557 "bgp log-neighbor-changes",
3558 "BGP specific commands\n"
3559 "Log neighbor up/down and reset reason\n")
848973c7 3560{
87ce2564
CS
3561 nb_cli_enqueue_change(
3562 vty, "./global/global-neighbor-config/log-neighbor-changes",
3563 NB_OP_MODIFY, "true");
ff8a8a7a
CS
3564
3565 return nb_cli_apply_changes(vty, NULL);
848973c7 3566}
3567
ff8a8a7a
CS
3568DEFUN_YANG(no_bgp_log_neighbor_changes,
3569 no_bgp_log_neighbor_changes_cmd,
3570 "no bgp log-neighbor-changes",
3571 NO_STR
3572 "BGP specific commands\n"
3573 "Log neighbor up/down and reset reason\n")
848973c7 3574{
87ce2564
CS
3575 nb_cli_enqueue_change(
3576 vty, "./global/global-neighbor-config/log-neighbor-changes",
3577 NB_OP_MODIFY, "false");
ff8a8a7a
CS
3578
3579 return nb_cli_apply_changes(vty, NULL);
848973c7 3580}
6b0655a2 3581
718e3744 3582/* "bgp bestpath med" configuration. */
ff8a8a7a 3583DEFUN_YANG (bgp_bestpath_med,
718e3744 3584 bgp_bestpath_med_cmd,
2d8c1a4d 3585 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 3586 "BGP specific commands\n"
3587 "Change the default bestpath selection\n"
3588 "MED attribute\n"
3589 "Compare MED among confederation paths\n"
838758ac
DW
3590 "Treat missing MED as the least preferred one\n"
3591 "Treat missing MED as the least preferred one\n"
3592 "Compare MED among confederation paths\n")
718e3744 3593{
d62a17ae 3594 int idx = 0;
ff8a8a7a
CS
3595 bool confed = false;
3596 bool worst_med = false;
3597
3598
d62a17ae 3599 if (argv_find(argv, argc, "confed", &idx))
ff8a8a7a
CS
3600 confed = true;
3601
87ce2564
CS
3602 nb_cli_enqueue_change(vty,
3603 "./global/route-selection-options/confed-med",
ff8a8a7a
CS
3604 NB_OP_MODIFY, confed ? "true" : "false");
3605
d62a17ae 3606 idx = 0;
3607 if (argv_find(argv, argc, "missing-as-worst", &idx))
ff8a8a7a 3608 worst_med = true;
e52702f2 3609
87ce2564
CS
3610 nb_cli_enqueue_change(
3611 vty, "./global/route-selection-options/missing-as-worst-med",
3612 NB_OP_MODIFY, worst_med ? "true" : "false");
7aafcaca 3613
ff8a8a7a 3614 return nb_cli_apply_changes(vty, NULL);
718e3744 3615}
3616
ff8a8a7a 3617DEFUN_YANG (no_bgp_bestpath_med,
718e3744 3618 no_bgp_bestpath_med_cmd,
2d8c1a4d 3619 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 3620 NO_STR
3621 "BGP specific commands\n"
3622 "Change the default bestpath selection\n"
3623 "MED attribute\n"
3624 "Compare MED among confederation paths\n"
3a2d747c
QY
3625 "Treat missing MED as the least preferred one\n"
3626 "Treat missing MED as the least preferred one\n"
3627 "Compare MED among confederation paths\n")
718e3744 3628{
d62a17ae 3629 int idx = 0;
ff8a8a7a 3630
d62a17ae 3631 if (argv_find(argv, argc, "confed", &idx))
87ce2564
CS
3632 nb_cli_enqueue_change(
3633 vty, "./global/route-selection-options/confed-med",
3634 NB_OP_MODIFY, "false");
ff8a8a7a 3635
d62a17ae 3636 idx = 0;
3637 if (argv_find(argv, argc, "missing-as-worst", &idx))
ff8a8a7a 3638 nb_cli_enqueue_change(
87ce2564
CS
3639 vty,
3640 "./global/route-selection-options/missing-as-worst-med",
ff8a8a7a 3641 NB_OP_MODIFY, "false");
718e3744 3642
ff8a8a7a 3643 return nb_cli_apply_changes(vty, NULL);
718e3744 3644}
3645
f7e1c681 3646/* "bgp bestpath bandwidth" configuration. */
3647DEFPY (bgp_bestpath_bw,
3648 bgp_bestpath_bw_cmd,
ad36d216 3649 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
f7e1c681 3650 "BGP specific commands\n"
3651 "Change the default bestpath selection\n"
3652 "Link Bandwidth attribute\n"
3653 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3654 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3655 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3656{
3657 VTY_DECLVAR_CONTEXT(bgp, bgp);
3658 afi_t afi;
3659 safi_t safi;
3660
ad36d216
DS
3661 if (!bw_cfg) {
3662 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3663 return CMD_ERR_INCOMPLETE;
f7e1c681 3664 }
ad36d216
DS
3665 if (!strcmp(bw_cfg, "ignore"))
3666 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3667 else if (!strcmp(bw_cfg, "skip-missing"))
3668 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3669 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3670 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3671 else
3672 return CMD_ERR_NO_MATCH;
f7e1c681 3673
3674 /* This config is used in route install, so redo that. */
3675 FOREACH_AFI_SAFI (afi, safi) {
3676 if (!bgp_fibupd_safi(safi))
3677 continue;
3678 bgp_zebra_announce_table(bgp, afi, safi);
3679 }
3680
3681 return CMD_SUCCESS;
3682}
3683
ad36d216
DS
3684DEFPY (no_bgp_bestpath_bw,
3685 no_bgp_bestpath_bw_cmd,
3686 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3687 NO_STR
3688 "BGP specific commands\n"
3689 "Change the default bestpath selection\n"
3690 "Link Bandwidth attribute\n"
3691 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3692 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3693 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3694{
3695 VTY_DECLVAR_CONTEXT(bgp, bgp);
3696 afi_t afi;
3697 safi_t safi;
3698
3699 bgp->lb_handling = BGP_LINK_BW_ECMP;
3700
3701 /* This config is used in route install, so redo that. */
3702 FOREACH_AFI_SAFI (afi, safi) {
3703 if (!bgp_fibupd_safi(safi))
3704 continue;
3705 bgp_zebra_announce_table(bgp, afi, safi);
3706 }
3707 return CMD_SUCCESS;
3708}
3709
718e3744 3710/* "no bgp default ipv4-unicast". */
3711DEFUN (no_bgp_default_ipv4_unicast,
3712 no_bgp_default_ipv4_unicast_cmd,
3713 "no bgp default ipv4-unicast",
3714 NO_STR
3715 "BGP specific commands\n"
3716 "Configure BGP defaults\n"
3717 "Activate ipv4-unicast for a peer by default\n")
3718{
d62a17ae 3719 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3720 SET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
d62a17ae 3721 return CMD_SUCCESS;
718e3744 3722}
3723
3724DEFUN (bgp_default_ipv4_unicast,
3725 bgp_default_ipv4_unicast_cmd,
3726 "bgp default ipv4-unicast",
3727 "BGP specific commands\n"
3728 "Configure BGP defaults\n"
3729 "Activate ipv4-unicast for a peer by default\n")
3730{
d62a17ae 3731 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3732 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
d62a17ae 3733 return CMD_SUCCESS;
718e3744 3734}
6b0655a2 3735
04b6bdc0 3736/* Display hostname in certain command outputs */
ff8a8a7a 3737DEFUN_YANG (bgp_default_show_hostname,
04b6bdc0
DW
3738 bgp_default_show_hostname_cmd,
3739 "bgp default show-hostname",
3740 "BGP specific commands\n"
3741 "Configure BGP defaults\n"
0437e105 3742 "Show hostname in certain command outputs\n")
04b6bdc0 3743{
87ce2564
CS
3744 nb_cli_enqueue_change(vty, "./global/show-hostname", NB_OP_MODIFY,
3745 "true");
ff8a8a7a
CS
3746
3747 return nb_cli_apply_changes(vty, NULL);
04b6bdc0
DW
3748}
3749
ff8a8a7a
CS
3750DEFUN_YANG(no_bgp_default_show_hostname,
3751 no_bgp_default_show_hostname_cmd,
3752 "no bgp default show-hostname",
3753 NO_STR
3754 "BGP specific commands\n"
3755 "Configure BGP defaults\n"
3756 "Show hostname in certain command outputs\n")
04b6bdc0 3757{
87ce2564
CS
3758 nb_cli_enqueue_change(vty, "./global/show-hostname", NB_OP_MODIFY,
3759 "false");
ff8a8a7a
CS
3760
3761 return nb_cli_apply_changes(vty, NULL);
3762}
3763
3764void cli_show_router_bgp_show_hostname(struct vty *vty, struct lyd_node *dnode,
3765 bool show_defaults)
3766{
3767 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SHOW_HOSTNAME)
3768 vty_out(vty, " bgp default show-hostname\n");
04b6bdc0
DW
3769}
3770
aef999a2 3771/* Display hostname in certain command outputs */
232c75cd
CS
3772DEFUN_YANG(bgp_default_show_nexthop_hostname,
3773 bgp_default_show_nexthop_hostname_cmd,
3774 "bgp default show-nexthop-hostname",
3775 "BGP specific commands\n"
3776 "Configure BGP defaults\n"
3777 "Show hostname for nexthop in certain command outputs\n")
aef999a2 3778{
87ce2564
CS
3779 nb_cli_enqueue_change(vty, "./global/show-nexthop-hostname",
3780 NB_OP_MODIFY, "true");
ff8a8a7a
CS
3781
3782 return nb_cli_apply_changes(vty, NULL);
aef999a2
DA
3783}
3784
3785DEFUN (no_bgp_default_show_nexthop_hostname,
3786 no_bgp_default_show_nexthop_hostname_cmd,
3787 "no bgp default show-nexthop-hostname",
3788 NO_STR
3789 "BGP specific commands\n"
3790 "Configure BGP defaults\n"
3791 "Show hostname for nexthop in certain command outputs\n")
3792{
87ce2564
CS
3793 nb_cli_enqueue_change(vty, "./global/show-nexthop-hostname",
3794 NB_OP_MODIFY, "false");
ff8a8a7a
CS
3795
3796 return nb_cli_apply_changes(vty, NULL);
3797}
3798
3799void cli_show_router_bgp_show_nexthop_hostname(struct vty *vty,
3800 struct lyd_node *dnode,
3801 bool show_defaults)
3802{
3803 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SHOW_HOSTNAME)
3804 vty_out(vty, " bgp default show-nexthop-hostname\n");
aef999a2
DA
3805}
3806
8233ef81 3807/* "bgp network import-check" configuration. */
ff8a8a7a
CS
3808DEFUN_YANG(bgp_network_import_check,
3809 bgp_network_import_check_cmd,
3810 "bgp network import-check",
3811 "BGP specific commands\n"
3812 "BGP network command\n"
3813 "Check BGP network route exists in IGP\n")
718e3744 3814{
87ce2564
CS
3815 nb_cli_enqueue_change(vty, "./global/import-check", NB_OP_MODIFY,
3816 "true");
078430f6 3817
ff8a8a7a 3818 return nb_cli_apply_changes(vty, NULL);
718e3744 3819}
3820
d62a17ae 3821ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3822 "bgp network import-check exact",
3823 "BGP specific commands\n"
3824 "BGP network command\n"
3825 "Check BGP network route exists in IGP\n"
3826 "Match route precisely\n")
8233ef81 3827
ff8a8a7a
CS
3828DEFUN_YANG(no_bgp_network_import_check,
3829 no_bgp_network_import_check_cmd,
3830 "no bgp network import-check",
3831 NO_STR
3832 "BGP specific commands\n"
3833 "BGP network command\n"
3834 "Check BGP network route exists in IGP\n")
718e3744 3835{
87ce2564
CS
3836 nb_cli_enqueue_change(vty, "./global/import-check", NB_OP_MODIFY,
3837 "false");
5623e905 3838
ff8a8a7a 3839 return nb_cli_apply_changes(vty, NULL);
718e3744 3840}
6b0655a2 3841
ff8a8a7a
CS
3842void cli_show_router_bgp_import_check(struct vty *vty, struct lyd_node *dnode,
3843 bool show_defaults)
718e3744 3844{
ff8a8a7a
CS
3845 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_IMPORT_CHECK)
3846 vty_out(vty, " bgp network import-check\n");
3847}
718e3744 3848
ff8a8a7a
CS
3849DEFUN_YANG(bgp_default_local_preference,
3850 bgp_default_local_preference_cmd,
3851 "bgp default local-preference (0-4294967295)",
3852 "BGP specific commands\n"
3853 "Configure BGP defaults\n"
3854 "local preference (higher=more preferred)\n"
3855 "Configure default local preference value\n")
3856{
3857 int idx_number = 3;
718e3744 3858
87ce2564 3859 nb_cli_enqueue_change(vty, "./global/local-pref", NB_OP_MODIFY,
ff8a8a7a 3860 argv[idx_number]->arg);
718e3744 3861
ff8a8a7a 3862 return nb_cli_apply_changes(vty, NULL);
718e3744 3863}
3864
ff8a8a7a
CS
3865DEFUN_YANG(no_bgp_default_local_preference,
3866 no_bgp_default_local_preference_cmd,
3867 "no bgp default local-preference [(0-4294967295)]",
3868 NO_STR
3869 "BGP specific commands\n"
3870 "Configure BGP defaults\n"
3871 "local preference (higher=more preferred)\n"
3872 "Configure default local preference value\n")
718e3744 3873{
87ce2564 3874 nb_cli_enqueue_change(vty, "./global/local-pref", NB_OP_MODIFY, NULL);
7aafcaca 3875
ff8a8a7a 3876 return nb_cli_apply_changes(vty, NULL);
718e3744 3877}
3878
ff8a8a7a
CS
3879void cli_show_router_bgp_local_pref(struct vty *vty, struct lyd_node *dnode,
3880 bool show_defaults)
3881{
3882 vty_out(vty, " bgp default local-preference %u\n",
3883 yang_dnode_get_uint32(dnode, NULL));
3884}
6b0655a2 3885
ff8a8a7a
CS
3886
3887DEFUN_YANG(bgp_default_subgroup_pkt_queue_max,
3888 bgp_default_subgroup_pkt_queue_max_cmd,
3889 "bgp default subgroup-pkt-queue-max (20-100)",
3890 "BGP specific commands\n"
3891 "Configure BGP defaults\n"
3892 "subgroup-pkt-queue-max\n"
3893 "Configure subgroup packet queue max\n")
8bd9d948 3894{
d62a17ae 3895 int idx_number = 3;
3f9c7369 3896
ff8a8a7a 3897 nb_cli_enqueue_change(
87ce2564
CS
3898 vty,
3899 "./global/global-update-group-config/subgroup-pkt-queue-size",
ff8a8a7a 3900 NB_OP_MODIFY, argv[idx_number]->arg);
3f9c7369 3901
ff8a8a7a 3902 return nb_cli_apply_changes(vty, NULL);
3f9c7369
DS
3903}
3904
ff8a8a7a
CS
3905DEFUN_YANG(no_bgp_default_subgroup_pkt_queue_max,
3906 no_bgp_default_subgroup_pkt_queue_max_cmd,
3907 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3908 NO_STR
3909 "BGP specific commands\n"
3910 "Configure BGP defaults\n"
3911 "subgroup-pkt-queue-max\n"
3912 "Configure subgroup packet queue max\n")
3f9c7369 3913{
ff8a8a7a 3914 nb_cli_enqueue_change(
87ce2564
CS
3915 vty,
3916 "./global/global-update-group-config/subgroup-pkt-queue-size",
ff8a8a7a
CS
3917 NB_OP_MODIFY, NULL);
3918
3919 return nb_cli_apply_changes(vty, NULL);
8bd9d948
DS
3920}
3921
ff8a8a7a
CS
3922void cli_show_router_global_update_group_config_subgroup_pkt_queue_size(
3923 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
3924{
3925 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
3926 yang_dnode_get_uint32(dnode, NULL));
3927}
813d4307 3928
ff8a8a7a
CS
3929DEFUN_YANG(bgp_rr_allow_outbound_policy,
3930 bgp_rr_allow_outbound_policy_cmd,
3931 "bgp route-reflector allow-outbound-policy",
3932 "BGP specific commands\n"
3933 "Allow modifications made by out route-map\n"
3934 "on ibgp neighbors\n")
8bd9d948 3935{
87ce2564
CS
3936 nb_cli_enqueue_change(vty,
3937 "./global/route-reflector/allow-outbound-policy",
ff8a8a7a 3938 NB_OP_MODIFY, "true");
8bd9d948 3939
ff8a8a7a
CS
3940 return nb_cli_apply_changes(vty, NULL);
3941}
8bd9d948 3942
ff8a8a7a
CS
3943DEFUN_YANG(no_bgp_rr_allow_outbound_policy,
3944 no_bgp_rr_allow_outbound_policy_cmd,
3945 "no bgp route-reflector allow-outbound-policy",
3946 NO_STR
3947 "BGP specific commands\n"
3948 "Allow modifications made by out route-map\n"
3949 "on ibgp neighbors\n")
3950{
87ce2564
CS
3951 nb_cli_enqueue_change(vty,
3952 "./global/route-reflector/allow-outbound-policy",
ff8a8a7a
CS
3953 NB_OP_MODIFY, "false");
3954
3955 return nb_cli_apply_changes(vty, NULL);
8bd9d948
DS
3956}
3957
ff8a8a7a
CS
3958
3959void cli_show_router_global_neighbor_config(struct vty *vty,
3960 struct lyd_node *dnode,
3961 bool show_defaults)
8bd9d948 3962{
ff8a8a7a
CS
3963 uint32_t write_quanta, read_quanta;
3964
3965 if (yang_dnode_get_bool(dnode, "./log-neighbor-changes"))
3966 vty_out(vty, " bgp log-neighbor-changes\n");
8bd9d948 3967
ff8a8a7a
CS
3968 if (yang_dnode_exists(dnode, "./dynamic-neighbors-limit")) {
3969 uint32_t listen_limit = yang_dnode_get_uint32(
3970 dnode, "./dynamic-neighbors-limit");
3971 vty_out(vty, " bgp listen limit %u\n", listen_limit);
d62a17ae 3972 }
8bd9d948 3973
ff8a8a7a
CS
3974 write_quanta = yang_dnode_get_uint32(
3975 dnode, "./packet-quanta-config/wpkt-quanta");
3976 if (write_quanta != BGP_WRITE_PACKET_MAX)
3977 vty_out(vty, " write-quanta %d\n", write_quanta);
3978
3979 read_quanta = yang_dnode_get_uint32(
3980 dnode, "./packet-quanta-config/rpkt-quanta");
3981
3982 if (read_quanta != BGP_READ_PACKET_MAX)
3983 vty_out(vty, " read-quanta %d\n", read_quanta);
8bd9d948
DS
3984}
3985
ff8a8a7a
CS
3986DEFUN_YANG(bgp_listen_limit,
3987 bgp_listen_limit_cmd,
3988 "bgp listen limit (1-5000)",
3989 "BGP specific commands\n"
3990 "BGP Dynamic Neighbors listen commands\n"
3991 "Maximum number of BGP Dynamic Neighbors that can be created\n"
3992 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 3993{
d62a17ae 3994 int idx_number = 3;
f14e6fdb 3995
ff8a8a7a 3996 nb_cli_enqueue_change(
87ce2564 3997 vty, "./global/global-neighbor-config/dynamic-neighbors-limit",
ff8a8a7a 3998 NB_OP_MODIFY, argv[idx_number]->arg);
f14e6fdb 3999
ff8a8a7a 4000 return nb_cli_apply_changes(vty, NULL);
f14e6fdb
DS
4001}
4002
ff8a8a7a
CS
4003DEFUN_YANG(no_bgp_listen_limit,
4004 no_bgp_listen_limit_cmd,
4005 "no bgp listen limit [(1-5000)]",
4006 NO_STR
4007 "BGP specific commands\n"
4008 "BGP Dynamic Neighbors listen commands\n"
4009 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4010 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 4011{
ff8a8a7a 4012 nb_cli_enqueue_change(
87ce2564 4013 vty, "./global/global-neighbor-config/dynamic-neighbors-limit",
ff8a8a7a
CS
4014 NB_OP_DESTROY, NULL);
4015
4016 return nb_cli_apply_changes(vty, NULL);
f14e6fdb
DS
4017}
4018
4019
20eb8864 4020/*
4021 * Check if this listen range is already configured. Check for exact
4022 * match or overlap based on input.
4023 */
d62a17ae 4024static struct peer_group *listen_range_exists(struct bgp *bgp,
4025 struct prefix *range, int exact)
4026{
4027 struct listnode *node, *nnode;
4028 struct listnode *node1, *nnode1;
4029 struct peer_group *group;
4030 struct prefix *lr;
4031 afi_t afi;
4032 int match;
4033
4034 afi = family2afi(range->family);
4035 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4036 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
4037 lr)) {
4038 if (exact)
4039 match = prefix_same(range, lr);
4040 else
4041 match = (prefix_match(range, lr)
4042 || prefix_match(lr, range));
4043 if (match)
4044 return group;
4045 }
4046 }
4047
4048 return NULL;
20eb8864 4049}
4050
f14e6fdb
DS
4051DEFUN (bgp_listen_range,
4052 bgp_listen_range_cmd,
d7b9898c 4053 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
f14e6fdb 4054 "BGP specific commands\n"
d7fa34c1
QY
4055 "Configure BGP dynamic neighbors listen range\n"
4056 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
4057 NEIGHBOR_ADDR_STR
4058 "Member of the peer-group\n"
4059 "Peer-group name\n")
f14e6fdb 4060{
d62a17ae 4061 VTY_DECLVAR_CONTEXT(bgp, bgp);
4062 struct prefix range;
4063 struct peer_group *group, *existing_group;
4064 afi_t afi;
4065 int ret;
4066 int idx = 0;
4067
4068 argv_find(argv, argc, "A.B.C.D/M", &idx);
4069 argv_find(argv, argc, "X:X::X:X/M", &idx);
4070 char *prefix = argv[idx]->arg;
d7b9898c 4071 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 4072 char *peergroup = argv[idx]->arg;
4073
4074 /* Convert IP prefix string to struct prefix. */
4075 ret = str2prefix(prefix, &range);
4076 if (!ret) {
4077 vty_out(vty, "%% Malformed listen range\n");
4078 return CMD_WARNING_CONFIG_FAILED;
4079 }
4080
4081 afi = family2afi(range.family);
4082
4083 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4084 vty_out(vty,
4085 "%% Malformed listen range (link-local address)\n");
4086 return CMD_WARNING_CONFIG_FAILED;
4087 }
4088
4089 apply_mask(&range);
4090
4091 /* Check if same listen range is already configured. */
4092 existing_group = listen_range_exists(bgp, &range, 1);
4093 if (existing_group) {
4094 if (strcmp(existing_group->name, peergroup) == 0)
4095 return CMD_SUCCESS;
4096 else {
4097 vty_out(vty,
4098 "%% Same listen range is attached to peer-group %s\n",
4099 existing_group->name);
4100 return CMD_WARNING_CONFIG_FAILED;
4101 }
4102 }
4103
4104 /* Check if an overlapping listen range exists. */
4105 if (listen_range_exists(bgp, &range, 0)) {
4106 vty_out(vty,
4107 "%% Listen range overlaps with existing listen range\n");
4108 return CMD_WARNING_CONFIG_FAILED;
4109 }
4110
4111 group = peer_group_lookup(bgp, peergroup);
4112 if (!group) {
4113 vty_out(vty, "%% Configure the peer-group first\n");
4114 return CMD_WARNING_CONFIG_FAILED;
4115 }
4116
4117 ret = peer_group_listen_range_add(group, &range);
4118 return bgp_vty_return(vty, ret);
f14e6fdb
DS
4119}
4120
4121DEFUN (no_bgp_listen_range,
4122 no_bgp_listen_range_cmd,
d7b9898c 4123 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
d7fa34c1 4124 NO_STR
f14e6fdb 4125 "BGP specific commands\n"
d7fa34c1
QY
4126 "Unconfigure BGP dynamic neighbors listen range\n"
4127 "Unconfigure BGP dynamic neighbors listen range\n"
4128 NEIGHBOR_ADDR_STR
4129 "Member of the peer-group\n"
4130 "Peer-group name\n")
f14e6fdb 4131{
d62a17ae 4132 VTY_DECLVAR_CONTEXT(bgp, bgp);
4133 struct prefix range;
4134 struct peer_group *group;
4135 afi_t afi;
4136 int ret;
4137 int idx = 0;
4138
4139 argv_find(argv, argc, "A.B.C.D/M", &idx);
4140 argv_find(argv, argc, "X:X::X:X/M", &idx);
4141 char *prefix = argv[idx]->arg;
21d88a71 4142 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 4143 char *peergroup = argv[idx]->arg;
4144
4145 /* Convert IP prefix string to struct prefix. */
4146 ret = str2prefix(prefix, &range);
4147 if (!ret) {
4148 vty_out(vty, "%% Malformed listen range\n");
4149 return CMD_WARNING_CONFIG_FAILED;
4150 }
4151
4152 afi = family2afi(range.family);
4153
4154 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4155 vty_out(vty,
4156 "%% Malformed listen range (link-local address)\n");
4157 return CMD_WARNING_CONFIG_FAILED;
4158 }
4159
4160 apply_mask(&range);
4161
4162 group = peer_group_lookup(bgp, peergroup);
4163 if (!group) {
4164 vty_out(vty, "%% Peer-group does not exist\n");
4165 return CMD_WARNING_CONFIG_FAILED;
4166 }
4167
4168 ret = peer_group_listen_range_del(group, &range);
4169 return bgp_vty_return(vty, ret);
4170}
4171
2b791107 4172void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 4173{
4174 struct peer_group *group;
4175 struct listnode *node, *nnode, *rnode, *nrnode;
4176 struct prefix *range;
4177 afi_t afi;
d62a17ae 4178
4179 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4180 vty_out(vty, " bgp listen limit %d\n",
4181 bgp->dynamic_neighbors_limit);
4182
4183 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4184 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4185 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4186 nrnode, range)) {
d62a17ae 4187 vty_out(vty,
2dbe669b
DA
4188 " bgp listen range %pFX peer-group %s\n",
4189 range, group->name);
d62a17ae 4190 }
4191 }
4192 }
f14e6fdb
DS
4193}
4194
4195
ff8a8a7a
CS
4196DEFUN_YANG(bgp_disable_connected_route_check,
4197 bgp_disable_connected_route_check_cmd,
4198 "bgp disable-ebgp-connected-route-check",
4199 "BGP specific commands\n"
4200 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4201{
87ce2564
CS
4202 nb_cli_enqueue_change(vty,
4203 "./global/ebgp-multihop-connected-route-check",
ff8a8a7a 4204 NB_OP_MODIFY, "true");
7aafcaca 4205
ff8a8a7a 4206 return nb_cli_apply_changes(vty, NULL);
907f92c8
DS
4207}
4208
ff8a8a7a
CS
4209DEFUN_YANG(no_bgp_disable_connected_route_check,
4210 no_bgp_disable_connected_route_check_cmd,
4211 "no bgp disable-ebgp-connected-route-check",
4212 NO_STR
4213 "BGP specific commands\n"
4214 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4215{
87ce2564
CS
4216 nb_cli_enqueue_change(vty,
4217 "./global/ebgp-multihop-connected-route-check",
ff8a8a7a 4218 NB_OP_MODIFY, "false");
d62a17ae 4219
ff8a8a7a 4220 return nb_cli_apply_changes(vty, NULL);
d62a17ae 4221}
4222
ff8a8a7a
CS
4223void cli_show_router_global_ebgp_multihop_connected_route_check(
4224 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
4225{
4226 if (yang_dnode_get_bool(dnode, NULL))
4227 vty_out(vty, " bgp disable-ebgp-connected-route-check\n");
4228}
d62a17ae 4229
ff8a8a7a
CS
4230DEFUN_YANG(bgp_default_shutdown,
4231 bgp_default_shutdown_cmd,
4232 "[no] bgp default shutdown",
4233 NO_STR BGP_STR
4234 "Configure BGP defaults\n"
4235 "Apply administrative shutdown to newly configured peers\n")
f26845f9 4236{
87ce2564 4237 nb_cli_enqueue_change(vty, "./global/default-shutdown", NB_OP_MODIFY,
ff8a8a7a
CS
4238 strmatch(argv[0]->text, "no") ? "false" : "true");
4239
4240 return nb_cli_apply_changes(vty, NULL);
4241}
4242
4243void cli_show_router_bgp_default_shutdown(struct vty *vty,
4244 struct lyd_node *dnode,
4245 bool show_defaults)
4246{
4247 if (yang_dnode_get_bool(dnode, NULL))
4248 vty_out(vty, " bgp default shutdown\n");
f26845f9
QY
4249}
4250
736b68f3
DS
4251DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4252 BGP_STR
9ddf4b81 4253 "Administrative shutdown of the BGP instance\n"
736b68f3
DS
4254 "Add a shutdown message (RFC 8203)\n"
4255 "Shutdown message\n")
9cf59432 4256{
736b68f3 4257 char *msgstr = NULL;
8389c83a 4258
9cf59432
DS
4259 VTY_DECLVAR_CONTEXT(bgp, bgp);
4260
8389c83a 4261 if (argc > 3)
f80e35b6 4262 msgstr = argv_concat(argv, argc, 3);
8389c83a
DS
4263
4264 bgp_shutdown_enable(bgp, msgstr);
4265 XFREE(MTYPE_TMP, msgstr);
9cf59432
DS
4266
4267 return CMD_SUCCESS;
4268}
4269
736b68f3 4270DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
9ddf4b81 4271 BGP_STR "Administrative shutdown of the BGP instance\n")
1e12ebbc
DS
4272{
4273 VTY_DECLVAR_CONTEXT(bgp, bgp);
4274
4275 bgp_shutdown_enable(bgp, NULL);
4276
4277 return CMD_SUCCESS;
4278}
8389c83a 4279
736b68f3 4280DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
9ddf4b81 4281 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
9cf59432
DS
4282{
4283 VTY_DECLVAR_CONTEXT(bgp, bgp);
4284
4285 bgp_shutdown_disable(bgp);
4286
4287 return CMD_SUCCESS;
4288}
4289
9ddf4b81 4290ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
1b6e7a88 4291 "no bgp shutdown message MSG...", NO_STR BGP_STR
9ddf4b81 4292 "Administrative shutdown of the BGP instance\n"
1b6e7a88 4293 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
1b6e7a88 4294
f4b8ec07
CS
4295DEFUN_YANG(neighbor_remote_as,
4296 neighbor_remote_as_cmd,
4297 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4298 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4299 "Specify a BGP neighbor\n" AS_STR
4300 "Internal BGP peer\n"
4301 "External BGP peer\n")
718e3744 4302{
d62a17ae 4303 int idx_peer = 1;
4304 int idx_remote_as = 3;
f4b8ec07
CS
4305 char base_xpath[XPATH_MAXLEN];
4306 char unnbr_xpath[XPATH_MAXLEN];
4307 char prgrp_xpath[XPATH_MAXLEN];
4308 union sockunion su;
4309 const char *as_type_str = "as-specified";
4310
4311 if (str2sockunion(argv[idx_peer]->arg, &su) < 0) {
4312 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
4313 FRR_BGP_NEIGHBOR_UNNUM_XPATH, argv[idx_peer]->arg, "");
4314
4315 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
4316 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg, "");
4317
4318 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4319 VTY_CURR_XPATH, unnbr_xpath + 1)) {
4320 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
4321 } else if (yang_dnode_exists(vty->candidate_config->dnode,
4322 "%s%s", VTY_CURR_XPATH,
4323 prgrp_xpath + 1)) {
4324 snprintf(base_xpath, sizeof(base_xpath),
4325 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg,
4326 "");
4327 } else {
4328 vty_out(vty,
4329 "%% Create the peer-group or interface first\n");
4330 return CMD_WARNING_CONFIG_FAILED;
4331 }
4332 } else {
4333 snprintf(base_xpath, sizeof(base_xpath),
4334 FRR_BGP_NEIGHBOR_NUM_XPATH, argv[idx_peer]->arg, "");
4335 }
4336
4337 if (argv[idx_remote_as]->arg[0] == 'i') {
4338 as_type_str = "internal";
4339 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4340 as_type_str = "external";
4341 } else {
4342 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4343 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4344 }
4345 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4346 NB_OP_MODIFY, as_type_str);
4347
4348 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 4349}
4350
f4b8ec07
CS
4351int peer_conf_interface_create(struct bgp *bgp, const char *conf_if, afi_t afi,
4352 safi_t safi, bool v6only,
4353 const char *peer_group_name, int as_type,
4354 as_t as, char *errmsg, size_t errmsg_len)
d62a17ae 4355{
d62a17ae 4356 struct peer *peer;
4357 struct peer_group *group;
4358 int ret = 0;
d62a17ae 4359
4360 group = peer_group_lookup(bgp, conf_if);
4361
4362 if (group) {
f4b8ec07
CS
4363 snprintf(errmsg, errmsg_len,
4364 "Name conflict with peer-group \n");
4365 return -1;
d62a17ae 4366 }
4367
4368 peer = peer_lookup_by_conf_if(bgp, conf_if);
4369 if (peer) {
f4b8ec07 4370 if (as_type != AS_UNSPECIFIED)
cc4d4ce8 4371 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
d62a17ae 4372 afi, safi);
4373 } else {
892fedb6 4374 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4)
d62a17ae 4375 && afi == AFI_IP && safi == SAFI_UNICAST)
4376 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
4377 as_type, 0, 0, NULL);
4378 else
4379 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
4380 as_type, afi, safi, NULL);
4381
4382 if (!peer) {
f4b8ec07
CS
4383 snprintf(errmsg, errmsg_len,
4384 "BGP failed to create peer\n");
4385 return -1;
d62a17ae 4386 }
4387
4388 if (v6only)
527de3dc 4389 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4390
4391 /* Request zebra to initiate IPv6 RAs on this interface. We do
4392 * this
4393 * any unnumbered peer in order to not worry about run-time
4394 * transitions
4395 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4396 * address
4397 * gets deleted later etc.)
4398 */
4399 if (peer->ifp)
4400 bgp_zebra_initiate_radv(bgp, peer);
4401 }
4402
4403 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4404 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4405 if (v6only)
527de3dc 4406 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4407 else
527de3dc 4408 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4409
4410 /* v6only flag changed. Reset bgp seesion */
4411 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4412 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4413 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4414 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4415 } else
4416 bgp_session_reset(peer);
4417 }
4418
9fb964de
PM
4419 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4420 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4421 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
dc2f50f3 4422 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
9fb964de 4423 }
d62a17ae 4424
4425 if (peer_group_name) {
4426 group = peer_group_lookup(bgp, peer_group_name);
4427 if (!group) {
f4b8ec07
CS
4428 snprintf(errmsg, errmsg_len,
4429 "Configure the peer-group first\n");
4430 return -1;
d62a17ae 4431 }
4432
8395c1f8 4433 ret = peer_group_bind(bgp, NULL, peer, group, &as);
d62a17ae 4434 }
4435
f4b8ec07 4436 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
a80beece
DS
4437}
4438
232c75cd
CS
4439DEFUN_YANG(neighbor_interface_config,
4440 neighbor_interface_config_cmd,
f4b8ec07
CS
4441 "neighbor WORD interface [peer-group PGNAME]",
4442 NEIGHBOR_STR
4443 "Interface name or neighbor tag\n"
4444 "Enable BGP on interface\n"
4445 "Member of the peer-group\n"
4446 "Peer-group name\n")
4c48cf63 4447{
d62a17ae 4448 int idx_word = 1;
4449 int idx_peer_group_word = 4;
f4b8ec07
CS
4450 char base_xpath[XPATH_MAXLEN];
4451
4452 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4453 argv[idx_word]->arg, "");
31500417 4454
f4b8ec07 4455 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 4456 if (argc > idx_peer_group_word)
f4b8ec07
CS
4457 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_MODIFY,
4458 argv[idx_peer_group_word]->arg);
4459
4460 return nb_cli_apply_changes(vty, base_xpath);
4c48cf63
DW
4461}
4462
f4b8ec07
CS
4463DEFUN_YANG(neighbor_interface_config_v6only,
4464 neighbor_interface_config_v6only_cmd,
4465 "neighbor WORD interface v6only [peer-group PGNAME]",
4466 NEIGHBOR_STR
4467 "Interface name or neighbor tag\n"
4468 "Enable BGP on interface\n"
4469 "Enable BGP with v6 link-local only\n"
4470 "Member of the peer-group\n"
4471 "Peer-group name\n")
4c48cf63 4472{
d62a17ae 4473 int idx_word = 1;
4474 int idx_peer_group_word = 5;
f4b8ec07
CS
4475 char base_xpath[XPATH_MAXLEN];
4476
4477 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4478 argv[idx_word]->arg, "");
31500417 4479
f4b8ec07 4480 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 4481 if (argc > idx_peer_group_word)
f4b8ec07
CS
4482 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_MODIFY,
4483 argv[idx_peer_group_word]->arg);
31500417 4484
f4b8ec07
CS
4485 nb_cli_enqueue_change(vty, "./v6only", NB_OP_MODIFY, "true");
4486
4487 return nb_cli_apply_changes(vty, base_xpath);
4c48cf63
DW
4488}
4489
a80beece 4490
f4b8ec07
CS
4491DEFUN_YANG(
4492 neighbor_interface_config_remote_as,
4493 neighbor_interface_config_remote_as_cmd,
4494 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4495 NEIGHBOR_STR
4496 "Interface name or neighbor tag\n"
4497 "Enable BGP on interface\n"
4498 "Specify a BGP neighbor\n" AS_STR
4499 "Internal BGP peer\n"
4500 "External BGP peer\n")
b3a39dc5 4501{
d62a17ae 4502 int idx_word = 1;
4503 int idx_remote_as = 4;
f4b8ec07
CS
4504 char base_xpath[XPATH_MAXLEN];
4505 const char *as_type_str = "as-specified";
4506
4507 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4508 argv[idx_word]->arg, "");
4509
4510 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4511
4512 if (argv[idx_remote_as]->arg[0] == 'i') {
4513 as_type_str = "internal";
4514 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4515 as_type_str = "external";
4516 } else {
4517 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4518 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4519 }
4520 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4521 NB_OP_MODIFY, as_type_str);
4522
4523 return nb_cli_apply_changes(vty, base_xpath);
b3a39dc5
DD
4524}
4525
f4b8ec07
CS
4526DEFUN_YANG(
4527 neighbor_interface_v6only_config_remote_as,
4528 neighbor_interface_v6only_config_remote_as_cmd,
4529 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4530 NEIGHBOR_STR
4531 "Interface name or neighbor tag\n"
4532 "Enable BGP with v6 link-local only\n"
4533 "Enable BGP on interface\n"
4534 "Specify a BGP neighbor\n" AS_STR
4535 "Internal BGP peer\n"
4536 "External BGP peer\n")
b3a39dc5 4537{
d62a17ae 4538 int idx_word = 1;
4539 int idx_remote_as = 5;
f4b8ec07
CS
4540 char base_xpath[XPATH_MAXLEN];
4541 const char *as_type_str = "as-specified";
4542
4543 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4544 argv[idx_word]->arg, "");
4545
4546 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4547
4548 nb_cli_enqueue_change(vty, "./v6only", NB_OP_MODIFY, "true");
4549
4550 if (argv[idx_remote_as]->arg[0] == 'i') {
4551 as_type_str = "internal";
4552 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4553 as_type_str = "external";
4554 } else {
4555 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4556 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4557 }
4558 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4559 NB_OP_MODIFY, as_type_str);
4560
4561 return nb_cli_apply_changes(vty, base_xpath);
b3a39dc5
DD
4562}
4563
f4b8ec07
CS
4564DEFUN_YANG(neighbor_peer_group, neighbor_peer_group_cmd,
4565 "neighbor WORD peer-group",
4566 NEIGHBOR_STR
4567 "Interface name or neighbor tag\n"
4568 "Configure peer-group\n")
718e3744 4569{
f4b8ec07 4570 char base_xpath[XPATH_MAXLEN];
d62a17ae 4571 int idx_word = 1;
718e3744 4572
f4b8ec07
CS
4573 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_PEER_GROUP_XPATH,
4574 argv[idx_word]->arg, "");
718e3744 4575
f4b8ec07 4576 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
718e3744 4577
f4b8ec07 4578 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4579}
4580
232c75cd
CS
4581DEFUN_YANG(no_neighbor,
4582 no_neighbor_cmd,
4583 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4584 NO_STR NEIGHBOR_STR
4585 NEIGHBOR_ADDR_STR2
4586 "Specify a BGP neighbor\n" AS_STR
4587 "Internal BGP peer\n"
4588 "External BGP peer\n")
718e3744 4589{
d62a17ae 4590 int idx_peer = 2;
f4b8ec07
CS
4591 char base_xpath[XPATH_MAXLEN];
4592 char num_xpath[XPATH_MAXLEN];
4593 char unnbr_xpath[XPATH_MAXLEN];
4594 char prgrp_xpath[XPATH_MAXLEN];
d62a17ae 4595 union sockunion su;
d62a17ae 4596
f4b8ec07
CS
4597 if (str2sockunion(argv[idx_peer]->arg, &su) == 0) {
4598 snprintf(num_xpath, sizeof(num_xpath),
4599 FRR_BGP_NEIGHBOR_NUM_XPATH, argv[idx_peer]->arg, "");
4600 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4601 VTY_CURR_XPATH, num_xpath + 1)) {
4602 strlcpy(base_xpath, num_xpath, sizeof(base_xpath));
d62a17ae 4603 }
f4b8ec07
CS
4604 } else {
4605 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
4606 FRR_BGP_NEIGHBOR_UNNUM_XPATH, argv[idx_peer]->arg, "");
4607
4608 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
4609 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg, "");
4610
4611 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4612 VTY_CURR_XPATH, unnbr_xpath + 1)) {
4613 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
4614 } else if (yang_dnode_exists(vty->candidate_config->dnode,
4615 "%s%s", VTY_CURR_XPATH,
4616 prgrp_xpath + 1)) {
4617 strlcpy(base_xpath, prgrp_xpath, sizeof(base_xpath));
4e2786df 4618 } else {
f4b8ec07
CS
4619 vty_out(vty,
4620 "%% Create the peer-group or interface first\n");
d62a17ae 4621 return CMD_WARNING_CONFIG_FAILED;
4622 }
1ff9a340 4623 }
718e3744 4624
f4b8ec07
CS
4625 nb_cli_enqueue_change(vty, base_xpath, NB_OP_DESTROY, NULL);
4626
4627 return nb_cli_apply_changes(vty, NULL);
718e3744 4628}
4629
f4b8ec07
CS
4630DEFUN_YANG(no_neighbor_interface_config,
4631 no_neighbor_interface_config_cmd,
4632 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4633 NO_STR NEIGHBOR_STR
4634 "Interface name\n"
4635 "Configure BGP on interface\n"
4636 "Enable BGP with v6 link-local only\n"
4637 "Member of the peer-group\n"
4638 "Peer-group name\n"
4639 "Specify a BGP neighbor\n" AS_STR
4640 "Internal BGP peer\n"
4641 "External BGP peer\n")
a80beece 4642{
d62a17ae 4643 int idx_word = 2;
f4b8ec07 4644 char base_xpath[XPATH_MAXLEN];
d62a17ae 4645
f4b8ec07
CS
4646 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4647 argv[idx_word]->arg, "");
4648
4649 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
4650
4651 return nb_cli_apply_changes(vty, base_xpath);
a80beece
DS
4652}
4653
f4b8ec07
CS
4654DEFUN_YANG(no_neighbor_peer_group,
4655 no_neighbor_peer_group_cmd,
4656 "no neighbor WORD peer-group",
4657 NO_STR NEIGHBOR_STR
4658 "Neighbor tag\n"
4659 "Configure peer-group\n")
718e3744 4660{
f4b8ec07 4661 char base_xpath[XPATH_MAXLEN];
d62a17ae 4662 int idx_word = 2;
718e3744 4663
f4b8ec07
CS
4664 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_PEER_GROUP_XPATH,
4665 argv[idx_word]->arg, "");
4666
4667 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
4668
4669 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4670}
4671
f4b8ec07
CS
4672DEFUN_YANG(no_neighbor_interface_peer_group_remote_as,
4673 no_neighbor_interface_peer_group_remote_as_cmd,
4674 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4675 NO_STR NEIGHBOR_STR
4676 "Interface name or neighbor tag\n"
4677 "Specify a BGP neighbor\n" AS_STR
4678 "Internal BGP peer\n"
4679 "External BGP peer\n")
718e3744 4680{
f4b8ec07
CS
4681 int idx_peer = 2;
4682 char base_xpath[XPATH_MAXLEN];
4683 char unnbr_xpath[XPATH_MAXLEN];
4684 char prgrp_xpath[XPATH_MAXLEN];
d62a17ae 4685
f4b8ec07
CS
4686 snprintf(unnbr_xpath, sizeof(unnbr_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4687 argv[idx_peer]->arg, "");
d62a17ae 4688
f4b8ec07
CS
4689 snprintf(prgrp_xpath, sizeof(prgrp_xpath), FRR_BGP_PEER_GROUP_XPATH,
4690 argv[idx_peer]->arg, "");
4691
4692 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4693 VTY_CURR_XPATH, unnbr_xpath + 1)) {
4694 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
4695 } else if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4696 VTY_CURR_XPATH, prgrp_xpath + 1)) {
4697 strlcpy(base_xpath, prgrp_xpath, sizeof(base_xpath));
4698 } else {
d62a17ae 4699 vty_out(vty, "%% Create the peer-group or interface first\n");
4700 return CMD_WARNING_CONFIG_FAILED;
4701 }
f4b8ec07
CS
4702
4703 strlcat(base_xpath, "/neighbor-remote-as/remote-as-type",
4704 sizeof(base_xpath));
4705
4706 nb_cli_enqueue_change(vty, base_xpath, NB_OP_DESTROY, NULL);
4707
4708 return nb_cli_apply_changes(vty, NULL);
718e3744 4709}
6b0655a2 4710
f4b8ec07
CS
4711DEFUN_YANG(neighbor_local_as,
4712 neighbor_local_as_cmd,
4713 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4714 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4715 "Specify a local-as number\n"
4716 "AS number used as local AS\n")
718e3744 4717{
d62a17ae 4718 int idx_peer = 1;
4719 int idx_number = 3;
f4b8ec07 4720 char base_xpath[XPATH_MAXLEN];
718e3744 4721
f4b8ec07
CS
4722 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4723 sizeof(base_xpath), NULL)
4724 < 0)
d62a17ae 4725 return CMD_WARNING_CONFIG_FAILED;
718e3744 4726
f4b8ec07
CS
4727 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4728 argv[idx_number]->arg);
4729
4730 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4731}
4732
f4b8ec07
CS
4733DEFUN_YANG(
4734 neighbor_local_as_no_prepend, neighbor_local_as_no_prepend_cmd,
4735 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
4736 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4737 "Specify a local-as number\n"
4738 "AS number used as local AS\n"
4739 "Do not prepend local-as to updates from ebgp peers\n")
718e3744 4740{
d62a17ae 4741 int idx_peer = 1;
4742 int idx_number = 3;
f4b8ec07 4743 char base_xpath[XPATH_MAXLEN];
718e3744 4744
f4b8ec07
CS
4745 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4746 sizeof(base_xpath), NULL)
4747 < 0)
d62a17ae 4748 return CMD_WARNING_CONFIG_FAILED;
718e3744 4749
f4b8ec07
CS
4750 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4751 argv[idx_number]->arg);
4752 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4753 "true");
4754
4755 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4756}
4757
f4b8ec07
CS
4758DEFUN_YANG(
4759 neighbor_local_as_no_prepend_replace_as,
4760 neighbor_local_as_no_prepend_replace_as_cmd,
4761 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4762 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4763 "Specify a local-as number\n"
4764 "AS number used as local AS\n"
4765 "Do not prepend local-as to updates from ebgp peers\n"
4766 "Do not prepend local-as to updates from ibgp peers\n")
9d3f9705 4767{
d62a17ae 4768 int idx_peer = 1;
4769 int idx_number = 3;
f4b8ec07 4770 char base_xpath[XPATH_MAXLEN];
9d3f9705 4771
f4b8ec07
CS
4772 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4773 sizeof(base_xpath), NULL)
4774 < 0)
d62a17ae 4775 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 4776
f4b8ec07
CS
4777 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4778 argv[idx_number]->arg);
4779 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4780 "true");
4781 nb_cli_enqueue_change(vty, "./local-as/no-replace-as", NB_OP_MODIFY,
4782 "true");
4783
4784 return nb_cli_apply_changes(vty, base_xpath);
9d3f9705
AC
4785}
4786
f4b8ec07
CS
4787DEFUN_YANG(no_neighbor_local_as,
4788 no_neighbor_local_as_cmd,
4789 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
4790 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4791 "Specify a local-as number\n"
4792 "AS number used as local AS\n"
4793 "Do not prepend local-as to updates from ebgp peers\n"
4794 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 4795{
d62a17ae 4796 int idx_peer = 2;
f4b8ec07 4797 char base_xpath[XPATH_MAXLEN];
718e3744 4798
f4b8ec07
CS
4799 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4800 sizeof(base_xpath), NULL)
4801 < 0)
d62a17ae 4802 return CMD_WARNING_CONFIG_FAILED;
718e3744 4803
f4b8ec07
CS
4804 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_DESTROY, NULL);
4805 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4806 "false");
4807 nb_cli_enqueue_change(vty, "./local-as/no-replace-as", NB_OP_MODIFY,
4808 "false");
4809
4810 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4811}
4812
718e3744 4813
3f9c7369
DS
4814DEFUN (neighbor_solo,
4815 neighbor_solo_cmd,
9ccf14f7 4816 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4817 NEIGHBOR_STR
4818 NEIGHBOR_ADDR_STR2
4819 "Solo peer - part of its own update group\n")
4820{
d62a17ae 4821 int idx_peer = 1;
4822 struct peer *peer;
4823 int ret;
3f9c7369 4824
d62a17ae 4825 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4826 if (!peer)
4827 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4828
d62a17ae 4829 ret = update_group_adjust_soloness(peer, 1);
4830 return bgp_vty_return(vty, ret);
3f9c7369
DS
4831}
4832
4833DEFUN (no_neighbor_solo,
4834 no_neighbor_solo_cmd,
9ccf14f7 4835 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4836 NO_STR
4837 NEIGHBOR_STR
4838 NEIGHBOR_ADDR_STR2
4839 "Solo peer - part of its own update group\n")
4840{
d62a17ae 4841 int idx_peer = 2;
4842 struct peer *peer;
4843 int ret;
3f9c7369 4844
d62a17ae 4845 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4846 if (!peer)
4847 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4848
d62a17ae 4849 ret = update_group_adjust_soloness(peer, 0);
4850 return bgp_vty_return(vty, ret);
3f9c7369
DS
4851}
4852
f4b8ec07
CS
4853DEFUN_YANG(neighbor_password,
4854 neighbor_password_cmd,
4855 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
4856 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4857 "Set a password\n"
4858 "The password\n")
0df7c91f 4859{
d62a17ae 4860 int idx_peer = 1;
4861 int idx_line = 3;
f4b8ec07 4862 char base_xpath[XPATH_MAXLEN];
0df7c91f 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;
0df7c91f 4868
f4b8ec07
CS
4869 nb_cli_enqueue_change(vty, "./password", NB_OP_MODIFY,
4870 argv[idx_line]->arg);
4871
4872 return nb_cli_apply_changes(vty, base_xpath);
0df7c91f
PJ
4873}
4874
f4b8ec07
CS
4875DEFUN_YANG(no_neighbor_password,
4876 no_neighbor_password_cmd,
4877 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
4878 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4879 "Set a password\n"
4880 "The password\n")
0df7c91f 4881{
d62a17ae 4882 int idx_peer = 2;
f4b8ec07 4883 char base_xpath[XPATH_MAXLEN];
0df7c91f 4884
f4b8ec07
CS
4885 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4886 sizeof(base_xpath), NULL)
4887 < 0)
d62a17ae 4888 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 4889
f4b8ec07
CS
4890 nb_cli_enqueue_change(vty, "./password", NB_OP_DESTROY, NULL);
4891
4892 return nb_cli_apply_changes(vty, base_xpath);
0df7c91f 4893}
6b0655a2 4894
f4b8ec07
CS
4895DEFUN_YANG(neighbor_activate,
4896 neighbor_activate_cmd,
4897 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4898 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4899 "Enable the Address Family for this Neighbor\n")
718e3744 4900{
d62a17ae 4901 int idx_peer = 1;
f4b8ec07 4902 char base_xpath[XPATH_MAXLEN];
f4b8ec07
CS
4903 char af_xpath[XPATH_MAXLEN];
4904 afi_t afi = bgp_node_afi(vty);
4905 safi_t safi = bgp_node_safi(vty);
718e3744 4906
f4b8ec07
CS
4907 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
4908 yang_afi_safi_value2identity(afi, safi));
555c8ab7
CS
4909 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4910 sizeof(base_xpath), af_xpath)
f4b8ec07 4911 < 0)
d62a17ae 4912 return CMD_WARNING_CONFIG_FAILED;
718e3744 4913
555c8ab7 4914 nb_cli_enqueue_change(vty, "./enabled", NB_OP_MODIFY, "true");
f4b8ec07
CS
4915
4916 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4917}
4918
d62a17ae 4919ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
4920 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4921 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4922 "Enable the Address Family for this Neighbor\n")
596c17ba 4923
f4b8ec07
CS
4924DEFUN_YANG(no_neighbor_activate,
4925 no_neighbor_activate_cmd,
4926 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4927 NO_STR NEIGHBOR_STR
4928 NEIGHBOR_ADDR_STR2
4929 "Enable the Address Family for this Neighbor\n")
718e3744 4930{
d62a17ae 4931 int idx_peer = 2;
f4b8ec07
CS
4932 char base_xpath[XPATH_MAXLEN];
4933 char af_xpath[XPATH_MAXLEN];
4934 afi_t afi = bgp_node_afi(vty);
4935 safi_t safi = bgp_node_safi(vty);
718e3744 4936
f4b8ec07
CS
4937 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
4938 yang_afi_safi_value2identity(afi, safi));
4939
4940 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4941 sizeof(base_xpath), af_xpath)
4942 < 0)
d62a17ae 4943 return CMD_WARNING_CONFIG_FAILED;
718e3744 4944
f4b8ec07
CS
4945 nb_cli_enqueue_change(vty, "./enabled", NB_OP_MODIFY, "false");
4946
4947 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4948}
6b0655a2 4949
d62a17ae 4950ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
4951 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4952 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4953 "Enable the Address Family for this Neighbor\n")
596c17ba 4954
2a059a54
DS
4955DEFUN (neighbor_set_peer_group,
4956 neighbor_set_peer_group_cmd,
4957 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4958 NEIGHBOR_STR
4959 NEIGHBOR_ADDR_STR2
4960 "Member of the peer-group\n"
4961 "Peer-group name\n")
718e3744 4962{
2a059a54 4963 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4964 int idx_peer = 1;
4965 int idx_word = 3;
2a059a54
DS
4966 int ret;
4967 as_t as;
4968 union sockunion su;
4969 struct peer *peer;
4970 struct peer_group *group;
d62a17ae 4971
2a059a54
DS
4972 ret = str2sockunion(argv[idx_peer]->arg, &su);
4973 if (ret < 0) {
4974 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4975 if (!peer) {
4976 vty_out(vty, "%% Malformed address or name: %s\n",
4977 argv[idx_peer]->arg);
4978 return CMD_WARNING_CONFIG_FAILED;
4979 }
4980 } else {
4981 if (peer_address_self_check(bgp, &su)) {
4982 vty_out(vty,
4983 "%% Can not configure the local system as neighbor\n");
4984 return CMD_WARNING_CONFIG_FAILED;
4985 }
4986
4987 /* Disallow for dynamic neighbor. */
4988 peer = peer_lookup(bgp, &su);
4989 if (peer && peer_dynamic_neighbor(peer)) {
4990 vty_out(vty,
4991 "%% Operation not allowed on a dynamic neighbor\n");
4992 return CMD_WARNING_CONFIG_FAILED;
4993 }
4994 }
4995
4996 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4997 if (!group) {
4998 vty_out(vty, "%% Configure the peer-group first\n");
d62a17ae 4999 return CMD_WARNING_CONFIG_FAILED;
2a059a54 5000 }
d62a17ae 5001
2a059a54 5002 ret = peer_group_bind(bgp, &su, peer, group, &as);
d62a17ae 5003
2a059a54
DS
5004 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
5005 vty_out(vty,
5006 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
5007 as);
5008 return CMD_WARNING_CONFIG_FAILED;
5009 }
5010
5011 return bgp_vty_return(vty, ret);
d62a17ae 5012}
5013
5014ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
d7b9898c 5015 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 5016 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5017 "Member of the peer-group\n"
5018 "Peer-group name\n")
596c17ba 5019
f4b8ec07
CS
5020DEFUN_YANG (no_neighbor_set_peer_group,
5021 no_neighbor_set_peer_group_cmd,
5022 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5023 NO_STR
5024 NEIGHBOR_STR
5025 NEIGHBOR_ADDR_STR2
5026 "Member of the peer-group\n"
5027 "Peer-group name\n")
718e3744 5028{
d62a17ae 5029 int idx_peer = 2;
f4b8ec07 5030 char base_xpath[XPATH_MAXLEN];
d62a17ae 5031
f4b8ec07
CS
5032 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5033 sizeof(base_xpath), NULL)
5034 < 0)
d62a17ae 5035 return CMD_WARNING_CONFIG_FAILED;
b3a3290e 5036
f4b8ec07 5037 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_DESTROY, NULL);
718e3744 5038
f4b8ec07 5039 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5040}
6b0655a2 5041
d62a17ae 5042ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
d7b9898c 5043 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 5044 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5045 "Member of the peer-group\n"
5046 "Peer-group name\n")
596c17ba 5047
d62a17ae 5048static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
47cbc09b 5049 uint32_t flag, int set)
718e3744 5050{
d62a17ae 5051 int ret;
5052 struct peer *peer;
718e3744 5053
d62a17ae 5054 peer = peer_and_group_lookup_vty(vty, ip_str);
5055 if (!peer)
5056 return CMD_WARNING_CONFIG_FAILED;
718e3744 5057
7ebe625c
QY
5058 /*
5059 * If 'neighbor <interface>', then this is for directly connected peers,
5060 * we should not accept disable-connected-check.
5061 */
5062 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5063 vty_out(vty,
3efd0893 5064 "%s is directly connected peer, cannot accept disable-connected-check\n",
7ebe625c
QY
5065 ip_str);
5066 return CMD_WARNING_CONFIG_FAILED;
5067 }
5068
d62a17ae 5069 if (!set && flag == PEER_FLAG_SHUTDOWN)
5070 peer_tx_shutdown_message_unset(peer);
ae9b0e11 5071
d62a17ae 5072 if (set)
5073 ret = peer_flag_set(peer, flag);
5074 else
5075 ret = peer_flag_unset(peer, flag);
718e3744 5076
d62a17ae 5077 return bgp_vty_return(vty, ret);
718e3744 5078}
5079
47cbc09b 5080static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
718e3744 5081{
d62a17ae 5082 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 5083}
5084
d62a17ae 5085static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
47cbc09b 5086 uint32_t flag)
718e3744 5087{
d62a17ae 5088 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 5089}
5090
f4b8ec07
CS
5091int peer_flag_modify_nb(struct bgp *bgp, const char *ip_str, struct peer *peer,
5092 uint32_t flag, bool set, char *errmsg,
5093 size_t errmsg_len)
5094{
5095 int ret;
5096
5097 /*
5098 * If 'neighbor <interface>', then this is for directly connected peers,
5099 * we should not accept disable-connected-check.
5100 */
5101 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5102 snprintf(
5103 errmsg, errmsg_len,
5104 "%s is directly connected peer, cannot accept disable-connected-check\n",
5105 ip_str);
5106 return -1;
5107 }
5108
5109 if (!set && flag == PEER_FLAG_SHUTDOWN)
5110 peer_tx_shutdown_message_unset(peer);
5111
5112 if (set)
5113 ret = peer_flag_set(peer, flag);
5114 else
5115 ret = peer_flag_unset(peer, flag);
5116
5117 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
5118}
5119
718e3744 5120/* neighbor passive. */
f4b8ec07
CS
5121DEFUN_YANG(neighbor_passive,
5122 neighbor_passive_cmd,
5123 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5124 NEIGHBOR_STR
5125 NEIGHBOR_ADDR_STR2
5126 "Don't send open messages to this neighbor\n")
718e3744 5127{
d62a17ae 5128 int idx_peer = 1;
f4b8ec07
CS
5129 char base_xpath[XPATH_MAXLEN];
5130
5131 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5132 sizeof(base_xpath), NULL)
5133 < 0)
5134 return CMD_WARNING_CONFIG_FAILED;
5135
5136 nb_cli_enqueue_change(vty, "./passive-mode", NB_OP_MODIFY, "true");
5137
5138 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5139}
5140
f4b8ec07
CS
5141DEFUN_YANG(no_neighbor_passive,
5142 no_neighbor_passive_cmd,
5143 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5144 NO_STR NEIGHBOR_STR
5145 NEIGHBOR_ADDR_STR2
5146 "Don't send open messages to this neighbor\n")
718e3744 5147{
d62a17ae 5148 int idx_peer = 2;
f4b8ec07
CS
5149 char base_xpath[XPATH_MAXLEN];
5150
5151 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5152 sizeof(base_xpath), NULL)
5153 < 0)
5154 return CMD_WARNING_CONFIG_FAILED;
5155
5156 nb_cli_enqueue_change(vty, "./passive-mode", NB_OP_MODIFY, "false");
5157
5158 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5159}
6b0655a2 5160
718e3744 5161/* neighbor shutdown. */
f4b8ec07
CS
5162DEFUN_YANG(neighbor_shutdown_msg,
5163 neighbor_shutdown_msg_cmd,
5164 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5165 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5166 "Administratively shut down this neighbor\n"
5167 "Add a shutdown message (RFC 8203)\n"
5168 "Shutdown message\n")
718e3744 5169{
d62a17ae 5170 int idx_peer = 1;
f4b8ec07
CS
5171 char base_xpath[XPATH_MAXLEN];
5172
5173 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5174 sizeof(base_xpath), NULL)
5175 < 0)
5176 return CMD_WARNING_CONFIG_FAILED;
73d70fa6 5177
d62a17ae 5178 if (argc >= 5) {
d62a17ae 5179 char *message;
73d70fa6 5180
d62a17ae 5181 message = argv_concat(argv, argc, 4);
f4b8ec07
CS
5182 nb_cli_enqueue_change(vty, "./admin-shutdown/message",
5183 NB_OP_MODIFY, message);
d62a17ae 5184 }
73d70fa6 5185
f4b8ec07
CS
5186 nb_cli_enqueue_change(vty, "./admin-shutdown/enable", NB_OP_MODIFY,
5187 "true");
5188
5189 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5190}
5191
232c75cd 5192ALIAS_YANG(neighbor_shutdown_msg, neighbor_shutdown_cmd,
d62a17ae 5193 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5194 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5195 "Administratively shut down this neighbor\n")
73d70fa6 5196
f4b8ec07
CS
5197DEFUN_YANG(no_neighbor_shutdown_msg,
5198 no_neighbor_shutdown_msg_cmd,
5199 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5200 NO_STR NEIGHBOR_STR
5201 NEIGHBOR_ADDR_STR2
5202 "Administratively shut down this neighbor\n"
5203 "Remove a shutdown message (RFC 8203)\n"
5204 "Shutdown message\n")
718e3744 5205{
d62a17ae 5206 int idx_peer = 2;
f4b8ec07 5207 char base_xpath[XPATH_MAXLEN];
73d70fa6 5208
f4b8ec07
CS
5209 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5210 sizeof(base_xpath), NULL)
5211 < 0)
5212 return CMD_WARNING_CONFIG_FAILED;
5213
5214 nb_cli_enqueue_change(vty, "./admin-shutdown/enable", NB_OP_MODIFY,
5215 "false");
5216
5217 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5218}
6b0655a2 5219
232c75cd 5220ALIAS_YANG(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
d62a17ae 5221 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5222 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5223 "Administratively shut down this neighbor\n")
73d70fa6 5224
8336c896
DA
5225DEFUN(neighbor_shutdown_rtt,
5226 neighbor_shutdown_rtt_cmd,
5227 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5228 NEIGHBOR_STR
5229 NEIGHBOR_ADDR_STR2
5230 "Administratively shut down this neighbor\n"
5231 "Shutdown if round-trip-time is higher than expected\n"
5232 "Round-trip-time in milliseconds\n"
5233 "Specify the number of keepalives before shutdown\n"
5234 "The number of keepalives with higher RTT to shutdown\n")
5235{
5236 int idx_peer = 1;
5237 int idx_rtt = 4;
5238 int idx_count = 0;
5239 struct peer *peer;
5240
5241 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5242
5243 if (!peer)
5244 return CMD_WARNING_CONFIG_FAILED;
5245
5246 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5247
5248 if (argv_find(argv, argc, "count", &idx_count))
5249 peer->rtt_keepalive_conf =
5250 strtol(argv[idx_count + 1]->arg, NULL, 10);
5251
5252 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5253 PEER_FLAG_RTT_SHUTDOWN);
5254}
5255
5256DEFUN(no_neighbor_shutdown_rtt,
5257 no_neighbor_shutdown_rtt_cmd,
5258 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5259 NO_STR
5260 NEIGHBOR_STR
5261 NEIGHBOR_ADDR_STR2
5262 "Administratively shut down this neighbor\n"
5263 "Shutdown if round-trip-time is higher than expected\n"
5264 "Round-trip-time in milliseconds\n"
5265 "Specify the number of keepalives before shutdown\n"
5266 "The number of keepalives with higher RTT to shutdown\n")
5267{
5268 int idx_peer = 2;
5269 struct peer *peer;
5270
5271 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5272
5273 if (!peer)
5274 return CMD_WARNING_CONFIG_FAILED;
5275
5276 peer->rtt_expected = 0;
5277 peer->rtt_keepalive_conf = 1;
5278
5279 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5280 PEER_FLAG_RTT_SHUTDOWN);
5281}
5282
718e3744 5283/* neighbor capability dynamic. */
f4b8ec07
CS
5284DEFUN_YANG (neighbor_capability_dynamic,
5285 neighbor_capability_dynamic_cmd,
5286 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5287 NEIGHBOR_STR
5288 NEIGHBOR_ADDR_STR2
5289 "Advertise capability to the peer\n"
5290 "Advertise dynamic capability to this neighbor\n")
718e3744 5291{
d62a17ae 5292 int idx_peer = 1;
f4b8ec07
CS
5293 char base_xpath[XPATH_MAXLEN];
5294
5295 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5296 sizeof(base_xpath), NULL)
5297 < 0)
5298 return CMD_WARNING_CONFIG_FAILED;
5299
5300 nb_cli_enqueue_change(vty, "./capability-options/dynamic-capability",
5301 NB_OP_MODIFY, "true");
5302
5303 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5304}
5305
f4b8ec07
CS
5306DEFUN_YANG (no_neighbor_capability_dynamic,
5307 no_neighbor_capability_dynamic_cmd,
5308 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5309 NO_STR
5310 NEIGHBOR_STR
5311 NEIGHBOR_ADDR_STR2
5312 "Advertise capability to the peer\n"
5313 "Advertise dynamic capability to this neighbor\n")
718e3744 5314{
d62a17ae 5315 int idx_peer = 2;
f4b8ec07
CS
5316 char base_xpath[XPATH_MAXLEN];
5317
5318 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5319 sizeof(base_xpath), NULL)
5320 < 0)
5321 return CMD_WARNING_CONFIG_FAILED;
5322
5323 nb_cli_enqueue_change(vty, "./capability-options/dynamic-capability",
5324 NB_OP_MODIFY, "false");
5325
5326 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5327}
6b0655a2 5328
718e3744 5329/* neighbor dont-capability-negotiate */
5330DEFUN (neighbor_dont_capability_negotiate,
5331 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5332 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5333 NEIGHBOR_STR
5334 NEIGHBOR_ADDR_STR2
5335 "Do not perform capability negotiation\n")
5336{
d62a17ae 5337 int idx_peer = 1;
5338 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5339 PEER_FLAG_DONT_CAPABILITY);
718e3744 5340}
5341
5342DEFUN (no_neighbor_dont_capability_negotiate,
5343 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5344 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5345 NO_STR
5346 NEIGHBOR_STR
5347 NEIGHBOR_ADDR_STR2
5348 "Do not perform capability negotiation\n")
5349{
d62a17ae 5350 int idx_peer = 2;
5351 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5352 PEER_FLAG_DONT_CAPABILITY);
718e3744 5353}
6b0655a2 5354
8a92a8a0 5355/* neighbor capability extended next hop encoding */
f4b8ec07
CS
5356DEFUN_YANG (neighbor_capability_enhe,
5357 neighbor_capability_enhe_cmd,
5358 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5359 NEIGHBOR_STR
5360 NEIGHBOR_ADDR_STR2
5361 "Advertise capability to the peer\n"
5362 "Advertise extended next-hop capability to the peer\n")
8a92a8a0 5363{
d62a17ae 5364 int idx_peer = 1;
f4b8ec07
CS
5365 char base_xpath[XPATH_MAXLEN];
5366
5367 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5368 sizeof(base_xpath), NULL)
5369 < 0)
5370 return CMD_WARNING_CONFIG_FAILED;
5371
5372 nb_cli_enqueue_change(
5373 vty, "./capability-options/extended-nexthop-capability",
5374 NB_OP_MODIFY, "true");
5375
5376 return nb_cli_apply_changes(vty, base_xpath);
8a92a8a0
DS
5377}
5378
f4b8ec07
CS
5379DEFUN_YANG (no_neighbor_capability_enhe,
5380 no_neighbor_capability_enhe_cmd,
5381 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5382 NO_STR
5383 NEIGHBOR_STR
5384 NEIGHBOR_ADDR_STR2
5385 "Advertise capability to the peer\n"
5386 "Advertise extended next-hop capability to the peer\n")
8a92a8a0 5387{
d62a17ae 5388 int idx_peer = 2;
f4b8ec07
CS
5389 char base_xpath[XPATH_MAXLEN];
5390
5391 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5392 sizeof(base_xpath), NULL)
5393 < 0)
5394 return CMD_WARNING_CONFIG_FAILED;
5395
5396 nb_cli_enqueue_change(
5397 vty, "./capability-options/extended-nexthop-capability",
5398 NB_OP_MODIFY, "false");
5399
5400 return nb_cli_apply_changes(vty, base_xpath);
5401}
5402
5403int peer_af_flag_modify_nb(struct peer *peer, afi_t afi, safi_t safi,
5404 uint32_t flag, int set, char *errmsg,
5405 size_t errmsg_len)
5406{
5407 int ret;
5408
5409 if (set)
5410 ret = peer_af_flag_set(peer, afi, safi, flag);
5411 else
5412 ret = peer_af_flag_unset(peer, afi, safi, flag);
5413
5414 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
8a92a8a0
DS
5415}
5416
d62a17ae 5417static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5418 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 5419 int set)
718e3744 5420{
d62a17ae 5421 int ret;
5422 struct peer *peer;
718e3744 5423
d62a17ae 5424 peer = peer_and_group_lookup_vty(vty, peer_str);
5425 if (!peer)
5426 return CMD_WARNING_CONFIG_FAILED;
718e3744 5427
d62a17ae 5428 if (set)
5429 ret = peer_af_flag_set(peer, afi, safi, flag);
5430 else
5431 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 5432
d62a17ae 5433 return bgp_vty_return(vty, ret);
718e3744 5434}
5435
d62a17ae 5436static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5437 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5438{
d62a17ae 5439 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 5440}
5441
d62a17ae 5442static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5443 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5444{
d62a17ae 5445 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 5446}
6b0655a2 5447
718e3744 5448/* neighbor capability orf prefix-list. */
5449DEFUN (neighbor_capability_orf_prefix,
5450 neighbor_capability_orf_prefix_cmd,
9ccf14f7 5451 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5452 NEIGHBOR_STR
5453 NEIGHBOR_ADDR_STR2
5454 "Advertise capability to the peer\n"
5455 "Advertise ORF capability to the peer\n"
5456 "Advertise prefixlist ORF capability to this neighbor\n"
5457 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5458 "Capability to RECEIVE the ORF from this neighbor\n"
5459 "Capability to SEND the ORF to this neighbor\n")
5460{
d62a17ae 5461 int idx_send_recv = 5;
db45f64d
DS
5462 char *peer_str = argv[1]->arg;
5463 struct peer *peer;
5464 afi_t afi = bgp_node_afi(vty);
5465 safi_t safi = bgp_node_safi(vty);
d62a17ae 5466
db45f64d
DS
5467 peer = peer_and_group_lookup_vty(vty, peer_str);
5468 if (!peer)
d62a17ae 5469 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5470
db45f64d
DS
5471 if (strmatch(argv[idx_send_recv]->text, "send"))
5472 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5473 PEER_FLAG_ORF_PREFIX_SM);
5474
5475 if (strmatch(argv[idx_send_recv]->text, "receive"))
5476 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5477 PEER_FLAG_ORF_PREFIX_RM);
5478
5479 if (strmatch(argv[idx_send_recv]->text, "both"))
5480 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5481 PEER_FLAG_ORF_PREFIX_SM)
5482 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5483 PEER_FLAG_ORF_PREFIX_RM);
5484
5485 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5486}
5487
5488ALIAS_HIDDEN(
5489 neighbor_capability_orf_prefix,
5490 neighbor_capability_orf_prefix_hidden_cmd,
5491 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5492 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5493 "Advertise capability to the peer\n"
5494 "Advertise ORF capability to the peer\n"
5495 "Advertise prefixlist ORF capability to this neighbor\n"
5496 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5497 "Capability to RECEIVE the ORF from this neighbor\n"
5498 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5499
718e3744 5500DEFUN (no_neighbor_capability_orf_prefix,
5501 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 5502 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5503 NO_STR
5504 NEIGHBOR_STR
5505 NEIGHBOR_ADDR_STR2
5506 "Advertise capability to the peer\n"
5507 "Advertise ORF capability to the peer\n"
5508 "Advertise prefixlist ORF capability to this neighbor\n"
5509 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5510 "Capability to RECEIVE the ORF from this neighbor\n"
5511 "Capability to SEND the ORF to this neighbor\n")
5512{
d62a17ae 5513 int idx_send_recv = 6;
db45f64d
DS
5514 char *peer_str = argv[2]->arg;
5515 struct peer *peer;
5516 afi_t afi = bgp_node_afi(vty);
5517 safi_t safi = bgp_node_safi(vty);
d62a17ae 5518
db45f64d
DS
5519 peer = peer_and_group_lookup_vty(vty, peer_str);
5520 if (!peer)
d62a17ae 5521 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5522
db45f64d
DS
5523 if (strmatch(argv[idx_send_recv]->text, "send"))
5524 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5525 PEER_FLAG_ORF_PREFIX_SM);
5526
5527 if (strmatch(argv[idx_send_recv]->text, "receive"))
5528 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5529 PEER_FLAG_ORF_PREFIX_RM);
5530
5531 if (strmatch(argv[idx_send_recv]->text, "both"))
5532 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5533 PEER_FLAG_ORF_PREFIX_SM)
5534 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5535 PEER_FLAG_ORF_PREFIX_RM);
5536
5537 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5538}
5539
5540ALIAS_HIDDEN(
5541 no_neighbor_capability_orf_prefix,
5542 no_neighbor_capability_orf_prefix_hidden_cmd,
5543 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5544 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5545 "Advertise capability to the peer\n"
5546 "Advertise ORF capability to the peer\n"
5547 "Advertise prefixlist ORF capability to this neighbor\n"
5548 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5549 "Capability to RECEIVE the ORF from this neighbor\n"
5550 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5551
718e3744 5552/* neighbor next-hop-self. */
f4b8ec07
CS
5553DEFUN_YANG (neighbor_nexthop_self,
5554 neighbor_nexthop_self_cmd,
5555 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5556 NEIGHBOR_STR
5557 NEIGHBOR_ADDR_STR2
5558 "Disable the next hop calculation for this neighbor\n")
718e3744 5559{
d62a17ae 5560 int idx_peer = 1;
f4b8ec07
CS
5561 char base_xpath[XPATH_MAXLEN];
5562 char af_xpath[XPATH_MAXLEN];
5563 char attr_xpath[XPATH_MAXLEN];
5564 afi_t afi = bgp_node_afi(vty);
5565 safi_t safi = bgp_node_safi(vty);
5566
f4b8ec07
CS
5567 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5568 yang_afi_safi_value2identity(afi, safi));
5569
5570 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5571 sizeof(base_xpath), af_xpath)
5572 < 0)
5573 return CMD_WARNING_CONFIG_FAILED;
5574
5575 snprintf(attr_xpath, sizeof(attr_xpath),
5576 "./%s/nexthop-self/next-hop-self",
5577 bgp_afi_safi_get_container_str(afi, safi));
5578
5579 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5580
5581 return nb_cli_apply_changes(vty, base_xpath);
a538debe 5582}
9e7a53c1 5583
d62a17ae 5584ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5585 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5586 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5587 "Disable the next hop calculation for this neighbor\n")
596c17ba 5588
f4b8ec07
CS
5589/* neighbor next-hop-self. */
5590DEFUN_YANG(neighbor_nexthop_self_force,
5591 neighbor_nexthop_self_force_cmd,
5592 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5593 NEIGHBOR_STR
5594 NEIGHBOR_ADDR_STR2
5595 "Disable the next hop calculation for this neighbor\n"
5596 "Set the next hop to self for reflected routes\n")
5597{
5598 int idx_peer = 1;
5599 char base_xpath[XPATH_MAXLEN];
5600 char af_xpath[XPATH_MAXLEN];
5601 char attr_xpath[XPATH_MAXLEN];
5602 afi_t afi = bgp_node_afi(vty);
5603 safi_t safi = bgp_node_safi(vty);
5604
f4b8ec07
CS
5605 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5606 yang_afi_safi_value2identity(afi, safi));
5607
5608 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5609 sizeof(base_xpath), af_xpath)
5610 < 0)
5611 return CMD_WARNING_CONFIG_FAILED;
5612
5613 snprintf(attr_xpath, sizeof(attr_xpath),
5614 "./%s/nexthop-self/next-hop-self-force",
5615 bgp_afi_safi_get_container_str(afi, safi));
5616
5617 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5618
5619 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5620}
5621
d62a17ae 5622ALIAS_HIDDEN(neighbor_nexthop_self_force,
5623 neighbor_nexthop_self_force_hidden_cmd,
5624 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5625 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5626 "Disable the next hop calculation for this neighbor\n"
5627 "Set the next hop to self for reflected routes\n")
596c17ba 5628
1bc4e531
DA
5629ALIAS_HIDDEN(neighbor_nexthop_self_force,
5630 neighbor_nexthop_self_all_hidden_cmd,
5631 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5632 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5633 "Disable the next hop calculation for this neighbor\n"
5634 "Set the next hop to self for reflected routes\n")
5635
f4b8ec07
CS
5636DEFUN_YANG (no_neighbor_nexthop_self,
5637 no_neighbor_nexthop_self_cmd,
5638 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5639 NO_STR
5640 NEIGHBOR_STR
5641 NEIGHBOR_ADDR_STR2
5642 "Disable the next hop calculation for this neighbor\n")
718e3744 5643{
d62a17ae 5644 int idx_peer = 2;
f4b8ec07
CS
5645 char base_xpath[XPATH_MAXLEN];
5646 char af_xpath[XPATH_MAXLEN];
5647 char attr_xpath[XPATH_MAXLEN];
5648 afi_t afi = bgp_node_afi(vty);
5649 safi_t safi = bgp_node_safi(vty);
5650
5651 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5652 yang_afi_safi_value2identity(afi, safi));
5653
5654 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5655 sizeof(base_xpath), af_xpath)
5656 < 0)
5657 return CMD_WARNING_CONFIG_FAILED;
5658
5659 snprintf(attr_xpath, sizeof(attr_xpath),
5660 "./%s/nexthop-self/next-hop-self",
5661 bgp_afi_safi_get_container_str(afi, safi));
5662
5663 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5664
5665 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5666}
6b0655a2 5667
d62a17ae 5668ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5669 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5670 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5671 "Disable the next hop calculation for this neighbor\n")
596c17ba 5672
f4b8ec07
CS
5673DEFUN_YANG (no_neighbor_nexthop_self_force,
5674 no_neighbor_nexthop_self_force_cmd,
5675 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5676 NO_STR
5677 NEIGHBOR_STR
5678 NEIGHBOR_ADDR_STR2
5679 "Disable the next hop calculation for this neighbor\n"
5680 "Set the next hop to self for reflected routes\n")
88b8ed8d 5681{
d62a17ae 5682 int idx_peer = 2;
f4b8ec07
CS
5683 char base_xpath[XPATH_MAXLEN];
5684 char af_xpath[XPATH_MAXLEN];
5685 char attr_xpath[XPATH_MAXLEN];
5686 afi_t afi = bgp_node_afi(vty);
5687 safi_t safi = bgp_node_safi(vty);
5688
f4b8ec07
CS
5689 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5690 yang_afi_safi_value2identity(afi, safi));
5691
5692 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5693 sizeof(base_xpath), af_xpath)
5694 < 0)
5695 return CMD_WARNING_CONFIG_FAILED;
5696
5697 snprintf(attr_xpath, sizeof(attr_xpath),
5698 "./%s/nexthop-self/next-hop-self-force",
5699 bgp_afi_safi_get_container_str(afi, safi));
5700
5701 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5702
5703 return nb_cli_apply_changes(vty, base_xpath);
88b8ed8d 5704}
a538debe 5705
d62a17ae 5706ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5707 no_neighbor_nexthop_self_force_hidden_cmd,
5708 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5709 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5710 "Disable the next hop calculation for this neighbor\n"
5711 "Set the next hop to self for reflected routes\n")
596c17ba 5712
1bc4e531
DA
5713ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5714 no_neighbor_nexthop_self_all_hidden_cmd,
5715 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5716 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5717 "Disable the next hop calculation for this neighbor\n"
5718 "Set the next hop to self for reflected routes\n")
5719
c7122e14 5720/* neighbor as-override */
f4b8ec07
CS
5721DEFUN_YANG (neighbor_as_override,
5722 neighbor_as_override_cmd,
5723 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5724 NEIGHBOR_STR
5725 NEIGHBOR_ADDR_STR2
5726 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5727{
d62a17ae 5728 int idx_peer = 1;
f4b8ec07
CS
5729 char base_xpath[XPATH_MAXLEN];
5730 char af_xpath[XPATH_MAXLEN];
5731 char attr_xpath[XPATH_MAXLEN];
5732 afi_t afi = bgp_node_afi(vty);
5733 safi_t safi = bgp_node_safi(vty);
5734
5735 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5736 yang_afi_safi_value2identity(afi, safi));
5737
5738 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5739 sizeof(base_xpath), af_xpath)
5740 < 0)
5741 return CMD_WARNING_CONFIG_FAILED;
5742
5743 snprintf(attr_xpath, sizeof(attr_xpath),
5744 "./%s/as-path-options/replace-peer-as",
5745 bgp_afi_safi_get_container_str(afi, safi));
5746
5747 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5748
5749 return nb_cli_apply_changes(vty, base_xpath);
c7122e14
DS
5750}
5751
d62a17ae 5752ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5753 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5754 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5755 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5756
f4b8ec07
CS
5757DEFUN_YANG (no_neighbor_as_override,
5758 no_neighbor_as_override_cmd,
5759 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5760 NO_STR
5761 NEIGHBOR_STR
5762 NEIGHBOR_ADDR_STR2
5763 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5764{
d62a17ae 5765 int idx_peer = 2;
f4b8ec07
CS
5766 char base_xpath[XPATH_MAXLEN];
5767 char af_xpath[XPATH_MAXLEN];
5768 char attr_xpath[XPATH_MAXLEN];
5769 afi_t afi = bgp_node_afi(vty);
5770 safi_t safi = bgp_node_safi(vty);
5771
5772 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5773 yang_afi_safi_value2identity(afi, safi));
5774
5775 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5776 sizeof(base_xpath), af_xpath)
5777 < 0)
5778 return CMD_WARNING_CONFIG_FAILED;
5779
5780 snprintf(attr_xpath, sizeof(attr_xpath),
5781 "./%s/as-path-options/replace-peer-as",
5782 bgp_afi_safi_get_container_str(afi, safi));
5783
5784 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5785
5786 return nb_cli_apply_changes(vty, base_xpath);
c7122e14
DS
5787}
5788
d62a17ae 5789ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5790 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5791 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5792 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5793
718e3744 5794/* neighbor remove-private-AS. */
f4b8ec07
CS
5795DEFUN_YANG (neighbor_remove_private_as,
5796 neighbor_remove_private_as_cmd,
5797 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5798 NEIGHBOR_STR
5799 NEIGHBOR_ADDR_STR2
5800 "Remove private ASNs in outbound updates\n")
718e3744 5801{
d62a17ae 5802 int idx_peer = 1;
f4b8ec07
CS
5803 char base_xpath[XPATH_MAXLEN];
5804 char af_xpath[XPATH_MAXLEN];
5805 char attr_xpath[XPATH_MAXLEN];
5806 afi_t afi = bgp_node_afi(vty);
5807 safi_t safi = bgp_node_safi(vty);
5808
5809 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5810 yang_afi_safi_value2identity(afi, safi));
5811
5812 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5813 sizeof(base_xpath), af_xpath)
5814 < 0)
5815 return CMD_WARNING_CONFIG_FAILED;
5816
5817 snprintf(attr_xpath, sizeof(attr_xpath),
5818 "./%s/private-as/remove-private-as",
5819 bgp_afi_safi_get_container_str(afi, safi));
5820
5821 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5822
5823 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5824}
5825
d62a17ae 5826ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5827 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5828 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5829 "Remove private ASNs in outbound updates\n")
596c17ba 5830
f4b8ec07
CS
5831DEFUN_YANG (neighbor_remove_private_as_all,
5832 neighbor_remove_private_as_all_cmd,
5833 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5834 NEIGHBOR_STR
5835 NEIGHBOR_ADDR_STR2
5836 "Remove private ASNs in outbound updates\n"
5837 "Apply to all AS numbers\n")
5000f21c 5838{
d62a17ae 5839 int idx_peer = 1;
f4b8ec07
CS
5840 char base_xpath[XPATH_MAXLEN];
5841 char af_xpath[XPATH_MAXLEN];
5842 char attr_xpath[XPATH_MAXLEN];
5843 afi_t afi = bgp_node_afi(vty);
5844 safi_t safi = bgp_node_safi(vty);
5845
f4b8ec07
CS
5846 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5847 yang_afi_safi_value2identity(afi, safi));
5848
5849 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5850 sizeof(base_xpath), af_xpath)
5851 < 0)
5852 return CMD_WARNING_CONFIG_FAILED;
5853
5854 snprintf(attr_xpath, sizeof(attr_xpath),
5855 "./%s/private-as/remove-private-as-all",
5856 bgp_afi_safi_get_container_str(afi, safi));
5857
5858 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5859
5860 return nb_cli_apply_changes(vty, base_xpath);
5000f21c
DS
5861}
5862
d62a17ae 5863ALIAS_HIDDEN(neighbor_remove_private_as_all,
5864 neighbor_remove_private_as_all_hidden_cmd,
5865 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5866 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5867 "Remove private ASNs in outbound updates\n"
5868 "Apply to all AS numbers")
596c17ba 5869
f4b8ec07
CS
5870DEFUN_YANG (neighbor_remove_private_as_replace_as,
5871 neighbor_remove_private_as_replace_as_cmd,
5872 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5873 NEIGHBOR_STR
5874 NEIGHBOR_ADDR_STR2
5875 "Remove private ASNs in outbound updates\n"
5876 "Replace private ASNs with our ASN in outbound updates\n")
5000f21c 5877{
d62a17ae 5878 int idx_peer = 1;
f4b8ec07
CS
5879 char base_xpath[XPATH_MAXLEN];
5880 char af_xpath[XPATH_MAXLEN];
5881 char attr_xpath[XPATH_MAXLEN];
5882 afi_t afi = bgp_node_afi(vty);
5883 safi_t safi = bgp_node_safi(vty);
5884
f4b8ec07
CS
5885 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5886 yang_afi_safi_value2identity(afi, safi));
5887
5888 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5889 sizeof(base_xpath), af_xpath)
5890 < 0)
5891 return CMD_WARNING_CONFIG_FAILED;
5892
5893 snprintf(attr_xpath, sizeof(attr_xpath),
5894 "./%s/private-as/remove-private-as-replace",
5895 bgp_afi_safi_get_container_str(afi, safi));
5896
5897 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5898
5899 return nb_cli_apply_changes(vty, base_xpath);
5000f21c
DS
5900}
5901
d62a17ae 5902ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5903 neighbor_remove_private_as_replace_as_hidden_cmd,
5904 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5905 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5906 "Remove private ASNs in outbound updates\n"
5907 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5908
f4b8ec07
CS
5909DEFUN_YANG (neighbor_remove_private_as_all_replace_as,
5910 neighbor_remove_private_as_all_replace_as_cmd,
5911 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5912 NEIGHBOR_STR
5913 NEIGHBOR_ADDR_STR2
5914 "Remove private ASNs in outbound updates\n"
5915 "Apply to all AS numbers\n"
5916 "Replace private ASNs with our ASN in outbound updates\n")
5000f21c 5917{
d62a17ae 5918 int idx_peer = 1;
f4b8ec07
CS
5919 char base_xpath[XPATH_MAXLEN];
5920 char af_xpath[XPATH_MAXLEN];
5921 char attr_xpath[XPATH_MAXLEN];
5922 afi_t afi = bgp_node_afi(vty);
5923 safi_t safi = bgp_node_safi(vty);
5924
f4b8ec07
CS
5925 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5926 yang_afi_safi_value2identity(afi, safi));
5927
5928 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5929 sizeof(base_xpath), af_xpath)
5930 < 0)
5931 return CMD_WARNING_CONFIG_FAILED;
5932
5933 snprintf(attr_xpath, sizeof(attr_xpath),
5934 "./%s/private-as/remove-private-as-all-replace",
5935 bgp_afi_safi_get_container_str(afi, safi));
5936
5937 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5938
5939 return nb_cli_apply_changes(vty, base_xpath);
5000f21c
DS
5940}
5941
d62a17ae 5942ALIAS_HIDDEN(
5943 neighbor_remove_private_as_all_replace_as,
5944 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5945 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5946 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5947 "Remove private ASNs in outbound updates\n"
5948 "Apply to all AS numbers\n"
5949 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5950
f4b8ec07
CS
5951DEFUN_YANG (no_neighbor_remove_private_as,
5952 no_neighbor_remove_private_as_cmd,
5953 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5954 NO_STR
5955 NEIGHBOR_STR
5956 NEIGHBOR_ADDR_STR2
5957 "Remove private ASNs in outbound updates\n")
718e3744 5958{
d62a17ae 5959 int idx_peer = 2;
f4b8ec07
CS
5960 char base_xpath[XPATH_MAXLEN];
5961 char af_xpath[XPATH_MAXLEN];
5962 char attr_xpath[XPATH_MAXLEN];
5963 afi_t afi = bgp_node_afi(vty);
5964 safi_t safi = bgp_node_safi(vty);
5965
5966 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5967 yang_afi_safi_value2identity(afi, safi));
5968
5969 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5970 sizeof(base_xpath), af_xpath)
5971 < 0)
5972 return CMD_WARNING_CONFIG_FAILED;
5973
5974 snprintf(attr_xpath, sizeof(attr_xpath),
5975 "./%s/private-as/remove-private-as",
5976 bgp_afi_safi_get_container_str(afi, safi));
5977
5978 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5979
5980 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5981}
6b0655a2 5982
d62a17ae 5983ALIAS_HIDDEN(no_neighbor_remove_private_as,
5984 no_neighbor_remove_private_as_hidden_cmd,
5985 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5986 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5987 "Remove private ASNs in outbound updates\n")
596c17ba 5988
f4b8ec07
CS
5989DEFUN_YANG (no_neighbor_remove_private_as_all,
5990 no_neighbor_remove_private_as_all_cmd,
5991 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5992 NO_STR
5993 NEIGHBOR_STR
5994 NEIGHBOR_ADDR_STR2
5995 "Remove private ASNs in outbound updates\n"
5996 "Apply to all AS numbers\n")
88b8ed8d 5997{
d62a17ae 5998 int idx_peer = 2;
f4b8ec07
CS
5999 char base_xpath[XPATH_MAXLEN];
6000 char af_xpath[XPATH_MAXLEN];
6001 char attr_xpath[XPATH_MAXLEN];
6002 afi_t afi = bgp_node_afi(vty);
6003 safi_t safi = bgp_node_safi(vty);
6004
f4b8ec07
CS
6005 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6006 yang_afi_safi_value2identity(afi, safi));
6007
6008 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6009 sizeof(base_xpath), af_xpath)
6010 < 0)
6011 return CMD_WARNING_CONFIG_FAILED;
6012
6013 snprintf(attr_xpath, sizeof(attr_xpath),
6014 "./%s/private-as/remove-private-as-all",
6015 bgp_afi_safi_get_container_str(afi, safi));
6016
6017 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6018
6019 return nb_cli_apply_changes(vty, base_xpath);
88b8ed8d 6020}
5000f21c 6021
d62a17ae 6022ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
6023 no_neighbor_remove_private_as_all_hidden_cmd,
6024 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
6025 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6026 "Remove private ASNs in outbound updates\n"
6027 "Apply to all AS numbers\n")
596c17ba 6028
f4b8ec07
CS
6029DEFUN_YANG (no_neighbor_remove_private_as_replace_as,
6030 no_neighbor_remove_private_as_replace_as_cmd,
6031 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
6032 NO_STR
6033 NEIGHBOR_STR
6034 NEIGHBOR_ADDR_STR2
6035 "Remove private ASNs in outbound updates\n"
6036 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 6037{
d62a17ae 6038 int idx_peer = 2;
f4b8ec07
CS
6039 char base_xpath[XPATH_MAXLEN];
6040 char af_xpath[XPATH_MAXLEN];
6041 char attr_xpath[XPATH_MAXLEN];
6042 afi_t afi = bgp_node_afi(vty);
6043 safi_t safi = bgp_node_safi(vty);
6044
f4b8ec07
CS
6045 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6046 yang_afi_safi_value2identity(afi, safi));
6047
6048 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6049 sizeof(base_xpath), af_xpath)
6050 < 0)
6051 return CMD_WARNING_CONFIG_FAILED;
6052
6053 snprintf(attr_xpath, sizeof(attr_xpath),
6054 "./%s/private-as/remove-private-as-replace",
6055 bgp_afi_safi_get_container_str(afi, safi));
6056
6057 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6058
6059 return nb_cli_apply_changes(vty, base_xpath);
88b8ed8d 6060}
5000f21c 6061
d62a17ae 6062ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
6063 no_neighbor_remove_private_as_replace_as_hidden_cmd,
6064 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
6065 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6066 "Remove private ASNs in outbound updates\n"
6067 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 6068
f4b8ec07
CS
6069DEFUN_YANG (no_neighbor_remove_private_as_all_replace_as,
6070 no_neighbor_remove_private_as_all_replace_as_cmd,
6071 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6072 NO_STR
6073 NEIGHBOR_STR
6074 NEIGHBOR_ADDR_STR2
6075 "Remove private ASNs in outbound updates\n"
6076 "Apply to all AS numbers\n"
6077 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 6078{
d62a17ae 6079 int idx_peer = 2;
f4b8ec07
CS
6080 char base_xpath[XPATH_MAXLEN];
6081 char af_xpath[XPATH_MAXLEN];
6082 char attr_xpath[XPATH_MAXLEN];
6083 afi_t afi = bgp_node_afi(vty);
6084 safi_t safi = bgp_node_safi(vty);
6085
f4b8ec07
CS
6086 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6087 yang_afi_safi_value2identity(afi, safi));
6088
6089 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6090 sizeof(base_xpath), af_xpath)
6091 < 0)
6092 return CMD_WARNING_CONFIG_FAILED;
6093
6094 snprintf(attr_xpath, sizeof(attr_xpath),
6095 "./%s/private-as/remove-private-as-all-replace",
6096 bgp_afi_safi_get_container_str(afi, safi));
6097
6098 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6099
6100 return nb_cli_apply_changes(vty, base_xpath);
88b8ed8d 6101}
5000f21c 6102
d62a17ae 6103ALIAS_HIDDEN(
6104 no_neighbor_remove_private_as_all_replace_as,
6105 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
6106 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6107 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6108 "Remove private ASNs in outbound updates\n"
6109 "Apply to all AS numbers\n"
6110 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 6111
5000f21c 6112
718e3744 6113/* neighbor send-community. */
f4b8ec07
CS
6114DEFUN_YANG (neighbor_send_community,
6115 neighbor_send_community_cmd,
6116 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6117 NEIGHBOR_STR
6118 NEIGHBOR_ADDR_STR2
6119 "Send Community attribute to this neighbor\n")
718e3744 6120{
d62a17ae 6121 int idx_peer = 1;
27c05d4d 6122
d62a17ae 6123 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6124 bgp_node_safi(vty),
6125 PEER_FLAG_SEND_COMMUNITY);
718e3744 6126}
6127
d62a17ae 6128ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
6129 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6130 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6131 "Send Community attribute to this neighbor\n")
596c17ba 6132
f4b8ec07
CS
6133DEFUN_YANG (no_neighbor_send_community,
6134 no_neighbor_send_community_cmd,
6135 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6136 NO_STR
6137 NEIGHBOR_STR
6138 NEIGHBOR_ADDR_STR2
6139 "Send Community attribute to this neighbor\n")
718e3744 6140{
d62a17ae 6141 int idx_peer = 2;
27c05d4d 6142
d62a17ae 6143 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6144 bgp_node_afi(vty), bgp_node_safi(vty),
6145 PEER_FLAG_SEND_COMMUNITY);
718e3744 6146}
6b0655a2 6147
d62a17ae 6148ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
6149 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6150 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6151 "Send Community attribute to this neighbor\n")
596c17ba 6152
718e3744 6153/* neighbor send-community extended. */
f4b8ec07
CS
6154DEFUN_YANG (neighbor_send_community_type,
6155 neighbor_send_community_type_cmd,
6156 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6157 NEIGHBOR_STR
6158 NEIGHBOR_ADDR_STR2
6159 "Send Community attribute to this neighbor\n"
6160 "Send Standard and Extended Community attributes\n"
6161 "Send Standard, Large and Extended Community attributes\n"
6162 "Send Extended Community attributes\n"
6163 "Send Standard Community attributes\n"
6164 "Send Large Community attributes\n")
718e3744 6165{
27c05d4d 6166 const char *type = argv[argc - 1]->text;
db45f64d 6167 char *peer_str = argv[1]->arg;
f4b8ec07
CS
6168 char base_xpath[XPATH_MAXLEN];
6169 char af_xpath[XPATH_MAXLEN];
6170 char std_xpath[XPATH_MAXLEN];
6171 char ext_xpath[XPATH_MAXLEN];
6172 char lrg_xpath[XPATH_MAXLEN];
db45f64d
DS
6173 afi_t afi = bgp_node_afi(vty);
6174 safi_t safi = bgp_node_safi(vty);
d62a17ae 6175
f4b8ec07
CS
6176 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6177 yang_afi_safi_value2identity(afi, safi));
6178
6179 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6180 sizeof(base_xpath), af_xpath)
6181 < 0)
db45f64d 6182 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6183
f4b8ec07
CS
6184 if (strmatch(type, "standard")) {
6185 snprintf(std_xpath, sizeof(std_xpath),
6186 "./%s/send-community/send-community",
6187 bgp_afi_safi_get_container_str(afi, safi));
db45f64d 6188
f4b8ec07
CS
6189 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6190 }
db45f64d 6191
f4b8ec07
CS
6192 if (strmatch(type, "extended")) {
6193 snprintf(ext_xpath, sizeof(ext_xpath),
6194 "./%s/send-community/send-ext-community",
6195 bgp_afi_safi_get_container_str(afi, safi));
6196
6197 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
6198 }
6199
6200 if (strmatch(type, "large")) {
6201 snprintf(lrg_xpath, sizeof(lrg_xpath),
6202 "./%s/send-community/send-large-community",
6203 bgp_afi_safi_get_container_str(afi, safi));
6204
6205 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "true");
6206 }
db45f64d
DS
6207
6208 if (strmatch(type, "both")) {
f4b8ec07
CS
6209 snprintf(std_xpath, sizeof(std_xpath),
6210 "./%s/send-community/send-community",
6211 bgp_afi_safi_get_container_str(afi, safi));
6212
6213 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6214
6215 snprintf(ext_xpath, sizeof(ext_xpath),
6216 "./%s/send-community/send-ext-community",
6217 bgp_afi_safi_get_container_str(afi, safi));
6218
6219 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
db45f64d 6220 }
f4b8ec07
CS
6221
6222 if (strmatch(type, "all")) {
6223 snprintf(std_xpath, sizeof(std_xpath),
6224 "./%s/send-community/send-community",
6225 bgp_afi_safi_get_container_str(afi, safi));
6226
6227 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6228
6229 snprintf(ext_xpath, sizeof(ext_xpath),
6230 "./%s/send-community/send-ext-community",
6231 bgp_afi_safi_get_container_str(afi, safi));
6232
6233 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
6234
6235 snprintf(lrg_xpath, sizeof(lrg_xpath),
6236 "./%s/send-community/send-large-community",
6237 bgp_afi_safi_get_container_str(afi, safi));
6238
6239 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "true");
6240 }
6241
6242 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 6243}
6244
6245ALIAS_HIDDEN(
6246 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
6247 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6248 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6249 "Send Community attribute to this neighbor\n"
6250 "Send Standard and Extended Community attributes\n"
6251 "Send Standard, Large and Extended Community attributes\n"
6252 "Send Extended Community attributes\n"
6253 "Send Standard Community attributes\n"
6254 "Send Large Community attributes\n")
596c17ba 6255
f4b8ec07
CS
6256DEFUN_YANG (no_neighbor_send_community_type,
6257 no_neighbor_send_community_type_cmd,
6258 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6259 NO_STR
6260 NEIGHBOR_STR
6261 NEIGHBOR_ADDR_STR2
6262 "Send Community attribute to this neighbor\n"
6263 "Send Standard and Extended Community attributes\n"
6264 "Send Standard, Large and Extended Community attributes\n"
6265 "Send Extended Community attributes\n"
6266 "Send Standard Community attributes\n"
6267 "Send Large Community attributes\n")
718e3744 6268{
d62a17ae 6269 const char *type = argv[argc - 1]->text;
db45f64d 6270 char *peer_str = argv[2]->arg;
f4b8ec07
CS
6271 char base_xpath[XPATH_MAXLEN];
6272 char af_xpath[XPATH_MAXLEN];
6273 char std_xpath[XPATH_MAXLEN];
6274 char ext_xpath[XPATH_MAXLEN];
6275 char lrg_xpath[XPATH_MAXLEN];
db45f64d
DS
6276 afi_t afi = bgp_node_afi(vty);
6277 safi_t safi = bgp_node_safi(vty);
6278
f4b8ec07
CS
6279 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6280 yang_afi_safi_value2identity(afi, safi));
6281
6282 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6283 sizeof(base_xpath), af_xpath)
6284 < 0)
6285 return CMD_WARNING_CONFIG_FAILED;
6286
6287 if (strmatch(type, "standard")) {
6288 snprintf(std_xpath, sizeof(std_xpath),
6289 "./%s/send-community/send-community",
6290 bgp_afi_safi_get_container_str(afi, safi));
6291
6292 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6293 }
6294
6295 if (strmatch(type, "extended")) {
6296 snprintf(ext_xpath, sizeof(ext_xpath),
6297 "./%s/send-community/send-ext-community",
6298 bgp_afi_safi_get_container_str(afi, safi));
6299
6300 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
6301 }
6302
6303 if (strmatch(type, "large")) {
6304 snprintf(lrg_xpath, sizeof(lrg_xpath),
6305 "./%s/send-community/send-large-community",
6306 bgp_afi_safi_get_container_str(afi, safi));
6307
6308 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "false");
6309 }
6310
6311 if (strmatch(type, "both")) {
6312 snprintf(std_xpath, sizeof(std_xpath),
6313 "./%s/send-community/send-community",
6314 bgp_afi_safi_get_container_str(afi, safi));
6315
6316 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6317
6318 snprintf(ext_xpath, sizeof(ext_xpath),
6319 "./%s/send-community/send-ext-community",
6320 bgp_afi_safi_get_container_str(afi, safi));
6321
6322 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
6323 }
6324
6325 if (strmatch(type, "all")) {
6326 snprintf(std_xpath, sizeof(std_xpath),
6327 "./%s/send-community/send-community",
6328 bgp_afi_safi_get_container_str(afi, safi));
db45f64d 6329
f4b8ec07 6330 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
db45f64d 6331
f4b8ec07
CS
6332 snprintf(ext_xpath, sizeof(ext_xpath),
6333 "./%s/send-community/send-ext-community",
6334 bgp_afi_safi_get_container_str(afi, safi));
db45f64d 6335
f4b8ec07 6336 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
db45f64d 6337
f4b8ec07
CS
6338 snprintf(lrg_xpath, sizeof(lrg_xpath),
6339 "./%s/send-community/send-large-community",
6340 bgp_afi_safi_get_container_str(afi, safi));
d62a17ae 6341
f4b8ec07 6342 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "false");
27c05d4d
PM
6343 }
6344
f4b8ec07 6345 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 6346}
6347
6348ALIAS_HIDDEN(
6349 no_neighbor_send_community_type,
6350 no_neighbor_send_community_type_hidden_cmd,
6351 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6352 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6353 "Send Community attribute to this neighbor\n"
6354 "Send Standard and Extended Community attributes\n"
6355 "Send Standard, Large and Extended Community attributes\n"
6356 "Send Extended Community attributes\n"
6357 "Send Standard Community attributes\n"
6358 "Send Large Community attributes\n")
596c17ba 6359
718e3744 6360/* neighbor soft-reconfig. */
f4b8ec07
CS
6361DEFUN_YANG (neighbor_soft_reconfiguration,
6362 neighbor_soft_reconfiguration_cmd,
6363 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6364 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6365 "Per neighbor soft reconfiguration\n"
6366 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 6367{
d62a17ae 6368 int idx_peer = 1;
f4b8ec07
CS
6369 char base_xpath[XPATH_MAXLEN];
6370 char af_xpath[XPATH_MAXLEN];
6371 char soft_xpath[XPATH_MAXLEN];
6372 afi_t afi = bgp_node_afi(vty);
6373 safi_t safi = bgp_node_safi(vty);
6374
f4b8ec07
CS
6375 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6376 yang_afi_safi_value2identity(afi, safi));
6377
6378 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6379 sizeof(base_xpath), af_xpath)
6380 < 0)
6381 return CMD_WARNING_CONFIG_FAILED;
6382
6383 snprintf(soft_xpath, sizeof(soft_xpath), "./%s/soft-reconfiguration",
6384 bgp_afi_safi_get_container_str(afi, safi));
6385
6386 nb_cli_enqueue_change(vty, soft_xpath, NB_OP_MODIFY, "true");
6387
6388 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6389}
6390
d62a17ae 6391ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6392 neighbor_soft_reconfiguration_hidden_cmd,
6393 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6394 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6395 "Per neighbor soft reconfiguration\n"
6396 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 6397
f4b8ec07
CS
6398DEFUN_YANG (no_neighbor_soft_reconfiguration,
6399 no_neighbor_soft_reconfiguration_cmd,
6400 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6401 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6402 "Per neighbor soft reconfiguration\n"
6403 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 6404{
d62a17ae 6405 int idx_peer = 2;
f4b8ec07
CS
6406 char base_xpath[XPATH_MAXLEN];
6407 char af_xpath[XPATH_MAXLEN];
6408 char soft_xpath[XPATH_MAXLEN];
6409 afi_t afi = bgp_node_afi(vty);
6410 safi_t safi = bgp_node_safi(vty);
6411
6412 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6413 yang_afi_safi_value2identity(afi, safi));
6414
6415 snprintf(soft_xpath, sizeof(soft_xpath), "./%s/soft-reconfiguration",
6416 bgp_afi_safi_get_container_str(afi, safi));
6417
6418 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6419 sizeof(base_xpath), af_xpath)
6420 < 0)
6421 return CMD_WARNING_CONFIG_FAILED;
6422
6423 nb_cli_enqueue_change(vty, soft_xpath, NB_OP_MODIFY, "false");
6424
6425 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6426}
6b0655a2 6427
d62a17ae 6428ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6429 no_neighbor_soft_reconfiguration_hidden_cmd,
6430 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6431 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6432 "Per neighbor soft reconfiguration\n"
6433 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 6434
f4b8ec07
CS
6435DEFUN_YANG (neighbor_route_reflector_client,
6436 neighbor_route_reflector_client_cmd,
6437 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6438 NEIGHBOR_STR
6439 NEIGHBOR_ADDR_STR2
6440 "Configure a neighbor as Route Reflector client\n")
718e3744 6441{
d62a17ae 6442 int idx_peer = 1;
f4b8ec07
CS
6443 char base_xpath[XPATH_MAXLEN];
6444 char af_xpath[XPATH_MAXLEN];
6445 char attr_xpath[XPATH_MAXLEN];
6446 afi_t afi = bgp_node_afi(vty);
6447 safi_t safi = bgp_node_safi(vty);
718e3744 6448
f4b8ec07
CS
6449 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6450 yang_afi_safi_value2identity(afi, safi));
718e3744 6451
f4b8ec07
CS
6452 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6453 sizeof(base_xpath), af_xpath)
6454 < 0)
d62a17ae 6455 return CMD_WARNING_CONFIG_FAILED;
718e3744 6456
f4b8ec07
CS
6457 snprintf(attr_xpath, sizeof(attr_xpath),
6458 "./%s/route-reflector/route-reflector-client",
6459 bgp_afi_safi_get_container_str(afi, safi));
6460
6461 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
6462
6463 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6464}
6465
d62a17ae 6466ALIAS_HIDDEN(neighbor_route_reflector_client,
6467 neighbor_route_reflector_client_hidden_cmd,
6468 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6469 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6470 "Configure a neighbor as Route Reflector client\n")
596c17ba 6471
f4b8ec07
CS
6472DEFUN_YANG (no_neighbor_route_reflector_client,
6473 no_neighbor_route_reflector_client_cmd,
6474 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6475 NO_STR
6476 NEIGHBOR_STR
6477 NEIGHBOR_ADDR_STR2
6478 "Configure a neighbor as Route Reflector client\n")
718e3744 6479{
d62a17ae 6480 int idx_peer = 2;
f4b8ec07
CS
6481 char base_xpath[XPATH_MAXLEN];
6482 char af_xpath[XPATH_MAXLEN];
6483 char attr_xpath[XPATH_MAXLEN];
6484 afi_t afi = bgp_node_afi(vty);
6485 safi_t safi = bgp_node_safi(vty);
6486
6487 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6488 yang_afi_safi_value2identity(afi, safi));
6489
6490 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6491 sizeof(base_xpath), af_xpath)
6492 < 0)
6493 return CMD_WARNING_CONFIG_FAILED;
6494
6495 snprintf(attr_xpath, sizeof(attr_xpath),
6496 "./%s/route-reflector/route-reflector-client",
6497 bgp_afi_safi_get_container_str(afi, safi));
6498
6499 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6500
6501 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6502}
6b0655a2 6503
d62a17ae 6504ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6505 no_neighbor_route_reflector_client_hidden_cmd,
6506 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6507 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6508 "Configure a neighbor as Route Reflector client\n")
596c17ba 6509
718e3744 6510/* neighbor route-server-client. */
f4b8ec07
CS
6511DEFUN_YANG (neighbor_route_server_client,
6512 neighbor_route_server_client_cmd,
6513 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6514 NEIGHBOR_STR
6515 NEIGHBOR_ADDR_STR2
6516 "Configure a neighbor as Route Server client\n")
718e3744 6517{
d62a17ae 6518 int idx_peer = 1;
f4b8ec07
CS
6519 char base_xpath[XPATH_MAXLEN];
6520 char af_xpath[XPATH_MAXLEN];
6521 char attr_xpath[XPATH_MAXLEN];
6522 afi_t afi = bgp_node_afi(vty);
6523 safi_t safi = bgp_node_safi(vty);
2a3d5731 6524
f4b8ec07
CS
6525 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6526 yang_afi_safi_value2identity(afi, safi));
6527
6528 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6529 sizeof(base_xpath), af_xpath)
6530 < 0)
d62a17ae 6531 return CMD_WARNING_CONFIG_FAILED;
f4b8ec07
CS
6532
6533 snprintf(attr_xpath, sizeof(attr_xpath),
6534 "./%s/route-server/route-server-client",
6535 bgp_afi_safi_get_container_str(afi, safi));
6536
6537 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
6538
6539 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6540}
6541
d62a17ae 6542ALIAS_HIDDEN(neighbor_route_server_client,
6543 neighbor_route_server_client_hidden_cmd,
6544 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6545 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6546 "Configure a neighbor as Route Server client\n")
596c17ba 6547
f4b8ec07
CS
6548DEFUN_YANG (no_neighbor_route_server_client,
6549 no_neighbor_route_server_client_cmd,
6550 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6551 NO_STR
6552 NEIGHBOR_STR
6553 NEIGHBOR_ADDR_STR2
6554 "Configure a neighbor as Route Server client\n")
fee0f4c6 6555{
d62a17ae 6556 int idx_peer = 2;
f4b8ec07
CS
6557 char base_xpath[XPATH_MAXLEN];
6558 char af_xpath[XPATH_MAXLEN];
6559 char attr_xpath[XPATH_MAXLEN];
6560 afi_t afi = bgp_node_afi(vty);
6561 safi_t safi = bgp_node_safi(vty);
6562
6563 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6564 yang_afi_safi_value2identity(afi, safi));
6565
6566 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6567 sizeof(base_xpath), af_xpath)
6568 < 0)
6569 return CMD_WARNING_CONFIG_FAILED;
6570
6571 snprintf(attr_xpath, sizeof(attr_xpath),
6572 "./%s/route-server/route-server-client",
6573 bgp_afi_safi_get_container_str(afi, safi));
6574
6575 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6576
6577 return nb_cli_apply_changes(vty, base_xpath);
fee0f4c6 6578}
6b0655a2 6579
d62a17ae 6580ALIAS_HIDDEN(no_neighbor_route_server_client,
6581 no_neighbor_route_server_client_hidden_cmd,
6582 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6583 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6584 "Configure a neighbor as Route Server client\n")
596c17ba 6585
fee0f4c6 6586DEFUN (neighbor_nexthop_local_unchanged,
6587 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 6588 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 6589 NEIGHBOR_STR
6590 NEIGHBOR_ADDR_STR2
6591 "Configure treatment of outgoing link-local nexthop attribute\n"
6592 "Leave link-local nexthop unchanged for this peer\n")
6593{
d62a17ae 6594 int idx_peer = 1;
6595 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6596 bgp_node_safi(vty),
6597 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 6598}
6b0655a2 6599
fee0f4c6 6600DEFUN (no_neighbor_nexthop_local_unchanged,
6601 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 6602 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 6603 NO_STR
6604 NEIGHBOR_STR
6605 NEIGHBOR_ADDR_STR2
6606 "Configure treatment of outgoing link-local-nexthop attribute\n"
6607 "Leave link-local nexthop unchanged for this peer\n")
718e3744 6608{
d62a17ae 6609 int idx_peer = 2;
6610 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6611 bgp_node_afi(vty), bgp_node_safi(vty),
6612 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 6613}
6b0655a2 6614
f4b8ec07
CS
6615DEFUN_YANG (neighbor_attr_unchanged,
6616 neighbor_attr_unchanged_cmd,
6617 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6618 NEIGHBOR_STR
6619 NEIGHBOR_ADDR_STR2
6620 "BGP attribute is propagated unchanged to this neighbor\n"
6621 "As-path attribute\n"
6622 "Nexthop attribute\n"
6623 "Med attribute\n")
718e3744 6624{
d62a17ae 6625 int idx = 0;
8eeb0335 6626 char *peer_str = argv[1]->arg;
db45f64d
DS
6627 bool aspath = false;
6628 bool nexthop = false;
6629 bool med = false;
8eeb0335
DW
6630 afi_t afi = bgp_node_afi(vty);
6631 safi_t safi = bgp_node_safi(vty);
f4b8ec07
CS
6632 char base_xpath[XPATH_MAXLEN];
6633 char af_xpath[XPATH_MAXLEN];
6634 char as_xpath[XPATH_MAXLEN];
6635 char nxthop_xpath[XPATH_MAXLEN];
6636 char med_xpath[XPATH_MAXLEN];
8eeb0335 6637
f4b8ec07
CS
6638 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6639 yang_afi_safi_value2identity(afi, safi));
6640
6641 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6642 sizeof(base_xpath), af_xpath)
6643 < 0)
8eeb0335 6644 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6645
6646 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
6647 aspath = true;
6648
d62a17ae 6649 idx = 0;
6650 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6651 nexthop = true;
6652
d62a17ae 6653 idx = 0;
6654 if (argv_find(argv, argc, "med", &idx))
db45f64d 6655 med = true;
d62a17ae 6656
f4b8ec07
CS
6657 snprintf(as_xpath, sizeof(as_xpath),
6658 "./%s/attr-unchanged/as-path-unchanged",
6659 bgp_afi_safi_get_container_str(afi, safi));
6660 snprintf(nxthop_xpath, sizeof(nxthop_xpath),
6661 "./%s/attr-unchanged/next-hop-unchanged",
6662 bgp_afi_safi_get_container_str(afi, safi));
6663 snprintf(med_xpath, sizeof(med_xpath),
6664 "./%s/attr-unchanged/med-unchanged",
6665 bgp_afi_safi_get_container_str(afi, safi));
6666
8eeb0335 6667 /* no flags means all of them! */
db45f64d 6668 if (!aspath && !nexthop && !med) {
f4b8ec07
CS
6669 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "true");
6670 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "true");
6671 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "true");
8eeb0335 6672 } else {
f4b8ec07
CS
6673 if (!aspath)
6674 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY,
6675 "false");
6676 else
6677 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY,
6678 "true");
6679
6680 if (!nexthop)
6681 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY,
6682 "false");
6683 else
6684 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY,
6685 "true");
6686
6687 if (!med)
6688 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY,
6689 "false");
6690 else
6691 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY,
6692 "true");
d62a17ae 6693 }
6694
f4b8ec07 6695 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 6696}
6697
6698ALIAS_HIDDEN(
6699 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6700 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6701 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6702 "BGP attribute is propagated unchanged to this neighbor\n"
6703 "As-path attribute\n"
6704 "Nexthop attribute\n"
6705 "Med attribute\n")
596c17ba 6706
f4b8ec07
CS
6707DEFUN_YANG (no_neighbor_attr_unchanged,
6708 no_neighbor_attr_unchanged_cmd,
6709 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6710 NO_STR
6711 NEIGHBOR_STR
6712 NEIGHBOR_ADDR_STR2
6713 "BGP attribute is propagated unchanged to this neighbor\n"
6714 "As-path attribute\n"
6715 "Nexthop attribute\n"
6716 "Med attribute\n")
718e3744 6717{
d62a17ae 6718 int idx = 0;
db45f64d 6719 char *peer_str = argv[2]->arg;
db45f64d
DS
6720 bool aspath = false;
6721 bool nexthop = false;
6722 bool med = false;
6723 afi_t afi = bgp_node_afi(vty);
6724 safi_t safi = bgp_node_safi(vty);
f4b8ec07
CS
6725 char base_xpath[XPATH_MAXLEN];
6726 char af_xpath[XPATH_MAXLEN];
6727 char as_xpath[XPATH_MAXLEN];
6728 char nxthop_xpath[XPATH_MAXLEN];
6729 char med_xpath[XPATH_MAXLEN];
db45f64d 6730
f4b8ec07
CS
6731 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6732 yang_afi_safi_value2identity(afi, safi));
6733
6734 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6735 sizeof(base_xpath), af_xpath)
6736 < 0)
db45f64d 6737 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6738
6739 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
6740 aspath = true;
6741
d62a17ae 6742 idx = 0;
6743 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6744 nexthop = true;
6745
d62a17ae 6746 idx = 0;
6747 if (argv_find(argv, argc, "med", &idx))
db45f64d 6748 med = true;
d62a17ae 6749
f4b8ec07
CS
6750 snprintf(as_xpath, sizeof(as_xpath),
6751 "./%s/attr-unchanged/as-path-unchanged",
6752 bgp_afi_safi_get_container_str(afi, safi));
6753 snprintf(nxthop_xpath, sizeof(nxthop_xpath),
6754 "./%s/attr-unchanged/next-hop-unchanged",
6755 bgp_afi_safi_get_container_str(afi, safi));
6756 snprintf(med_xpath, sizeof(med_xpath),
6757 "./%s/attr-unchanged/med-unchanged",
6758 bgp_afi_safi_get_container_str(afi, safi));
6759
6760 /* no flags means all of them! */
6761 if (!aspath && !nexthop && !med) {
6762 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "false");
6763 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "false");
6764 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "false");
6765 }
db45f64d
DS
6766
6767 if (aspath)
f4b8ec07 6768 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "false");
db45f64d
DS
6769
6770 if (nexthop)
f4b8ec07 6771 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "false");
d62a17ae 6772
db45f64d 6773 if (med)
f4b8ec07 6774 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "false");
db45f64d 6775
f4b8ec07 6776 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 6777}
6778
6779ALIAS_HIDDEN(
6780 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6781 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6782 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6783 "BGP attribute is propagated unchanged to this neighbor\n"
6784 "As-path attribute\n"
6785 "Nexthop attribute\n"
6786 "Med attribute\n")
718e3744 6787
f4b8ec07
CS
6788/* neighbor ebgp-multihop. */
6789DEFUN_YANG (neighbor_ebgp_multihop,
6790 neighbor_ebgp_multihop_cmd,
6791 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6792 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6793 "Allow EBGP neighbors not on directly connected networks\n")
718e3744 6794{
f4b8ec07
CS
6795 int idx_peer = 1;
6796 char base_xpath[XPATH_MAXLEN];
718e3744 6797
f4b8ec07
CS
6798 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6799 sizeof(base_xpath), NULL)
6800 < 0)
d62a17ae 6801 return CMD_WARNING_CONFIG_FAILED;
718e3744 6802
f4b8ec07
CS
6803 nb_cli_enqueue_change(vty, "./ebgp-multihop/enabled", NB_OP_MODIFY,
6804 "true");
718e3744 6805
f4b8ec07 6806 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6807}
6808
f4b8ec07
CS
6809DEFUN_YANG (neighbor_ebgp_multihop_ttl,
6810 neighbor_ebgp_multihop_ttl_cmd,
6811 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6812 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6813 "Allow EBGP neighbors not on directly connected networks\n"
6814 "maximum hop count\n")
718e3744 6815{
f4b8ec07
CS
6816 int idx_peer = 1;
6817 int idx_number = 3;
6818 char base_xpath[XPATH_MAXLEN];
718e3744 6819
f4b8ec07
CS
6820 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6821 sizeof(base_xpath), NULL)
6822 < 0)
d62a17ae 6823 return CMD_WARNING_CONFIG_FAILED;
718e3744 6824
f4b8ec07
CS
6825 nb_cli_enqueue_change(vty, "./ebgp-multihop/multihop-ttl", NB_OP_MODIFY,
6826 argv[idx_number]->arg);
718e3744 6827
f4b8ec07 6828 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6829}
6830
f4b8ec07
CS
6831DEFUN_YANG (no_neighbor_ebgp_multihop,
6832 no_neighbor_ebgp_multihop_cmd,
6833 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6834 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6835 "Allow EBGP neighbors not on directly connected networks\n"
6836 "maximum hop count\n")
718e3744 6837{
d62a17ae 6838 int idx_peer = 2;
f4b8ec07
CS
6839 char base_xpath[XPATH_MAXLEN];
6840
6841 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6842 sizeof(base_xpath), NULL)
6843 < 0)
6844 return CMD_WARNING_CONFIG_FAILED;
6845
6846 if (argc > 4)
6847 nb_cli_enqueue_change(vty, "./ebgp-multihop/multihop-ttl",
6848 NB_OP_DESTROY, NULL);
6849 else
6850 nb_cli_enqueue_change(vty, "./ebgp-multihop/enabled",
6851 NB_OP_MODIFY, "false");
6852
6853 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6854}
6855
6b0655a2 6856
6ffd2079 6857/* disable-connected-check */
f4b8ec07
CS
6858DEFUN_YANG (neighbor_disable_connected_check,
6859 neighbor_disable_connected_check_cmd,
6860 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6861 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6862 "one-hop away EBGP peer using loopback address\n"
6863 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6864{
d62a17ae 6865 int idx_peer = 1;
f4b8ec07
CS
6866 char base_xpath[XPATH_MAXLEN];
6867
6868 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6869 sizeof(base_xpath), NULL)
6870 < 0)
6871 return CMD_WARNING_CONFIG_FAILED;
6872
6873 nb_cli_enqueue_change(vty, "./ebgp-multihop/disable-connected-check",
6874 NB_OP_MODIFY, "true");
6875
6876 return nb_cli_apply_changes(vty, base_xpath);
6ffd2079 6877}
6878
f4b8ec07
CS
6879DEFUN_YANG (no_neighbor_disable_connected_check,
6880 no_neighbor_disable_connected_check_cmd,
6881 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6882 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6883 "one-hop away EBGP peer using loopback address\n"
6884 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6885{
d62a17ae 6886 int idx_peer = 2;
f4b8ec07
CS
6887 char base_xpath[XPATH_MAXLEN];
6888
6889 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6890 sizeof(base_xpath), NULL)
6891 < 0)
6892 return CMD_WARNING_CONFIG_FAILED;
6893
6894 nb_cli_enqueue_change(vty, "./ebgp-multihop/disable-connected-check",
6895 NB_OP_MODIFY, "false");
6896
6897 return nb_cli_apply_changes(vty, base_xpath);
6ffd2079 6898}
6899
47cbc09b
PM
6900
6901/* enforce-first-as */
f4b8ec07
CS
6902DEFUN_YANG (neighbor_enforce_first_as,
6903 neighbor_enforce_first_as_cmd,
6904 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6905 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6906 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
6907{
6908 int idx_peer = 1;
f4b8ec07 6909 char base_xpath[XPATH_MAXLEN];
47cbc09b 6910
f4b8ec07
CS
6911 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6912 sizeof(base_xpath), NULL)
6913 < 0)
6914 return CMD_WARNING_CONFIG_FAILED;
6915
6916 nb_cli_enqueue_change(vty, "./enforce-first-as", NB_OP_MODIFY, "true");
6917
6918 return nb_cli_apply_changes(vty, base_xpath);
47cbc09b
PM
6919}
6920
f4b8ec07
CS
6921DEFUN_YANG (no_neighbor_enforce_first_as,
6922 no_neighbor_enforce_first_as_cmd,
6923 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6924 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6925 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
6926{
6927 int idx_peer = 2;
f4b8ec07 6928 char base_xpath[XPATH_MAXLEN];
47cbc09b 6929
f4b8ec07
CS
6930 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6931 sizeof(base_xpath), NULL)
6932 < 0)
6933 return CMD_WARNING_CONFIG_FAILED;
6934
6935 nb_cli_enqueue_change(vty, "./enforce-first-as", NB_OP_MODIFY, "false");
6936
6937 return nb_cli_apply_changes(vty, base_xpath);
47cbc09b
PM
6938}
6939
f4b8ec07
CS
6940static int peer_and_group_lookup_nb(struct vty *vty, const char *peer_str,
6941 char *base_xpath, int xpath_len,
6942 char *xpath)
6943{
6944 union sockunion su;
6945 char num_xpath[XPATH_MAXLEN];
6946 char unnbr_xpath[XPATH_MAXLEN];
6947 char prgrp_xpath[XPATH_MAXLEN];
6948
6949 if (str2sockunion(peer_str, &su) == 0) {
6950 snprintf(num_xpath, sizeof(num_xpath),
6951 "/neighbors/neighbor[remote-address='%s']", peer_str);
6952 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
6953 VTY_CURR_XPATH, num_xpath)) {
6954 snprintf(base_xpath, xpath_len,
6955 FRR_BGP_NEIGHBOR_NUM_XPATH, peer_str,
6956 xpath ? xpath : "");
6957 } else {
6958 vty_out(vty,
6959 "%% Specify remote-as or peer-group commands first\n");
6960 return -1;
6961 }
6962
6963 } else {
6964 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
6965 "/neighbors/unnumbered-neighbor[interface='%s']",
6966 peer_str);
6967
6968 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
6969 "/peer-groups/peer-group[peer-group-name='%s']",
6970 peer_str);
6971
6972 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
6973 VTY_CURR_XPATH, unnbr_xpath)) {
6974 snprintf(base_xpath, xpath_len,
6975 FRR_BGP_NEIGHBOR_UNNUM_XPATH, peer_str,
6976 xpath ? xpath : "");
6977 } else if (yang_dnode_exists(vty->candidate_config->dnode,
6978 "%s%s", VTY_CURR_XPATH,
6979 prgrp_xpath)) {
6980 snprintf(base_xpath, xpath_len,
6981 FRR_BGP_PEER_GROUP_XPATH, peer_str,
6982 xpath ? xpath : "");
6983 } else {
6984 vty_out(vty,
6985 "%% Create the peer-group or interface first\n");
6986 return -1;
6987 }
6988 }
6989
6990 return 0;
6991}
47cbc09b 6992
f4b8ec07
CS
6993DEFUN_YANG (neighbor_description,
6994 neighbor_description_cmd,
6995 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6996 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6997 "Neighbor specific description\n"
6998 "Up to 80 characters describing this neighbor\n")
718e3744 6999{
d62a17ae 7000 int idx_peer = 1;
7001 int idx_line = 3;
f4b8ec07
CS
7002 int ret;
7003 char base_xpath[XPATH_MAXLEN];
d62a17ae 7004 char *str;
718e3744 7005
f4b8ec07
CS
7006 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7007 sizeof(base_xpath), NULL)
7008 < 0)
d62a17ae 7009 return CMD_WARNING_CONFIG_FAILED;
718e3744 7010
d62a17ae 7011 str = argv_concat(argv, argc, idx_line);
718e3744 7012
f4b8ec07
CS
7013 nb_cli_enqueue_change(vty, "./description", NB_OP_MODIFY, str);
7014
7015 ret = nb_cli_apply_changes(vty, base_xpath);
718e3744 7016
d62a17ae 7017 XFREE(MTYPE_TMP, str);
718e3744 7018
f4b8ec07 7019 return ret;
718e3744 7020}
7021
f4b8ec07
CS
7022DEFUN_YANG (no_neighbor_description,
7023 no_neighbor_description_cmd,
7024 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
7025 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7026 "Neighbor specific description\n")
718e3744 7027{
d62a17ae 7028 int idx_peer = 2;
f4b8ec07
CS
7029 char base_xpath[XPATH_MAXLEN];
7030
7031 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7032 sizeof(base_xpath), NULL)
7033 < 0)
d62a17ae 7034 return CMD_WARNING_CONFIG_FAILED;
718e3744 7035
f4b8ec07 7036 nb_cli_enqueue_change(vty, "./description", NB_OP_DESTROY, NULL);
718e3744 7037
f4b8ec07 7038 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7039}
7040
232c75cd 7041ALIAS_YANG(no_neighbor_description, no_neighbor_description_comment_cmd,
a14810f4
PM
7042 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
7043 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7044 "Neighbor specific description\n"
7045 "Up to 80 characters describing this neighbor\n")
6b0655a2 7046
d62a17ae 7047#define BGP_UPDATE_SOURCE_HELP_STR \
7048 "IPv4 address\n" \
7049 "IPv6 address\n" \
7050 "Interface name (requires zebra to be running)\n"
369688c0 7051
f4b8ec07
CS
7052DEFUN_YANG (neighbor_update_source,
7053 neighbor_update_source_cmd,
7054 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
7055 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7056 "Source of routing updates\n"
7057 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 7058{
d62a17ae 7059 int idx_peer = 1;
7060 int idx_peer_2 = 3;
f4b8ec07
CS
7061 union sockunion su;
7062 char base_xpath[XPATH_MAXLEN];
7063
7064 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7065 sizeof(base_xpath), NULL)
7066 < 0)
7067 return CMD_WARNING_CONFIG_FAILED;
7068
f4b8ec07
CS
7069 if (str2sockunion(argv[idx_peer_2]->arg, &su) == 0)
7070 nb_cli_enqueue_change(vty, "./update-source/ip", NB_OP_MODIFY,
d62a17ae 7071 argv[idx_peer_2]->arg);
f4b8ec07
CS
7072 else
7073 nb_cli_enqueue_change(vty, "./update-source/interface",
7074 NB_OP_MODIFY, argv[idx_peer_2]->arg);
7075
7076 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7077}
7078
f4b8ec07
CS
7079DEFUN_YANG (no_neighbor_update_source,
7080 no_neighbor_update_source_cmd,
7081 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
7082 NO_STR NEIGHBOR_STR
7083 NEIGHBOR_ADDR_STR2
7084 "Source of routing updates\n"
7085 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 7086{
d62a17ae 7087 int idx_peer = 2;
f4b8ec07 7088 char base_xpath[XPATH_MAXLEN];
f4b8ec07
CS
7089
7090 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7091 sizeof(base_xpath), NULL)
7092 < 0)
7093 return CMD_WARNING_CONFIG_FAILED;
7094
555c8ab7
CS
7095 nb_cli_enqueue_change(vty, "./update-source/ip", NB_OP_DESTROY, NULL);
7096 nb_cli_enqueue_change(vty, "./update-source/interface", NB_OP_DESTROY,
7097 NULL);
f4b8ec07
CS
7098
7099 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7100}
6b0655a2 7101
d62a17ae 7102static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
7103 afi_t afi, safi_t safi,
7104 const char *rmap, int set)
718e3744 7105{
d62a17ae 7106 int ret;
7107 struct peer *peer;
80912664 7108 struct route_map *route_map = NULL;
718e3744 7109
d62a17ae 7110 peer = peer_and_group_lookup_vty(vty, peer_str);
7111 if (!peer)
7112 return CMD_WARNING_CONFIG_FAILED;
718e3744 7113
1de27621 7114 if (set) {
80912664
DS
7115 if (rmap)
7116 route_map = route_map_lookup_warn_noexist(vty, rmap);
1de27621
DA
7117 ret = peer_default_originate_set(peer, afi, safi,
7118 rmap, route_map);
7119 } else
d62a17ae 7120 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 7121
d62a17ae 7122 return bgp_vty_return(vty, ret);
718e3744 7123}
7124
7125/* neighbor default-originate. */
7126DEFUN (neighbor_default_originate,
7127 neighbor_default_originate_cmd,
9ccf14f7 7128 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 7129 NEIGHBOR_STR
7130 NEIGHBOR_ADDR_STR2
7131 "Originate default route to this neighbor\n")
7132{
d62a17ae 7133 int idx_peer = 1;
7134 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7135 bgp_node_afi(vty),
7136 bgp_node_safi(vty), NULL, 1);
718e3744 7137}
7138
d62a17ae 7139ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
7140 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
7141 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7142 "Originate default route to this neighbor\n")
596c17ba 7143
718e3744 7144DEFUN (neighbor_default_originate_rmap,
7145 neighbor_default_originate_rmap_cmd,
9ccf14f7 7146 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 7147 NEIGHBOR_STR
7148 NEIGHBOR_ADDR_STR2
7149 "Originate default route to this neighbor\n"
7150 "Route-map to specify criteria to originate default\n"
7151 "route-map name\n")
7152{
d62a17ae 7153 int idx_peer = 1;
7154 int idx_word = 4;
7155 return peer_default_originate_set_vty(
7156 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7157 argv[idx_word]->arg, 1);
718e3744 7158}
7159
d62a17ae 7160ALIAS_HIDDEN(
7161 neighbor_default_originate_rmap,
7162 neighbor_default_originate_rmap_hidden_cmd,
7163 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
7164 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7165 "Originate default route to this neighbor\n"
7166 "Route-map to specify criteria to originate default\n"
7167 "route-map name\n")
596c17ba 7168
718e3744 7169DEFUN (no_neighbor_default_originate,
7170 no_neighbor_default_originate_cmd,
a636c635 7171 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 7172 NO_STR
7173 NEIGHBOR_STR
7174 NEIGHBOR_ADDR_STR2
a636c635
DW
7175 "Originate default route to this neighbor\n"
7176 "Route-map to specify criteria to originate default\n"
7177 "route-map name\n")
718e3744 7178{
d62a17ae 7179 int idx_peer = 2;
7180 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7181 bgp_node_afi(vty),
7182 bgp_node_safi(vty), NULL, 0);
718e3744 7183}
7184
d62a17ae 7185ALIAS_HIDDEN(
7186 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
7187 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
7188 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7189 "Originate default route to this neighbor\n"
7190 "Route-map to specify criteria to originate default\n"
7191 "route-map name\n")
596c17ba 7192
6b0655a2 7193
f418446b 7194/* Set specified peer's BGP port. */
f4b8ec07
CS
7195DEFUN_YANG (neighbor_port,
7196 neighbor_port_cmd,
7197 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
7198 NEIGHBOR_STR
7199 NEIGHBOR_ADDR_STR
7200 "Neighbor's BGP port\n"
7201 "TCP port number\n")
718e3744 7202{
d62a17ae 7203 int idx_ip = 1;
7204 int idx_number = 3;
f4b8ec07 7205 char base_xpath[XPATH_MAXLEN];
718e3744 7206
f4b8ec07
CS
7207 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7208 argv[idx_ip]->arg, "");
718e3744 7209
f4b8ec07
CS
7210 nb_cli_enqueue_change(vty, "./local-port", NB_OP_MODIFY,
7211 argv[idx_number]->arg);
7212
7213 return nb_cli_apply_changes(vty, base_xpath);
7214}
6b0655a2 7215
f4b8ec07
CS
7216DEFUN_YANG (no_neighbor_port,
7217 no_neighbor_port_cmd,
7218 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
7219 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR
7220 "Neighbor's BGP port\n"
7221 "TCP port number\n")
718e3744 7222{
f4b8ec07
CS
7223 int idx_ip = 2;
7224 char base_xpath[XPATH_MAXLEN];
718e3744 7225
f4b8ec07
CS
7226 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7227 argv[idx_ip]->arg, "");
718e3744 7228
f4b8ec07 7229 nb_cli_enqueue_change(vty, "./local-port", NB_OP_DESTROY, NULL);
718e3744 7230
f4b8ec07 7231 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7232}
7233
f4b8ec07
CS
7234DEFUN_YANG (neighbor_weight,
7235 neighbor_weight_cmd,
7236 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7237 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7238 "Set default weight for routes from this neighbor\n"
7239 "default weight\n")
718e3744 7240{
f4b8ec07
CS
7241 int idx_peer = 1;
7242 int idx_number = 3;
7243 char base_xpath[XPATH_MAXLEN];
7244 char af_xpath[XPATH_MAXLEN];
7245 char attr_xpath[XPATH_MAXLEN];
7246 afi_t afi = bgp_node_afi(vty);
7247 safi_t safi = bgp_node_safi(vty);
718e3744 7248
f4b8ec07
CS
7249 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7250 yang_afi_safi_value2identity(afi, safi));
7251
7252 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7253 sizeof(base_xpath), af_xpath)
7254 < 0)
d62a17ae 7255 return CMD_WARNING_CONFIG_FAILED;
718e3744 7256
f4b8ec07
CS
7257 snprintf(attr_xpath, sizeof(attr_xpath), "./%s/weight/weight-attribute",
7258 bgp_afi_safi_get_container_str(afi, safi));
718e3744 7259
f4b8ec07
CS
7260 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY,
7261 argv[idx_number]->arg);
7262
7263 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7264}
7265
d62a17ae 7266ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
7267 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7268 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7269 "Set default weight for routes from this neighbor\n"
7270 "default weight\n")
596c17ba 7271
f4b8ec07
CS
7272DEFUN_YANG (no_neighbor_weight,
7273 no_neighbor_weight_cmd,
7274 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7275 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7276 "Set default weight for routes from this neighbor\n"
7277 "default weight\n")
718e3744 7278{
d62a17ae 7279 int idx_peer = 2;
f4b8ec07
CS
7280 char base_xpath[XPATH_MAXLEN];
7281 char af_xpath[XPATH_MAXLEN];
7282 char attr_xpath[XPATH_MAXLEN];
7283 afi_t afi = bgp_node_afi(vty);
7284 safi_t safi = bgp_node_safi(vty);
7285
7286 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7287 yang_afi_safi_value2identity(afi, safi));
7288
7289 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7290 sizeof(base_xpath), af_xpath)
7291 < 0)
7292 return CMD_WARNING_CONFIG_FAILED;
7293
7294 snprintf(attr_xpath, sizeof(attr_xpath), "./%s/weight/weight-attribute",
7295 bgp_afi_safi_get_container_str(afi, safi));
7296
7297 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_DESTROY, NULL);
7298
7299 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7300}
7301
d62a17ae 7302ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
7303 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7304 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7305 "Set default weight for routes from this neighbor\n"
7306 "default weight\n")
596c17ba 7307
6b0655a2 7308
718e3744 7309/* Override capability negotiation. */
8611c7f3
CS
7310DEFUN_YANG (neighbor_override_capability,
7311 neighbor_override_capability_cmd,
7312 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7313 NEIGHBOR_STR
7314 NEIGHBOR_ADDR_STR2
7315 "Override capability negotiation result\n")
718e3744 7316{
d62a17ae 7317 int idx_peer = 1;
8611c7f3
CS
7318 char base_xpath[XPATH_MAXLEN];
7319
7320 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7321 sizeof(base_xpath), NULL)
7322 < 0)
7323 return CMD_WARNING_CONFIG_FAILED;
7324
7325 nb_cli_enqueue_change(
7326 vty, "./capability-options/override-capability",
7327 NB_OP_MODIFY, "true");
7328
7329 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7330}
7331
8611c7f3
CS
7332DEFUN_YANG (no_neighbor_override_capability,
7333 no_neighbor_override_capability_cmd,
7334 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7335 NO_STR
7336 NEIGHBOR_STR
7337 NEIGHBOR_ADDR_STR2
7338 "Override capability negotiation result\n")
718e3744 7339{
d62a17ae 7340 int idx_peer = 2;
8611c7f3
CS
7341 char base_xpath[XPATH_MAXLEN];
7342
7343 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7344 sizeof(base_xpath), NULL)
7345 < 0)
7346 return CMD_WARNING_CONFIG_FAILED;
7347
7348 nb_cli_enqueue_change(
7349 vty, "./capability-options/override-capability",
7350 NB_OP_MODIFY, "false");
7351
7352 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7353}
6b0655a2 7354
8611c7f3
CS
7355DEFUN_YANG (neighbor_strict_capability,
7356 neighbor_strict_capability_cmd,
7357 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7358 NEIGHBOR_STR
7359 NEIGHBOR_ADDR_STR2
7360 "Strict capability negotiation match\n")
718e3744 7361{
9fb964de 7362 int idx_peer = 1;
8611c7f3 7363 char base_xpath[XPATH_MAXLEN];
9fb964de 7364
8611c7f3
CS
7365 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7366 sizeof(base_xpath), NULL)
7367 < 0)
7368 return CMD_WARNING_CONFIG_FAILED;
7369
7370 nb_cli_enqueue_change(
7371 vty, "./capability-options/strict-capability",
7372 NB_OP_MODIFY, "true");
7373
7374 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7375}
7376
8611c7f3
CS
7377DEFUN_YANG (no_neighbor_strict_capability,
7378 no_neighbor_strict_capability_cmd,
7379 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7380 NO_STR
7381 NEIGHBOR_STR
7382 NEIGHBOR_ADDR_STR2
7383 "Strict capability negotiation match\n")
718e3744 7384{
9fb964de 7385 int idx_peer = 2;
8611c7f3 7386 char base_xpath[XPATH_MAXLEN];
9fb964de 7387
8611c7f3
CS
7388 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7389 sizeof(base_xpath), NULL)
7390 < 0)
7391 return CMD_WARNING_CONFIG_FAILED;
7392
7393 nb_cli_enqueue_change(
7394 vty, "./capability-options/strict-capability",
7395 NB_OP_MODIFY, "false");
7396
7397 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7398}
6b0655a2 7399
f4b8ec07
CS
7400DEFUN_YANG (neighbor_timers,
7401 neighbor_timers_cmd,
7402 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
7403 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7404 "BGP per neighbor timers\n"
7405 "Keepalive interval\n"
7406 "Holdtime\n")
718e3744 7407{
f4b8ec07
CS
7408 int idx_peer = 1;
7409 int idx_number = 3;
7410 int idx_number_2 = 4;
7411 char base_xpath[XPATH_MAXLEN];
718e3744 7412
f4b8ec07
CS
7413 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7414 sizeof(base_xpath), NULL)
7415 < 0)
d62a17ae 7416 return CMD_WARNING_CONFIG_FAILED;
718e3744 7417
f4b8ec07
CS
7418 nb_cli_enqueue_change(vty, "./timers/keepalive", NB_OP_MODIFY,
7419 argv[idx_number]->arg);
718e3744 7420
f4b8ec07
CS
7421 nb_cli_enqueue_change(vty, "./timers/hold-time", NB_OP_MODIFY,
7422 argv[idx_number_2]->arg);
718e3744 7423
f4b8ec07 7424 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7425}
6b0655a2 7426
f4b8ec07
CS
7427DEFUN_YANG (no_neighbor_timers,
7428 no_neighbor_timers_cmd,
7429 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
7430 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7431 "BGP per neighbor timers\n"
7432 "Keepalive interval\n"
7433 "Holdtime\n")
718e3744 7434{
f4b8ec07
CS
7435 int idx_peer = 2;
7436 char base_xpath[XPATH_MAXLEN];
718e3744 7437
f4b8ec07
CS
7438 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7439 sizeof(base_xpath), NULL)
7440 < 0)
d62a17ae 7441 return CMD_WARNING_CONFIG_FAILED;
718e3744 7442
f4b8ec07 7443 nb_cli_enqueue_change(vty, "./timers/hold-time", NB_OP_DESTROY, NULL);
718e3744 7444
f4b8ec07 7445 nb_cli_enqueue_change(vty, "./timers/keepalive", NB_OP_DESTROY, NULL);
718e3744 7446
f4b8ec07 7447 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7448}
6b0655a2 7449
f4b8ec07
CS
7450DEFUN_YANG (neighbor_timers_connect,
7451 neighbor_timers_connect_cmd,
7452 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7453 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7454 "BGP per neighbor timers\n"
7455 "BGP connect timer\n"
7456 "Connect timer\n")
718e3744 7457{
f4b8ec07
CS
7458 int idx_peer = 1;
7459 int idx_number = 4;
7460 char base_xpath[XPATH_MAXLEN];
718e3744 7461
f4b8ec07
CS
7462 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7463 sizeof(base_xpath), NULL)
7464 < 0)
d62a17ae 7465 return CMD_WARNING_CONFIG_FAILED;
718e3744 7466
f4b8ec07
CS
7467 nb_cli_enqueue_change(vty, "./timers/connect-time", NB_OP_MODIFY,
7468 argv[idx_number]->arg);
718e3744 7469
f4b8ec07 7470 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7471}
7472
f4b8ec07
CS
7473DEFUN_YANG (no_neighbor_timers_connect,
7474 no_neighbor_timers_connect_cmd,
7475 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7476 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7477 "BGP per neighbor timers\n"
7478 "BGP connect timer\n"
7479 "Connect timer\n")
718e3744 7480{
f4b8ec07
CS
7481 int idx_peer = 2;
7482 char base_xpath[XPATH_MAXLEN];
718e3744 7483
f4b8ec07
CS
7484 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7485 sizeof(base_xpath), NULL)
7486 < 0)
d62a17ae 7487 return CMD_WARNING_CONFIG_FAILED;
718e3744 7488
f4b8ec07
CS
7489 nb_cli_enqueue_change(vty, "./timers/connect-time", NB_OP_DESTROY,
7490 NULL);
718e3744 7491
f4b8ec07 7492 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7493}
7494
d43114f3
DS
7495DEFPY (neighbor_timers_delayopen,
7496 neighbor_timers_delayopen_cmd,
7497 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
7498 NEIGHBOR_STR
7499 NEIGHBOR_ADDR_STR2
7500 "BGP per neighbor timers\n"
7501 "RFC 4271 DelayOpenTimer\n"
7502 "DelayOpenTime timer interval\n")
7503{
7504 struct peer *peer;
7505
7506 peer = peer_and_group_lookup_vty(vty, neighbor);
7507 if (!peer)
7508 return CMD_WARNING_CONFIG_FAILED;
7509
7510 if (!interval) {
7511 if (peer_timers_delayopen_unset(peer))
7512 return CMD_WARNING_CONFIG_FAILED;
7513 } else {
7514 if (peer_timers_delayopen_set(peer, interval))
7515 return CMD_WARNING_CONFIG_FAILED;
7516 }
7517
7518 return CMD_SUCCESS;
7519}
7520
7521DEFPY (no_neighbor_timers_delayopen,
7522 no_neighbor_timers_delayopen_cmd,
7523 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7524 NO_STR
7525 NEIGHBOR_STR
7526 NEIGHBOR_ADDR_STR2
7527 "BGP per neighbor timers\n"
7528 "RFC 4271 DelayOpenTimer\n"
7529 "DelayOpenTime timer interval\n")
7530{
7531 struct peer *peer;
7532
7533 peer = peer_and_group_lookup_vty(vty, neighbor);
7534 if (!peer)
7535 return CMD_WARNING_CONFIG_FAILED;
7536
7537 if (peer_timers_delayopen_unset(peer))
7538 return CMD_WARNING_CONFIG_FAILED;
7539
7540 return CMD_SUCCESS;
7541}
7542
f4b8ec07
CS
7543DEFUN_YANG (neighbor_advertise_interval,
7544 neighbor_advertise_interval_cmd,
7545 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7546 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7547 "Minimum interval between sending BGP routing updates\n"
7548 "time in seconds\n")
718e3744 7549{
d62a17ae 7550 int idx_peer = 1;
f4b8ec07
CS
7551 int idx_number = 3;
7552 char base_xpath[XPATH_MAXLEN];
718e3744 7553
f4b8ec07
CS
7554 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7555 sizeof(base_xpath), NULL)
7556 < 0)
d62a17ae 7557 return CMD_WARNING_CONFIG_FAILED;
718e3744 7558
f4b8ec07
CS
7559 nb_cli_enqueue_change(vty, "./timers/advertise-interval", NB_OP_MODIFY,
7560 argv[idx_number]->arg);
718e3744 7561
f4b8ec07 7562 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7563}
7564
f4b8ec07
CS
7565DEFUN_YANG (no_neighbor_advertise_interval,
7566 no_neighbor_advertise_interval_cmd,
7567 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7568 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7569 "Minimum interval between sending BGP routing updates\n"
7570 "time in seconds\n")
718e3744 7571{
d62a17ae 7572 int idx_peer = 2;
f4b8ec07
CS
7573 char base_xpath[XPATH_MAXLEN];
7574
7575 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7576 sizeof(base_xpath), NULL)
7577 < 0)
7578 return CMD_WARNING_CONFIG_FAILED;
7579
7580 nb_cli_enqueue_change(vty, "./timers/advertise-interval", NB_OP_DESTROY,
7581 NULL);
7582
7583 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7584}
7585
6b0655a2 7586
518f0eb1
DS
7587/* Time to wait before processing route-map updates */
7588DEFUN (bgp_set_route_map_delay_timer,
7589 bgp_set_route_map_delay_timer_cmd,
6147e2c6 7590 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
7591 SET_STR
7592 "BGP route-map delay timer\n"
7593 "Time in secs to wait before processing route-map changes\n"
f414725f 7594 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 7595{
d62a17ae 7596 int idx_number = 3;
d7c0a89a 7597 uint32_t rmap_delay_timer;
d62a17ae 7598
7599 if (argv[idx_number]->arg) {
7600 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7601 bm->rmap_update_timer = rmap_delay_timer;
7602
7603 /* if the dynamic update handling is being disabled, and a timer
7604 * is
7605 * running, stop the timer and act as if the timer has already
7606 * fired.
7607 */
7608 if (!rmap_delay_timer && bm->t_rmap_update) {
7609 BGP_TIMER_OFF(bm->t_rmap_update);
7610 thread_execute(bm->master, bgp_route_map_update_timer,
7611 NULL, 0);
7612 }
7613 return CMD_SUCCESS;
7614 } else {
7615 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7616 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 7617 }
518f0eb1
DS
7618}
7619
7620DEFUN (no_bgp_set_route_map_delay_timer,
7621 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 7622 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 7623 NO_STR
3a2d747c 7624 BGP_STR
518f0eb1 7625 "Default BGP route-map delay timer\n"
8334fd5a
DW
7626 "Reset to default time to wait for processing route-map changes\n"
7627 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 7628{
518f0eb1 7629
d62a17ae 7630 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 7631
d62a17ae 7632 return CMD_SUCCESS;
518f0eb1
DS
7633}
7634
f4b8ec07
CS
7635DEFUN_YANG (neighbor_interface,
7636 neighbor_interface_cmd,
7637 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7638 NEIGHBOR_STR NEIGHBOR_ADDR_STR
7639 "Interface\n"
7640 "Interface name\n")
718e3744 7641{
f4b8ec07
CS
7642 int idx_ip = 1;
7643 int idx_word = 3;
7644 char base_xpath[XPATH_MAXLEN];
718e3744 7645
f4b8ec07
CS
7646 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7647 argv[idx_ip]->arg, "");
718e3744 7648
f4b8ec07
CS
7649 nb_cli_enqueue_change(vty, "./local-interface", NB_OP_MODIFY,
7650 argv[idx_word]->arg);
718e3744 7651
f4b8ec07 7652 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7653}
7654
f4b8ec07
CS
7655DEFUN_YANG (no_neighbor_interface,
7656 no_neighbor_interface_cmd,
7657 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
7658 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7659 "Interface\n"
7660 "Interface name\n")
718e3744 7661{
d62a17ae 7662 int idx_peer = 2;
f4b8ec07
CS
7663 char base_xpath[XPATH_MAXLEN];
7664
7665 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7666 argv[idx_peer]->arg, "");
7667
7668 nb_cli_enqueue_change(vty, "./local-interface", NB_OP_DESTROY, NULL);
7669
7670 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7671}
6b0655a2 7672
718e3744 7673DEFUN (neighbor_distribute_list,
7674 neighbor_distribute_list_cmd,
9ccf14f7 7675 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 7676 NEIGHBOR_STR
7677 NEIGHBOR_ADDR_STR2
7678 "Filter updates to/from this neighbor\n"
7679 "IP access-list number\n"
7680 "IP access-list number (expanded range)\n"
7681 "IP Access-list name\n"
7682 "Filter incoming updates\n"
7683 "Filter outgoing updates\n")
7684{
d62a17ae 7685 int idx_peer = 1;
7686 int idx_acl = 3;
7687 int direct, ret;
7688 struct peer *peer;
a8206004 7689
d62a17ae 7690 const char *pstr = argv[idx_peer]->arg;
7691 const char *acl = argv[idx_acl]->arg;
7692 const char *inout = argv[argc - 1]->text;
a8206004 7693
d62a17ae 7694 peer = peer_and_group_lookup_vty(vty, pstr);
7695 if (!peer)
7696 return CMD_WARNING_CONFIG_FAILED;
a8206004 7697
d62a17ae 7698 /* Check filter direction. */
7699 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7700 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7701 direct, acl);
a8206004 7702
d62a17ae 7703 return bgp_vty_return(vty, ret);
718e3744 7704}
7705
d62a17ae 7706ALIAS_HIDDEN(
7707 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
7708 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7709 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7710 "Filter updates to/from this neighbor\n"
7711 "IP access-list number\n"
7712 "IP access-list number (expanded range)\n"
7713 "IP Access-list name\n"
7714 "Filter incoming updates\n"
7715 "Filter outgoing updates\n")
596c17ba 7716
718e3744 7717DEFUN (no_neighbor_distribute_list,
7718 no_neighbor_distribute_list_cmd,
9ccf14f7 7719 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 7720 NO_STR
7721 NEIGHBOR_STR
7722 NEIGHBOR_ADDR_STR2
7723 "Filter updates to/from this neighbor\n"
7724 "IP access-list number\n"
7725 "IP access-list number (expanded range)\n"
7726 "IP Access-list name\n"
7727 "Filter incoming updates\n"
7728 "Filter outgoing updates\n")
7729{
d62a17ae 7730 int idx_peer = 2;
7731 int direct, ret;
7732 struct peer *peer;
a8206004 7733
d62a17ae 7734 const char *pstr = argv[idx_peer]->arg;
7735 const char *inout = argv[argc - 1]->text;
a8206004 7736
d62a17ae 7737 peer = peer_and_group_lookup_vty(vty, pstr);
7738 if (!peer)
7739 return CMD_WARNING_CONFIG_FAILED;
a8206004 7740
d62a17ae 7741 /* Check filter direction. */
7742 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7743 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7744 direct);
a8206004 7745
d62a17ae 7746 return bgp_vty_return(vty, ret);
718e3744 7747}
6b0655a2 7748
d62a17ae 7749ALIAS_HIDDEN(
7750 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
7751 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7752 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7753 "Filter updates to/from this neighbor\n"
7754 "IP access-list number\n"
7755 "IP access-list number (expanded range)\n"
7756 "IP Access-list name\n"
7757 "Filter incoming updates\n"
7758 "Filter outgoing updates\n")
596c17ba 7759
718e3744 7760/* Set prefix list to the peer. */
d9986d26
CS
7761DEFPY_YANG(
7762 neighbor_prefix_list, neighbor_prefix_list_cmd,
7763 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor_str prefix-list WORD$prefix_str <in|out>$direction",
7764 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7765 "Filter updates to/from this neighbor\n"
7766 "Name of a prefix list\n"
7767 "Filter incoming updates\n"
7768 "Filter outgoing updates\n")
718e3744 7769{
d9986d26
CS
7770 char base_xpath[XPATH_MAXLEN];
7771 char af_xpath[XPATH_MAXLEN];
c6685575 7772 char plist_xpath[XPATH_MAXLEN];
d9986d26
CS
7773 afi_t afi = bgp_node_afi(vty);
7774 safi_t safi = bgp_node_safi(vty);
718e3744 7775
d9986d26
CS
7776 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7777 yang_afi_safi_value2identity(afi, safi));
7778 if (peer_and_group_lookup_nb(vty, neighbor_str, base_xpath,
7779 sizeof(base_xpath), af_xpath)
7780 < 0)
d62a17ae 7781 return CMD_WARNING_CONFIG_FAILED;
e52702f2 7782
d9986d26
CS
7783 if (strmatch(direction, "in"))
7784 snprintf(plist_xpath, sizeof(plist_xpath),
7785 "./%s/filter-config/plist-import",
7786 bgp_afi_safi_get_container_str(afi, safi));
7787 else if (strmatch(direction, "out"))
7788 snprintf(plist_xpath, sizeof(plist_xpath),
7789 "./%s/filter-config/plist-export",
7790 bgp_afi_safi_get_container_str(afi, safi));
718e3744 7791
d9986d26
CS
7792 if (!no)
7793 nb_cli_enqueue_change(vty, plist_xpath, NB_OP_MODIFY,
7794 prefix_str);
7795 else
7796 nb_cli_enqueue_change(vty, plist_xpath, NB_OP_DESTROY, NULL);
718e3744 7797
d9986d26 7798 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7799}
7800
d62a17ae 7801ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7802 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7803 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7804 "Filter updates to/from this neighbor\n"
7805 "Name of a prefix list\n"
7806 "Filter incoming updates\n"
7807 "Filter outgoing updates\n")
596c17ba 7808
d62a17ae 7809static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7810 safi_t safi, const char *name_str,
7811 const char *direct_str)
718e3744 7812{
d62a17ae 7813 int ret;
7814 struct peer *peer;
7815 int direct = FILTER_IN;
718e3744 7816
d62a17ae 7817 peer = peer_and_group_lookup_vty(vty, ip_str);
7818 if (!peer)
7819 return CMD_WARNING_CONFIG_FAILED;
718e3744 7820
d62a17ae 7821 /* Check filter direction. */
7822 if (strncmp(direct_str, "i", 1) == 0)
7823 direct = FILTER_IN;
7824 else if (strncmp(direct_str, "o", 1) == 0)
7825 direct = FILTER_OUT;
718e3744 7826
d62a17ae 7827 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 7828
d62a17ae 7829 return bgp_vty_return(vty, ret);
718e3744 7830}
7831
d62a17ae 7832static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7833 safi_t safi, const char *direct_str)
718e3744 7834{
d62a17ae 7835 int ret;
7836 struct peer *peer;
7837 int direct = FILTER_IN;
718e3744 7838
d62a17ae 7839 peer = peer_and_group_lookup_vty(vty, ip_str);
7840 if (!peer)
7841 return CMD_WARNING_CONFIG_FAILED;
718e3744 7842
d62a17ae 7843 /* Check filter direction. */
7844 if (strncmp(direct_str, "i", 1) == 0)
7845 direct = FILTER_IN;
7846 else if (strncmp(direct_str, "o", 1) == 0)
7847 direct = FILTER_OUT;
718e3744 7848
d62a17ae 7849 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 7850
d62a17ae 7851 return bgp_vty_return(vty, ret);
718e3744 7852}
7853
7854DEFUN (neighbor_filter_list,
7855 neighbor_filter_list_cmd,
9ccf14f7 7856 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 7857 NEIGHBOR_STR
7858 NEIGHBOR_ADDR_STR2
7859 "Establish BGP filters\n"
7860 "AS path access-list name\n"
7861 "Filter incoming routes\n"
7862 "Filter outgoing routes\n")
7863{
d62a17ae 7864 int idx_peer = 1;
7865 int idx_word = 3;
7866 int idx_in_out = 4;
7867 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7868 bgp_node_safi(vty), argv[idx_word]->arg,
7869 argv[idx_in_out]->arg);
718e3744 7870}
7871
d62a17ae 7872ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
7873 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7874 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7875 "Establish BGP filters\n"
7876 "AS path access-list name\n"
7877 "Filter incoming routes\n"
7878 "Filter outgoing routes\n")
596c17ba 7879
718e3744 7880DEFUN (no_neighbor_filter_list,
7881 no_neighbor_filter_list_cmd,
9ccf14f7 7882 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 7883 NO_STR
7884 NEIGHBOR_STR
7885 NEIGHBOR_ADDR_STR2
7886 "Establish BGP filters\n"
7887 "AS path access-list name\n"
7888 "Filter incoming routes\n"
7889 "Filter outgoing routes\n")
7890{
d62a17ae 7891 int idx_peer = 2;
7892 int idx_in_out = 5;
7893 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7894 bgp_node_afi(vty), bgp_node_safi(vty),
7895 argv[idx_in_out]->arg);
718e3744 7896}
6b0655a2 7897
d62a17ae 7898ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
7899 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7900 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7901 "Establish BGP filters\n"
7902 "AS path access-list name\n"
7903 "Filter incoming routes\n"
7904 "Filter outgoing routes\n")
596c17ba 7905
7f7940e6
MK
7906/* Set advertise-map to the peer. */
7907static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7908 afi_t afi, safi_t safi,
cf2ad4d8
MK
7909 const char *advertise_str,
7910 const char *condition_str, bool condition,
7911 bool set)
7f7940e6
MK
7912{
7913 int ret = CMD_WARNING_CONFIG_FAILED;
7914 struct peer *peer;
7915 struct route_map *advertise_map;
7916 struct route_map *condition_map;
7917
7918 peer = peer_and_group_lookup_vty(vty, ip_str);
7919 if (!peer)
7920 return ret;
7921
7922 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7923 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7924
cf2ad4d8
MK
7925 if (set)
7926 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7927 advertise_map, condition_str,
7928 condition_map, condition);
7929 else
7930 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7931 advertise_map, condition_str,
7932 condition_map, condition);
7f7940e6
MK
7933
7934 return bgp_vty_return(vty, ret);
7935}
7936
cf2ad4d8 7937DEFPY (neighbor_advertise_map,
7f7940e6 7938 neighbor_advertise_map_cmd,
52b84062 7939 "[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 7940 NO_STR
7f7940e6
MK
7941 NEIGHBOR_STR
7942 NEIGHBOR_ADDR_STR2
7943 "Route-map to conditionally advertise routes\n"
7944 "Name of advertise map\n"
7945 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 7946 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 7947 "Name of the exist or non exist map\n")
7f7940e6 7948{
7f7940e6
MK
7949 bool condition = CONDITION_EXIST;
7950
52b84062 7951 if (!strcmp(exist, "non-exist-map"))
7f7940e6
MK
7952 condition = CONDITION_NON_EXIST;
7953
52b84062
MK
7954 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7955 bgp_node_safi(vty), advertise_str,
7956 condition_str, condition, !no);
7f7940e6
MK
7957}
7958
7959ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
52b84062 7960 "[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
7961 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7962 "Route-map to conditionally advertise routes\n"
7963 "Name of advertise map\n"
7964 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 7965 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 7966 "Name of the exist or non exist map\n")
7f7940e6 7967
718e3744 7968/* Set route-map to the peer. */
c6685575
CS
7969DEFPY_YANG(
7970 neighbor_route_map, neighbor_route_map_cmd,
7971 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor_str route-map WORD$rmap_str <in|out>$direction",
7972 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7973 "Apply route map to neighbor\n"
7974 "Name of route map\n"
7975 "Apply map to incoming routes\n"
7976 "Apply map to outbound routes\n")
718e3744 7977{
c6685575
CS
7978 char base_xpath[XPATH_MAXLEN];
7979 char af_xpath[XPATH_MAXLEN];
7980 char rmap_xpath[XPATH_MAXLEN];
7981 afi_t afi = bgp_node_afi(vty);
7982 safi_t safi = bgp_node_safi(vty);
718e3744 7983
c6685575
CS
7984 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7985 yang_afi_safi_value2identity(afi, safi));
7986 if (peer_and_group_lookup_nb(vty, neighbor_str, base_xpath,
7987 sizeof(base_xpath), af_xpath)
7988 < 0)
d62a17ae 7989 return CMD_WARNING_CONFIG_FAILED;
718e3744 7990
c6685575
CS
7991 if (strmatch(direction, "in"))
7992 snprintf(rmap_xpath, sizeof(rmap_xpath),
7993 "./%s/filter-config/rmap-import",
7994 bgp_afi_safi_get_container_str(afi, safi));
7995 else if (strmatch(direction, "out"))
7996 snprintf(rmap_xpath, sizeof(rmap_xpath),
7997 "./%s/filter-config/rmap-export",
7998 bgp_afi_safi_get_container_str(afi, safi));
718e3744 7999
c6685575
CS
8000 if (!no) {
8001 if (!yang_dnode_exists(
8002 vty->candidate_config->dnode,
8003 "/frr-route-map:lib/route-map[name='%s']",
8004 rmap_str)) {
8005 if (vty_shell_serv(vty))
8006 vty_out(vty,
8007 "The route-map '%s' does not exist.\n",
8008 rmap_str);
8009 }
8010 nb_cli_enqueue_change(vty, rmap_xpath, NB_OP_MODIFY, rmap_str);
8011 } else
8012 nb_cli_enqueue_change(vty, rmap_xpath, NB_OP_DESTROY, NULL);
718e3744 8013
c6685575 8014 return nb_cli_apply_changes(vty, base_xpath);
718e3744 8015}
8016
d62a17ae 8017ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
8018 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
8019 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8020 "Apply route map to neighbor\n"
8021 "Name of route map\n"
8022 "Apply map to incoming routes\n"
8023 "Apply map to outbound routes\n")
596c17ba 8024
c6685575 8025ALIAS_HIDDEN(neighbor_route_map, no_neighbor_route_map_hidden_cmd,
d62a17ae 8026 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
8027 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8028 "Apply route map to neighbor\n"
8029 "Name of route map\n"
8030 "Apply map to incoming routes\n"
8031 "Apply map to outbound routes\n")
596c17ba 8032
718e3744 8033/* Set unsuppress-map to the peer. */
d62a17ae 8034static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
8035 afi_t afi, safi_t safi,
8036 const char *name_str)
718e3744 8037{
d62a17ae 8038 int ret;
8039 struct peer *peer;
1de27621 8040 struct route_map *route_map;
718e3744 8041
d62a17ae 8042 peer = peer_and_group_lookup_vty(vty, ip_str);
8043 if (!peer)
8044 return CMD_WARNING_CONFIG_FAILED;
718e3744 8045
1de27621
DA
8046 route_map = route_map_lookup_warn_noexist(vty, name_str);
8047 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
718e3744 8048
d62a17ae 8049 return bgp_vty_return(vty, ret);
718e3744 8050}
8051
8052/* Unset route-map from the peer. */
d62a17ae 8053static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
8054 afi_t afi, safi_t safi)
718e3744 8055{
d62a17ae 8056 int ret;
8057 struct peer *peer;
718e3744 8058
d62a17ae 8059 peer = peer_and_group_lookup_vty(vty, ip_str);
8060 if (!peer)
8061 return CMD_WARNING_CONFIG_FAILED;
718e3744 8062
d62a17ae 8063 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 8064
d62a17ae 8065 return bgp_vty_return(vty, ret);
718e3744 8066}
8067
8068DEFUN (neighbor_unsuppress_map,
8069 neighbor_unsuppress_map_cmd,
9ccf14f7 8070 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 8071 NEIGHBOR_STR
8072 NEIGHBOR_ADDR_STR2
8073 "Route-map to selectively unsuppress suppressed routes\n"
8074 "Name of route map\n")
8075{
d62a17ae 8076 int idx_peer = 1;
8077 int idx_word = 3;
8078 return peer_unsuppress_map_set_vty(
8079 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8080 argv[idx_word]->arg);
718e3744 8081}
8082
d62a17ae 8083ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
8084 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8085 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8086 "Route-map to selectively unsuppress suppressed routes\n"
8087 "Name of route map\n")
596c17ba 8088
718e3744 8089DEFUN (no_neighbor_unsuppress_map,
8090 no_neighbor_unsuppress_map_cmd,
9ccf14f7 8091 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 8092 NO_STR
8093 NEIGHBOR_STR
8094 NEIGHBOR_ADDR_STR2
8095 "Route-map to selectively unsuppress suppressed routes\n"
8096 "Name of route map\n")
8097{
d62a17ae 8098 int idx_peer = 2;
8099 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
8100 bgp_node_afi(vty),
8101 bgp_node_safi(vty));
718e3744 8102}
6b0655a2 8103
d62a17ae 8104ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
8105 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8106 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8107 "Route-map to selectively unsuppress suppressed routes\n"
8108 "Name of route map\n")
596c17ba 8109
fde246e8 8110/* Maximum number of prefix to be sent to the neighbor. */
232c75cd
CS
8111DEFUN_YANG(neighbor_maximum_prefix_out,
8112 neighbor_maximum_prefix_out_cmd,
8113 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
8114 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8115 "Maximum number of prefixes to be sent to this peer\n"
8116 "Maximum no. of prefix limit\n")
fde246e8 8117{
04261dec
CS
8118 char base_xpath[XPATH_MAXLEN];
8119 char af_xpath[XPATH_MAXLEN];
8120 char attr_xpath[XPATH_MAXLEN];
fde246e8
DA
8121 int idx_peer = 1;
8122 int idx_number = 3;
fde246e8
DA
8123 afi_t afi = bgp_node_afi(vty);
8124 safi_t safi = bgp_node_safi(vty);
8125
04261dec
CS
8126 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8127 yang_afi_safi_value2identity(afi, safi));
8128 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8129 sizeof(base_xpath), af_xpath)
8130 < 0)
fde246e8
DA
8131 return CMD_WARNING_CONFIG_FAILED;
8132
04261dec
CS
8133 snprintf(attr_xpath, sizeof(attr_xpath),
8134 "/%s/prefix-limit/direction-list[direction='out']",
8135 bgp_afi_safi_get_container_str(afi, safi));
8136 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
fde246e8 8137
04261dec 8138 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
fde246e8 8139
04261dec
CS
8140 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8141 argv[idx_number]->arg);
8142
8143 return nb_cli_apply_changes(vty, base_xpath);
fde246e8
DA
8144}
8145
232c75cd
CS
8146DEFUN_YANG(no_neighbor_maximum_prefix_out,
8147 no_neighbor_maximum_prefix_out_cmd,
8148 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out",
8149 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8150 "Maximum number of prefixes to be sent to this peer\n")
fde246e8 8151{
04261dec
CS
8152 char base_xpath[XPATH_MAXLEN];
8153 char af_xpath[XPATH_MAXLEN];
8154 char attr_xpath[XPATH_MAXLEN];
fde246e8 8155 int idx_peer = 2;
fde246e8
DA
8156 afi_t afi = bgp_node_afi(vty);
8157 safi_t safi = bgp_node_safi(vty);
8158
04261dec
CS
8159 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8160 yang_afi_safi_value2identity(afi, safi));
8161 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8162 sizeof(base_xpath), af_xpath)
8163 < 0)
fde246e8
DA
8164 return CMD_WARNING_CONFIG_FAILED;
8165
04261dec
CS
8166 snprintf(attr_xpath, sizeof(attr_xpath),
8167 "/%s/prefix-limit/direction-list[direction='out']",
8168 bgp_afi_safi_get_container_str(afi, safi));
8169 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8170
8171 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
fde246e8 8172
04261dec 8173 return nb_cli_apply_changes(vty, base_xpath);
fde246e8
DA
8174}
8175
9cbd06e0
DA
8176/* Maximum number of prefix configuration. Prefix count is different
8177 for each peer configuration. So this configuration can be set for
718e3744 8178 each peer configuration. */
232c75cd
CS
8179DEFUN_YANG(neighbor_maximum_prefix,
8180 neighbor_maximum_prefix_cmd,
8181 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8182 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8183 "Maximum number of prefix accept from this peer\n"
8184 "maximum no. of prefix limit\n"
8185 "Force checking all received routes not only accepted\n")
718e3744 8186{
d62a17ae 8187 int idx_peer = 1;
8188 int idx_number = 3;
9cbd06e0 8189 int idx_force = 0;
04261dec
CS
8190 char base_xpath[XPATH_MAXLEN];
8191 char af_xpath[XPATH_MAXLEN];
8192 char attr_xpath[XPATH_MAXLEN];
8193 afi_t afi = bgp_node_afi(vty);
8194 safi_t safi = bgp_node_safi(vty);
8195
8196 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8197 yang_afi_safi_value2identity(afi, safi));
8198 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8199 sizeof(base_xpath), af_xpath)
8200 < 0)
8201 return CMD_WARNING_CONFIG_FAILED;
8202
8203 snprintf(attr_xpath, sizeof(attr_xpath),
8204 "/%s/prefix-limit/direction-list[direction='in']",
8205 bgp_afi_safi_get_container_str(afi, safi));
8206 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8207
8208 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
9cbd06e0 8209
04261dec
CS
8210 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8211 argv[idx_number]->arg);
9cbd06e0 8212 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8213 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8214 "true");
9cbd06e0 8215
04261dec 8216 return nb_cli_apply_changes(vty, base_xpath);
718e3744 8217}
8218
d62a17ae 8219ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 8220 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
d62a17ae 8221 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8222 "Maximum number of prefix accept from this peer\n"
9cbd06e0
DA
8223 "maximum no. of prefix limit\n"
8224 "Force checking all received routes not only accepted\n")
596c17ba 8225
232c75cd
CS
8226DEFUN_YANG(neighbor_maximum_prefix_threshold,
8227 neighbor_maximum_prefix_threshold_cmd,
8228 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8229 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8230 "Maximum number of prefix accept from this peer\n"
8231 "maximum no. of prefix limit\n"
8232 "Threshold value (%) at which to generate a warning msg\n"
8233 "Force checking all received routes not only accepted\n")
e0701b79 8234{
d62a17ae 8235 int idx_peer = 1;
8236 int idx_number = 3;
8237 int idx_number_2 = 4;
9cbd06e0 8238 int idx_force = 0;
04261dec
CS
8239 char base_xpath[XPATH_MAXLEN];
8240 char af_xpath[XPATH_MAXLEN];
8241 char attr_xpath[XPATH_MAXLEN];
8242 afi_t afi = bgp_node_afi(vty);
8243 safi_t safi = bgp_node_safi(vty);
8244
8245 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8246 yang_afi_safi_value2identity(afi, safi));
8247 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8248 sizeof(base_xpath), af_xpath)
8249 < 0)
8250 return CMD_WARNING_CONFIG_FAILED;
8251
8252 snprintf(attr_xpath, sizeof(attr_xpath),
8253 "/%s/prefix-limit/direction-list[direction='in']",
8254 bgp_afi_safi_get_container_str(afi, safi));
8255 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8256
8257 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8258
8259 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8260 argv[idx_number]->arg);
8261
8262 nb_cli_enqueue_change(vty, "./options/shutdown-threshold-pct",
8263 NB_OP_MODIFY, argv[idx_number_2]->arg);
9cbd06e0
DA
8264
8265 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8266 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8267 "true");
9cbd06e0 8268
04261dec 8269 return nb_cli_apply_changes(vty, base_xpath);
0a486e5f 8270}
e0701b79 8271
d62a17ae 8272ALIAS_HIDDEN(
8273 neighbor_maximum_prefix_threshold,
8274 neighbor_maximum_prefix_threshold_hidden_cmd,
9cbd06e0 8275 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
d62a17ae 8276 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8277 "Maximum number of prefix accept from this peer\n"
8278 "maximum no. of prefix limit\n"
9cbd06e0
DA
8279 "Threshold value (%) at which to generate a warning msg\n"
8280 "Force checking all received routes not only accepted\n")
596c17ba 8281
232c75cd
CS
8282DEFUN_YANG(neighbor_maximum_prefix_warning,
8283 neighbor_maximum_prefix_warning_cmd,
8284 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8285 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8286 "Maximum number of prefix accept from this peer\n"
8287 "maximum no. of prefix limit\n"
8288 "Only give warning message when limit is exceeded\n"
8289 "Force checking all received routes not only accepted\n")
718e3744 8290{
d62a17ae 8291 int idx_peer = 1;
8292 int idx_number = 3;
9cbd06e0 8293 int idx_force = 0;
04261dec
CS
8294 char base_xpath[XPATH_MAXLEN];
8295 char af_xpath[XPATH_MAXLEN];
8296 char attr_xpath[XPATH_MAXLEN];
8297 afi_t afi = bgp_node_afi(vty);
8298 safi_t safi = bgp_node_safi(vty);
8299
8300 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8301 yang_afi_safi_value2identity(afi, safi));
8302 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8303 sizeof(base_xpath), af_xpath)
8304 < 0)
8305 return CMD_WARNING_CONFIG_FAILED;
9cbd06e0 8306
04261dec
CS
8307 snprintf(attr_xpath, sizeof(attr_xpath),
8308 "/%s/prefix-limit/direction-list[direction='in']",
8309 bgp_afi_safi_get_container_str(afi, safi));
8310 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8311
8312 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8313
8314 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8315 argv[idx_number]->arg);
8316
8317 nb_cli_enqueue_change(vty, "./options/warning-only", NB_OP_MODIFY,
8318 "true");
9cbd06e0 8319 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8320 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8321 "true");
9cbd06e0 8322
04261dec 8323 return nb_cli_apply_changes(vty, base_xpath);
718e3744 8324}
8325
d62a17ae 8326ALIAS_HIDDEN(
8327 neighbor_maximum_prefix_warning,
8328 neighbor_maximum_prefix_warning_hidden_cmd,
9cbd06e0 8329 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
d62a17ae 8330 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8331 "Maximum number of prefix accept from this peer\n"
8332 "maximum no. of prefix limit\n"
9cbd06e0
DA
8333 "Only give warning message when limit is exceeded\n"
8334 "Force checking all received routes not only accepted\n")
596c17ba 8335
232c75cd
CS
8336DEFUN_YANG(neighbor_maximum_prefix_threshold_warning,
8337 neighbor_maximum_prefix_threshold_warning_cmd,
8338 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8339 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8340 "Maximum number of prefix accept from this peer\n"
8341 "maximum no. of prefix limit\n"
8342 "Threshold value (%) at which to generate a warning msg\n"
8343 "Only give warning message when limit is exceeded\n"
8344 "Force checking all received routes not only accepted\n")
e0701b79 8345{
d62a17ae 8346 int idx_peer = 1;
8347 int idx_number = 3;
8348 int idx_number_2 = 4;
9cbd06e0 8349 int idx_force = 0;
04261dec
CS
8350 char base_xpath[XPATH_MAXLEN];
8351 char af_xpath[XPATH_MAXLEN];
8352 char attr_xpath[XPATH_MAXLEN];
8353 afi_t afi = bgp_node_afi(vty);
8354 safi_t safi = bgp_node_safi(vty);
9cbd06e0 8355
04261dec
CS
8356 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8357 yang_afi_safi_value2identity(afi, safi));
8358 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8359 sizeof(base_xpath), af_xpath)
8360 < 0)
8361 return CMD_WARNING_CONFIG_FAILED;
8362
8363 snprintf(attr_xpath, sizeof(attr_xpath),
8364 "/%s/prefix-limit/direction-list[direction='in']",
8365 bgp_afi_safi_get_container_str(afi, safi));
8366 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8367
8368 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8369
8370 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8371 argv[idx_number]->arg);
8372 nb_cli_enqueue_change(vty, "./options/tw-shutdown-threshold-pct",
8373 NB_OP_MODIFY, argv[idx_number_2]->arg);
8374 nb_cli_enqueue_change(vty, "./options/tw-warning-only", NB_OP_MODIFY,
8375 "true");
9cbd06e0 8376 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8377 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8378 "true");
9cbd06e0 8379
04261dec 8380 return nb_cli_apply_changes(vty, base_xpath);
0a486e5f 8381}
8382
d62a17ae 8383ALIAS_HIDDEN(
8384 neighbor_maximum_prefix_threshold_warning,
8385 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
9cbd06e0 8386 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
d62a17ae 8387 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8388 "Maximum number of prefix accept from this peer\n"
8389 "maximum no. of prefix limit\n"
8390 "Threshold value (%) at which to generate a warning msg\n"
9cbd06e0
DA
8391 "Only give warning message when limit is exceeded\n"
8392 "Force checking all received routes not only accepted\n")
596c17ba 8393
232c75cd
CS
8394DEFUN_YANG(neighbor_maximum_prefix_restart,
8395 neighbor_maximum_prefix_restart_cmd,
8396 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8397 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8398 "Maximum number of prefix accept from this peer\n"
8399 "maximum no. of prefix limit\n"
8400 "Restart bgp connection after limit is exceeded\n"
8401 "Restart interval in minutes\n"
8402 "Force checking all received routes not only accepted\n")
0a486e5f 8403{
d62a17ae 8404 int idx_peer = 1;
8405 int idx_number = 3;
8406 int idx_number_2 = 5;
9cbd06e0 8407 int idx_force = 0;
04261dec
CS
8408 char base_xpath[XPATH_MAXLEN];
8409 char af_xpath[XPATH_MAXLEN];
8410 char attr_xpath[XPATH_MAXLEN];
8411 afi_t afi = bgp_node_afi(vty);
8412 safi_t safi = bgp_node_safi(vty);
9cbd06e0 8413
04261dec
CS
8414 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8415 yang_afi_safi_value2identity(afi, safi));
8416 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8417 sizeof(base_xpath), af_xpath)
8418 < 0)
8419 return CMD_WARNING_CONFIG_FAILED;
8420
8421 snprintf(attr_xpath, sizeof(attr_xpath),
8422 "/%s/prefix-limit/direction-list[direction='in']",
8423 bgp_afi_safi_get_container_str(afi, safi));
8424 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8425
8426 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8427
8428 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8429 argv[idx_number]->arg);
8430 nb_cli_enqueue_change(vty, "./options/restart-timer", NB_OP_MODIFY,
8431 argv[idx_number_2]->arg);
9cbd06e0 8432 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8433 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8434 "true");
9cbd06e0 8435
04261dec 8436 return nb_cli_apply_changes(vty, base_xpath);
0a486e5f 8437}
8438
d62a17ae 8439ALIAS_HIDDEN(
8440 neighbor_maximum_prefix_restart,
8441 neighbor_maximum_prefix_restart_hidden_cmd,
9cbd06e0 8442 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
d62a17ae 8443 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8444 "Maximum number of prefix accept from this peer\n"
8445 "maximum no. of prefix limit\n"
8446 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
8447 "Restart interval in minutes\n"
8448 "Force checking all received routes not only accepted\n")
596c17ba 8449
232c75cd
CS
8450DEFUN_YANG(neighbor_maximum_prefix_threshold_restart,
8451 neighbor_maximum_prefix_threshold_restart_cmd,
8452 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8453 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8454 "Maximum number of prefixes to accept from this peer\n"
8455 "maximum no. of prefix limit\n"
8456 "Threshold value (%) at which to generate a warning msg\n"
8457 "Restart bgp connection after limit is exceeded\n"
8458 "Restart interval in minutes\n"
8459 "Force checking all received routes not only accepted\n")
0a486e5f 8460{
d62a17ae 8461 int idx_peer = 1;
8462 int idx_number = 3;
8463 int idx_number_2 = 4;
8464 int idx_number_3 = 6;
9cbd06e0 8465 int idx_force = 0;
04261dec
CS
8466 char base_xpath[XPATH_MAXLEN];
8467 char af_xpath[XPATH_MAXLEN];
8468 char attr_xpath[XPATH_MAXLEN];
8469 afi_t afi = bgp_node_afi(vty);
8470 safi_t safi = bgp_node_safi(vty);
9cbd06e0 8471
04261dec
CS
8472 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8473 yang_afi_safi_value2identity(afi, safi));
8474 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8475 sizeof(base_xpath), af_xpath)
8476 < 0)
8477 return CMD_WARNING_CONFIG_FAILED;
8478
8479 snprintf(attr_xpath, sizeof(attr_xpath),
8480 "/%s/prefix-limit/direction-list[direction='in']",
8481 bgp_afi_safi_get_container_str(afi, safi));
8482 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8483
8484 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8485
8486 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8487 argv[idx_number]->arg);
8488 nb_cli_enqueue_change(vty, "./options/tr-shutdown-threshold-pct",
8489 NB_OP_MODIFY, argv[idx_number_2]->arg);
8490 nb_cli_enqueue_change(vty, "./options/tr-restart-timer", NB_OP_MODIFY,
8491 argv[idx_number_3]->arg);
9cbd06e0 8492 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8493 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8494 "true");
9cbd06e0 8495
04261dec 8496 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 8497}
8498
8499ALIAS_HIDDEN(
8500 neighbor_maximum_prefix_threshold_restart,
8501 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
9cbd06e0 8502 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
d62a17ae 8503 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8504 "Maximum number of prefixes to accept from this peer\n"
8505 "maximum no. of prefix limit\n"
8506 "Threshold value (%) at which to generate a warning msg\n"
8507 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
8508 "Restart interval in minutes\n"
8509 "Force checking all received routes not only accepted\n")
596c17ba 8510
232c75cd
CS
8511DEFUN_YANG(no_neighbor_maximum_prefix,
8512 no_neighbor_maximum_prefix_cmd,
8513 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8514 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8515 "Maximum number of prefixes to accept from this peer\n"
8516 "maximum no. of prefix limit\n"
8517 "Threshold value (%) at which to generate a warning msg\n"
8518 "Restart bgp connection after limit is exceeded\n"
8519 "Restart interval in minutes\n"
8520 "Only give warning message when limit is exceeded\n"
8521 "Force checking all received routes not only accepted\n")
718e3744 8522{
d62a17ae 8523 int idx_peer = 2;
04261dec
CS
8524 char base_xpath[XPATH_MAXLEN];
8525 char af_xpath[XPATH_MAXLEN];
8526 char attr_xpath[XPATH_MAXLEN];
8527 afi_t afi = bgp_node_afi(vty);
8528 safi_t safi = bgp_node_safi(vty);
8529
8530 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8531 yang_afi_safi_value2identity(afi, safi));
8532 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8533 sizeof(base_xpath), af_xpath)
8534 < 0)
8535 return CMD_WARNING_CONFIG_FAILED;
8536
8537 snprintf(attr_xpath, sizeof(attr_xpath),
8538 "/%s/prefix-limit/direction-list[direction='in']",
8539 bgp_afi_safi_get_container_str(afi, safi));
8540 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8541
8542 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
8543
8544 return nb_cli_apply_changes(vty, base_xpath);
718e3744 8545}
e52702f2 8546
d62a17ae 8547ALIAS_HIDDEN(
8548 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 8549 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
d62a17ae 8550 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8551 "Maximum number of prefixes to accept from this peer\n"
8552 "maximum no. of prefix limit\n"
8553 "Threshold value (%) at which to generate a warning msg\n"
8554 "Restart bgp connection after limit is exceeded\n"
8555 "Restart interval in minutes\n"
9cbd06e0
DA
8556 "Only give warning message when limit is exceeded\n"
8557 "Force checking all received routes not only accepted\n")
596c17ba 8558
718e3744 8559
718e3744 8560/* "neighbor allowas-in" */
8561DEFUN (neighbor_allowas_in,
8562 neighbor_allowas_in_cmd,
fd8503f5 8563 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 8564 NEIGHBOR_STR
8565 NEIGHBOR_ADDR_STR2
31500417 8566 "Accept as-path with my AS present in it\n"
f79f7a7b 8567 "Number of occurrences of AS number\n"
fd8503f5 8568 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 8569{
d62a17ae 8570 int idx_peer = 1;
8571 int idx_number_origin = 3;
8572 int ret;
8573 int origin = 0;
8574 struct peer *peer;
8575 int allow_num = 0;
8576
8577 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8578 if (!peer)
8579 return CMD_WARNING_CONFIG_FAILED;
8580
8581 if (argc <= idx_number_origin)
8582 allow_num = 3;
8583 else {
8584 if (argv[idx_number_origin]->type == WORD_TKN)
8585 origin = 1;
8586 else
8587 allow_num = atoi(argv[idx_number_origin]->arg);
8588 }
8589
8590 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8591 allow_num, origin);
8592
8593 return bgp_vty_return(vty, ret);
8594}
8595
8596ALIAS_HIDDEN(
8597 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8598 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8599 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8600 "Accept as-path with my AS present in it\n"
f79f7a7b 8601 "Number of occurrences of AS number\n"
d62a17ae 8602 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 8603
718e3744 8604DEFUN (no_neighbor_allowas_in,
8605 no_neighbor_allowas_in_cmd,
fd8503f5 8606 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 8607 NO_STR
8608 NEIGHBOR_STR
8609 NEIGHBOR_ADDR_STR2
8334fd5a 8610 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8611 "Number of occurrences of AS number\n"
fd8503f5 8612 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 8613{
d62a17ae 8614 int idx_peer = 2;
8615 int ret;
8616 struct peer *peer;
718e3744 8617
d62a17ae 8618 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8619 if (!peer)
8620 return CMD_WARNING_CONFIG_FAILED;
718e3744 8621
d62a17ae 8622 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8623 bgp_node_safi(vty));
718e3744 8624
d62a17ae 8625 return bgp_vty_return(vty, ret);
718e3744 8626}
6b0655a2 8627
d62a17ae 8628ALIAS_HIDDEN(
8629 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8630 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8631 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8632 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8633 "Number of occurrences of AS number\n"
d62a17ae 8634 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 8635
f4b8ec07
CS
8636DEFUN_YANG (neighbor_ttl_security,
8637 neighbor_ttl_security_cmd,
8638 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8639 NEIGHBOR_STR
8640 NEIGHBOR_ADDR_STR2
8641 "BGP ttl-security parameters\n"
8642 "Specify the maximum number of hops to the BGP peer\n"
8643 "Number of hops to BGP peer\n")
fa411a21 8644{
d62a17ae 8645 int idx_peer = 1;
8646 int idx_number = 4;
f4b8ec07 8647 char base_xpath[XPATH_MAXLEN];
d62a17ae 8648
f4b8ec07
CS
8649 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8650 sizeof(base_xpath), NULL)
8651 < 0)
d62a17ae 8652 return CMD_WARNING_CONFIG_FAILED;
8653
f4b8ec07
CS
8654 nb_cli_enqueue_change(vty, "./ttl-security", NB_OP_MODIFY,
8655 argv[idx_number]->arg);
7ebe625c 8656
f4b8ec07 8657 return nb_cli_apply_changes(vty, base_xpath);
fa411a21
NH
8658}
8659
232c75cd
CS
8660DEFUN_YANG(no_neighbor_ttl_security,
8661 no_neighbor_ttl_security_cmd,
8662 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8663 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8664 "BGP ttl-security parameters\n"
8665 "Specify the maximum number of hops to the BGP peer\n"
8666 "Number of hops to BGP peer\n")
fa411a21 8667{
d62a17ae 8668 int idx_peer = 2;
f4b8ec07 8669 char base_xpath[XPATH_MAXLEN];
fa411a21 8670
f4b8ec07
CS
8671 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8672 sizeof(base_xpath), NULL)
8673 < 0)
d62a17ae 8674 return CMD_WARNING_CONFIG_FAILED;
fa411a21 8675
f4b8ec07
CS
8676 nb_cli_enqueue_change(vty, "./ttl-security", NB_OP_DESTROY, NULL);
8677
8678 return nb_cli_apply_changes(vty, base_xpath);
fa411a21 8679}
6b0655a2 8680
adbac85e
DW
8681DEFUN (neighbor_addpath_tx_all_paths,
8682 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8683 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8684 NEIGHBOR_STR
8685 NEIGHBOR_ADDR_STR2
8686 "Use addpath to advertise all paths to a neighbor\n")
8687{
d62a17ae 8688 int idx_peer = 1;
8689 struct peer *peer;
adbac85e 8690
d62a17ae 8691 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8692 if (!peer)
8693 return CMD_WARNING_CONFIG_FAILED;
adbac85e 8694
dcc68b5e
MS
8695 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8696 BGP_ADDPATH_ALL);
8697 return CMD_SUCCESS;
adbac85e
DW
8698}
8699
d62a17ae 8700ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8701 neighbor_addpath_tx_all_paths_hidden_cmd,
8702 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8703 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8704 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8705
adbac85e
DW
8706DEFUN (no_neighbor_addpath_tx_all_paths,
8707 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8708 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8709 NO_STR
8710 NEIGHBOR_STR
8711 NEIGHBOR_ADDR_STR2
8712 "Use addpath to advertise all paths to a neighbor\n")
8713{
d62a17ae 8714 int idx_peer = 2;
dcc68b5e
MS
8715 struct peer *peer;
8716
8717 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8718 if (!peer)
8719 return CMD_WARNING_CONFIG_FAILED;
8720
8721 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8722 != BGP_ADDPATH_ALL) {
8723 vty_out(vty,
8724 "%% Peer not currently configured to transmit all paths.");
8725 return CMD_WARNING_CONFIG_FAILED;
8726 }
8727
8728 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8729 BGP_ADDPATH_NONE);
8730
8731 return CMD_SUCCESS;
adbac85e
DW
8732}
8733
d62a17ae 8734ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8735 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8736 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8737 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8738 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8739
06370dac
DW
8740DEFUN (neighbor_addpath_tx_bestpath_per_as,
8741 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8742 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8743 NEIGHBOR_STR
8744 NEIGHBOR_ADDR_STR2
8745 "Use addpath to advertise the bestpath per each neighboring AS\n")
8746{
d62a17ae 8747 int idx_peer = 1;
8748 struct peer *peer;
06370dac 8749
d62a17ae 8750 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8751 if (!peer)
8752 return CMD_WARNING_CONFIG_FAILED;
06370dac 8753
dcc68b5e
MS
8754 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8755 BGP_ADDPATH_BEST_PER_AS);
8756
8757 return CMD_SUCCESS;
06370dac
DW
8758}
8759
d62a17ae 8760ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8761 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8762 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8763 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8764 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8765
06370dac
DW
8766DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8767 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8768 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8769 NO_STR
8770 NEIGHBOR_STR
8771 NEIGHBOR_ADDR_STR2
8772 "Use addpath to advertise the bestpath per each neighboring AS\n")
8773{
d62a17ae 8774 int idx_peer = 2;
dcc68b5e
MS
8775 struct peer *peer;
8776
8777 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8778 if (!peer)
8779 return CMD_WARNING_CONFIG_FAILED;
8780
8781 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8782 != BGP_ADDPATH_BEST_PER_AS) {
8783 vty_out(vty,
8784 "%% Peer not currently configured to transmit all best path per as.");
8785 return CMD_WARNING_CONFIG_FAILED;
8786 }
8787
8788 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8789 BGP_ADDPATH_NONE);
8790
8791 return CMD_SUCCESS;
06370dac
DW
8792}
8793
d62a17ae 8794ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8795 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8796 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8797 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8798 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8799
2b31007c
RZ
8800DEFPY(
8801 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8802 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8803 NEIGHBOR_STR
8804 NEIGHBOR_ADDR_STR2
8805 "Detect AS loops before sending to neighbor\n")
8806{
8807 struct peer *peer;
8808
8809 peer = peer_and_group_lookup_vty(vty, neighbor);
8810 if (!peer)
8811 return CMD_WARNING_CONFIG_FAILED;
8812
8813 peer->as_path_loop_detection = true;
8814
8815 return CMD_SUCCESS;
8816}
8817
8818DEFPY(
8819 no_neighbor_aspath_loop_detection,
8820 no_neighbor_aspath_loop_detection_cmd,
8821 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8822 NO_STR
8823 NEIGHBOR_STR
8824 NEIGHBOR_ADDR_STR2
8825 "Detect AS loops before sending to neighbor\n")
8826{
8827 struct peer *peer;
8828
8829 peer = peer_and_group_lookup_vty(vty, neighbor);
8830 if (!peer)
8831 return CMD_WARNING_CONFIG_FAILED;
8832
8833 peer->as_path_loop_detection = false;
8834
8835 return CMD_SUCCESS;
8836}
8837
0221327c
DS
8838DEFPY(neighbor_damp,
8839 neighbor_damp_cmd,
8840 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor dampening [(1-45)$half [(1-20000)$reuse (1-20000)$suppress (1-255)$max]]",
8841 NEIGHBOR_STR
8842 NEIGHBOR_ADDR_STR2
8843 "Enable neighbor route-flap dampening\n"
8844 "Half-life time for the penalty\n"
8845 "Value to start reusing a route\n"
8846 "Value to start suppressing a route\n"
8847 "Maximum duration to suppress a stable route\n")
8848{
8849 struct peer *peer = peer_and_group_lookup_vty(vty, neighbor);
8850
8851 if (!peer)
8852 return CMD_WARNING_CONFIG_FAILED;
8853 if (!half)
8854 half = DEFAULT_HALF_LIFE;
8855 if (!reuse) {
8856 reuse = DEFAULT_REUSE;
8857 suppress = DEFAULT_SUPPRESS;
8858 max = half * 4;
8859 }
8860 if (suppress < reuse) {
8861 vty_out(vty,
8862 "Suppress value cannot be less than reuse value\n");
8863 return CMD_WARNING_CONFIG_FAILED;
8864 }
8865 bgp_peer_damp_enable(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8866 half * 60, reuse, suppress, max * 60);
8867 return CMD_SUCCESS;
8868}
8869
8870DEFPY(no_neighbor_damp,
8871 no_neighbor_damp_cmd,
8872 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor dampening [HALF [REUSE SUPPRESS MAX]]",
8873 NO_STR
8874 NEIGHBOR_STR
8875 NEIGHBOR_ADDR_STR2
8876 "Enable neighbor route-flap dampening\n"
8877 "Half-life time for the penalty\n"
8878 "Value to start reusing a route\n"
8879 "Value to start suppressing a route\n"
8880 "Maximum duration to suppress a stable route\n")
8881{
8882 struct peer *peer = peer_and_group_lookup_vty(vty, neighbor);
8883
8884 if (!peer)
8885 return CMD_WARNING_CONFIG_FAILED;
8886 bgp_peer_damp_disable(peer, bgp_node_afi(vty), bgp_node_safi(vty));
8887 return CMD_SUCCESS;
8888}
8889
8890DEFPY (show_ip_bgp_neighbor_damp_param,
8891 show_ip_bgp_neighbor_damp_param_cmd,
8892 "show [ip] bgp [<ipv4|ipv6> [unicast]] neighbors <A.B.C.D|X:X::X:X|WORD>$neighbor dampening parameters [json]$json",
8893 SHOW_STR
8894 IP_STR
8895 BGP_STR
8896 BGP_AFI_HELP_STR
8897 "Address Family modifier\n"
8898 NEIGHBOR_STR
8899 NEIGHBOR_ADDR_STR2
8900 "Neighbor route-flap dampening information\n"
8901 "Display detail of configured dampening parameters\n"
8902 JSON_STR)
8903{
8904 bool use_json = false;
8905 int idx = 0;
8906 afi_t afi = AFI_IP;
8907 safi_t safi = SAFI_UNICAST;
8908 struct peer *peer;
8909
8910 if (argv_find(argv, argc, "ip", &idx))
8911 afi = AFI_IP;
8912 if (argv_find(argv, argc, "ipv4", &idx))
8913 afi = AFI_IP;
8914 if (argv_find(argv, argc, "ipv6", &idx))
8915 afi = AFI_IP6;
8916 peer = peer_and_group_lookup_vty(vty, neighbor);
8917 if (!peer)
8918 return CMD_WARNING;
8919 if (json)
8920 use_json = true;
8921 bgp_show_peer_dampening_parameters(vty, peer, afi, safi, use_json);
8922 return CMD_SUCCESS;
8923}
8924
b9c7bc5a 8925static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
c6423c31 8926 struct ecommunity **list, bool is_rt6)
ddb5b488 8927{
b9c7bc5a
PZ
8928 struct ecommunity *ecom = NULL;
8929 struct ecommunity *ecomadd;
ddb5b488 8930
b9c7bc5a 8931 for (; argc; --argc, ++argv) {
9a659715
PG
8932 if (is_rt6)
8933 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8934 ECOMMUNITY_ROUTE_TARGET,
8935 0);
8936 else
8937 ecomadd = ecommunity_str2com(argv[0]->arg,
8938 ECOMMUNITY_ROUTE_TARGET,
8939 0);
b9c7bc5a
PZ
8940 if (!ecomadd) {
8941 vty_out(vty, "Malformed community-list value\n");
8942 if (ecom)
8943 ecommunity_free(&ecom);
8944 return CMD_WARNING_CONFIG_FAILED;
8945 }
ddb5b488 8946
b9c7bc5a
PZ
8947 if (ecom) {
8948 ecommunity_merge(ecom, ecomadd);
8949 ecommunity_free(&ecomadd);
8950 } else {
8951 ecom = ecomadd;
8952 }
8953 }
8954
8955 if (*list) {
8956 ecommunity_free(&*list);
ddb5b488 8957 }
b9c7bc5a
PZ
8958 *list = ecom;
8959
8960 return CMD_SUCCESS;
ddb5b488
PZ
8961}
8962
37a87b8f
CS
8963bool vpn_policy_check_import(struct bgp *bgp, afi_t afi, safi_t safi,
8964 bool v2vimport, char *errmsg, size_t errmsg_len)
8965{
8966 if (!v2vimport) {
8967 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8968 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8969 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8970 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8971 snprintf(
8972 errmsg, errmsg_len, "%s",
8973 "%% error: Please unconfigure import vrf commands before using vpn commands");
8974 return false;
8975 }
8976 } else {
8977 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8978 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8979 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8980 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8981 snprintf(
8982 errmsg, errmsg_len, "%s",
8983 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands");
8984 return false;
8985 }
8986 }
8987 return true;
8988}
8989
0ca70ba5
DS
8990/*
8991 * v2vimport is true if we are handling a `import vrf ...` command
8992 */
8993static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 8994{
0ca70ba5
DS
8995 afi_t afi;
8996
ddb5b488 8997 switch (vty->node) {
b9c7bc5a 8998 case BGP_IPV4_NODE:
0ca70ba5
DS
8999 afi = AFI_IP;
9000 break;
b9c7bc5a 9001 case BGP_IPV6_NODE:
0ca70ba5
DS
9002 afi = AFI_IP6;
9003 break;
ddb5b488
PZ
9004 default:
9005 vty_out(vty,
b9c7bc5a 9006 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 9007 return AFI_MAX;
ddb5b488 9008 }
69b07479 9009
0ca70ba5
DS
9010 if (!v2vimport) {
9011 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9012 BGP_CONFIG_VRF_TO_VRF_IMPORT)
9013 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9014 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
9015 vty_out(vty,
9016 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
9017 return AFI_MAX;
9018 }
9019 } else {
9020 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9021 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
9022 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9023 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
9024 vty_out(vty,
9025 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
9026 return AFI_MAX;
9027 }
9028 }
9029 return afi;
ddb5b488
PZ
9030}
9031
37a87b8f
CS
9032DEFPY_YANG(
9033 af_rd_vpn_export,
9034 af_rd_vpn_export_cmd,
9035 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
9036 NO_STR
9037 "Specify route distinguisher\n"
9038 "Between current address-family and vpn\n"
9039 "For routes leaked from current address-family to vpn\n"
9040 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
ddb5b488 9041{
37a87b8f 9042 char base_xpath[XPATH_MAXLEN];
ddb5b488 9043 afi_t afi;
37a87b8f 9044 safi_t safi;
b9c7bc5a 9045 int idx = 0;
b9c7bc5a 9046
37a87b8f
CS
9047 afi = bgp_node_afi(vty);
9048 safi = bgp_node_safi(vty);
ddb5b488 9049
37a87b8f
CS
9050 snprintf(
9051 base_xpath, sizeof(base_xpath),
9052 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9053 yang_afi_safi_value2identity(afi, safi),
9054 bgp_afi_safi_get_container_str(afi, safi));
ddb5b488 9055
37a87b8f
CS
9056 if (argv_find(argv, argc, "no", &idx))
9057 nb_cli_enqueue_change(vty, "./rd", NB_OP_DESTROY, NULL);
9058 else
9059 nb_cli_enqueue_change(vty, "./rd", NB_OP_MODIFY, rd_str);
ddb5b488 9060
37a87b8f
CS
9061 return nb_cli_apply_changes(vty, base_xpath);
9062}
ddb5b488 9063
37a87b8f
CS
9064void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rd(
9065 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9066{
9067 int indent = 2;
69b07479 9068
37a87b8f
CS
9069 vty_out(vty, "%*srd vpn export %s\n", indent, "",
9070 yang_dnode_get_string(dnode, NULL));
ddb5b488
PZ
9071}
9072
b9c7bc5a
PZ
9073ALIAS (af_rd_vpn_export,
9074 af_no_rd_vpn_export_cmd,
9075 "no rd vpn export",
ddb5b488 9076 NO_STR
b9c7bc5a
PZ
9077 "Specify route distinguisher\n"
9078 "Between current address-family and vpn\n"
9079 "For routes leaked from current address-family to vpn\n")
ddb5b488 9080
b9c7bc5a
PZ
9081DEFPY (af_label_vpn_export,
9082 af_label_vpn_export_cmd,
e70e9f8e 9083 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 9084 NO_STR
ddb5b488 9085 "label value for VRF\n"
b9c7bc5a
PZ
9086 "Between current address-family and vpn\n"
9087 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
9088 "Label Value <0-1048575>\n"
9089 "Automatically assign a label\n")
ddb5b488
PZ
9090{
9091 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 9092 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 9093 afi_t afi;
b9c7bc5a 9094 int idx = 0;
c6423c31 9095 bool yes = true;
b9c7bc5a
PZ
9096
9097 if (argv_find(argv, argc, "no", &idx))
c6423c31 9098 yes = false;
ddb5b488 9099
21a16cc2
PZ
9100 /* If "no ...", squash trailing parameter */
9101 if (!yes)
9102 label_auto = NULL;
9103
e70e9f8e
PZ
9104 if (yes) {
9105 if (!label_auto)
9106 label = label_val; /* parser should force unsigned */
9107 }
ddb5b488 9108
0ca70ba5 9109 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9110 if (afi == AFI_MAX)
9111 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 9112
e70e9f8e 9113
69b07479
DS
9114 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9115 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
9116 /* no change */
9117 return CMD_SUCCESS;
e70e9f8e 9118
69b07479
DS
9119 /*
9120 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9121 */
9122 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9123 bgp_get_default(), bgp);
9124
9125 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9126 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
9127
9128 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
9129
9130 /*
9131 * label has previously been automatically
9132 * assigned by labelpool: release it
9133 *
9134 * NB if tovpn_label == MPLS_LABEL_NONE it
9135 * means the automatic assignment is in flight
9136 * and therefore the labelpool callback must
9137 * detect that the auto label is not needed.
9138 */
9139
9140 bgp_lp_release(LP_TYPE_VRF,
9141 &bgp->vpn_policy[afi],
9142 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 9143 }
69b07479
DS
9144 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9145 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9146 }
ddb5b488 9147
69b07479
DS
9148 bgp->vpn_policy[afi].tovpn_label = label;
9149 if (label_auto) {
9150 SET_FLAG(bgp->vpn_policy[afi].flags,
9151 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9152 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
9153 vpn_leak_label_callback);
ddb5b488
PZ
9154 }
9155
69b07479
DS
9156 /* post-change: re-export vpn routes */
9157 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9158 bgp_get_default(), bgp);
9159
ddb5b488
PZ
9160 return CMD_SUCCESS;
9161}
9162
b9c7bc5a
PZ
9163ALIAS (af_label_vpn_export,
9164 af_no_label_vpn_export_cmd,
9165 "no label vpn export",
9166 NO_STR
9167 "label value for VRF\n"
9168 "Between current address-family and vpn\n"
9169 "For routes leaked from current address-family to vpn\n")
ddb5b488 9170
37a87b8f 9171DEFPY_YANG (af_nexthop_vpn_export,
b9c7bc5a 9172 af_nexthop_vpn_export_cmd,
8c85ca28 9173 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
b9c7bc5a 9174 NO_STR
ddb5b488 9175 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
9176 "Between current address-family and vpn\n"
9177 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
9178 "IPv4 prefix\n"
9179 "IPv6 prefix\n")
9180{
37a87b8f 9181 char base_xpath[XPATH_MAXLEN];
ddb5b488 9182 afi_t afi;
37a87b8f
CS
9183 safi_t safi;
9184 int idx = 0;
ddb5b488
PZ
9185 struct prefix p;
9186
8c85ca28
QY
9187 if (!no) {
9188 if (!nexthop_su) {
9189 vty_out(vty, "%% Nexthop required\n");
9190 return CMD_WARNING_CONFIG_FAILED;
9191 }
8c85ca28 9192 if (!sockunion2hostprefix(nexthop_su, &p))
b9c7bc5a
PZ
9193 return CMD_WARNING_CONFIG_FAILED;
9194 }
ddb5b488 9195
37a87b8f
CS
9196 afi = bgp_node_afi(vty);
9197 safi = bgp_node_safi(vty);
ddb5b488 9198
37a87b8f
CS
9199 snprintf(
9200 base_xpath, sizeof(base_xpath),
9201 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9202 yang_afi_safi_value2identity(afi, safi),
9203 bgp_afi_safi_get_container_str(afi, safi));
ddb5b488 9204
37a87b8f
CS
9205 if (argv_find(argv, argc, "no", &idx))
9206 nb_cli_enqueue_change(vty, "./nexthop", NB_OP_DESTROY, NULL);
9207 else
9208 nb_cli_enqueue_change(vty, "./nexthop", NB_OP_MODIFY,
9209 nexthop_su_str);
ddb5b488 9210
37a87b8f
CS
9211 return nb_cli_apply_changes(vty, base_xpath);
9212}
69b07479 9213
37a87b8f
CS
9214void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_nexthop(
9215 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9216{
9217 int indent = 2;
9218
9219 vty_out(vty, "%*snexthop vpn export %s\n", indent, "",
9220 yang_dnode_get_string(dnode, NULL));
ddb5b488
PZ
9221}
9222
b9c7bc5a 9223static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 9224{
b9c7bc5a
PZ
9225 if (!strcmp(dstr, "import")) {
9226 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9227 } else if (!strcmp(dstr, "export")) {
9228 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9229 } else if (!strcmp(dstr, "both")) {
9230 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9231 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9232 } else {
9233 vty_out(vty, "%% direction parse error\n");
9234 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9235 }
ddb5b488
PZ
9236 return CMD_SUCCESS;
9237}
9238
b9c7bc5a
PZ
9239DEFPY (af_rt_vpn_imexport,
9240 af_rt_vpn_imexport_cmd,
9241 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9242 NO_STR
9243 "Specify route target list\n"
ddb5b488 9244 "Specify route target list\n"
b9c7bc5a
PZ
9245 "Between current address-family and vpn\n"
9246 "For routes leaked from vpn to current address-family: match any\n"
9247 "For routes leaked from current address-family to vpn: set\n"
9248 "both import: match any and export: set\n"
ddb5b488
PZ
9249 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9250{
9251 VTY_DECLVAR_CONTEXT(bgp, bgp);
9252 int ret;
9253 struct ecommunity *ecom = NULL;
9254 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
9255 vpn_policy_direction_t dir;
9256 afi_t afi;
9257 int idx = 0;
c6423c31 9258 bool yes = true;
ddb5b488 9259
b9c7bc5a 9260 if (argv_find(argv, argc, "no", &idx))
c6423c31 9261 yes = false;
b9c7bc5a 9262
0ca70ba5 9263 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9264 if (afi == AFI_MAX)
9265 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9266
b9c7bc5a 9267 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
9268 if (ret != CMD_SUCCESS)
9269 return ret;
9270
b9c7bc5a
PZ
9271 if (yes) {
9272 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9273 vty_out(vty, "%% Missing RTLIST\n");
9274 return CMD_WARNING_CONFIG_FAILED;
9275 }
c6423c31 9276 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
b9c7bc5a
PZ
9277 if (ret != CMD_SUCCESS) {
9278 return ret;
9279 }
ddb5b488
PZ
9280 }
9281
69b07479
DS
9282 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9283 if (!dodir[dir])
ddb5b488 9284 continue;
ddb5b488 9285
69b07479 9286 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 9287
69b07479
DS
9288 if (yes) {
9289 if (bgp->vpn_policy[afi].rtlist[dir])
9290 ecommunity_free(
9291 &bgp->vpn_policy[afi].rtlist[dir]);
9292 bgp->vpn_policy[afi].rtlist[dir] =
9293 ecommunity_dup(ecom);
9294 } else {
9295 if (bgp->vpn_policy[afi].rtlist[dir])
9296 ecommunity_free(
9297 &bgp->vpn_policy[afi].rtlist[dir]);
9298 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 9299 }
69b07479
DS
9300
9301 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 9302 }
69b07479 9303
d555f3e9
PZ
9304 if (ecom)
9305 ecommunity_free(&ecom);
ddb5b488
PZ
9306
9307 return CMD_SUCCESS;
9308}
9309
b9c7bc5a
PZ
9310ALIAS (af_rt_vpn_imexport,
9311 af_no_rt_vpn_imexport_cmd,
9312 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
9313 NO_STR
9314 "Specify route target list\n"
b9c7bc5a
PZ
9315 "Specify route target list\n"
9316 "Between current address-family and vpn\n"
9317 "For routes leaked from vpn to current address-family\n"
9318 "For routes leaked from current address-family to vpn\n"
9319 "both import and export\n")
9320
37a87b8f 9321DEFPY_YANG (af_route_map_vpn_imexport,
b9c7bc5a
PZ
9322 af_route_map_vpn_imexport_cmd,
9323/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9324 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9325 NO_STR
ddb5b488 9326 "Specify route map\n"
b9c7bc5a
PZ
9327 "Between current address-family and vpn\n"
9328 "For routes leaked from vpn to current address-family\n"
9329 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
9330 "name of route-map\n")
9331{
37a87b8f 9332 char base_xpath[XPATH_MAXLEN];
ddb5b488 9333 afi_t afi;
37a87b8f 9334 safi_t safi;
ddb5b488 9335 int idx = 0;
ddb5b488 9336
37a87b8f
CS
9337 afi = bgp_node_afi(vty);
9338 safi = bgp_node_safi(vty);
ddb5b488 9339
37a87b8f
CS
9340 snprintf(
9341 base_xpath, sizeof(base_xpath),
9342 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9343 yang_afi_safi_value2identity(afi, safi),
9344 bgp_afi_safi_get_container_str(afi, safi));
9345
9346 if (argv_find(argv, argc, "no", &idx)) {
9347 if (!strcmp(direction_str, "import"))
9348 nb_cli_enqueue_change(vty, "./rmap-import",
9349 NB_OP_DESTROY, NULL);
9350 else if (!strcmp(direction_str, "export"))
9351 nb_cli_enqueue_change(vty, "./rmap-export",
9352 NB_OP_DESTROY, NULL);
9353 } else {
9354 if (!strcmp(direction_str, "import"))
9355 nb_cli_enqueue_change(vty, "./rmap-import",
9356 NB_OP_MODIFY, rmap_str);
9357 if (!strcmp(direction_str, "export"))
9358 nb_cli_enqueue_change(vty, "./rmap-export",
9359 NB_OP_MODIFY, rmap_str);
9360 }
9361 return nb_cli_apply_changes(vty, base_xpath);
9362}
ddb5b488 9363
37a87b8f
CS
9364void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_import(
9365 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9366{
9367 int indent = 2;
ddb5b488 9368
37a87b8f
CS
9369 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
9370 yang_dnode_get_string(dnode, NULL));
9371}
69b07479 9372
37a87b8f
CS
9373void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_export(
9374 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9375{
9376 int indent = 2;
ddb5b488 9377
37a87b8f
CS
9378 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
9379 yang_dnode_get_string(dnode, NULL));
ddb5b488
PZ
9380}
9381
b9c7bc5a
PZ
9382ALIAS (af_route_map_vpn_imexport,
9383 af_no_route_map_vpn_imexport_cmd,
9384 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
9385 NO_STR
9386 "Specify route map\n"
b9c7bc5a
PZ
9387 "Between current address-family and vpn\n"
9388 "For routes leaked from vpn to current address-family\n"
9389 "For routes leaked from current address-family to vpn\n")
9390
bb4f6190 9391DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
ae6a6fb4 9392 "import vrf route-map RMAP$rmap_str",
bb4f6190
DS
9393 "Import routes from another VRF\n"
9394 "Vrf routes being filtered\n"
9395 "Specify route map\n"
9396 "name of route-map\n")
9397{
9398 VTY_DECLVAR_CONTEXT(bgp, bgp);
bb4f6190
DS
9399 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
9400 afi_t afi;
bb4f6190
DS
9401 struct bgp *bgp_default;
9402
0ca70ba5 9403 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
9404 if (afi == AFI_MAX)
9405 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
9406
9407 bgp_default = bgp_get_default();
9408 if (!bgp_default) {
9409 int32_t ret;
9410 as_t as = bgp->as;
9411
9412 /* Auto-create assuming the same AS */
5d5393b9
DL
9413 ret = bgp_get_vty(&bgp_default, &as, NULL,
9414 BGP_INSTANCE_TYPE_DEFAULT);
bb4f6190
DS
9415
9416 if (ret) {
9417 vty_out(vty,
9418 "VRF default is not configured as a bgp instance\n");
9419 return CMD_WARNING;
9420 }
9421 }
9422
69b07479 9423 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 9424
ae6a6fb4
DS
9425 if (bgp->vpn_policy[afi].rmap_name[dir])
9426 XFREE(MTYPE_ROUTE_MAP_NAME,
9427 bgp->vpn_policy[afi].rmap_name[dir]);
9428 bgp->vpn_policy[afi].rmap_name[dir] =
9429 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9430 bgp->vpn_policy[afi].rmap[dir] =
9431 route_map_lookup_warn_noexist(vty, rmap_str);
9432 if (!bgp->vpn_policy[afi].rmap[dir])
9433 return CMD_SUCCESS;
9434
9435 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9436 BGP_CONFIG_VRF_TO_VRF_IMPORT);
bb4f6190 9437
69b07479
DS
9438 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9439
bb4f6190
DS
9440 return CMD_SUCCESS;
9441}
9442
ae6a6fb4
DS
9443DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9444 "no import vrf route-map [RMAP$rmap_str]",
bb4f6190
DS
9445 NO_STR
9446 "Import routes from another VRF\n"
9447 "Vrf routes being filtered\n"
ae6a6fb4
DS
9448 "Specify route map\n"
9449 "name of route-map\n")
9450{
9451 VTY_DECLVAR_CONTEXT(bgp, bgp);
9452 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
9453 afi_t afi;
9454
9455 afi = vpn_policy_getafi(vty, bgp, true);
9456 if (afi == AFI_MAX)
9457 return CMD_WARNING_CONFIG_FAILED;
9458
9459 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9460
9461 if (bgp->vpn_policy[afi].rmap_name[dir])
9462 XFREE(MTYPE_ROUTE_MAP_NAME,
9463 bgp->vpn_policy[afi].rmap_name[dir]);
9464 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9465 bgp->vpn_policy[afi].rmap[dir] = NULL;
9466
9467 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9468 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9469 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9470
9471 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9472
9473 return CMD_SUCCESS;
9474}
bb4f6190 9475
37a87b8f
CS
9476DEFPY_YANG(bgp_imexport_vrf,
9477 bgp_imexport_vrf_cmd,
9478 "[no] import vrf VIEWVRFNAME$import_name",
9479 NO_STR
9480 "Import routes from another VRF\n"
9481 "VRF to import from\n"
9482 "The name of the VRF\n")
12a844a5 9483{
37a87b8f 9484 char base_xpath[XPATH_MAXLEN];
12a844a5
DS
9485 safi_t safi;
9486 afi_t afi;
37a87b8f 9487 int32_t idx = 0;
12a844a5 9488
867f0cca 9489 if (import_name == NULL) {
9490 vty_out(vty, "%% Missing import name\n");
9491 return CMD_WARNING;
9492 }
9493
ae6a6fb4
DS
9494 if (strcmp(import_name, "route-map") == 0) {
9495 vty_out(vty, "%% Must include route-map name\n");
9496 return CMD_WARNING;
9497 }
9498
37a87b8f 9499 afi = bgp_node_afi(vty);
12a844a5
DS
9500 safi = bgp_node_safi(vty);
9501
37a87b8f
CS
9502 snprintf(
9503 base_xpath, sizeof(base_xpath),
9504 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/import-vrf-list[vrf='%s']",
9505 yang_afi_safi_value2identity(afi, safi),
9506 bgp_afi_safi_get_container_str(afi, safi), import_name);
25679caa 9507
37a87b8f
CS
9508 if (argv_find(argv, argc, "no", &idx))
9509 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
9510 else
9511 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
12a844a5 9512
37a87b8f
CS
9513 return nb_cli_apply_changes(vty, base_xpath);
9514}
12a844a5 9515
37a87b8f
CS
9516void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vrfs(
9517 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9518{
9519 vty_out(vty, " import vrf %s\n",
9520 yang_dnode_get_string(dnode, "./vrf"));
12a844a5
DS
9521}
9522
b9c7bc5a 9523/* This command is valid only in a bgp vrf instance or the default instance */
37a87b8f 9524DEFPY_YANG (bgp_imexport_vpn,
b9c7bc5a
PZ
9525 bgp_imexport_vpn_cmd,
9526 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
9527 NO_STR
9528 "Import routes to this address-family\n"
9529 "Export routes from this address-family\n"
9530 "to/from default instance VPN RIB\n")
ddb5b488 9531{
37a87b8f 9532 char base_xpath[XPATH_MAXLEN];
b9c7bc5a 9533 safi_t safi;
37a87b8f
CS
9534 afi_t afi;
9535 int32_t idx = 0;
ddb5b488 9536
b9c7bc5a
PZ
9537 afi = bgp_node_afi(vty);
9538 safi = bgp_node_safi(vty);
ddb5b488 9539
b9c7bc5a 9540 if (!strcmp(direction_str, "import")) {
37a87b8f
CS
9541 snprintf(
9542 base_xpath, sizeof(base_xpath),
9543 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/import-vpn",
9544 yang_afi_safi_value2identity(afi, safi),
9545 bgp_afi_safi_get_container_str(afi, safi));
b9c7bc5a 9546 } else if (!strcmp(direction_str, "export")) {
37a87b8f
CS
9547 snprintf(
9548 base_xpath, sizeof(base_xpath),
9549 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/export-vpn",
9550 yang_afi_safi_value2identity(afi, safi),
9551 bgp_afi_safi_get_container_str(afi, safi));
b9c7bc5a
PZ
9552 } else {
9553 vty_out(vty, "%% unknown direction %s\n", direction_str);
9554 return CMD_WARNING_CONFIG_FAILED;
9555 }
9556
37a87b8f
CS
9557 if (argv_find(argv, argc, "no", &idx))
9558 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
9559 else
9560 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, "true");
ddb5b488 9561
37a87b8f
CS
9562 return nb_cli_apply_changes(vty, base_xpath);
9563}
ddb5b488 9564
37a87b8f
CS
9565void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vpn(
9566 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9567{
9568 if (yang_dnode_get_bool(dnode, NULL))
9569 vty_out(vty, " import vpn\n");
9570}
9571
9572void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_export_vpn(
9573 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9574{
9575 if (yang_dnode_get_bool(dnode, NULL))
9576 vty_out(vty, " export vpn\n");
ddb5b488
PZ
9577}
9578
301ad80a
PG
9579DEFPY (af_routetarget_import,
9580 af_routetarget_import_cmd,
9a659715 9581 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
301ad80a
PG
9582 NO_STR
9583 "Specify route target list\n"
9584 "Specify route target list\n"
9a659715
PG
9585 "Specify route target list\n"
9586 "Specify route target list\n"
301ad80a
PG
9587 "Flow-spec redirect type route target\n"
9588 "Import routes to this address-family\n"
9a659715 9589 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
301ad80a
PG
9590{
9591 VTY_DECLVAR_CONTEXT(bgp, bgp);
9592 int ret;
9593 struct ecommunity *ecom = NULL;
301ad80a 9594 afi_t afi;
9a659715 9595 int idx = 0, idx_unused = 0;
c6423c31
PG
9596 bool yes = true;
9597 bool rt6 = false;
301ad80a
PG
9598
9599 if (argv_find(argv, argc, "no", &idx))
c6423c31 9600 yes = false;
301ad80a 9601
9a659715
PG
9602 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9603 argv_find(argv, argc, "route-target6", &idx_unused))
c6423c31 9604 rt6 = true;
301ad80a 9605
0ca70ba5 9606 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9607 if (afi == AFI_MAX)
9608 return CMD_WARNING_CONFIG_FAILED;
9609
9a659715
PG
9610 if (rt6 && afi != AFI_IP6)
9611 return CMD_WARNING_CONFIG_FAILED;
9612
301ad80a
PG
9613 if (yes) {
9614 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9615 vty_out(vty, "%% Missing RTLIST\n");
9616 return CMD_WARNING_CONFIG_FAILED;
9617 }
9a659715 9618 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
301ad80a
PG
9619 if (ret != CMD_SUCCESS)
9620 return ret;
9621 }
69b07479
DS
9622
9623 if (yes) {
9624 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9625 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9626 .import_redirect_rtlist);
69b07479
DS
9627 bgp->vpn_policy[afi].import_redirect_rtlist =
9628 ecommunity_dup(ecom);
9629 } else {
9630 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9631 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9632 .import_redirect_rtlist);
69b07479 9633 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 9634 }
69b07479 9635
301ad80a
PG
9636 if (ecom)
9637 ecommunity_free(&ecom);
9638
9639 return CMD_SUCCESS;
9640}
9641
37a87b8f
CS
9642void cli_show_bgp_global_afi_safi_header(struct vty *vty,
9643 struct lyd_node *dnode,
9644 bool show_defaults)
9645{
9646 const char *af_name;
9647 afi_t afi;
9648 safi_t safi;
9649
9650 af_name = yang_dnode_get_string(dnode, "./afi-safi-name");
9651 yang_afi_safi_identity2value(af_name, &afi, &safi);
9652
9653 vty_out(vty, " !\n address-family ");
9654 if (afi == AFI_IP) {
9655 if (safi == SAFI_UNICAST)
9656 vty_out(vty, "ipv4 unicast");
9657 else if (safi == SAFI_LABELED_UNICAST)
9658 vty_out(vty, "ipv4 labeled-unicast");
9659 else if (safi == SAFI_MULTICAST)
9660 vty_out(vty, "ipv4 multicast");
9661 else if (safi == SAFI_MPLS_VPN)
9662 vty_out(vty, "ipv4 vpn");
9663 else if (safi == SAFI_ENCAP)
9664 vty_out(vty, "ipv4 encap");
9665 else if (safi == SAFI_FLOWSPEC)
9666 vty_out(vty, "ipv4 flowspec");
9667 } else if (afi == AFI_IP6) {
9668 if (safi == SAFI_UNICAST)
9669 vty_out(vty, "ipv6 unicast");
9670 else if (safi == SAFI_LABELED_UNICAST)
9671 vty_out(vty, "ipv6 labeled-unicast");
9672 else if (safi == SAFI_MULTICAST)
9673 vty_out(vty, "ipv6 multicast");
9674 else if (safi == SAFI_MPLS_VPN)
9675 vty_out(vty, "ipv6 vpn");
9676 else if (safi == SAFI_ENCAP)
9677 vty_out(vty, "ipv6 encap");
9678 else if (safi == SAFI_FLOWSPEC)
9679 vty_out(vty, "ipv6 flowspec");
9680 } else if (afi == AFI_L2VPN) {
9681 if (safi == SAFI_EVPN)
9682 vty_out(vty, "l2vpn evpn");
9683 }
9684 vty_out(vty, "\n");
9685}
9686
505e5056 9687DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 9688 address_family_ipv4_safi_cmd,
9689 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9690 "Enter Address Family command mode\n"
9691 "Address Family\n"
9692 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 9693{
f51bae9c 9694
37a87b8f
CS
9695 safi_t safi = SAFI_UNICAST;
9696 const struct lyd_node *vrf_dnode, *bgp_glb_dnode;
9697 const char *vrf_name = NULL;
9698
d62a17ae 9699 if (argc == 3) {
37a87b8f
CS
9700 safi = bgp_vty_safi_from_str(argv[2]->text);
9701
9702 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
9703 VTY_CURR_XPATH);
9704 vrf_dnode = yang_dnode_get_parent(bgp_glb_dnode,
9705 "control-plane-protocol");
9706 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
9707
9708 if (!strmatch(vrf_name, VRF_DEFAULT_NAME)
a4d82a8a 9709 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9710 && safi != SAFI_EVPN) {
31947174
MK
9711 vty_out(vty,
9712 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9713 return CMD_WARNING_CONFIG_FAILED;
9714 }
37a87b8f
CS
9715 }
9716 vty->node = bgp_node_type(AFI_IP, safi);
718e3744 9717
d62a17ae 9718 return CMD_SUCCESS;
718e3744 9719}
9720
505e5056 9721DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 9722 address_family_ipv6_safi_cmd,
9723 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9724 "Enter Address Family command mode\n"
9725 "Address Family\n"
9726 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 9727{
37a87b8f
CS
9728 safi_t safi = SAFI_UNICAST;
9729 const struct lyd_node *vrf_dnode, *bgp_glb_dnode;
9730 const char *vrf_name = NULL;
9731
d62a17ae 9732 if (argc == 3) {
37a87b8f
CS
9733 safi = bgp_vty_safi_from_str(argv[2]->text);
9734 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
9735 VTY_CURR_XPATH);
9736 vrf_dnode = yang_dnode_get_parent(bgp_glb_dnode,
9737 "control-plane-protocol");
9738 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
9739
9740 if (!strmatch(vrf_name, VRF_DEFAULT_NAME)
a4d82a8a 9741 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9742 && safi != SAFI_EVPN) {
31947174
MK
9743 vty_out(vty,
9744 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9745 return CMD_WARNING_CONFIG_FAILED;
9746 }
37a87b8f
CS
9747 }
9748 vty->node = bgp_node_type(AFI_IP6, safi);
25ffbdc1 9749
d62a17ae 9750 return CMD_SUCCESS;
25ffbdc1 9751}
718e3744 9752
d6902373 9753#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 9754DEFUN_NOSH (address_family_vpnv4,
718e3744 9755 address_family_vpnv4_cmd,
8334fd5a 9756 "address-family vpnv4 [unicast]",
718e3744 9757 "Enter Address Family command mode\n"
8c3deaae 9758 "Address Family\n"
3a2d747c 9759 "Address Family modifier\n")
718e3744 9760{
d62a17ae 9761 vty->node = BGP_VPNV4_NODE;
9762 return CMD_SUCCESS;
718e3744 9763}
9764
505e5056 9765DEFUN_NOSH (address_family_vpnv6,
8ecd3266 9766 address_family_vpnv6_cmd,
8334fd5a 9767 "address-family vpnv6 [unicast]",
8ecd3266 9768 "Enter Address Family command mode\n"
8c3deaae 9769 "Address Family\n"
3a2d747c 9770 "Address Family modifier\n")
8ecd3266 9771{
d62a17ae 9772 vty->node = BGP_VPNV6_NODE;
9773 return CMD_SUCCESS;
8ecd3266 9774}
64e4a6c5 9775#endif /* KEEP_OLD_VPN_COMMANDS */
d6902373 9776
505e5056 9777DEFUN_NOSH (address_family_evpn,
4e0b7b6d 9778 address_family_evpn_cmd,
7111c1a0 9779 "address-family l2vpn evpn",
4e0b7b6d 9780 "Enter Address Family command mode\n"
7111c1a0
QY
9781 "Address Family\n"
9782 "Address Family modifier\n")
4e0b7b6d 9783{
2131d5cf 9784 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 9785 vty->node = BGP_EVPN_NODE;
9786 return CMD_SUCCESS;
4e0b7b6d
PG
9787}
9788
505e5056 9789DEFUN_NOSH (exit_address_family,
718e3744 9790 exit_address_family_cmd,
9791 "exit-address-family",
9792 "Exit from Address Family configuration mode\n")
9793{
d62a17ae 9794 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9795 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9796 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9797 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
9798 || vty->node == BGP_EVPN_NODE
9799 || vty->node == BGP_FLOWSPECV4_NODE
9800 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 9801 vty->node = BGP_NODE;
9802 return CMD_SUCCESS;
718e3744 9803}
6b0655a2 9804
37a87b8f
CS
9805void cli_show_bgp_global_afi_safi_header_end(struct vty *vty,
9806 struct lyd_node *dnode
9807 __attribute__((__unused__)))
9808{
9809 vty_out(vty, " exit-address-family\n");
9810}
9811
8ad7271d 9812/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 9813static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9814 const char *ip_str, afi_t afi, safi_t safi,
9815 struct prefix_rd *prd)
9816{
9817 int ret;
9818 struct prefix match;
9bcb3eef
DS
9819 struct bgp_dest *dest;
9820 struct bgp_dest *rm;
d62a17ae 9821 struct bgp *bgp;
9822 struct bgp_table *table;
9823 struct bgp_table *rib;
9824
9825 /* BGP structure lookup. */
9826 if (view_name) {
9827 bgp = bgp_lookup_by_name(view_name);
9828 if (bgp == NULL) {
9829 vty_out(vty, "%% Can't find BGP instance %s\n",
9830 view_name);
9831 return CMD_WARNING;
9832 }
9833 } else {
9834 bgp = bgp_get_default();
9835 if (bgp == NULL) {
9836 vty_out(vty, "%% No BGP process is configured\n");
9837 return CMD_WARNING;
9838 }
9839 }
9840
9841 /* Check IP address argument. */
9842 ret = str2prefix(ip_str, &match);
9843 if (!ret) {
9844 vty_out(vty, "%% address is malformed\n");
9845 return CMD_WARNING;
9846 }
9847
9848 match.family = afi2family(afi);
9849 rib = bgp->rib[afi][safi];
9850
9851 if (safi == SAFI_MPLS_VPN) {
9bcb3eef
DS
9852 for (dest = bgp_table_top(rib); dest;
9853 dest = bgp_route_next(dest)) {
9854 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 9855
9bcb3eef 9856 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
d62a17ae 9857 continue;
9858
9bcb3eef 9859 table = bgp_dest_get_bgp_table_info(dest);
b54892e0
DS
9860 if (table == NULL)
9861 continue;
9862
9863 if ((rm = bgp_node_match(table, &match)) != NULL) {
9864 const struct prefix *rm_p =
9bcb3eef 9865 bgp_dest_get_prefix(rm);
b54892e0
DS
9866
9867 if (rm_p->prefixlen == match.prefixlen) {
9868 SET_FLAG(rm->flags,
9869 BGP_NODE_USER_CLEAR);
9870 bgp_process(bgp, rm, afi, safi);
d62a17ae 9871 }
9bcb3eef 9872 bgp_dest_unlock_node(rm);
d62a17ae 9873 }
9874 }
9875 } else {
9bcb3eef
DS
9876 if ((dest = bgp_node_match(rib, &match)) != NULL) {
9877 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 9878
9bcb3eef
DS
9879 if (dest_p->prefixlen == match.prefixlen) {
9880 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
9881 bgp_process(bgp, dest, afi, safi);
d62a17ae 9882 }
9bcb3eef 9883 bgp_dest_unlock_node(dest);
d62a17ae 9884 }
9885 }
9886
9887 return CMD_SUCCESS;
8ad7271d
DS
9888}
9889
b09b5ae0 9890/* one clear bgp command to rule them all */
718e3744 9891DEFUN (clear_ip_bgp_all,
9892 clear_ip_bgp_all_cmd,
453c92f6 9893 "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 9894 CLEAR_STR
9895 IP_STR
9896 BGP_STR
838758ac 9897 BGP_INSTANCE_HELP_STR
510afcd6 9898 BGP_AFI_HELP_STR
fd5e7b70 9899 "Address Family\n"
510afcd6 9900 BGP_SAFI_WITH_LABEL_HELP_STR
fd5e7b70 9901 "Address Family modifier\n"
b09b5ae0 9902 "Clear all peers\n"
453c92f6 9903 "BGP IPv4 neighbor to clear\n"
a80beece 9904 "BGP IPv6 neighbor to clear\n"
838758ac 9905 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
9906 "Clear peers with the AS number\n"
9907 "Clear all external peers\n"
718e3744 9908 "Clear all members of peer-group\n"
b09b5ae0 9909 "BGP peer-group name\n"
b09b5ae0
DW
9910 BGP_SOFT_STR
9911 BGP_SOFT_IN_STR
b09b5ae0
DW
9912 BGP_SOFT_OUT_STR
9913 BGP_SOFT_IN_STR
9914 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 9915 BGP_SOFT_OUT_STR)
718e3744 9916{
d62a17ae 9917 char *vrf = NULL;
9918
dc912615
DS
9919 afi_t afi = AFI_UNSPEC;
9920 safi_t safi = SAFI_UNSPEC;
d62a17ae 9921 enum clear_sort clr_sort = clear_peer;
9922 enum bgp_clear_type clr_type;
9923 char *clr_arg = NULL;
9924
9925 int idx = 0;
ff8a8a7a
CS
9926 char errmsg[BUFSIZ] = {'\0'};
9927 int ret;
d62a17ae 9928
9929 /* clear [ip] bgp */
9930 if (argv_find(argv, argc, "ip", &idx))
9931 afi = AFI_IP;
9932
9a8bdf1c
PG
9933 /* [<vrf> VIEWVRFNAME] */
9934 if (argv_find(argv, argc, "vrf", &idx)) {
9935 vrf = argv[idx + 1]->arg;
9936 idx += 2;
9937 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9938 vrf = NULL;
9939 } else if (argv_find(argv, argc, "view", &idx)) {
9940 /* [<view> VIEWVRFNAME] */
d62a17ae 9941 vrf = argv[idx + 1]->arg;
9942 idx += 2;
9943 }
d62a17ae 9944 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9945 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
9946 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9947
d7b9898c 9948 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
d62a17ae 9949 if (argv_find(argv, argc, "*", &idx)) {
9950 clr_sort = clear_all;
9951 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
9952 clr_sort = clear_peer;
9953 clr_arg = argv[idx]->arg;
9954 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
9955 clr_sort = clear_peer;
9956 clr_arg = argv[idx]->arg;
9957 } else if (argv_find(argv, argc, "peer-group", &idx)) {
9958 clr_sort = clear_group;
9959 idx++;
9960 clr_arg = argv[idx]->arg;
d7b9898c 9961 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
d62a17ae 9962 clr_sort = clear_peer;
9963 clr_arg = argv[idx]->arg;
8fa7d444
DS
9964 } else if (argv_find(argv, argc, "WORD", &idx)) {
9965 clr_sort = clear_peer;
9966 clr_arg = argv[idx]->arg;
d62a17ae 9967 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
9968 clr_sort = clear_as;
9969 clr_arg = argv[idx]->arg;
9970 } else if (argv_find(argv, argc, "external", &idx)) {
9971 clr_sort = clear_external;
9972 }
9973
9974 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
9975 if (argv_find(argv, argc, "soft", &idx)) {
9976 if (argv_find(argv, argc, "in", &idx)
9977 || argv_find(argv, argc, "out", &idx))
9978 clr_type = strmatch(argv[idx]->text, "in")
9979 ? BGP_CLEAR_SOFT_IN
9980 : BGP_CLEAR_SOFT_OUT;
9981 else
9982 clr_type = BGP_CLEAR_SOFT_BOTH;
9983 } else if (argv_find(argv, argc, "in", &idx)) {
9984 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
9985 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
9986 : BGP_CLEAR_SOFT_IN;
9987 } else if (argv_find(argv, argc, "out", &idx)) {
9988 clr_type = BGP_CLEAR_SOFT_OUT;
9989 } else
9990 clr_type = BGP_CLEAR_SOFT_NONE;
9991
ff8a8a7a
CS
9992 ret = bgp_clear_vty(vrf, afi, safi, clr_sort, clr_type, clr_arg, errmsg,
9993 sizeof(errmsg));
9994 if (ret != NB_OK)
9995 vty_out(vty, "Error description: %s\n", errmsg);
9996
9997 return ret;
838758ac 9998}
01080f7c 9999
8ad7271d
DS
10000DEFUN (clear_ip_bgp_prefix,
10001 clear_ip_bgp_prefix_cmd,
18c57037 10002 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
10003 CLEAR_STR
10004 IP_STR
10005 BGP_STR
838758ac 10006 BGP_INSTANCE_HELP_STR
8ad7271d 10007 "Clear bestpath and re-advertise\n"
0c7b1b01 10008 "IPv4 prefix\n")
8ad7271d 10009{
d62a17ae 10010 char *vrf = NULL;
10011 char *prefix = NULL;
8ad7271d 10012
d62a17ae 10013 int idx = 0;
01080f7c 10014
d62a17ae 10015 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
10016 if (argv_find(argv, argc, "vrf", &idx)) {
10017 vrf = argv[idx + 1]->arg;
10018 idx += 2;
10019 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10020 vrf = NULL;
10021 } else if (argv_find(argv, argc, "view", &idx)) {
10022 /* [<view> VIEWVRFNAME] */
10023 vrf = argv[idx + 1]->arg;
10024 idx += 2;
10025 }
0c7b1b01 10026
d62a17ae 10027 prefix = argv[argc - 1]->arg;
8ad7271d 10028
d62a17ae 10029 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 10030}
8ad7271d 10031
b09b5ae0
DW
10032DEFUN (clear_bgp_ipv6_safi_prefix,
10033 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 10034 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 10035 CLEAR_STR
3a2d747c 10036 IP_STR
718e3744 10037 BGP_STR
8c3deaae 10038 "Address Family\n"
46f296b4 10039 BGP_SAFI_HELP_STR
b09b5ae0 10040 "Clear bestpath and re-advertise\n"
0c7b1b01 10041 "IPv6 prefix\n")
718e3744 10042{
9b475e76
PG
10043 int idx_safi = 0;
10044 int idx_ipv6_prefix = 0;
10045 safi_t safi = SAFI_UNICAST;
10046 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10047 argv[idx_ipv6_prefix]->arg : NULL;
10048
10049 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 10050 return bgp_clear_prefix(
9b475e76
PG
10051 vty, NULL, prefix, AFI_IP6,
10052 safi, NULL);
838758ac 10053}
01080f7c 10054
b09b5ae0
DW
10055DEFUN (clear_bgp_instance_ipv6_safi_prefix,
10056 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 10057 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 10058 CLEAR_STR
3a2d747c 10059 IP_STR
718e3744 10060 BGP_STR
838758ac 10061 BGP_INSTANCE_HELP_STR
8c3deaae 10062 "Address Family\n"
46f296b4 10063 BGP_SAFI_HELP_STR
b09b5ae0 10064 "Clear bestpath and re-advertise\n"
0c7b1b01 10065 "IPv6 prefix\n")
718e3744 10066{
9b475e76 10067 int idx_safi = 0;
9a8bdf1c 10068 int idx_vrfview = 0;
9b475e76
PG
10069 int idx_ipv6_prefix = 0;
10070 safi_t safi = SAFI_UNICAST;
10071 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10072 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 10073 char *vrfview = NULL;
9b475e76 10074
9a8bdf1c
PG
10075 /* [<view|vrf> VIEWVRFNAME] */
10076 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
10077 vrfview = argv[idx_vrfview + 1]->arg;
10078 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
10079 vrfview = NULL;
10080 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
10081 /* [<view> VIEWVRFNAME] */
10082 vrfview = argv[idx_vrfview + 1]->arg;
10083 }
9b475e76
PG
10084 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10085
d62a17ae 10086 return bgp_clear_prefix(
9b475e76
PG
10087 vty, vrfview, prefix,
10088 AFI_IP6, safi, NULL);
718e3744 10089}
10090
b09b5ae0
DW
10091DEFUN (show_bgp_views,
10092 show_bgp_views_cmd,
d6e3c605 10093 "show [ip] bgp views",
b09b5ae0 10094 SHOW_STR
d6e3c605 10095 IP_STR
01080f7c 10096 BGP_STR
b09b5ae0 10097 "Show the defined BGP views\n")
01080f7c 10098{
d62a17ae 10099 struct list *inst = bm->bgp;
10100 struct listnode *node;
10101 struct bgp *bgp;
01080f7c 10102
d62a17ae 10103 vty_out(vty, "Defined BGP views:\n");
10104 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10105 /* Skip VRFs. */
10106 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
10107 continue;
10108 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
10109 bgp->as);
10110 }
e52702f2 10111
d62a17ae 10112 return CMD_SUCCESS;
e0081f70
ML
10113}
10114
8386ac43 10115DEFUN (show_bgp_vrfs,
10116 show_bgp_vrfs_cmd,
d6e3c605 10117 "show [ip] bgp vrfs [json]",
8386ac43 10118 SHOW_STR
d6e3c605 10119 IP_STR
8386ac43 10120 BGP_STR
10121 "Show BGP VRFs\n"
9973d184 10122 JSON_STR)
8386ac43 10123{
fe1dc5a3 10124 char buf[ETHER_ADDR_STRLEN];
d62a17ae 10125 struct list *inst = bm->bgp;
10126 struct listnode *node;
10127 struct bgp *bgp;
9f049418 10128 bool uj = use_json(argc, argv);
d62a17ae 10129 json_object *json = NULL;
10130 json_object *json_vrfs = NULL;
10131 int count = 0;
d62a17ae 10132
d62a17ae 10133 if (uj) {
10134 json = json_object_new_object();
10135 json_vrfs = json_object_new_object();
10136 }
10137
10138 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10139 const char *name, *type;
10140 struct peer *peer;
7fe96307 10141 struct listnode *node2, *nnode2;
d62a17ae 10142 int peers_cfg, peers_estb;
10143 json_object *json_vrf = NULL;
d62a17ae 10144
10145 /* Skip Views. */
10146 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
10147 continue;
10148
10149 count++;
efb4077a 10150 if (!uj && count == 1) {
fe1dc5a3 10151 vty_out(vty,
efb4077a 10152 "%4s %-5s %-16s %9s %10s %-37s\n",
3c0e7aa4 10153 "Type", "Id", "routerId", "#PeersCfg",
efb4077a
CS
10154 "#PeersEstb", "Name");
10155 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
10156 "L3-VNI", "RouterMAC", "Interface");
10157 }
d62a17ae 10158
10159 peers_cfg = peers_estb = 0;
10160 if (uj)
10161 json_vrf = json_object_new_object();
10162
10163
7fe96307 10164 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
d62a17ae 10165 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10166 continue;
10167 peers_cfg++;
10168 if (peer->status == Established)
10169 peers_estb++;
10170 }
10171
10172 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
5742e42b 10173 name = VRF_DEFAULT_NAME;
d62a17ae 10174 type = "DFLT";
10175 } else {
10176 name = bgp->name;
10177 type = "VRF";
10178 }
10179
a8bf7d9c 10180
d62a17ae 10181 if (uj) {
a4d82a8a
PZ
10182 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10183 ? -1
10184 : (int64_t)bgp->vrf_id;
23d0a753
DA
10185 char buf[BUFSIZ] = {0};
10186
d62a17ae 10187 json_object_string_add(json_vrf, "type", type);
10188 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
10189 json_object_string_add(json_vrf, "routerId",
23d0a753
DA
10190 inet_ntop(AF_INET,
10191 &bgp->router_id, buf,
10192 sizeof(buf)));
d62a17ae 10193 json_object_int_add(json_vrf, "numConfiguredPeers",
10194 peers_cfg);
10195 json_object_int_add(json_vrf, "numEstablishedPeers",
10196 peers_estb);
10197
fe1dc5a3 10198 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
10199 json_object_string_add(
10200 json_vrf, "rmac",
10201 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
efb4077a
CS
10202 json_object_string_add(json_vrf, "interface",
10203 ifindex2ifname(bgp->l3vni_svi_ifindex,
10204 bgp->vrf_id));
d62a17ae 10205 json_object_object_add(json_vrfs, name, json_vrf);
efb4077a 10206 } else {
23d0a753 10207 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
a4d82a8a
PZ
10208 type,
10209 bgp->vrf_id == VRF_UNKNOWN ? -1
10210 : (int)bgp->vrf_id,
23d0a753 10211 &bgp->router_id, peers_cfg, peers_estb, name);
efb4077a
CS
10212 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
10213 bgp->l3vni,
10214 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
10215 ifindex2ifname(bgp->l3vni_svi_ifindex,
10216 bgp->vrf_id));
10217 }
d62a17ae 10218 }
10219
10220 if (uj) {
10221 json_object_object_add(json, "vrfs", json_vrfs);
10222
10223 json_object_int_add(json, "totalVrfs", count);
10224
996c9314
LB
10225 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10226 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 10227 json_object_free(json);
10228 } else {
10229 if (count)
10230 vty_out(vty,
10231 "\nTotal number of VRFs (including default): %d\n",
10232 count);
10233 }
10234
10235 return CMD_SUCCESS;
8386ac43 10236}
10237
48ecf8f5
DS
10238DEFUN (show_bgp_mac_hash,
10239 show_bgp_mac_hash_cmd,
10240 "show bgp mac hash",
10241 SHOW_STR
10242 BGP_STR
10243 "Mac Address\n"
10244 "Mac Address database\n")
10245{
10246 bgp_mac_dump_table(vty);
10247
10248 return CMD_SUCCESS;
10249}
acf71666 10250
e3b78da8 10251static void show_tip_entry(struct hash_bucket *bucket, void *args)
acf71666 10252{
0291c246 10253 struct vty *vty = (struct vty *)args;
e3b78da8 10254 struct tip_addr *tip = (struct tip_addr *)bucket->data;
acf71666 10255
23d0a753 10256 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
acf71666
MK
10257}
10258
10259static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10260{
10261 vty_out(vty, "self nexthop database:\n");
af97a18b 10262 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
10263
10264 vty_out(vty, "Tunnel-ip database:\n");
10265 hash_iterate(bgp->tip_hash,
e3b78da8 10266 (void (*)(struct hash_bucket *, void *))show_tip_entry,
acf71666
MK
10267 vty);
10268}
10269
15c81ca4
DS
10270DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10271 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10272 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
10273 "martian next-hops\n"
10274 "martian next-hop database\n")
acf71666 10275{
0291c246 10276 struct bgp *bgp = NULL;
15c81ca4 10277 int idx = 0;
9a8bdf1c
PG
10278 char *name = NULL;
10279
10280 /* [<vrf> VIEWVRFNAME] */
10281 if (argv_find(argv, argc, "vrf", &idx)) {
10282 name = argv[idx + 1]->arg;
10283 if (name && strmatch(name, VRF_DEFAULT_NAME))
10284 name = NULL;
10285 } else if (argv_find(argv, argc, "view", &idx))
10286 /* [<view> VIEWVRFNAME] */
10287 name = argv[idx + 1]->arg;
10288 if (name)
10289 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
10290 else
10291 bgp = bgp_get_default();
acf71666 10292
acf71666
MK
10293 if (!bgp) {
10294 vty_out(vty, "%% No BGP process is configured\n");
10295 return CMD_WARNING;
10296 }
10297 bgp_show_martian_nexthops(vty, bgp);
10298
10299 return CMD_SUCCESS;
10300}
10301
f412b39a 10302DEFUN (show_bgp_memory,
4bf6a362 10303 show_bgp_memory_cmd,
7fa12b13 10304 "show [ip] bgp memory",
4bf6a362 10305 SHOW_STR
3a2d747c 10306 IP_STR
4bf6a362
PJ
10307 BGP_STR
10308 "Global BGP memory statistics\n")
10309{
d62a17ae 10310 char memstrbuf[MTYPE_MEMSTR_LEN];
10311 unsigned long count;
10312
10313 /* RIB related usage stats */
10314 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10315 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10316 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9bcb3eef 10317 count * sizeof(struct bgp_dest)));
d62a17ae 10318
10319 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10320 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10321 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 10322 count * sizeof(struct bgp_path_info)));
d62a17ae 10323 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10324 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10325 count,
4b7e6066
DS
10326 mtype_memstr(
10327 memstrbuf, sizeof(memstrbuf),
10328 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 10329
10330 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10331 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10332 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10333 count * sizeof(struct bgp_static)));
10334
10335 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10336 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10337 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10338 count * sizeof(struct bpacket)));
10339
10340 /* Adj-In/Out */
10341 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10342 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10343 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10344 count * sizeof(struct bgp_adj_in)));
10345 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10346 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10347 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10348 count * sizeof(struct bgp_adj_out)));
10349
10350 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10351 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10352 count,
10353 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10354 count * sizeof(struct bgp_nexthop_cache)));
10355
10356 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10357 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10358 count,
10359 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10360 count * sizeof(struct bgp_damp_info)));
10361
10362 /* Attributes */
10363 count = attr_count();
10364 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10365 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10366 count * sizeof(struct attr)));
10367
10368 if ((count = attr_unknown_count()))
10369 vty_out(vty, "%ld unknown attributes\n", count);
10370
10371 /* AS_PATH attributes */
10372 count = aspath_count();
10373 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10374 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10375 count * sizeof(struct aspath)));
10376
10377 count = mtype_stats_alloc(MTYPE_AS_SEG);
10378 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10379 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10380 count * sizeof(struct assegment)));
10381
10382 /* Other attributes */
10383 if ((count = community_count()))
10384 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
10385 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10386 count * sizeof(struct community)));
d62a17ae 10387 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
10388 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
10389 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10390 count * sizeof(struct ecommunity)));
d62a17ae 10391 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10392 vty_out(vty,
10393 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
10394 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10395 count * sizeof(struct lcommunity)));
d62a17ae 10396
10397 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10398 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10399 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10400 count * sizeof(struct cluster_list)));
10401
10402 /* Peer related usage */
10403 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10404 vty_out(vty, "%ld peers, using %s of memory\n", count,
10405 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10406 count * sizeof(struct peer)));
10407
10408 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10409 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10410 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10411 count * sizeof(struct peer_group)));
10412
10413 /* Other */
d62a17ae 10414 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10415 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
10416 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10417 count * sizeof(regex_t)));
d62a17ae 10418 return CMD_SUCCESS;
4bf6a362 10419}
fee0f4c6 10420
57a9c8a8
DS
10421static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10422{
10423 json_object *bestpath = json_object_new_object();
10424
892fedb6 10425 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
57a9c8a8
DS
10426 json_object_string_add(bestpath, "asPath", "ignore");
10427
892fedb6 10428 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
57a9c8a8
DS
10429 json_object_string_add(bestpath, "asPath", "confed");
10430
892fedb6
DA
10431 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10432 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
a4d82a8a 10433 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
10434 "as-set");
10435 else
a4d82a8a 10436 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
10437 "true");
10438 } else
a4d82a8a 10439 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8 10440
892fedb6 10441 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
57a9c8a8 10442 json_object_string_add(bestpath, "compareRouterId", "true");
892fedb6
DA
10443 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10444 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10445 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
a4d82a8a 10446 json_object_string_add(bestpath, "med", "confed");
892fedb6 10447 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
57a9c8a8
DS
10448 json_object_string_add(bestpath, "med",
10449 "missing-as-worst");
10450 else
10451 json_object_string_add(bestpath, "med", "true");
10452 }
10453
10454 json_object_object_add(json, "bestPath", bestpath);
10455}
10456
3577f1c5
DD
10457/* Print the error code/subcode for why the peer is down */
10458static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10459 json_object *json_peer, bool use_json)
10460{
10461 const char *code_str;
10462 const char *subcode_str;
10463
10464 if (use_json) {
10465 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10466 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10467 char errorcodesubcode_hexstr[5];
10468 char errorcodesubcode_str[256];
10469
10470 code_str = bgp_notify_code_str(peer->notify.code);
10471 subcode_str = bgp_notify_subcode_str(
10472 peer->notify.code,
10473 peer->notify.subcode);
10474
772270f3
QY
10475 snprintf(errorcodesubcode_hexstr,
10476 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10477 peer->notify.code, peer->notify.subcode);
3577f1c5
DD
10478 json_object_string_add(json_peer,
10479 "lastErrorCodeSubcode",
10480 errorcodesubcode_hexstr);
10481 snprintf(errorcodesubcode_str, 255, "%s%s",
10482 code_str, subcode_str);
10483 json_object_string_add(json_peer,
10484 "lastNotificationReason",
10485 errorcodesubcode_str);
10486 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10487 && peer->notify.code == BGP_NOTIFY_CEASE
10488 && (peer->notify.subcode
10489 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10490 || peer->notify.subcode
10491 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10492 && peer->notify.length) {
10493 char msgbuf[1024];
10494 const char *msg_str;
10495
10496 msg_str = bgp_notify_admin_message(
10497 msgbuf, sizeof(msgbuf),
10498 (uint8_t *)peer->notify.data,
10499 peer->notify.length);
10500 if (msg_str)
10501 json_object_string_add(
10502 json_peer,
10503 "lastShutdownDescription",
10504 msg_str);
10505 }
10506
c258527b 10507 }
3577f1c5
DD
10508 json_object_string_add(json_peer, "lastResetDueTo",
10509 peer_down_str[(int)peer->last_reset]);
05912a17
DD
10510 json_object_int_add(json_peer, "lastResetCode",
10511 peer->last_reset);
3577f1c5
DD
10512 } else {
10513 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10514 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10515 code_str = bgp_notify_code_str(peer->notify.code);
10516 subcode_str =
10517 bgp_notify_subcode_str(peer->notify.code,
10518 peer->notify.subcode);
10519 vty_out(vty, " Notification %s (%s%s)\n",
10520 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10521 ? "sent"
10522 : "received",
10523 code_str, subcode_str);
10524 } else {
e91c24c8 10525 vty_out(vty, " %s\n",
3577f1c5
DD
10526 peer_down_str[(int)peer->last_reset]);
10527 }
10528 }
10529}
10530
10531static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10532 safi_t safi)
10533{
10534 return ((peer->status != Established) ||
10535 !peer->afc_recv[afi][safi]);
10536}
10537
10538static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10539 struct peer *peer, json_object *json_peer,
10540 int max_neighbor_width, bool use_json)
10541{
10542 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10543 int len;
10544
10545 if (use_json) {
10546 if (peer_dynamic_neighbor(peer))
10547 json_object_boolean_true_add(json_peer,
10548 "dynamicPeer");
10549 if (peer->hostname)
10550 json_object_string_add(json_peer, "hostname",
10551 peer->hostname);
10552
10553 if (peer->domainname)
10554 json_object_string_add(json_peer, "domainname",
10555 peer->domainname);
10556 json_object_int_add(json_peer, "connectionsEstablished",
10557 peer->established);
10558 json_object_int_add(json_peer, "connectionsDropped",
10559 peer->dropped);
10560 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10561 use_json, json_peer);
10562 if (peer->status == Established)
10563 json_object_string_add(json_peer, "lastResetDueTo",
10564 "AFI/SAFI Not Negotiated");
10565 else
10566 bgp_show_peer_reset(NULL, peer, json_peer, true);
10567 } else {
10568 dn_flag[1] = '\0';
10569 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10570 if (peer->hostname
892fedb6 10571 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
3577f1c5
DD
10572 len = vty_out(vty, "%s%s(%s)", dn_flag,
10573 peer->hostname, peer->host);
10574 else
10575 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10576
10577 /* pad the neighbor column with spaces */
10578 if (len < max_neighbor_width)
10579 vty_out(vty, "%*s", max_neighbor_width - len,
10580 " ");
e91c24c8 10581 vty_out(vty, "%7d %7d %9s", peer->established,
3577f1c5
DD
10582 peer->dropped,
10583 peer_uptime(peer->uptime, timebuf,
10584 BGP_UPTIME_LEN, 0, NULL));
10585 if (peer->status == Established)
10586 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10587 else
10588 bgp_show_peer_reset(vty, peer, NULL,
10589 false);
10590 }
10591}
c258527b 10592
cb75bb31
DA
10593/* If the peer's description includes whitespaces
10594 * then return the first occurrence. Also strip description
10595 * to the given size if needed.
10596 */
10597static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10598{
10599 static char stripped[BUFSIZ];
10600 char *pnt;
10601 uint32_t len = size > strlen(desc) ? strlen(desc) : size;
10602
10603 pnt = strchr(desc, ' ');
10604 if (pnt)
10605 len = size > (uint32_t)(pnt - desc) ? (uint32_t)(pnt - desc)
10606 : size;
10607
10608 strlcpy(stripped, desc, len + 1);
10609
10610 return stripped;
10611}
3577f1c5 10612
718e3744 10613/* Show BGP peer's summary information. */
d62a17ae 10614static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
85eeb029 10615 uint8_t show_flags)
d62a17ae 10616{
10617 struct peer *peer;
10618 struct listnode *node, *nnode;
10619 unsigned int count = 0, dn_count = 0;
10620 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10621 char neighbor_buf[VTY_BUFSIZ];
10622 int neighbor_col_default_width = 16;
3577f1c5 10623 int len, failed_count = 0;
d62a17ae 10624 int max_neighbor_width = 0;
10625 int pfx_rcd_safi;
3c13337d 10626 json_object *json = NULL;
d62a17ae 10627 json_object *json_peer = NULL;
10628 json_object *json_peers = NULL;
50e05855 10629 struct peer_af *paf;
d3ada366 10630 struct bgp_filter *filter;
85eeb029
DA
10631 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10632 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10633 bool show_established =
10634 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10635 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
d62a17ae 10636
10637 /* labeled-unicast routes are installed in the unicast table so in order
10638 * to
10639 * display the correct PfxRcd value we must look at SAFI_UNICAST
10640 */
3577f1c5 10641
d62a17ae 10642 if (safi == SAFI_LABELED_UNICAST)
10643 pfx_rcd_safi = SAFI_UNICAST;
10644 else
10645 pfx_rcd_safi = safi;
10646
10647 if (use_json) {
3c13337d 10648 json = json_object_new_object();
d62a17ae 10649 json_peers = json_object_new_object();
3577f1c5
DD
10650 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10651 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10652 continue;
10653
10654 if (peer->afc[afi][safi]) {
10655 /* See if we have at least a single failed peer */
10656 if (bgp_has_peer_failed(peer, afi, safi))
10657 failed_count++;
10658 count++;
10659 }
10660 if (peer_dynamic_neighbor(peer))
10661 dn_count++;
10662 }
c258527b 10663
d62a17ae 10664 } else {
10665 /* Loop over all neighbors that will be displayed to determine
10666 * how many
10667 * characters are needed for the Neighbor column
10668 */
10669 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10670 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10671 continue;
10672
10673 if (peer->afc[afi][safi]) {
10674 memset(dn_flag, '\0', sizeof(dn_flag));
10675 if (peer_dynamic_neighbor(peer))
10676 dn_flag[0] = '*';
10677
10678 if (peer->hostname
892fedb6
DA
10679 && CHECK_FLAG(bgp->flags,
10680 BGP_FLAG_SHOW_HOSTNAME))
772270f3
QY
10681 snprintf(neighbor_buf,
10682 sizeof(neighbor_buf),
10683 "%s%s(%s) ", dn_flag,
10684 peer->hostname, peer->host);
d62a17ae 10685 else
772270f3
QY
10686 snprintf(neighbor_buf,
10687 sizeof(neighbor_buf), "%s%s ",
10688 dn_flag, peer->host);
d62a17ae 10689
10690 len = strlen(neighbor_buf);
10691
10692 if (len > max_neighbor_width)
10693 max_neighbor_width = len;
c258527b 10694
3577f1c5
DD
10695 /* See if we have at least a single failed peer */
10696 if (bgp_has_peer_failed(peer, afi, safi))
10697 failed_count++;
10698 count++;
d62a17ae 10699 }
10700 }
f933309e 10701
d62a17ae 10702 /* Originally we displayed the Neighbor column as 16
10703 * characters wide so make that the default
10704 */
10705 if (max_neighbor_width < neighbor_col_default_width)
10706 max_neighbor_width = neighbor_col_default_width;
10707 }
f933309e 10708
3577f1c5
DD
10709 if (show_failed && !failed_count) {
10710 if (use_json) {
10711 json_object_int_add(json, "failedPeersCount", 0);
10712 json_object_int_add(json, "dynamicPeers", dn_count);
c258527b 10713 json_object_int_add(json, "totalPeers", count);
3577f1c5
DD
10714
10715 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10716 json, JSON_C_TO_STRING_PRETTY));
10717 json_object_free(json);
10718 } else {
10719 vty_out(vty, "%% No failed BGP neighbors found\n");
10720 vty_out(vty, "\nTotal number of neighbors %d\n", count);
10721 }
10722 return CMD_SUCCESS;
10723 }
c258527b 10724
3577f1c5 10725 count = 0; /* Reset the value as its used again */
d62a17ae 10726 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10727 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10728 continue;
10729
ea47320b
DL
10730 if (!peer->afc[afi][safi])
10731 continue;
d62a17ae 10732
ea47320b
DL
10733 if (!count) {
10734 unsigned long ents;
10735 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 10736 int64_t vrf_id_ui;
d62a17ae 10737
a4d82a8a
PZ
10738 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10739 ? -1
10740 : (int64_t)bgp->vrf_id;
ea47320b
DL
10741
10742 /* Usage summary and header */
10743 if (use_json) {
23d0a753
DA
10744 char buf[BUFSIZ] = {0};
10745
ea47320b
DL
10746 json_object_string_add(
10747 json, "routerId",
23d0a753
DA
10748 inet_ntop(AF_INET, &bgp->router_id, buf,
10749 sizeof(buf)));
60466a63
QY
10750 json_object_int_add(json, "as", bgp->as);
10751 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
10752 json_object_string_add(
10753 json, "vrfName",
10754 (bgp->inst_type
10755 == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 10756 ? VRF_DEFAULT_NAME
ea47320b
DL
10757 : bgp->name);
10758 } else {
10759 vty_out(vty,
23d0a753
DA
10760 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10761 &bgp->router_id, bgp->as,
a4d82a8a
PZ
10762 bgp->vrf_id == VRF_UNKNOWN
10763 ? -1
10764 : (int)bgp->vrf_id);
ea47320b
DL
10765 vty_out(vty, "\n");
10766 }
d62a17ae 10767
ea47320b 10768 if (bgp_update_delay_configured(bgp)) {
d62a17ae 10769 if (use_json) {
ea47320b 10770 json_object_int_add(
60466a63 10771 json, "updateDelayLimit",
ea47320b 10772 bgp->v_update_delay);
d62a17ae 10773
ea47320b
DL
10774 if (bgp->v_update_delay
10775 != bgp->v_establish_wait)
d62a17ae 10776 json_object_int_add(
10777 json,
ea47320b
DL
10778 "updateDelayEstablishWait",
10779 bgp->v_establish_wait);
d62a17ae 10780
60466a63 10781 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
10782 json_object_string_add(
10783 json,
10784 "updateDelayFirstNeighbor",
10785 bgp->update_delay_begin_time);
10786 json_object_boolean_true_add(
10787 json,
10788 "updateDelayInProgress");
10789 } else {
10790 if (bgp->update_delay_over) {
d62a17ae 10791 json_object_string_add(
10792 json,
10793 "updateDelayFirstNeighbor",
10794 bgp->update_delay_begin_time);
ea47320b 10795 json_object_string_add(
d62a17ae 10796 json,
ea47320b
DL
10797 "updateDelayBestpathResumed",
10798 bgp->update_delay_end_time);
10799 json_object_string_add(
d62a17ae 10800 json,
ea47320b
DL
10801 "updateDelayZebraUpdateResume",
10802 bgp->update_delay_zebra_resume_time);
10803 json_object_string_add(
10804 json,
10805 "updateDelayPeerUpdateResume",
10806 bgp->update_delay_peers_resume_time);
d62a17ae 10807 }
ea47320b
DL
10808 }
10809 } else {
10810 vty_out(vty,
10811 "Read-only mode update-delay limit: %d seconds\n",
10812 bgp->v_update_delay);
10813 if (bgp->v_update_delay
10814 != bgp->v_establish_wait)
d62a17ae 10815 vty_out(vty,
ea47320b
DL
10816 " Establish wait: %d seconds\n",
10817 bgp->v_establish_wait);
d62a17ae 10818
60466a63 10819 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
10820 vty_out(vty,
10821 " First neighbor established: %s\n",
10822 bgp->update_delay_begin_time);
10823 vty_out(vty,
10824 " Delay in progress\n");
10825 } else {
10826 if (bgp->update_delay_over) {
d62a17ae 10827 vty_out(vty,
10828 " First neighbor established: %s\n",
10829 bgp->update_delay_begin_time);
10830 vty_out(vty,
ea47320b
DL
10831 " Best-paths resumed: %s\n",
10832 bgp->update_delay_end_time);
10833 vty_out(vty,
10834 " zebra update resumed: %s\n",
10835 bgp->update_delay_zebra_resume_time);
10836 vty_out(vty,
10837 " peers update resumed: %s\n",
10838 bgp->update_delay_peers_resume_time);
d62a17ae 10839 }
10840 }
10841 }
ea47320b 10842 }
d62a17ae 10843
ea47320b
DL
10844 if (use_json) {
10845 if (bgp_maxmed_onstartup_configured(bgp)
10846 && bgp->maxmed_active)
10847 json_object_boolean_true_add(
60466a63 10848 json, "maxMedOnStartup");
ea47320b
DL
10849 if (bgp->v_maxmed_admin)
10850 json_object_boolean_true_add(
60466a63 10851 json, "maxMedAdministrative");
d62a17ae 10852
ea47320b
DL
10853 json_object_int_add(
10854 json, "tableVersion",
60466a63 10855 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 10856
60466a63
QY
10857 ents = bgp_table_count(bgp->rib[afi][safi]);
10858 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
10859 json_object_int_add(
10860 json, "ribMemory",
9bcb3eef 10861 ents * sizeof(struct bgp_dest));
d62a17ae 10862
210ec2a0 10863 ents = bgp->af_peer_count[afi][safi];
60466a63
QY
10864 json_object_int_add(json, "peerCount", ents);
10865 json_object_int_add(json, "peerMemory",
10866 ents * sizeof(struct peer));
d62a17ae 10867
ea47320b
DL
10868 if ((ents = listcount(bgp->group))) {
10869 json_object_int_add(
60466a63 10870 json, "peerGroupCount", ents);
ea47320b
DL
10871 json_object_int_add(
10872 json, "peerGroupMemory",
996c9314
LB
10873 ents * sizeof(struct
10874 peer_group));
ea47320b 10875 }
d62a17ae 10876
ea47320b
DL
10877 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10878 BGP_CONFIG_DAMPENING))
10879 json_object_boolean_true_add(
60466a63 10880 json, "dampeningEnabled");
ea47320b
DL
10881 } else {
10882 if (bgp_maxmed_onstartup_configured(bgp)
10883 && bgp->maxmed_active)
d62a17ae 10884 vty_out(vty,
ea47320b
DL
10885 "Max-med on-startup active\n");
10886 if (bgp->v_maxmed_admin)
d62a17ae 10887 vty_out(vty,
ea47320b 10888 "Max-med administrative active\n");
d62a17ae 10889
60466a63
QY
10890 vty_out(vty, "BGP table version %" PRIu64 "\n",
10891 bgp_table_version(bgp->rib[afi][safi]));
d62a17ae 10892
60466a63 10893 ents = bgp_table_count(bgp->rib[afi][safi]);
ea47320b
DL
10894 vty_out(vty,
10895 "RIB entries %ld, using %s of memory\n",
10896 ents,
9bcb3eef
DS
10897 mtype_memstr(
10898 memstrbuf, sizeof(memstrbuf),
10899 ents
10900 * sizeof(struct
10901 bgp_dest)));
ea47320b
DL
10902
10903 /* Peer related usage */
210ec2a0 10904 ents = bgp->af_peer_count[afi][safi];
60466a63 10905 vty_out(vty, "Peers %ld, using %s of memory\n",
ea47320b
DL
10906 ents,
10907 mtype_memstr(
60466a63
QY
10908 memstrbuf, sizeof(memstrbuf),
10909 ents * sizeof(struct peer)));
ea47320b
DL
10910
10911 if ((ents = listcount(bgp->group)))
d62a17ae 10912 vty_out(vty,
ea47320b 10913 "Peer groups %ld, using %s of memory\n",
d62a17ae 10914 ents,
10915 mtype_memstr(
10916 memstrbuf,
10917 sizeof(memstrbuf),
996c9314
LB
10918 ents * sizeof(struct
10919 peer_group)));
d62a17ae 10920
ea47320b
DL
10921 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10922 BGP_CONFIG_DAMPENING))
60466a63 10923 vty_out(vty, "Dampening enabled.\n");
ea47320b 10924 vty_out(vty, "\n");
d62a17ae 10925
ea47320b
DL
10926 /* Subtract 8 here because 'Neighbor' is
10927 * 8 characters */
10928 vty_out(vty, "Neighbor");
60466a63
QY
10929 vty_out(vty, "%*s", max_neighbor_width - 8,
10930 " ");
3577f1c5 10931 if (show_failed)
85eeb029
DA
10932 vty_out(vty,
10933 BGP_SHOW_SUMMARY_HEADER_FAILED);
3577f1c5
DD
10934 else
10935 vty_out(vty,
85eeb029
DA
10936 show_wide
10937 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
10938 : BGP_SHOW_SUMMARY_HEADER_ALL);
d62a17ae 10939 }
ea47320b 10940 }
d62a17ae 10941
d55811cc 10942 paf = peer_af_find(peer, afi, safi);
d3ada366 10943 filter = &peer->filter[afi][safi];
db92d226 10944
ea47320b 10945 count++;
3577f1c5
DD
10946 /* Works for both failed & successful cases */
10947 if (peer_dynamic_neighbor(peer))
10948 dn_count++;
d62a17ae 10949
ea47320b 10950 if (use_json) {
3577f1c5
DD
10951 json_peer = NULL;
10952
10953 if (show_failed &&
10954 bgp_has_peer_failed(peer, afi, safi)) {
10955 json_peer = json_object_new_object();
10956 bgp_show_failed_summary(vty, bgp, peer,
10957 json_peer, 0, use_json);
10958 } else if (!show_failed) {
10b49f14
DA
10959 if (show_established
10960 && bgp_has_peer_failed(peer, afi, safi))
10961 continue;
10962
3577f1c5
DD
10963 json_peer = json_object_new_object();
10964 if (peer_dynamic_neighbor(peer)) {
10965 json_object_boolean_true_add(json_peer,
10966 "dynamicPeer");
10967 }
d62a17ae 10968
3577f1c5
DD
10969 if (peer->hostname)
10970 json_object_string_add(json_peer, "hostname",
10971 peer->hostname);
10972
10973 if (peer->domainname)
10974 json_object_string_add(json_peer, "domainname",
10975 peer->domainname);
10976
10977 json_object_int_add(json_peer, "remoteAs", peer->as);
c854765f
DA
10978 json_object_int_add(
10979 json_peer, "localAs",
10980 peer->change_local_as
10981 ? peer->change_local_as
10982 : peer->local_as);
3577f1c5
DD
10983 json_object_int_add(json_peer, "version", 4);
10984 json_object_int_add(json_peer, "msgRcvd",
10985 PEER_TOTAL_RX(peer));
10986 json_object_int_add(json_peer, "msgSent",
10987 PEER_TOTAL_TX(peer));
10988
43aa5965
QY
10989 atomic_size_t outq_count, inq_count;
10990 outq_count = atomic_load_explicit(
10991 &peer->obuf->count,
10992 memory_order_relaxed);
10993 inq_count = atomic_load_explicit(
10994 &peer->ibuf->count,
10995 memory_order_relaxed);
10996
3577f1c5
DD
10997 json_object_int_add(json_peer, "tableVersion",
10998 peer->version[afi][safi]);
10999 json_object_int_add(json_peer, "outq",
43aa5965
QY
11000 outq_count);
11001 json_object_int_add(json_peer, "inq",
11002 inq_count);
3577f1c5
DD
11003 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
11004 use_json, json_peer);
11005
3577f1c5
DD
11006 json_object_int_add(json_peer, "pfxRcd",
11007 peer->pcount[afi][pfx_rcd_safi]);
11008
3577f1c5 11009 if (paf && PAF_SUBGRP(paf))
a616dd1f
DA
11010 json_object_int_add(
11011 json_peer, "pfxSnt",
11012 (PAF_SUBGRP(paf))->scount);
11013 else
11014 json_object_int_add(json_peer, "pfxSnt",
11015 0);
0e1f8ab5
DA
11016
11017 /* BGP FSM state */
cb9196e7 11018 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
736b68f3
DS
11019 || CHECK_FLAG(peer->bgp->flags,
11020 BGP_FLAG_SHUTDOWN))
0e1f8ab5
DA
11021 json_object_string_add(json_peer,
11022 "state",
3577f1c5
DD
11023 "Idle (Admin)");
11024 else if (peer->afc_recv[afi][safi])
11025 json_object_string_add(
0e1f8ab5
DA
11026 json_peer, "state",
11027 lookup_msg(bgp_status_msg,
11028 peer->status, NULL));
11029 else if (CHECK_FLAG(
11030 peer->sflags,
11031 PEER_STATUS_PREFIX_OVERFLOW))
11032 json_object_string_add(json_peer,
11033 "state",
3577f1c5
DD
11034 "Idle (PfxCt)");
11035 else
11036 json_object_string_add(
0e1f8ab5
DA
11037 json_peer, "state",
11038 lookup_msg(bgp_status_msg,
11039 peer->status, NULL));
11040
11041 /* BGP peer state */
11042 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11043 || CHECK_FLAG(peer->bgp->flags,
11044 BGP_FLAG_SHUTDOWN))
11045 json_object_string_add(json_peer,
11046 "peerState",
11047 "Admin");
11048 else if (CHECK_FLAG(
11049 peer->sflags,
11050 PEER_STATUS_PREFIX_OVERFLOW))
11051 json_object_string_add(json_peer,
11052 "peerState",
11053 "PfxCt");
11054 else if (CHECK_FLAG(peer->flags,
11055 PEER_FLAG_PASSIVE))
11056 json_object_string_add(json_peer,
11057 "peerState",
11058 "Passive");
11059 else if (CHECK_FLAG(peer->sflags,
11060 PEER_STATUS_NSF_WAIT))
11061 json_object_string_add(json_peer,
11062 "peerState",
11063 "NSF passive");
11064 else if (CHECK_FLAG(
11065 peer->bgp->flags,
11066 BGP_FLAG_EBGP_REQUIRES_POLICY)
11067 && (!bgp_inbound_policy_exists(peer,
11068 filter)
11069 || !bgp_outbound_policy_exists(
11070 peer, filter)))
11071 json_object_string_add(json_peer,
11072 "peerState",
11073 "Policy");
11074 else
11075 json_object_string_add(
11076 json_peer, "peerState", "OK");
11077
200116db
DD
11078 json_object_int_add(json_peer, "connectionsEstablished",
11079 peer->established);
11080 json_object_int_add(json_peer, "connectionsDropped",
11081 peer->dropped);
aa72bd7e
PG
11082 if (peer->desc)
11083 json_object_string_add(
11084 json_peer, "desc", peer->desc);
b4e9dcba 11085 }
3577f1c5
DD
11086 /* Avoid creating empty peer dicts in JSON */
11087 if (json_peer == NULL)
11088 continue;
ea47320b
DL
11089
11090 if (peer->conf_if)
60466a63 11091 json_object_string_add(json_peer, "idType",
ea47320b
DL
11092 "interface");
11093 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
11094 json_object_string_add(json_peer, "idType",
11095 "ipv4");
ea47320b 11096 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
11097 json_object_string_add(json_peer, "idType",
11098 "ipv6");
ea47320b
DL
11099 json_object_object_add(json_peers, peer->host,
11100 json_peer);
11101 } else {
3577f1c5
DD
11102 if (show_failed &&
11103 bgp_has_peer_failed(peer, afi, safi)) {
11104 bgp_show_failed_summary(vty, bgp, peer, NULL,
11105 max_neighbor_width,
11106 use_json);
11107 } else if (!show_failed) {
10b49f14
DA
11108 if (show_established
11109 && bgp_has_peer_failed(peer, afi, safi))
11110 continue;
11111
3577f1c5
DD
11112 memset(dn_flag, '\0', sizeof(dn_flag));
11113 if (peer_dynamic_neighbor(peer)) {
11114 dn_flag[0] = '*';
11115 }
d62a17ae 11116
3577f1c5 11117 if (peer->hostname
892fedb6
DA
11118 && CHECK_FLAG(bgp->flags,
11119 BGP_FLAG_SHOW_HOSTNAME))
3577f1c5 11120 len = vty_out(vty, "%s%s(%s)", dn_flag,
892fedb6
DA
11121 peer->hostname,
11122 peer->host);
d62a17ae 11123 else
3577f1c5
DD
11124 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11125
11126 /* pad the neighbor column with spaces */
11127 if (len < max_neighbor_width)
11128 vty_out(vty, "%*s", max_neighbor_width - len,
11129 " ");
11130
43aa5965
QY
11131 atomic_size_t outq_count, inq_count;
11132 outq_count = atomic_load_explicit(
11133 &peer->obuf->count,
11134 memory_order_relaxed);
11135 inq_count = atomic_load_explicit(
11136 &peer->ibuf->count,
11137 memory_order_relaxed);
11138
85eeb029
DA
11139 if (show_wide)
11140 vty_out(vty,
11141 "4 %10u %10u %9u %9u %8" PRIu64
11142 " %4zu %4zu %8s",
11143 peer->as,
11144 peer->change_local_as
11145 ? peer->change_local_as
11146 : peer->local_as,
11147 PEER_TOTAL_RX(peer),
11148 PEER_TOTAL_TX(peer),
11149 peer->version[afi][safi],
11150 inq_count, outq_count,
11151 peer_uptime(peer->uptime,
11152 timebuf,
11153 BGP_UPTIME_LEN, 0,
11154 NULL));
11155 else
11156 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
11157 " %4zu %4zu %8s",
11158 peer->as, PEER_TOTAL_RX(peer),
11159 PEER_TOTAL_TX(peer),
11160 peer->version[afi][safi],
11161 inq_count, outq_count,
11162 peer_uptime(peer->uptime,
11163 timebuf,
11164 BGP_UPTIME_LEN, 0,
11165 NULL));
3577f1c5 11166
db92d226 11167 if (peer->status == Established) {
d3ada366
DA
11168 if (peer->afc_recv[afi][safi]) {
11169 if (CHECK_FLAG(
11170 bgp->flags,
11171 BGP_FLAG_EBGP_REQUIRES_POLICY)
11172 && !bgp_inbound_policy_exists(
11173 peer, filter))
11174 vty_out(vty, " %12s",
11175 "(Policy)");
11176 else
11177 vty_out(vty,
6cde4b45 11178 " %12u",
d3ada366
DA
11179 peer->pcount
11180 [afi]
11181 [pfx_rcd_safi]);
11182 } else {
3577f1c5 11183 vty_out(vty, " NoNeg");
d3ada366 11184 }
db92d226 11185
d3ada366
DA
11186 if (paf && PAF_SUBGRP(paf)) {
11187 if (CHECK_FLAG(
11188 bgp->flags,
11189 BGP_FLAG_EBGP_REQUIRES_POLICY)
11190 && !bgp_outbound_policy_exists(
11191 peer, filter))
11192 vty_out(vty, " %8s",
11193 "(Policy)");
11194 else
11195 vty_out(vty,
6cde4b45 11196 " %8u",
d3ada366
DA
11197 (PAF_SUBGRP(
11198 paf))
11199 ->scount);
11200 }
db92d226 11201 } else {
736b68f3
DS
11202 if (CHECK_FLAG(peer->flags,
11203 PEER_FLAG_SHUTDOWN)
11204 || CHECK_FLAG(peer->bgp->flags,
11205 BGP_FLAG_SHUTDOWN))
3577f1c5
DD
11206 vty_out(vty, " Idle (Admin)");
11207 else if (CHECK_FLAG(
11208 peer->sflags,
11209 PEER_STATUS_PREFIX_OVERFLOW))
11210 vty_out(vty, " Idle (PfxCt)");
11211 else
11212 vty_out(vty, " %12s",
11213 lookup_msg(bgp_status_msg,
11214 peer->status, NULL));
db92d226 11215
6cde4b45 11216 vty_out(vty, " %8u", 0);
3577f1c5 11217 }
aa72bd7e 11218 if (peer->desc)
cb75bb31
DA
11219 vty_out(vty, " %s",
11220 bgp_peer_description_stripped(
85eeb029
DA
11221 peer->desc,
11222 show_wide ? 64 : 20));
aa72bd7e
PG
11223 else
11224 vty_out(vty, " N/A");
3577f1c5 11225 vty_out(vty, "\n");
d62a17ae 11226 }
3577f1c5 11227
d62a17ae 11228 }
11229 }
f933309e 11230
d62a17ae 11231 if (use_json) {
11232 json_object_object_add(json, "peers", json_peers);
3577f1c5 11233 json_object_int_add(json, "failedPeers", failed_count);
d62a17ae 11234 json_object_int_add(json, "totalPeers", count);
11235 json_object_int_add(json, "dynamicPeers", dn_count);
11236
3577f1c5
DD
11237 if (!show_failed)
11238 bgp_show_bestpath_json(bgp, json);
57a9c8a8 11239
996c9314
LB
11240 vty_out(vty, "%s\n", json_object_to_json_string_ext(
11241 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 11242 json_object_free(json);
11243 } else {
11244 if (count)
11245 vty_out(vty, "\nTotal number of neighbors %d\n", count);
11246 else {
d6ceaca3 11247 vty_out(vty, "No %s neighbor is configured\n",
5cb5f4d0 11248 get_afi_safi_str(afi, safi, false));
d62a17ae 11249 }
b05a1c8b 11250
d6ceaca3 11251 if (dn_count) {
d62a17ae 11252 vty_out(vty, "* - dynamic neighbor\n");
11253 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11254 dn_count, bgp->dynamic_neighbors_limit);
11255 }
11256 }
1ff9a340 11257
d62a17ae 11258 return CMD_SUCCESS;
718e3744 11259}
11260
d62a17ae 11261static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
85eeb029 11262 int safi, uint8_t show_flags)
d62a17ae 11263{
11264 int is_first = 1;
11265 int afi_wildcard = (afi == AFI_MAX);
11266 int safi_wildcard = (safi == SAFI_MAX);
11267 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 11268 bool nbr_output = false;
85eeb029 11269 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 11270
11271 if (use_json && is_wildcard)
11272 vty_out(vty, "{\n");
11273 if (afi_wildcard)
11274 afi = 1; /* AFI_IP */
11275 while (afi < AFI_MAX) {
11276 if (safi_wildcard)
11277 safi = 1; /* SAFI_UNICAST */
11278 while (safi < SAFI_MAX) {
318cac96 11279 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 11280 nbr_output = true;
f86897b9 11281
d62a17ae 11282 if (is_wildcard) {
11283 /*
11284 * So limit output to those afi/safi
11285 * pairs that
11286 * actualy have something interesting in
11287 * them
11288 */
11289 if (use_json) {
d62a17ae 11290 if (!is_first)
11291 vty_out(vty, ",\n");
11292 else
11293 is_first = 0;
11294
11295 vty_out(vty, "\"%s\":",
5cb5f4d0
DD
11296 get_afi_safi_str(afi,
11297 safi,
11298 true));
d62a17ae 11299 } else {
11300 vty_out(vty, "\n%s Summary:\n",
5cb5f4d0
DD
11301 get_afi_safi_str(afi,
11302 safi,
11303 false));
d62a17ae 11304 }
11305 }
10b49f14 11306 bgp_show_summary(vty, bgp, afi, safi,
85eeb029 11307 show_flags);
d62a17ae 11308 }
11309 safi++;
d62a17ae 11310 if (!safi_wildcard)
11311 safi = SAFI_MAX;
11312 }
11313 afi++;
ee851c8c 11314 if (!afi_wildcard)
d62a17ae 11315 afi = AFI_MAX;
11316 }
11317
11318 if (use_json && is_wildcard)
11319 vty_out(vty, "}\n");
ca61fd25
DS
11320 else if (!nbr_output) {
11321 if (use_json)
11322 vty_out(vty, "{}\n");
11323 else
11324 vty_out(vty, "%% No BGP neighbors found\n");
11325 }
d62a17ae 11326}
11327
11328static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
85eeb029 11329 safi_t safi, uint8_t show_flags)
d62a17ae 11330{
11331 struct listnode *node, *nnode;
11332 struct bgp *bgp;
d62a17ae 11333 int is_first = 1;
9f049418 11334 bool nbr_output = false;
85eeb029 11335 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 11336
11337 if (use_json)
11338 vty_out(vty, "{\n");
11339
11340 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 11341 nbr_output = true;
d62a17ae 11342 if (use_json) {
d62a17ae 11343 if (!is_first)
11344 vty_out(vty, ",\n");
11345 else
11346 is_first = 0;
11347
11348 vty_out(vty, "\"%s\":",
11349 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11350 ? VRF_DEFAULT_NAME
d62a17ae 11351 : bgp->name);
11352 } else {
11353 vty_out(vty, "\nInstance %s:\n",
11354 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11355 ? VRF_DEFAULT_NAME
d62a17ae 11356 : bgp->name);
11357 }
85eeb029 11358 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_flags);
d62a17ae 11359 }
11360
11361 if (use_json)
11362 vty_out(vty, "}\n");
9f049418
DS
11363 else if (!nbr_output)
11364 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 11365}
11366
11367int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
85eeb029 11368 safi_t safi, uint8_t show_flags)
d62a17ae 11369{
11370 struct bgp *bgp;
85eeb029 11371 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 11372
11373 if (name) {
11374 if (strmatch(name, "all")) {
85eeb029
DA
11375 bgp_show_all_instances_summary_vty(vty, afi, safi,
11376 show_flags);
d62a17ae 11377 return CMD_SUCCESS;
11378 } else {
11379 bgp = bgp_lookup_by_name(name);
11380
11381 if (!bgp) {
11382 if (use_json)
11383 vty_out(vty, "{}\n");
11384 else
11385 vty_out(vty,
ca61fd25 11386 "%% BGP instance not found\n");
d62a17ae 11387 return CMD_WARNING;
11388 }
11389
f86897b9 11390 bgp_show_summary_afi_safi(vty, bgp, afi, safi,
85eeb029 11391 show_flags);
d62a17ae 11392 return CMD_SUCCESS;
11393 }
11394 }
11395
11396 bgp = bgp_get_default();
11397
11398 if (bgp)
85eeb029 11399 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_flags);
9f049418 11400 else {
ca61fd25
DS
11401 if (use_json)
11402 vty_out(vty, "{}\n");
11403 else
11404 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
11405 return CMD_WARNING;
11406 }
d62a17ae 11407
11408 return CMD_SUCCESS;
4fb25c53
DW
11409}
11410
716b2d8a 11411/* `show [ip] bgp summary' commands. */
96f3485c 11412DEFPY (show_ip_bgp_summary,
718e3744 11413 show_ip_bgp_summary_cmd,
85eeb029 11414 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] [all$all] summary [established|failed] [wide] [json$uj]",
718e3744 11415 SHOW_STR
11416 IP_STR
11417 BGP_STR
8386ac43 11418 BGP_INSTANCE_HELP_STR
46f296b4 11419 BGP_AFI_HELP_STR
dd6bd0f1 11420 BGP_SAFI_WITH_LABEL_HELP_STR
96f3485c 11421 "Display the entries for all address families\n"
b05a1c8b 11422 "Summary of BGP neighbor status\n"
10b49f14 11423 "Show only sessions in Established state\n"
3577f1c5 11424 "Show only sessions not in Established state\n"
85eeb029 11425 "Increase table width for longer output\n"
9973d184 11426 JSON_STR)
718e3744 11427{
d62a17ae 11428 char *vrf = NULL;
11429 afi_t afi = AFI_MAX;
11430 safi_t safi = SAFI_MAX;
85eeb029 11431 uint8_t show_flags = 0;
d62a17ae 11432
11433 int idx = 0;
11434
11435 /* show [ip] bgp */
96f3485c 11436 if (!all && argv_find(argv, argc, "ip", &idx))
d62a17ae 11437 afi = AFI_IP;
9a8bdf1c
PG
11438 /* [<vrf> VIEWVRFNAME] */
11439 if (argv_find(argv, argc, "vrf", &idx)) {
11440 vrf = argv[idx + 1]->arg;
11441 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11442 vrf = NULL;
11443 } else if (argv_find(argv, argc, "view", &idx))
11444 /* [<view> VIEWVRFNAME] */
11445 vrf = argv[idx + 1]->arg;
d62a17ae 11446 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11447 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11448 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11449 }
11450
3577f1c5 11451 if (argv_find(argv, argc, "failed", &idx))
85eeb029
DA
11452 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11453
10b49f14 11454 if (argv_find(argv, argc, "established", &idx))
85eeb029
DA
11455 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11456
11457 if (argv_find(argv, argc, "wide", &idx))
11458 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11459
11460 if (argv_find(argv, argc, "json", &idx))
11461 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
3577f1c5 11462
85eeb029 11463 return bgp_show_summary_vty(vty, vrf, afi, safi, show_flags);
d62a17ae 11464}
11465
5cb5f4d0 11466const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
d62a17ae 11467{
5cb5f4d0
DD
11468 if (for_json)
11469 return get_afi_safi_json_str(afi, safi);
d62a17ae 11470 else
5cb5f4d0 11471 return get_afi_safi_vty_str(afi, safi);
27162734
LB
11472}
11473
d62a17ae 11474
11475static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11476 afi_t afi, safi_t safi,
d7c0a89a
QY
11477 uint16_t adv_smcap, uint16_t adv_rmcap,
11478 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 11479 bool use_json, json_object *json_pref)
d62a17ae 11480{
11481 /* Send-Mode */
11482 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11483 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11484 if (use_json) {
11485 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11486 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11487 json_object_string_add(json_pref, "sendMode",
11488 "advertisedAndReceived");
11489 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11490 json_object_string_add(json_pref, "sendMode",
11491 "advertised");
11492 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11493 json_object_string_add(json_pref, "sendMode",
11494 "received");
11495 } else {
11496 vty_out(vty, " Send-mode: ");
11497 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11498 vty_out(vty, "advertised");
11499 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11500 vty_out(vty, "%sreceived",
11501 CHECK_FLAG(p->af_cap[afi][safi],
11502 adv_smcap)
11503 ? ", "
11504 : "");
11505 vty_out(vty, "\n");
11506 }
11507 }
11508
11509 /* Receive-Mode */
11510 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11511 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11512 if (use_json) {
11513 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11514 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11515 json_object_string_add(json_pref, "recvMode",
11516 "advertisedAndReceived");
11517 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11518 json_object_string_add(json_pref, "recvMode",
11519 "advertised");
11520 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11521 json_object_string_add(json_pref, "recvMode",
11522 "received");
11523 } else {
11524 vty_out(vty, " Receive-mode: ");
11525 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11526 vty_out(vty, "advertised");
11527 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11528 vty_out(vty, "%sreceived",
11529 CHECK_FLAG(p->af_cap[afi][safi],
11530 adv_rmcap)
11531 ? ", "
11532 : "");
11533 vty_out(vty, "\n");
11534 }
11535 }
11536}
11537
13909c4f
DS
11538static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty,
11539 struct peer *p,
11540 bool use_json,
11541 json_object *json)
2986cac2 11542{
08c2d52a 11543 bool rbit_status = false;
2986cac2 11544
11545 if (!use_json)
a53ca37b 11546 vty_out(vty, "\n R bit: ");
2986cac2 11547
13909c4f
DS
11548 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11549 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
11550 && (p->status == Established)) {
2986cac2 11551
11552 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV))
08c2d52a 11553 rbit_status = true;
2986cac2 11554 else
08c2d52a 11555 rbit_status = false;
2986cac2 11556 }
11557
11558 if (rbit_status) {
11559 if (use_json)
13909c4f 11560 json_object_boolean_true_add(json, "rBit");
2986cac2 11561 else
11562 vty_out(vty, "True\n");
11563 } else {
11564 if (use_json)
13909c4f 11565 json_object_boolean_false_add(json, "rBit");
2986cac2 11566 else
11567 vty_out(vty, "False\n");
11568 }
11569}
11570
13909c4f
DS
11571static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11572 struct peer *peer,
11573 bool use_json,
11574 json_object *json)
2986cac2 11575{
2bb5d39b 11576 const char *mode = "NotApplicable";
2986cac2 11577
11578 if (!use_json)
a53ca37b 11579 vty_out(vty, "\n Remote GR Mode: ");
2986cac2 11580
13909c4f
DS
11581 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11582 && (peer->status == Established)) {
2986cac2 11583
13909c4f
DS
11584 if ((peer->nsf_af_count == 0)
11585 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11586
2986cac2 11587 mode = "Disable";
11588
13909c4f
DS
11589 } else if (peer->nsf_af_count == 0
11590 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11591
2986cac2 11592 mode = "Helper";
11593
13909c4f
DS
11594 } else if (peer->nsf_af_count != 0
11595 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11596
2986cac2 11597 mode = "Restart";
2986cac2 11598 }
11599 }
11600
11601 if (use_json) {
13909c4f 11602 json_object_string_add(json, "remoteGrMode", mode);
2986cac2 11603 } else
11604 vty_out(vty, mode, "\n");
11605}
11606
13909c4f
DS
11607static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11608 struct peer *p,
11609 bool use_json,
11610 json_object *json)
2986cac2 11611{
11612 const char *mode = "Invalid";
11613
11614 if (!use_json)
a53ca37b 11615 vty_out(vty, " Local GR Mode: ");
2986cac2 11616
11617 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11618 mode = "Helper";
11619 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11620 mode = "Restart";
11621 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11622 mode = "Disable";
2ba1fe69 11623 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
2986cac2 11624 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11625 mode = "Helper*";
11626 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11627 mode = "Restart*";
11628 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11629 mode = "Disable*";
11630 else
11631 mode = "Invalid*";
2ba1fe69 11632 }
2986cac2 11633
11634 if (use_json) {
13909c4f 11635 json_object_string_add(json, "localGrMode", mode);
2986cac2 11636 } else {
11637 vty_out(vty, mode, "\n");
11638 }
11639}
11640
13909c4f
DS
11641static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11642 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
2986cac2 11643{
2ba1fe69 11644 afi_t afi;
11645 safi_t safi;
2986cac2 11646 json_object *json_afi_safi = NULL;
11647 json_object *json_timer = NULL;
11648 json_object *json_endofrib_status = NULL;
9e3b51a7 11649 bool eor_flag = false;
2986cac2 11650
11651 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11652 for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) {
13909c4f
DS
11653 if (!peer->afc[afi][safi])
11654 continue;
2986cac2 11655
13909c4f
DS
11656 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11657 || !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11658 continue;
9e3b51a7 11659
13909c4f
DS
11660 if (use_json) {
11661 json_afi_safi = json_object_new_object();
11662 json_endofrib_status = json_object_new_object();
11663 json_timer = json_object_new_object();
11664 }
2986cac2 11665
13909c4f
DS
11666 if (peer->eor_stime[afi][safi]
11667 >= peer->pkt_stime[afi][safi])
11668 eor_flag = true;
11669 else
11670 eor_flag = false;
2986cac2 11671
13909c4f 11672 if (!use_json) {
a53ca37b 11673 vty_out(vty, " %s:\n",
13909c4f 11674 get_afi_safi_str(afi, safi, false));
2986cac2 11675
a53ca37b 11676 vty_out(vty, " F bit: ");
698ba8d0 11677 }
2986cac2 11678
13909c4f
DS
11679 if (peer->nsf[afi][safi]
11680 && CHECK_FLAG(peer->af_cap[afi][safi],
11681 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
2986cac2 11682
13909c4f
DS
11683 if (use_json) {
11684 json_object_boolean_true_add(
2986cac2 11685 json_afi_safi, "fBit");
13909c4f
DS
11686 } else
11687 vty_out(vty, "True\n");
11688 } else {
11689 if (use_json)
11690 json_object_boolean_false_add(
11691 json_afi_safi, "fBit");
11692 else
11693 vty_out(vty, "False\n");
11694 }
2986cac2 11695
13909c4f 11696 if (!use_json)
a53ca37b 11697 vty_out(vty, " End-of-RIB sent: ");
2986cac2 11698
13909c4f
DS
11699 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11700 PEER_STATUS_EOR_SEND)) {
11701 if (use_json) {
11702 json_object_boolean_true_add(
2986cac2 11703 json_endofrib_status,
13909c4f 11704 "endOfRibSend");
9e3b51a7 11705
13909c4f
DS
11706 PRINT_EOR_JSON(eor_flag);
11707 } else {
11708 vty_out(vty, "Yes\n");
11709 vty_out(vty,
a53ca37b 11710 " End-of-RIB sent after update: ");
2986cac2 11711
13909c4f
DS
11712 PRINT_EOR(eor_flag);
11713 }
11714 } else {
11715 if (use_json) {
11716 json_object_boolean_false_add(
2986cac2 11717 json_endofrib_status,
13909c4f
DS
11718 "endOfRibSend");
11719 json_object_boolean_false_add(
9e3b51a7 11720 json_endofrib_status,
13909c4f
DS
11721 "endOfRibSentAfterUpdate");
11722 } else {
11723 vty_out(vty, "No\n");
11724 vty_out(vty,
a53ca37b 11725 " End-of-RIB sent after update: ");
13909c4f 11726 vty_out(vty, "No\n");
2986cac2 11727 }
13909c4f 11728 }
2986cac2 11729
a53ca37b
DA
11730 if (!use_json)
11731 vty_out(vty, " End-of-RIB received: ");
11732
11733 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11734 PEER_STATUS_EOR_RECEIVED)) {
11735 if (use_json)
11736 json_object_boolean_true_add(
11737 json_endofrib_status,
11738 "endOfRibRecv");
11739 else
11740 vty_out(vty, "Yes\n");
11741 } else {
11742 if (use_json)
11743 json_object_boolean_false_add(
11744 json_endofrib_status,
11745 "endOfRibRecv");
11746 else
11747 vty_out(vty, "No\n");
11748 }
11749
13909c4f
DS
11750 if (use_json) {
11751 json_object_int_add(json_timer,
11752 "stalePathTimer",
11753 peer->bgp->stalepath_time);
2986cac2 11754
13909c4f
DS
11755 if (peer->t_gr_stale != NULL) {
11756 json_object_int_add(
2986cac2 11757 json_timer,
11758 "stalePathTimerRemaining",
11759 thread_timer_remain_second(
13909c4f
DS
11760 peer->t_gr_stale));
11761 }
3a75afa4 11762
13909c4f
DS
11763 /* Display Configured Selection
11764 * Deferral only when when
11765 * Gr mode is enabled.
11766 */
11767 if (CHECK_FLAG(peer->flags,
11768 PEER_FLAG_GRACEFUL_RESTART)) {
11769 json_object_int_add(
3a75afa4 11770 json_timer,
2986cac2 11771 "selectionDeferralTimer",
11772 peer->bgp->stalepath_time);
13909c4f 11773 }
2986cac2 11774
13909c4f
DS
11775 if (peer->bgp->gr_info[afi][safi]
11776 .t_select_deferral
11777 != NULL) {
2986cac2 11778
13909c4f 11779 json_object_int_add(
2986cac2 11780 json_timer,
11781 "selectionDeferralTimerRemaining",
11782 thread_timer_remain_second(
13909c4f
DS
11783 peer->bgp
11784 ->gr_info[afi]
11785 [safi]
11786 .t_select_deferral));
11787 }
11788 } else {
a53ca37b 11789 vty_out(vty, " Timers:\n");
13909c4f 11790 vty_out(vty,
a53ca37b
DA
11791 " Configured Stale Path Time(sec): %u\n",
11792 peer->bgp->stalepath_time);
2986cac2 11793
a53ca37b 11794 if (peer->t_gr_stale != NULL)
2986cac2 11795 vty_out(vty,
a53ca37b 11796 " Stale Path Remaining(sec): %ld\n",
2986cac2 11797 thread_timer_remain_second(
13909c4f 11798 peer->t_gr_stale));
13909c4f
DS
11799 /* Display Configured Selection
11800 * Deferral only when when
11801 * Gr mode is enabled.
11802 */
11803 if (CHECK_FLAG(peer->flags,
a53ca37b 11804 PEER_FLAG_GRACEFUL_RESTART))
13909c4f 11805 vty_out(vty,
a53ca37b 11806 " Configured Selection Deferral Time(sec): %u\n",
3a75afa4 11807 peer->bgp->select_defer_time);
2986cac2 11808
13909c4f
DS
11809 if (peer->bgp->gr_info[afi][safi]
11810 .t_select_deferral
a53ca37b 11811 != NULL)
13909c4f 11812 vty_out(vty,
a53ca37b 11813 " Selection Deferral Time Remaining(sec): %ld\n",
2986cac2 11814 thread_timer_remain_second(
13909c4f
DS
11815 peer->bgp
11816 ->gr_info[afi]
11817 [safi]
11818 .t_select_deferral));
2986cac2 11819 }
13909c4f
DS
11820 if (use_json) {
11821 json_object_object_add(json_afi_safi,
11822 "endOfRibStatus",
11823 json_endofrib_status);
11824 json_object_object_add(json_afi_safi, "timers",
11825 json_timer);
11826 json_object_object_add(
11827 json, get_afi_safi_str(afi, safi, true),
11828 json_afi_safi);
11829 }
2986cac2 11830 }
11831 }
11832}
11833
36235319
QY
11834static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
11835 struct peer *p,
11836 bool use_json,
11837 json_object *json)
2986cac2 11838{
11839 if (use_json) {
11840 json_object *json_timer = NULL;
11841
11842 json_timer = json_object_new_object();
11843
13909c4f
DS
11844 json_object_int_add(json_timer, "configuredRestartTimer",
11845 p->bgp->restart_time);
2986cac2 11846
13909c4f
DS
11847 json_object_int_add(json_timer, "receivedRestartTimer",
11848 p->v_gr_restart);
2986cac2 11849
13909c4f
DS
11850 if (p->t_gr_restart != NULL)
11851 json_object_int_add(
11852 json_timer, "restartTimerRemaining",
11853 thread_timer_remain_second(p->t_gr_restart));
2986cac2 11854
11855 json_object_object_add(json, "timers", json_timer);
11856 } else {
11857
a53ca37b
DA
11858 vty_out(vty, " Timers:\n");
11859 vty_out(vty, " Configured Restart Time(sec): %u\n",
13909c4f 11860 p->bgp->restart_time);
2986cac2 11861
a53ca37b 11862 vty_out(vty, " Received Restart Time(sec): %u\n",
13909c4f
DS
11863 p->v_gr_restart);
11864 if (p->t_gr_restart != NULL)
a53ca37b 11865 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
13909c4f 11866 thread_timer_remain_second(p->t_gr_restart));
36235319 11867 if (p->t_gr_restart != NULL) {
a53ca37b 11868 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
36235319
QY
11869 thread_timer_remain_second(p->t_gr_restart));
11870 }
2986cac2 11871 }
11872}
11873
11874static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
36235319 11875 bool use_json, json_object *json)
2986cac2 11876{
11877 char buf[SU_ADDRSTRLEN] = {0};
11878 char dn_flag[2] = {0};
2b7165e7
QY
11879 /* '*' + v6 address of neighbor */
11880 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
2986cac2 11881
2986cac2 11882 if (!p->conf_if && peer_dynamic_neighbor(p))
11883 dn_flag[0] = '*';
11884
11885 if (p->conf_if) {
11886 if (use_json)
13909c4f
DS
11887 json_object_string_add(
11888 json, "neighborAddr",
2986cac2 11889 BGP_PEER_SU_UNSPEC(p)
13909c4f
DS
11890 ? "none"
11891 : sockunion2str(&p->su, buf,
11892 SU_ADDRSTRLEN));
2986cac2 11893 else
13909c4f 11894 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
2986cac2 11895 BGP_PEER_SU_UNSPEC(p)
11896 ? "none"
11897 : sockunion2str(&p->su, buf,
11898 SU_ADDRSTRLEN));
11899 } else {
772270f3
QY
11900 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
11901 p->host);
2986cac2 11902
11903 if (use_json)
36235319
QY
11904 json_object_string_add(json, "neighborAddr",
11905 neighborAddr);
2986cac2 11906 else
36235319 11907 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
2986cac2 11908 }
11909
11910 /* more gr info in new format */
11911 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
11912}
11913
d62a17ae 11914static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 11915 safi_t safi, bool use_json,
d62a17ae 11916 json_object *json_neigh)
11917{
0291c246
MK
11918 struct bgp_filter *filter;
11919 struct peer_af *paf;
11920 char orf_pfx_name[BUFSIZ];
11921 int orf_pfx_count;
11922 json_object *json_af = NULL;
11923 json_object *json_prefA = NULL;
11924 json_object *json_prefB = NULL;
11925 json_object *json_addr = NULL;
fa36596c 11926 json_object *json_advmap = NULL;
d62a17ae 11927
11928 if (use_json) {
11929 json_addr = json_object_new_object();
11930 json_af = json_object_new_object();
11931 filter = &p->filter[afi][safi];
11932
11933 if (peer_group_active(p))
11934 json_object_string_add(json_addr, "peerGroupMember",
11935 p->group->name);
11936
11937 paf = peer_af_find(p, afi, safi);
11938 if (paf && PAF_SUBGRP(paf)) {
11939 json_object_int_add(json_addr, "updateGroupId",
11940 PAF_UPDGRP(paf)->id);
11941 json_object_int_add(json_addr, "subGroupId",
11942 PAF_SUBGRP(paf)->id);
11943 json_object_int_add(json_addr, "packetQueueLength",
11944 bpacket_queue_virtual_length(paf));
11945 }
11946
11947 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11948 || CHECK_FLAG(p->af_cap[afi][safi],
11949 PEER_CAP_ORF_PREFIX_SM_RCV)
11950 || CHECK_FLAG(p->af_cap[afi][safi],
11951 PEER_CAP_ORF_PREFIX_RM_ADV)
11952 || CHECK_FLAG(p->af_cap[afi][safi],
11953 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11954 json_object_int_add(json_af, "orfType",
11955 ORF_TYPE_PREFIX);
11956 json_prefA = json_object_new_object();
11957 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
11958 PEER_CAP_ORF_PREFIX_SM_ADV,
11959 PEER_CAP_ORF_PREFIX_RM_ADV,
11960 PEER_CAP_ORF_PREFIX_SM_RCV,
11961 PEER_CAP_ORF_PREFIX_RM_RCV,
11962 use_json, json_prefA);
11963 json_object_object_add(json_af, "orfPrefixList",
11964 json_prefA);
11965 }
11966
11967 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11968 || CHECK_FLAG(p->af_cap[afi][safi],
11969 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11970 || CHECK_FLAG(p->af_cap[afi][safi],
11971 PEER_CAP_ORF_PREFIX_RM_ADV)
11972 || CHECK_FLAG(p->af_cap[afi][safi],
11973 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
11974 json_object_int_add(json_af, "orfOldType",
11975 ORF_TYPE_PREFIX_OLD);
11976 json_prefB = json_object_new_object();
11977 bgp_show_peer_afi_orf_cap(
11978 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11979 PEER_CAP_ORF_PREFIX_RM_ADV,
11980 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
11981 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
11982 json_prefB);
11983 json_object_object_add(json_af, "orfOldPrefixList",
11984 json_prefB);
11985 }
11986
11987 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11988 || CHECK_FLAG(p->af_cap[afi][safi],
11989 PEER_CAP_ORF_PREFIX_SM_RCV)
11990 || CHECK_FLAG(p->af_cap[afi][safi],
11991 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11992 || CHECK_FLAG(p->af_cap[afi][safi],
11993 PEER_CAP_ORF_PREFIX_RM_ADV)
11994 || CHECK_FLAG(p->af_cap[afi][safi],
11995 PEER_CAP_ORF_PREFIX_RM_RCV)
11996 || CHECK_FLAG(p->af_cap[afi][safi],
11997 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
11998 json_object_object_add(json_addr, "afDependentCap",
11999 json_af);
12000 else
12001 json_object_free(json_af);
12002
772270f3
QY
12003 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12004 p->host, afi, safi);
d62a17ae 12005 orf_pfx_count = prefix_bgp_show_prefix_list(
12006 NULL, afi, orf_pfx_name, use_json);
12007
12008 if (CHECK_FLAG(p->af_sflags[afi][safi],
12009 PEER_STATUS_ORF_PREFIX_SEND)
12010 || orf_pfx_count) {
12011 if (CHECK_FLAG(p->af_sflags[afi][safi],
12012 PEER_STATUS_ORF_PREFIX_SEND))
12013 json_object_boolean_true_add(json_neigh,
12014 "orfSent");
12015 if (orf_pfx_count)
12016 json_object_int_add(json_addr, "orfRecvCounter",
12017 orf_pfx_count);
12018 }
12019 if (CHECK_FLAG(p->af_sflags[afi][safi],
12020 PEER_STATUS_ORF_WAIT_REFRESH))
12021 json_object_string_add(
12022 json_addr, "orfFirstUpdate",
12023 "deferredUntilORFOrRouteRefreshRecvd");
12024
12025 if (CHECK_FLAG(p->af_flags[afi][safi],
12026 PEER_FLAG_REFLECTOR_CLIENT))
12027 json_object_boolean_true_add(json_addr,
12028 "routeReflectorClient");
12029 if (CHECK_FLAG(p->af_flags[afi][safi],
12030 PEER_FLAG_RSERVER_CLIENT))
12031 json_object_boolean_true_add(json_addr,
12032 "routeServerClient");
12033 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12034 json_object_boolean_true_add(json_addr,
12035 "inboundSoftConfigPermit");
12036
12037 if (CHECK_FLAG(p->af_flags[afi][safi],
12038 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12039 json_object_boolean_true_add(
12040 json_addr,
12041 "privateAsNumsAllReplacedInUpdatesToNbr");
12042 else if (CHECK_FLAG(p->af_flags[afi][safi],
12043 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12044 json_object_boolean_true_add(
12045 json_addr,
12046 "privateAsNumsReplacedInUpdatesToNbr");
12047 else if (CHECK_FLAG(p->af_flags[afi][safi],
12048 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12049 json_object_boolean_true_add(
12050 json_addr,
12051 "privateAsNumsAllRemovedInUpdatesToNbr");
12052 else if (CHECK_FLAG(p->af_flags[afi][safi],
12053 PEER_FLAG_REMOVE_PRIVATE_AS))
12054 json_object_boolean_true_add(
12055 json_addr,
12056 "privateAsNumsRemovedInUpdatesToNbr");
12057
dcc68b5e
MS
12058 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12059 json_object_boolean_true_add(
12060 json_addr,
12061 bgp_addpath_names(p->addpath_type[afi][safi])
12062 ->type_json_name);
d62a17ae 12063
12064 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12065 json_object_string_add(json_addr,
12066 "overrideASNsInOutboundUpdates",
12067 "ifAspathEqualRemoteAs");
12068
12069 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12070 || CHECK_FLAG(p->af_flags[afi][safi],
12071 PEER_FLAG_FORCE_NEXTHOP_SELF))
12072 json_object_boolean_true_add(json_addr,
12073 "routerAlwaysNextHop");
12074 if (CHECK_FLAG(p->af_flags[afi][safi],
12075 PEER_FLAG_AS_PATH_UNCHANGED))
12076 json_object_boolean_true_add(
12077 json_addr, "unchangedAsPathPropogatedToNbr");
12078 if (CHECK_FLAG(p->af_flags[afi][safi],
12079 PEER_FLAG_NEXTHOP_UNCHANGED))
12080 json_object_boolean_true_add(
12081 json_addr, "unchangedNextHopPropogatedToNbr");
12082 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12083 json_object_boolean_true_add(
12084 json_addr, "unchangedMedPropogatedToNbr");
12085 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12086 || CHECK_FLAG(p->af_flags[afi][safi],
12087 PEER_FLAG_SEND_EXT_COMMUNITY)) {
12088 if (CHECK_FLAG(p->af_flags[afi][safi],
12089 PEER_FLAG_SEND_COMMUNITY)
12090 && CHECK_FLAG(p->af_flags[afi][safi],
12091 PEER_FLAG_SEND_EXT_COMMUNITY))
12092 json_object_string_add(json_addr,
12093 "commAttriSentToNbr",
12094 "extendedAndStandard");
12095 else if (CHECK_FLAG(p->af_flags[afi][safi],
12096 PEER_FLAG_SEND_EXT_COMMUNITY))
12097 json_object_string_add(json_addr,
12098 "commAttriSentToNbr",
12099 "extended");
12100 else
12101 json_object_string_add(json_addr,
12102 "commAttriSentToNbr",
12103 "standard");
12104 }
12105 if (CHECK_FLAG(p->af_flags[afi][safi],
12106 PEER_FLAG_DEFAULT_ORIGINATE)) {
12107 if (p->default_rmap[afi][safi].name)
12108 json_object_string_add(
12109 json_addr, "defaultRouteMap",
12110 p->default_rmap[afi][safi].name);
12111
12112 if (paf && PAF_SUBGRP(paf)
12113 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12114 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12115 json_object_boolean_true_add(json_addr,
12116 "defaultSent");
12117 else
12118 json_object_boolean_true_add(json_addr,
12119 "defaultNotSent");
12120 }
12121
dff8f48d 12122 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 12123 if (is_evpn_enabled())
60466a63
QY
12124 json_object_boolean_true_add(
12125 json_addr, "advertiseAllVnis");
dff8f48d
MK
12126 }
12127
d62a17ae 12128 if (filter->plist[FILTER_IN].name
12129 || filter->dlist[FILTER_IN].name
12130 || filter->aslist[FILTER_IN].name
12131 || filter->map[RMAP_IN].name)
12132 json_object_boolean_true_add(json_addr,
12133 "inboundPathPolicyConfig");
12134 if (filter->plist[FILTER_OUT].name
12135 || filter->dlist[FILTER_OUT].name
12136 || filter->aslist[FILTER_OUT].name
12137 || filter->map[RMAP_OUT].name || filter->usmap.name)
12138 json_object_boolean_true_add(
12139 json_addr, "outboundPathPolicyConfig");
12140
12141 /* prefix-list */
12142 if (filter->plist[FILTER_IN].name)
12143 json_object_string_add(json_addr,
12144 "incomingUpdatePrefixFilterList",
12145 filter->plist[FILTER_IN].name);
12146 if (filter->plist[FILTER_OUT].name)
12147 json_object_string_add(json_addr,
12148 "outgoingUpdatePrefixFilterList",
12149 filter->plist[FILTER_OUT].name);
12150
12151 /* distribute-list */
12152 if (filter->dlist[FILTER_IN].name)
12153 json_object_string_add(
12154 json_addr, "incomingUpdateNetworkFilterList",
12155 filter->dlist[FILTER_IN].name);
12156 if (filter->dlist[FILTER_OUT].name)
12157 json_object_string_add(
12158 json_addr, "outgoingUpdateNetworkFilterList",
12159 filter->dlist[FILTER_OUT].name);
12160
12161 /* filter-list. */
12162 if (filter->aslist[FILTER_IN].name)
12163 json_object_string_add(json_addr,
12164 "incomingUpdateAsPathFilterList",
12165 filter->aslist[FILTER_IN].name);
12166 if (filter->aslist[FILTER_OUT].name)
12167 json_object_string_add(json_addr,
12168 "outgoingUpdateAsPathFilterList",
12169 filter->aslist[FILTER_OUT].name);
12170
12171 /* route-map. */
12172 if (filter->map[RMAP_IN].name)
12173 json_object_string_add(
12174 json_addr, "routeMapForIncomingAdvertisements",
12175 filter->map[RMAP_IN].name);
12176 if (filter->map[RMAP_OUT].name)
12177 json_object_string_add(
12178 json_addr, "routeMapForOutgoingAdvertisements",
12179 filter->map[RMAP_OUT].name);
12180
9dac9fc8 12181 /* ebgp-requires-policy (inbound) */
1d3fdccf 12182 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12183 && !bgp_inbound_policy_exists(p, filter))
12184 json_object_string_add(
12185 json_addr, "inboundEbgpRequiresPolicy",
12186 "Inbound updates discarded due to missing policy");
12187
12188 /* ebgp-requires-policy (outbound) */
1d3fdccf 12189 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12190 && (!bgp_outbound_policy_exists(p, filter)))
12191 json_object_string_add(
12192 json_addr, "outboundEbgpRequiresPolicy",
12193 "Outbound updates discarded due to missing policy");
12194
d62a17ae 12195 /* unsuppress-map */
12196 if (filter->usmap.name)
12197 json_object_string_add(json_addr,
12198 "selectiveUnsuppressRouteMap",
12199 filter->usmap.name);
12200
fa36596c
MK
12201 /* advertise-map */
12202 if (filter->advmap.aname) {
12203 json_advmap = json_object_new_object();
12204 json_object_string_add(json_advmap, "condition",
12205 filter->advmap.condition
12206 ? "EXIST"
12207 : "NON_EXIST");
12208 json_object_string_add(json_advmap, "conditionMap",
12209 filter->advmap.cname);
12210 json_object_string_add(json_advmap, "advertiseMap",
12211 filter->advmap.aname);
12212 json_object_string_add(json_advmap, "advertiseStatus",
12213 filter->advmap.update_type
12214 == ADVERTISE
12215 ? "Advertise"
12216 : "Withdraw");
12217 json_object_object_add(json_addr, "advertiseMap",
12218 json_advmap);
12219 }
12220
d62a17ae 12221 /* Receive prefix count */
12222 json_object_int_add(json_addr, "acceptedPrefixCounter",
12223 p->pcount[afi][safi]);
50e05855
AD
12224 if (paf && PAF_SUBGRP(paf))
12225 json_object_int_add(json_addr, "sentPrefixCounter",
12226 (PAF_SUBGRP(paf))->scount);
d62a17ae 12227
fde246e8
DA
12228 /* Maximum prefix */
12229 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12230 json_object_int_add(json_addr, "prefixOutAllowedMax",
12231 p->pmax_out[afi][safi]);
12232
d62a17ae 12233 /* Maximum prefix */
12234 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12235 json_object_int_add(json_addr, "prefixAllowedMax",
12236 p->pmax[afi][safi]);
12237 if (CHECK_FLAG(p->af_flags[afi][safi],
12238 PEER_FLAG_MAX_PREFIX_WARNING))
12239 json_object_boolean_true_add(
12240 json_addr, "prefixAllowedMaxWarning");
12241 json_object_int_add(json_addr,
12242 "prefixAllowedWarningThresh",
12243 p->pmax_threshold[afi][safi]);
12244 if (p->pmax_restart[afi][safi])
12245 json_object_int_add(
12246 json_addr,
12247 "prefixAllowedRestartIntervalMsecs",
12248 p->pmax_restart[afi][safi] * 60000);
12249 }
2986cac2 12250 json_object_object_add(json_neigh,
36235319 12251 get_afi_safi_str(afi, safi, true),
d62a17ae 12252 json_addr);
12253
12254 } else {
12255 filter = &p->filter[afi][safi];
12256
12257 vty_out(vty, " For address family: %s\n",
5cb5f4d0 12258 get_afi_safi_str(afi, safi, false));
d62a17ae 12259
12260 if (peer_group_active(p))
12261 vty_out(vty, " %s peer-group member\n",
12262 p->group->name);
12263
12264 paf = peer_af_find(p, afi, safi);
12265 if (paf && PAF_SUBGRP(paf)) {
6cde4b45 12266 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
d62a17ae 12267 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12268 vty_out(vty, " Packet Queue length %d\n",
12269 bpacket_queue_virtual_length(paf));
12270 } else {
12271 vty_out(vty, " Not part of any update group\n");
12272 }
12273 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12274 || CHECK_FLAG(p->af_cap[afi][safi],
12275 PEER_CAP_ORF_PREFIX_SM_RCV)
12276 || CHECK_FLAG(p->af_cap[afi][safi],
12277 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12278 || CHECK_FLAG(p->af_cap[afi][safi],
12279 PEER_CAP_ORF_PREFIX_RM_ADV)
12280 || CHECK_FLAG(p->af_cap[afi][safi],
12281 PEER_CAP_ORF_PREFIX_RM_RCV)
12282 || CHECK_FLAG(p->af_cap[afi][safi],
12283 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12284 vty_out(vty, " AF-dependant capabilities:\n");
12285
12286 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12287 || CHECK_FLAG(p->af_cap[afi][safi],
12288 PEER_CAP_ORF_PREFIX_SM_RCV)
12289 || CHECK_FLAG(p->af_cap[afi][safi],
12290 PEER_CAP_ORF_PREFIX_RM_ADV)
12291 || CHECK_FLAG(p->af_cap[afi][safi],
12292 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12293 vty_out(vty,
12294 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12295 ORF_TYPE_PREFIX);
12296 bgp_show_peer_afi_orf_cap(
12297 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12298 PEER_CAP_ORF_PREFIX_RM_ADV,
12299 PEER_CAP_ORF_PREFIX_SM_RCV,
12300 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12301 }
12302 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12303 || CHECK_FLAG(p->af_cap[afi][safi],
12304 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12305 || CHECK_FLAG(p->af_cap[afi][safi],
12306 PEER_CAP_ORF_PREFIX_RM_ADV)
12307 || CHECK_FLAG(p->af_cap[afi][safi],
12308 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12309 vty_out(vty,
12310 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12311 ORF_TYPE_PREFIX_OLD);
12312 bgp_show_peer_afi_orf_cap(
12313 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12314 PEER_CAP_ORF_PREFIX_RM_ADV,
12315 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12316 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12317 }
12318
772270f3
QY
12319 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12320 p->host, afi, safi);
d62a17ae 12321 orf_pfx_count = prefix_bgp_show_prefix_list(
12322 NULL, afi, orf_pfx_name, use_json);
12323
12324 if (CHECK_FLAG(p->af_sflags[afi][safi],
12325 PEER_STATUS_ORF_PREFIX_SEND)
12326 || orf_pfx_count) {
12327 vty_out(vty, " Outbound Route Filter (ORF):");
12328 if (CHECK_FLAG(p->af_sflags[afi][safi],
12329 PEER_STATUS_ORF_PREFIX_SEND))
12330 vty_out(vty, " sent;");
12331 if (orf_pfx_count)
12332 vty_out(vty, " received (%d entries)",
12333 orf_pfx_count);
12334 vty_out(vty, "\n");
12335 }
12336 if (CHECK_FLAG(p->af_sflags[afi][safi],
12337 PEER_STATUS_ORF_WAIT_REFRESH))
12338 vty_out(vty,
12339 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12340
12341 if (CHECK_FLAG(p->af_flags[afi][safi],
12342 PEER_FLAG_REFLECTOR_CLIENT))
12343 vty_out(vty, " Route-Reflector Client\n");
12344 if (CHECK_FLAG(p->af_flags[afi][safi],
12345 PEER_FLAG_RSERVER_CLIENT))
12346 vty_out(vty, " Route-Server Client\n");
12347 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12348 vty_out(vty,
12349 " Inbound soft reconfiguration allowed\n");
12350
12351 if (CHECK_FLAG(p->af_flags[afi][safi],
12352 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12353 vty_out(vty,
12354 " Private AS numbers (all) replaced in updates to this neighbor\n");
12355 else if (CHECK_FLAG(p->af_flags[afi][safi],
12356 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12357 vty_out(vty,
12358 " Private AS numbers replaced in updates to this neighbor\n");
12359 else if (CHECK_FLAG(p->af_flags[afi][safi],
12360 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12361 vty_out(vty,
12362 " Private AS numbers (all) removed in updates to this neighbor\n");
12363 else if (CHECK_FLAG(p->af_flags[afi][safi],
12364 PEER_FLAG_REMOVE_PRIVATE_AS))
12365 vty_out(vty,
12366 " Private AS numbers removed in updates to this neighbor\n");
12367
dcc68b5e
MS
12368 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12369 vty_out(vty, " %s\n",
12370 bgp_addpath_names(p->addpath_type[afi][safi])
12371 ->human_description);
d62a17ae 12372
12373 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12374 vty_out(vty,
12375 " Override ASNs in outbound updates if aspath equals remote-as\n");
12376
12377 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12378 || CHECK_FLAG(p->af_flags[afi][safi],
12379 PEER_FLAG_FORCE_NEXTHOP_SELF))
12380 vty_out(vty, " NEXT_HOP is always this router\n");
12381 if (CHECK_FLAG(p->af_flags[afi][safi],
12382 PEER_FLAG_AS_PATH_UNCHANGED))
12383 vty_out(vty,
12384 " AS_PATH is propagated unchanged to this neighbor\n");
12385 if (CHECK_FLAG(p->af_flags[afi][safi],
12386 PEER_FLAG_NEXTHOP_UNCHANGED))
12387 vty_out(vty,
12388 " NEXT_HOP is propagated unchanged to this neighbor\n");
12389 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12390 vty_out(vty,
12391 " MED is propagated unchanged to this neighbor\n");
12392 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12393 || CHECK_FLAG(p->af_flags[afi][safi],
12394 PEER_FLAG_SEND_EXT_COMMUNITY)
12395 || CHECK_FLAG(p->af_flags[afi][safi],
12396 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12397 vty_out(vty,
12398 " Community attribute sent to this neighbor");
12399 if (CHECK_FLAG(p->af_flags[afi][safi],
12400 PEER_FLAG_SEND_COMMUNITY)
12401 && CHECK_FLAG(p->af_flags[afi][safi],
12402 PEER_FLAG_SEND_EXT_COMMUNITY)
12403 && CHECK_FLAG(p->af_flags[afi][safi],
12404 PEER_FLAG_SEND_LARGE_COMMUNITY))
12405 vty_out(vty, "(all)\n");
12406 else if (CHECK_FLAG(p->af_flags[afi][safi],
12407 PEER_FLAG_SEND_LARGE_COMMUNITY))
12408 vty_out(vty, "(large)\n");
12409 else if (CHECK_FLAG(p->af_flags[afi][safi],
12410 PEER_FLAG_SEND_EXT_COMMUNITY))
12411 vty_out(vty, "(extended)\n");
12412 else
12413 vty_out(vty, "(standard)\n");
12414 }
12415 if (CHECK_FLAG(p->af_flags[afi][safi],
12416 PEER_FLAG_DEFAULT_ORIGINATE)) {
12417 vty_out(vty, " Default information originate,");
12418
12419 if (p->default_rmap[afi][safi].name)
12420 vty_out(vty, " default route-map %s%s,",
12421 p->default_rmap[afi][safi].map ? "*"
12422 : "",
12423 p->default_rmap[afi][safi].name);
12424 if (paf && PAF_SUBGRP(paf)
12425 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12426 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12427 vty_out(vty, " default sent\n");
12428 else
12429 vty_out(vty, " default not sent\n");
12430 }
12431
dff8f48d
MK
12432 /* advertise-vni-all */
12433 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 12434 if (is_evpn_enabled())
dff8f48d
MK
12435 vty_out(vty, " advertise-all-vni\n");
12436 }
12437
d62a17ae 12438 if (filter->plist[FILTER_IN].name
12439 || filter->dlist[FILTER_IN].name
12440 || filter->aslist[FILTER_IN].name
12441 || filter->map[RMAP_IN].name)
12442 vty_out(vty, " Inbound path policy configured\n");
12443 if (filter->plist[FILTER_OUT].name
12444 || filter->dlist[FILTER_OUT].name
12445 || filter->aslist[FILTER_OUT].name
12446 || filter->map[RMAP_OUT].name || filter->usmap.name)
12447 vty_out(vty, " Outbound path policy configured\n");
12448
12449 /* prefix-list */
12450 if (filter->plist[FILTER_IN].name)
12451 vty_out(vty,
12452 " Incoming update prefix filter list is %s%s\n",
12453 filter->plist[FILTER_IN].plist ? "*" : "",
12454 filter->plist[FILTER_IN].name);
12455 if (filter->plist[FILTER_OUT].name)
12456 vty_out(vty,
12457 " Outgoing update prefix filter list is %s%s\n",
12458 filter->plist[FILTER_OUT].plist ? "*" : "",
12459 filter->plist[FILTER_OUT].name);
12460
12461 /* distribute-list */
12462 if (filter->dlist[FILTER_IN].name)
12463 vty_out(vty,
12464 " Incoming update network filter list is %s%s\n",
12465 filter->dlist[FILTER_IN].alist ? "*" : "",
12466 filter->dlist[FILTER_IN].name);
12467 if (filter->dlist[FILTER_OUT].name)
12468 vty_out(vty,
12469 " Outgoing update network filter list is %s%s\n",
12470 filter->dlist[FILTER_OUT].alist ? "*" : "",
12471 filter->dlist[FILTER_OUT].name);
12472
12473 /* filter-list. */
12474 if (filter->aslist[FILTER_IN].name)
12475 vty_out(vty,
12476 " Incoming update AS path filter list is %s%s\n",
12477 filter->aslist[FILTER_IN].aslist ? "*" : "",
12478 filter->aslist[FILTER_IN].name);
12479 if (filter->aslist[FILTER_OUT].name)
12480 vty_out(vty,
12481 " Outgoing update AS path filter list is %s%s\n",
12482 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12483 filter->aslist[FILTER_OUT].name);
12484
12485 /* route-map. */
12486 if (filter->map[RMAP_IN].name)
12487 vty_out(vty,
12488 " Route map for incoming advertisements is %s%s\n",
12489 filter->map[RMAP_IN].map ? "*" : "",
12490 filter->map[RMAP_IN].name);
12491 if (filter->map[RMAP_OUT].name)
12492 vty_out(vty,
12493 " Route map for outgoing advertisements is %s%s\n",
12494 filter->map[RMAP_OUT].map ? "*" : "",
12495 filter->map[RMAP_OUT].name);
12496
9dac9fc8 12497 /* ebgp-requires-policy (inbound) */
1d3fdccf 12498 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12499 && !bgp_inbound_policy_exists(p, filter))
12500 vty_out(vty,
12501 " Inbound updates discarded due to missing policy\n");
12502
12503 /* ebgp-requires-policy (outbound) */
1d3fdccf 12504 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12505 && !bgp_outbound_policy_exists(p, filter))
12506 vty_out(vty,
12507 " Outbound updates discarded due to missing policy\n");
12508
d62a17ae 12509 /* unsuppress-map */
12510 if (filter->usmap.name)
12511 vty_out(vty,
12512 " Route map for selective unsuppress is %s%s\n",
12513 filter->usmap.map ? "*" : "",
12514 filter->usmap.name);
12515
7f7940e6
MK
12516 /* advertise-map */
12517 if (filter->advmap.aname && filter->advmap.cname)
12518 vty_out(vty,
12519 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12520 filter->advmap.condition ? "EXIST"
12521 : "NON_EXIST",
12522 filter->advmap.cmap ? "*" : "",
12523 filter->advmap.cname,
12524 filter->advmap.amap ? "*" : "",
12525 filter->advmap.aname,
fa36596c 12526 filter->advmap.update_type == ADVERTISE
c385f82a
MK
12527 ? "Advertise"
12528 : "Withdraw");
7f7940e6 12529
d62a17ae 12530 /* Receive prefix count */
6cde4b45 12531 vty_out(vty, " %u accepted prefixes\n",
a0a87037 12532 p->pcount[afi][safi]);
d62a17ae 12533
fde246e8
DA
12534 /* maximum-prefix-out */
12535 if (CHECK_FLAG(p->af_flags[afi][safi],
12536 PEER_FLAG_MAX_PREFIX_OUT))
12537 vty_out(vty,
6cde4b45 12538 " Maximum allowed prefixes sent %u\n",
fde246e8
DA
12539 p->pmax_out[afi][safi]);
12540
d62a17ae 12541 /* Maximum prefix */
12542 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
a0a87037 12543 vty_out(vty,
6cde4b45 12544 " Maximum prefixes allowed %u%s\n",
d62a17ae 12545 p->pmax[afi][safi],
12546 CHECK_FLAG(p->af_flags[afi][safi],
12547 PEER_FLAG_MAX_PREFIX_WARNING)
12548 ? " (warning-only)"
12549 : "");
12550 vty_out(vty, " Threshold for warning message %d%%",
12551 p->pmax_threshold[afi][safi]);
12552 if (p->pmax_restart[afi][safi])
12553 vty_out(vty, ", restart interval %d min",
12554 p->pmax_restart[afi][safi]);
12555 vty_out(vty, "\n");
12556 }
12557
12558 vty_out(vty, "\n");
12559 }
12560}
12561
9f049418 12562static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 12563 json_object *json)
718e3744 12564{
d62a17ae 12565 struct bgp *bgp;
12566 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
12567 char timebuf[BGP_UPTIME_LEN];
12568 char dn_flag[2];
d62a17ae 12569 afi_t afi;
12570 safi_t safi;
d7c0a89a
QY
12571 uint16_t i;
12572 uint8_t *msg;
d62a17ae 12573 json_object *json_neigh = NULL;
12574 time_t epoch_tbuf;
718e3744 12575
d62a17ae 12576 bgp = p->bgp;
12577
12578 if (use_json)
12579 json_neigh = json_object_new_object();
12580
12581 memset(dn_flag, '\0', sizeof(dn_flag));
12582 if (!p->conf_if && peer_dynamic_neighbor(p))
12583 dn_flag[0] = '*';
12584
12585 if (!use_json) {
12586 if (p->conf_if) /* Configured interface name. */
12587 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
12588 BGP_PEER_SU_UNSPEC(p)
12589 ? "None"
12590 : sockunion2str(&p->su, buf,
12591 SU_ADDRSTRLEN));
12592 else /* Configured IP address. */
12593 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12594 p->host);
12595 }
12596
12597 if (use_json) {
12598 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12599 json_object_string_add(json_neigh, "bgpNeighborAddr",
12600 "none");
12601 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12602 json_object_string_add(
12603 json_neigh, "bgpNeighborAddr",
12604 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
12605
12606 json_object_int_add(json_neigh, "remoteAs", p->as);
12607
12608 if (p->change_local_as)
12609 json_object_int_add(json_neigh, "localAs",
12610 p->change_local_as);
12611 else
12612 json_object_int_add(json_neigh, "localAs", p->local_as);
12613
12614 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12615 json_object_boolean_true_add(json_neigh,
12616 "localAsNoPrepend");
12617
12618 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12619 json_object_boolean_true_add(json_neigh,
12620 "localAsReplaceAs");
12621 } else {
12622 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12623 || (p->as_type == AS_INTERNAL))
12624 vty_out(vty, "remote AS %u, ", p->as);
12625 else
12626 vty_out(vty, "remote AS Unspecified, ");
12627 vty_out(vty, "local AS %u%s%s, ",
12628 p->change_local_as ? p->change_local_as : p->local_as,
12629 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12630 ? " no-prepend"
12631 : "",
12632 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12633 ? " replace-as"
12634 : "");
12635 }
faa16034
DS
12636 /* peer type internal or confed-internal */
12637 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
d62a17ae 12638 if (use_json) {
12639 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12640 json_object_boolean_true_add(
12641 json_neigh, "nbrConfedInternalLink");
12642 else
12643 json_object_boolean_true_add(json_neigh,
12644 "nbrInternalLink");
12645 } else {
12646 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12647 vty_out(vty, "confed-internal link\n");
12648 else
12649 vty_out(vty, "internal link\n");
12650 }
faa16034
DS
12651 /* peer type external or confed-external */
12652 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
d62a17ae 12653 if (use_json) {
12654 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12655 json_object_boolean_true_add(
12656 json_neigh, "nbrConfedExternalLink");
12657 else
12658 json_object_boolean_true_add(json_neigh,
12659 "nbrExternalLink");
12660 } else {
12661 if (bgp_confederation_peers_check(bgp, p->as))
12662 vty_out(vty, "confed-external link\n");
12663 else
12664 vty_out(vty, "external link\n");
12665 }
faa16034
DS
12666 } else {
12667 if (use_json)
12668 json_object_boolean_true_add(json_neigh,
12669 "nbrUnspecifiedLink");
12670 else
12671 vty_out(vty, "unspecified link\n");
d62a17ae 12672 }
12673
12674 /* Description. */
12675 if (p->desc) {
12676 if (use_json)
12677 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12678 else
12679 vty_out(vty, " Description: %s\n", p->desc);
12680 }
12681
12682 if (p->hostname) {
12683 if (use_json) {
12684 if (p->hostname)
12685 json_object_string_add(json_neigh, "hostname",
12686 p->hostname);
12687
12688 if (p->domainname)
12689 json_object_string_add(json_neigh, "domainname",
12690 p->domainname);
12691 } else {
12692 if (p->domainname && (p->domainname[0] != '\0'))
12693 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
12694 p->domainname);
12695 else
12696 vty_out(vty, "Hostname: %s\n", p->hostname);
12697 }
12698 }
12699
12700 /* Peer-group */
12701 if (p->group) {
12702 if (use_json) {
12703 json_object_string_add(json_neigh, "peerGroup",
12704 p->group->name);
12705
12706 if (dn_flag[0]) {
12707 struct prefix prefix, *range = NULL;
12708
0154d8ce
DS
12709 if (sockunion2hostprefix(&(p->su), &prefix))
12710 range = peer_group_lookup_dynamic_neighbor_range(
12711 p->group, &prefix);
d62a17ae 12712
12713 if (range) {
12714 prefix2str(range, buf1, sizeof(buf1));
12715 json_object_string_add(
12716 json_neigh,
12717 "peerSubnetRangeGroup", buf1);
12718 }
12719 }
12720 } else {
12721 vty_out(vty,
12722 " Member of peer-group %s for session parameters\n",
12723 p->group->name);
12724
12725 if (dn_flag[0]) {
12726 struct prefix prefix, *range = NULL;
12727
0154d8ce
DS
12728 if (sockunion2hostprefix(&(p->su), &prefix))
12729 range = peer_group_lookup_dynamic_neighbor_range(
12730 p->group, &prefix);
d62a17ae 12731
12732 if (range) {
d62a17ae 12733 vty_out(vty,
1b78780b
DL
12734 " Belongs to the subnet range group: %pFX\n",
12735 range);
d62a17ae 12736 }
12737 }
12738 }
12739 }
12740
12741 if (use_json) {
12742 /* Administrative shutdown. */
cb9196e7
DS
12743 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12744 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 12745 json_object_boolean_true_add(json_neigh,
12746 "adminShutDown");
12747
12748 /* BGP Version. */
12749 json_object_int_add(json_neigh, "bgpVersion", 4);
12750 json_object_string_add(
12751 json_neigh, "remoteRouterId",
12752 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
d0086e8e
AD
12753 json_object_string_add(
12754 json_neigh, "localRouterId",
12755 inet_ntop(AF_INET, &bgp->router_id, buf1,
12756 sizeof(buf1)));
d62a17ae 12757
12758 /* Confederation */
12759 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12760 && bgp_confederation_peers_check(bgp, p->as))
12761 json_object_boolean_true_add(json_neigh,
12762 "nbrCommonAdmin");
12763
12764 /* Status. */
12765 json_object_string_add(
12766 json_neigh, "bgpState",
12767 lookup_msg(bgp_status_msg, p->status, NULL));
12768
12769 if (p->status == Established) {
12770 time_t uptime;
d62a17ae 12771
12772 uptime = bgp_clock();
12773 uptime -= p->uptime;
d62a17ae 12774 epoch_tbuf = time(NULL) - uptime;
12775
d3c7efed
DS
12776 json_object_int_add(json_neigh, "bgpTimerUpMsec",
12777 uptime * 1000);
d62a17ae 12778 json_object_string_add(json_neigh, "bgpTimerUpString",
12779 peer_uptime(p->uptime, timebuf,
12780 BGP_UPTIME_LEN, 0,
12781 NULL));
12782 json_object_int_add(json_neigh,
12783 "bgpTimerUpEstablishedEpoch",
12784 epoch_tbuf);
12785 }
12786
12787 else if (p->status == Active) {
12788 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12789 json_object_string_add(json_neigh, "bgpStateIs",
12790 "passive");
12791 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12792 json_object_string_add(json_neigh, "bgpStateIs",
12793 "passiveNSF");
12794 }
12795
12796 /* read timer */
12797 time_t uptime;
a2700b50 12798 struct tm tm;
d62a17ae 12799
12800 uptime = bgp_clock();
12801 uptime -= p->readtime;
a2700b50
MS
12802 gmtime_r(&uptime, &tm);
12803
d62a17ae 12804 json_object_int_add(json_neigh, "bgpTimerLastRead",
a2700b50
MS
12805 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12806 + (tm.tm_hour * 3600000));
d62a17ae 12807
12808 uptime = bgp_clock();
12809 uptime -= p->last_write;
a2700b50
MS
12810 gmtime_r(&uptime, &tm);
12811
d62a17ae 12812 json_object_int_add(json_neigh, "bgpTimerLastWrite",
a2700b50
MS
12813 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12814 + (tm.tm_hour * 3600000));
d62a17ae 12815
12816 uptime = bgp_clock();
12817 uptime -= p->update_time;
a2700b50
MS
12818 gmtime_r(&uptime, &tm);
12819
d62a17ae 12820 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
a2700b50
MS
12821 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12822 + (tm.tm_hour * 3600000));
d62a17ae 12823
12824 /* Configured timer values. */
12825 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
12826 p->v_holdtime * 1000);
12827 json_object_int_add(json_neigh,
12828 "bgpTimerKeepAliveIntervalMsecs",
12829 p->v_keepalive * 1000);
d43114f3
DS
12830 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
12831 json_object_int_add(json_neigh,
12832 "bgpTimerDelayOpenTimeMsecs",
12833 p->v_delayopen * 1000);
12834 }
12835
b90a8e13 12836 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 12837 json_object_int_add(json_neigh,
12838 "bgpTimerConfiguredHoldTimeMsecs",
12839 p->holdtime * 1000);
12840 json_object_int_add(
12841 json_neigh,
12842 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12843 p->keepalive * 1000);
5d5393b9
DL
12844 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12845 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
12846 json_object_int_add(json_neigh,
12847 "bgpTimerConfiguredHoldTimeMsecs",
12848 bgp->default_holdtime);
12849 json_object_int_add(
12850 json_neigh,
12851 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12852 bgp->default_keepalive);
d62a17ae 12853 }
12854 } else {
12855 /* Administrative shutdown. */
cb9196e7
DS
12856 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12857 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 12858 vty_out(vty, " Administratively shut down\n");
12859
12860 /* BGP Version. */
12861 vty_out(vty, " BGP version 4");
0e38aeb4 12862 vty_out(vty, ", remote router ID %s",
d62a17ae 12863 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
0e38aeb4
AD
12864 vty_out(vty, ", local router ID %s\n",
12865 inet_ntop(AF_INET, &bgp->router_id, buf1,
12866 sizeof(buf1)));
d62a17ae 12867
12868 /* Confederation */
12869 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12870 && bgp_confederation_peers_check(bgp, p->as))
12871 vty_out(vty,
12872 " Neighbor under common administration\n");
12873
12874 /* Status. */
12875 vty_out(vty, " BGP state = %s",
12876 lookup_msg(bgp_status_msg, p->status, NULL));
12877
12878 if (p->status == Established)
12879 vty_out(vty, ", up for %8s",
12880 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
12881 0, NULL));
12882
12883 else if (p->status == Active) {
12884 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12885 vty_out(vty, " (passive)");
12886 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12887 vty_out(vty, " (NSF passive)");
12888 }
12889 vty_out(vty, "\n");
12890
12891 /* read timer */
12892 vty_out(vty, " Last read %s",
12893 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
12894 NULL));
12895 vty_out(vty, ", Last write %s\n",
12896 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
12897 NULL));
12898
12899 /* Configured timer values. */
12900 vty_out(vty,
12901 " Hold time is %d, keepalive interval is %d seconds\n",
12902 p->v_holdtime, p->v_keepalive);
b90a8e13 12903 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 12904 vty_out(vty, " Configured hold time is %d",
12905 p->holdtime);
12906 vty_out(vty, ", keepalive interval is %d seconds\n",
12907 p->keepalive);
5d5393b9
DL
12908 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12909 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
12910 vty_out(vty, " Configured hold time is %d",
12911 bgp->default_holdtime);
12912 vty_out(vty, ", keepalive interval is %d seconds\n",
12913 bgp->default_keepalive);
d62a17ae 12914 }
d43114f3
DS
12915 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
12916 vty_out(vty,
12917 " Configured DelayOpenTime is %d seconds\n",
12918 p->delayopen);
d62a17ae 12919 }
12920 /* Capability. */
12921 if (p->status == Established) {
12922 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
12923 || p->afc_recv[AFI_IP][SAFI_UNICAST]
12924 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
12925 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
12926 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
12927 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
12928 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
12929 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
12930 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
12931 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
12932 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
12933 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
7c40bf39 12934 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
12935 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
d62a17ae 12936 || p->afc_adv[AFI_IP][SAFI_ENCAP]
12937 || p->afc_recv[AFI_IP][SAFI_ENCAP]
7c40bf39 12938 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
12939 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
d62a17ae 12940 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
12941 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
12942 if (use_json) {
12943 json_object *json_cap = NULL;
12944
12945 json_cap = json_object_new_object();
12946
12947 /* AS4 */
12948 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
12949 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
12950 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
12951 && CHECK_FLAG(p->cap,
12952 PEER_CAP_AS4_RCV))
12953 json_object_string_add(
12954 json_cap, "4byteAs",
12955 "advertisedAndReceived");
12956 else if (CHECK_FLAG(p->cap,
12957 PEER_CAP_AS4_ADV))
12958 json_object_string_add(
12959 json_cap, "4byteAs",
12960 "advertised");
12961 else if (CHECK_FLAG(p->cap,
12962 PEER_CAP_AS4_RCV))
12963 json_object_string_add(
12964 json_cap, "4byteAs",
12965 "received");
12966 }
12967
12968 /* AddPath */
12969 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
12970 || CHECK_FLAG(p->cap,
12971 PEER_CAP_ADDPATH_ADV)) {
12972 json_object *json_add = NULL;
12973 const char *print_store;
12974
12975 json_add = json_object_new_object();
12976
05c7a1cc
QY
12977 FOREACH_AFI_SAFI (afi, safi) {
12978 json_object *json_sub = NULL;
12979 json_sub =
12980 json_object_new_object();
5cb5f4d0
DD
12981 print_store = get_afi_safi_str(
12982 afi, safi, true);
d62a17ae 12983
05c7a1cc
QY
12984 if (CHECK_FLAG(
12985 p->af_cap[afi]
12986 [safi],
12987 PEER_CAP_ADDPATH_AF_TX_ADV)
12988 || CHECK_FLAG(
12989 p->af_cap[afi]
12990 [safi],
12991 PEER_CAP_ADDPATH_AF_TX_RCV)) {
d62a17ae 12992 if (CHECK_FLAG(
12993 p->af_cap
12994 [afi]
12995 [safi],
12996 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 12997 && CHECK_FLAG(
d62a17ae 12998 p->af_cap
12999 [afi]
13000 [safi],
05c7a1cc
QY
13001 PEER_CAP_ADDPATH_AF_TX_RCV))
13002 json_object_boolean_true_add(
13003 json_sub,
13004 "txAdvertisedAndReceived");
13005 else if (
13006 CHECK_FLAG(
13007 p->af_cap
13008 [afi]
13009 [safi],
13010 PEER_CAP_ADDPATH_AF_TX_ADV))
13011 json_object_boolean_true_add(
13012 json_sub,
13013 "txAdvertised");
13014 else if (
13015 CHECK_FLAG(
13016 p->af_cap
13017 [afi]
13018 [safi],
13019 PEER_CAP_ADDPATH_AF_TX_RCV))
13020 json_object_boolean_true_add(
13021 json_sub,
13022 "txReceived");
13023 }
d62a17ae 13024
05c7a1cc
QY
13025 if (CHECK_FLAG(
13026 p->af_cap[afi]
13027 [safi],
13028 PEER_CAP_ADDPATH_AF_RX_ADV)
13029 || CHECK_FLAG(
13030 p->af_cap[afi]
13031 [safi],
13032 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 13033 if (CHECK_FLAG(
13034 p->af_cap
13035 [afi]
13036 [safi],
13037 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 13038 && CHECK_FLAG(
d62a17ae 13039 p->af_cap
13040 [afi]
13041 [safi],
13042 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
13043 json_object_boolean_true_add(
13044 json_sub,
13045 "rxAdvertisedAndReceived");
13046 else if (
13047 CHECK_FLAG(
13048 p->af_cap
13049 [afi]
13050 [safi],
13051 PEER_CAP_ADDPATH_AF_RX_ADV))
13052 json_object_boolean_true_add(
13053 json_sub,
13054 "rxAdvertised");
13055 else if (
13056 CHECK_FLAG(
13057 p->af_cap
13058 [afi]
13059 [safi],
13060 PEER_CAP_ADDPATH_AF_RX_RCV))
13061 json_object_boolean_true_add(
13062 json_sub,
13063 "rxReceived");
d62a17ae 13064 }
13065
05c7a1cc
QY
13066 if (CHECK_FLAG(
13067 p->af_cap[afi]
13068 [safi],
13069 PEER_CAP_ADDPATH_AF_TX_ADV)
13070 || CHECK_FLAG(
13071 p->af_cap[afi]
13072 [safi],
13073 PEER_CAP_ADDPATH_AF_TX_RCV)
13074 || CHECK_FLAG(
13075 p->af_cap[afi]
13076 [safi],
13077 PEER_CAP_ADDPATH_AF_RX_ADV)
13078 || CHECK_FLAG(
13079 p->af_cap[afi]
13080 [safi],
13081 PEER_CAP_ADDPATH_AF_RX_RCV))
13082 json_object_object_add(
13083 json_add,
13084 print_store,
13085 json_sub);
13086 else
13087 json_object_free(
13088 json_sub);
13089 }
13090
d62a17ae 13091 json_object_object_add(
13092 json_cap, "addPath", json_add);
13093 }
13094
13095 /* Dynamic */
13096 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
13097 || CHECK_FLAG(p->cap,
13098 PEER_CAP_DYNAMIC_ADV)) {
13099 if (CHECK_FLAG(p->cap,
13100 PEER_CAP_DYNAMIC_ADV)
13101 && CHECK_FLAG(p->cap,
13102 PEER_CAP_DYNAMIC_RCV))
13103 json_object_string_add(
13104 json_cap, "dynamic",
13105 "advertisedAndReceived");
13106 else if (CHECK_FLAG(
13107 p->cap,
13108 PEER_CAP_DYNAMIC_ADV))
13109 json_object_string_add(
13110 json_cap, "dynamic",
13111 "advertised");
13112 else if (CHECK_FLAG(
13113 p->cap,
13114 PEER_CAP_DYNAMIC_RCV))
13115 json_object_string_add(
13116 json_cap, "dynamic",
13117 "received");
13118 }
13119
13120 /* Extended nexthop */
13121 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
13122 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13123 json_object *json_nxt = NULL;
13124 const char *print_store;
13125
13126
13127 if (CHECK_FLAG(p->cap,
13128 PEER_CAP_ENHE_ADV)
13129 && CHECK_FLAG(p->cap,
13130 PEER_CAP_ENHE_RCV))
13131 json_object_string_add(
13132 json_cap,
13133 "extendedNexthop",
13134 "advertisedAndReceived");
13135 else if (CHECK_FLAG(p->cap,
13136 PEER_CAP_ENHE_ADV))
13137 json_object_string_add(
13138 json_cap,
13139 "extendedNexthop",
13140 "advertised");
13141 else if (CHECK_FLAG(p->cap,
13142 PEER_CAP_ENHE_RCV))
13143 json_object_string_add(
13144 json_cap,
13145 "extendedNexthop",
13146 "received");
13147
13148 if (CHECK_FLAG(p->cap,
13149 PEER_CAP_ENHE_RCV)) {
13150 json_nxt =
13151 json_object_new_object();
13152
13153 for (safi = SAFI_UNICAST;
13154 safi < SAFI_MAX; safi++) {
13155 if (CHECK_FLAG(
13156 p->af_cap
13157 [AFI_IP]
13158 [safi],
13159 PEER_CAP_ENHE_AF_RCV)) {
5cb5f4d0 13160 print_store = get_afi_safi_str(
d62a17ae 13161 AFI_IP,
5cb5f4d0 13162 safi, true);
d62a17ae 13163 json_object_string_add(
13164 json_nxt,
13165 print_store,
54f29523 13166 "recieved"); /* misspelled for compatibility */
d62a17ae 13167 }
13168 }
13169 json_object_object_add(
13170 json_cap,
13171 "extendedNexthopFamililesByPeer",
13172 json_nxt);
13173 }
13174 }
13175
13176 /* Route Refresh */
13177 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
13178 || CHECK_FLAG(p->cap,
13179 PEER_CAP_REFRESH_NEW_RCV)
13180 || CHECK_FLAG(p->cap,
13181 PEER_CAP_REFRESH_OLD_RCV)) {
13182 if (CHECK_FLAG(p->cap,
13183 PEER_CAP_REFRESH_ADV)
13184 && (CHECK_FLAG(
13185 p->cap,
13186 PEER_CAP_REFRESH_NEW_RCV)
13187 || CHECK_FLAG(
13188 p->cap,
13189 PEER_CAP_REFRESH_OLD_RCV))) {
13190 if (CHECK_FLAG(
13191 p->cap,
13192 PEER_CAP_REFRESH_OLD_RCV)
13193 && CHECK_FLAG(
13194 p->cap,
13195 PEER_CAP_REFRESH_NEW_RCV))
13196 json_object_string_add(
13197 json_cap,
13198 "routeRefresh",
13199 "advertisedAndReceivedOldNew");
13200 else {
13201 if (CHECK_FLAG(
13202 p->cap,
13203 PEER_CAP_REFRESH_OLD_RCV))
13204 json_object_string_add(
13205 json_cap,
13206 "routeRefresh",
13207 "advertisedAndReceivedOld");
13208 else
13209 json_object_string_add(
13210 json_cap,
13211 "routeRefresh",
13212 "advertisedAndReceivedNew");
13213 }
13214 } else if (
13215 CHECK_FLAG(
13216 p->cap,
13217 PEER_CAP_REFRESH_ADV))
13218 json_object_string_add(
13219 json_cap,
13220 "routeRefresh",
13221 "advertised");
13222 else if (
13223 CHECK_FLAG(
13224 p->cap,
13225 PEER_CAP_REFRESH_NEW_RCV)
13226 || CHECK_FLAG(
13227 p->cap,
13228 PEER_CAP_REFRESH_OLD_RCV))
13229 json_object_string_add(
13230 json_cap,
13231 "routeRefresh",
13232 "received");
13233 }
13234
9af52ccf
DA
13235 /* Enhanced Route Refresh */
13236 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV)
13237 || CHECK_FLAG(p->cap,
13238 PEER_CAP_ENHANCED_RR_RCV)) {
13239 if (CHECK_FLAG(p->cap,
13240 PEER_CAP_ENHANCED_RR_ADV)
13241 && CHECK_FLAG(
13242 p->cap,
13243 PEER_CAP_ENHANCED_RR_RCV))
13244 json_object_string_add(
13245 json_cap,
13246 "enhancedRouteRefresh",
13247 "advertisedAndReceived");
13248 else if (
13249 CHECK_FLAG(
13250 p->cap,
13251 PEER_CAP_ENHANCED_RR_ADV))
13252 json_object_string_add(
13253 json_cap,
13254 "enhancedRouteRefresh",
13255 "advertised");
13256 else if (
13257 CHECK_FLAG(
13258 p->cap,
13259 PEER_CAP_ENHANCED_RR_RCV))
13260 json_object_string_add(
13261 json_cap,
13262 "enhancedRouteRefresh",
13263 "received");
13264 }
13265
d62a17ae 13266 /* Multiprotocol Extensions */
13267 json_object *json_multi = NULL;
13268 json_multi = json_object_new_object();
13269
05c7a1cc
QY
13270 FOREACH_AFI_SAFI (afi, safi) {
13271 if (p->afc_adv[afi][safi]
13272 || p->afc_recv[afi][safi]) {
13273 json_object *json_exten = NULL;
13274 json_exten =
13275 json_object_new_object();
13276
d62a17ae 13277 if (p->afc_adv[afi][safi]
05c7a1cc
QY
13278 && p->afc_recv[afi][safi])
13279 json_object_boolean_true_add(
13280 json_exten,
13281 "advertisedAndReceived");
13282 else if (p->afc_adv[afi][safi])
13283 json_object_boolean_true_add(
13284 json_exten,
13285 "advertised");
13286 else if (p->afc_recv[afi][safi])
13287 json_object_boolean_true_add(
13288 json_exten,
13289 "received");
d62a17ae 13290
05c7a1cc
QY
13291 json_object_object_add(
13292 json_multi,
5cb5f4d0
DD
13293 get_afi_safi_str(afi,
13294 safi,
13295 true),
05c7a1cc 13296 json_exten);
d62a17ae 13297 }
13298 }
13299 json_object_object_add(
13300 json_cap, "multiprotocolExtensions",
13301 json_multi);
13302
d77114b7 13303 /* Hostname capabilities */
60466a63 13304 json_object *json_hname = NULL;
d77114b7
MK
13305
13306 json_hname = json_object_new_object();
13307
13308 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13309 json_object_string_add(
60466a63
QY
13310 json_hname, "advHostName",
13311 bgp->peer_self->hostname
13312 ? bgp->peer_self
13313 ->hostname
d77114b7
MK
13314 : "n/a");
13315 json_object_string_add(
60466a63
QY
13316 json_hname, "advDomainName",
13317 bgp->peer_self->domainname
13318 ? bgp->peer_self
13319 ->domainname
d77114b7
MK
13320 : "n/a");
13321 }
13322
13323
13324 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13325 json_object_string_add(
60466a63
QY
13326 json_hname, "rcvHostName",
13327 p->hostname ? p->hostname
13328 : "n/a");
d77114b7 13329 json_object_string_add(
60466a63
QY
13330 json_hname, "rcvDomainName",
13331 p->domainname ? p->domainname
13332 : "n/a");
d77114b7
MK
13333 }
13334
60466a63 13335 json_object_object_add(json_cap, "hostName",
d77114b7
MK
13336 json_hname);
13337
d62a17ae 13338 /* Gracefull Restart */
13339 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
13340 || CHECK_FLAG(p->cap,
13341 PEER_CAP_RESTART_ADV)) {
13342 if (CHECK_FLAG(p->cap,
13343 PEER_CAP_RESTART_ADV)
13344 && CHECK_FLAG(p->cap,
13345 PEER_CAP_RESTART_RCV))
13346 json_object_string_add(
13347 json_cap,
13348 "gracefulRestart",
13349 "advertisedAndReceived");
13350 else if (CHECK_FLAG(
13351 p->cap,
13352 PEER_CAP_RESTART_ADV))
13353 json_object_string_add(
13354 json_cap,
13355 "gracefulRestartCapability",
13356 "advertised");
13357 else if (CHECK_FLAG(
13358 p->cap,
13359 PEER_CAP_RESTART_RCV))
13360 json_object_string_add(
13361 json_cap,
13362 "gracefulRestartCapability",
13363 "received");
13364
13365 if (CHECK_FLAG(p->cap,
13366 PEER_CAP_RESTART_RCV)) {
13367 int restart_af_count = 0;
13368 json_object *json_restart =
13369 NULL;
13370 json_restart =
13371 json_object_new_object();
13372
13373 json_object_int_add(
13374 json_cap,
13375 "gracefulRestartRemoteTimerMsecs",
13376 p->v_gr_restart * 1000);
13377
05c7a1cc
QY
13378 FOREACH_AFI_SAFI (afi, safi) {
13379 if (CHECK_FLAG(
13380 p->af_cap
13381 [afi]
13382 [safi],
13383 PEER_CAP_RESTART_AF_RCV)) {
13384 json_object *
13385 json_sub =
13386 NULL;
13387 json_sub =
13388 json_object_new_object();
13389
d62a17ae 13390 if (CHECK_FLAG(
13391 p->af_cap
13392 [afi]
13393 [safi],
05c7a1cc
QY
13394 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13395 json_object_boolean_true_add(
13396 json_sub,
13397 "preserved");
13398 restart_af_count++;
13399 json_object_object_add(
13400 json_restart,
5cb5f4d0 13401 get_afi_safi_str(
05c7a1cc 13402 afi,
5cb5f4d0
DD
13403 safi,
13404 true),
05c7a1cc 13405 json_sub);
d62a17ae 13406 }
13407 }
13408 if (!restart_af_count) {
13409 json_object_string_add(
13410 json_cap,
13411 "addressFamiliesByPeer",
13412 "none");
13413 json_object_free(
13414 json_restart);
13415 } else
13416 json_object_object_add(
13417 json_cap,
13418 "addressFamiliesByPeer",
13419 json_restart);
13420 }
13421 }
13422 json_object_object_add(json_neigh,
13423 "neighborCapabilities",
13424 json_cap);
13425 } else {
13426 vty_out(vty, " Neighbor capabilities:\n");
13427
13428 /* AS4 */
13429 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
13430 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13431 vty_out(vty, " 4 Byte AS:");
13432 if (CHECK_FLAG(p->cap,
13433 PEER_CAP_AS4_ADV))
13434 vty_out(vty, " advertised");
13435 if (CHECK_FLAG(p->cap,
13436 PEER_CAP_AS4_RCV))
13437 vty_out(vty, " %sreceived",
13438 CHECK_FLAG(
13439 p->cap,
13440 PEER_CAP_AS4_ADV)
13441 ? "and "
13442 : "");
13443 vty_out(vty, "\n");
13444 }
13445
13446 /* AddPath */
13447 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
13448 || CHECK_FLAG(p->cap,
13449 PEER_CAP_ADDPATH_ADV)) {
13450 vty_out(vty, " AddPath:\n");
13451
05c7a1cc
QY
13452 FOREACH_AFI_SAFI (afi, safi) {
13453 if (CHECK_FLAG(
13454 p->af_cap[afi]
13455 [safi],
13456 PEER_CAP_ADDPATH_AF_TX_ADV)
13457 || CHECK_FLAG(
13458 p->af_cap[afi]
13459 [safi],
13460 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13461 vty_out(vty,
13462 " %s: TX ",
5cb5f4d0 13463 get_afi_safi_str(
05c7a1cc 13464 afi,
5cb5f4d0
DD
13465 safi,
13466 false));
05c7a1cc 13467
d62a17ae 13468 if (CHECK_FLAG(
13469 p->af_cap
13470 [afi]
13471 [safi],
05c7a1cc 13472 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 13473 vty_out(vty,
05c7a1cc 13474 "advertised %s",
5cb5f4d0 13475 get_afi_safi_str(
d62a17ae 13476 afi,
5cb5f4d0
DD
13477 safi,
13478 false));
d62a17ae 13479
05c7a1cc
QY
13480 if (CHECK_FLAG(
13481 p->af_cap
13482 [afi]
13483 [safi],
13484 PEER_CAP_ADDPATH_AF_TX_RCV))
13485 vty_out(vty,
13486 "%sreceived",
13487 CHECK_FLAG(
13488 p->af_cap
13489 [afi]
13490 [safi],
13491 PEER_CAP_ADDPATH_AF_TX_ADV)
13492 ? " and "
13493 : "");
d62a17ae 13494
05c7a1cc
QY
13495 vty_out(vty, "\n");
13496 }
d62a17ae 13497
05c7a1cc
QY
13498 if (CHECK_FLAG(
13499 p->af_cap[afi]
13500 [safi],
13501 PEER_CAP_ADDPATH_AF_RX_ADV)
13502 || CHECK_FLAG(
13503 p->af_cap[afi]
13504 [safi],
13505 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13506 vty_out(vty,
13507 " %s: RX ",
5cb5f4d0 13508 get_afi_safi_str(
05c7a1cc 13509 afi,
5cb5f4d0
DD
13510 safi,
13511 false));
d62a17ae 13512
13513 if (CHECK_FLAG(
13514 p->af_cap
13515 [afi]
13516 [safi],
05c7a1cc 13517 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 13518 vty_out(vty,
05c7a1cc 13519 "advertised %s",
5cb5f4d0 13520 get_afi_safi_str(
d62a17ae 13521 afi,
5cb5f4d0
DD
13522 safi,
13523 false));
d62a17ae 13524
05c7a1cc
QY
13525 if (CHECK_FLAG(
13526 p->af_cap
13527 [afi]
13528 [safi],
13529 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 13530 vty_out(vty,
05c7a1cc
QY
13531 "%sreceived",
13532 CHECK_FLAG(
13533 p->af_cap
13534 [afi]
13535 [safi],
13536 PEER_CAP_ADDPATH_AF_RX_ADV)
13537 ? " and "
13538 : "");
13539
13540 vty_out(vty, "\n");
d62a17ae 13541 }
05c7a1cc 13542 }
d62a17ae 13543 }
13544
13545 /* Dynamic */
13546 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
13547 || CHECK_FLAG(p->cap,
13548 PEER_CAP_DYNAMIC_ADV)) {
13549 vty_out(vty, " Dynamic:");
13550 if (CHECK_FLAG(p->cap,
13551 PEER_CAP_DYNAMIC_ADV))
13552 vty_out(vty, " advertised");
13553 if (CHECK_FLAG(p->cap,
13554 PEER_CAP_DYNAMIC_RCV))
13555 vty_out(vty, " %sreceived",
13556 CHECK_FLAG(
13557 p->cap,
13558 PEER_CAP_DYNAMIC_ADV)
13559 ? "and "
13560 : "");
13561 vty_out(vty, "\n");
13562 }
13563
13564 /* Extended nexthop */
13565 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
13566 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13567 vty_out(vty, " Extended nexthop:");
13568 if (CHECK_FLAG(p->cap,
13569 PEER_CAP_ENHE_ADV))
13570 vty_out(vty, " advertised");
13571 if (CHECK_FLAG(p->cap,
13572 PEER_CAP_ENHE_RCV))
13573 vty_out(vty, " %sreceived",
13574 CHECK_FLAG(
13575 p->cap,
13576 PEER_CAP_ENHE_ADV)
13577 ? "and "
13578 : "");
13579 vty_out(vty, "\n");
13580
13581 if (CHECK_FLAG(p->cap,
13582 PEER_CAP_ENHE_RCV)) {
13583 vty_out(vty,
13584 " Address families by peer:\n ");
13585 for (safi = SAFI_UNICAST;
13586 safi < SAFI_MAX; safi++)
13587 if (CHECK_FLAG(
13588 p->af_cap
13589 [AFI_IP]
13590 [safi],
13591 PEER_CAP_ENHE_AF_RCV))
13592 vty_out(vty,
13593 " %s\n",
5cb5f4d0 13594 get_afi_safi_str(
d62a17ae 13595 AFI_IP,
5cb5f4d0
DD
13596 safi,
13597 false));
d62a17ae 13598 }
13599 }
13600
13601 /* Route Refresh */
13602 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
13603 || CHECK_FLAG(p->cap,
13604 PEER_CAP_REFRESH_NEW_RCV)
13605 || CHECK_FLAG(p->cap,
13606 PEER_CAP_REFRESH_OLD_RCV)) {
13607 vty_out(vty, " Route refresh:");
13608 if (CHECK_FLAG(p->cap,
13609 PEER_CAP_REFRESH_ADV))
13610 vty_out(vty, " advertised");
13611 if (CHECK_FLAG(p->cap,
13612 PEER_CAP_REFRESH_NEW_RCV)
13613 || CHECK_FLAG(
13614 p->cap,
13615 PEER_CAP_REFRESH_OLD_RCV))
13616 vty_out(vty, " %sreceived(%s)",
13617 CHECK_FLAG(
13618 p->cap,
13619 PEER_CAP_REFRESH_ADV)
13620 ? "and "
13621 : "",
13622 (CHECK_FLAG(
13623 p->cap,
13624 PEER_CAP_REFRESH_OLD_RCV)
13625 && CHECK_FLAG(
13626 p->cap,
13627 PEER_CAP_REFRESH_NEW_RCV))
13628 ? "old & new"
13629 : CHECK_FLAG(
13630 p->cap,
13631 PEER_CAP_REFRESH_OLD_RCV)
13632 ? "old"
13633 : "new");
13634
13635 vty_out(vty, "\n");
13636 }
13637
9af52ccf
DA
13638 /* Enhanced Route Refresh */
13639 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV)
13640 || CHECK_FLAG(p->cap,
13641 PEER_CAP_ENHANCED_RR_RCV)) {
13642 vty_out(vty,
13643 " Enhanced Route Refresh:");
13644 if (CHECK_FLAG(
13645 p->cap,
13646 PEER_CAP_ENHANCED_RR_ADV))
13647 vty_out(vty, " advertised");
13648 if (CHECK_FLAG(
13649 p->cap,
13650 PEER_CAP_ENHANCED_RR_RCV))
13651 vty_out(vty, " %sreceived",
13652 CHECK_FLAG(
13653 p->cap,
13654 PEER_CAP_REFRESH_ADV)
13655 ? "and "
13656 : "");
13657 vty_out(vty, "\n");
13658 }
13659
d62a17ae 13660 /* Multiprotocol Extensions */
05c7a1cc
QY
13661 FOREACH_AFI_SAFI (afi, safi)
13662 if (p->afc_adv[afi][safi]
13663 || p->afc_recv[afi][safi]) {
13664 vty_out(vty,
13665 " Address Family %s:",
5cb5f4d0
DD
13666 get_afi_safi_str(
13667 afi,
13668 safi,
13669 false));
05c7a1cc 13670 if (p->afc_adv[afi][safi])
d62a17ae 13671 vty_out(vty,
05c7a1cc
QY
13672 " advertised");
13673 if (p->afc_recv[afi][safi])
13674 vty_out(vty,
13675 " %sreceived",
13676 p->afc_adv[afi]
13677 [safi]
13678 ? "and "
13679 : "");
13680 vty_out(vty, "\n");
13681 }
d62a17ae 13682
13683 /* Hostname capability */
60466a63 13684 vty_out(vty, " Hostname Capability:");
d77114b7
MK
13685
13686 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
13687 vty_out(vty,
13688 " advertised (name: %s,domain name: %s)",
60466a63
QY
13689 bgp->peer_self->hostname
13690 ? bgp->peer_self
13691 ->hostname
d77114b7 13692 : "n/a",
60466a63
QY
13693 bgp->peer_self->domainname
13694 ? bgp->peer_self
13695 ->domainname
d77114b7
MK
13696 : "n/a");
13697 } else {
13698 vty_out(vty, " not advertised");
d62a17ae 13699 }
13700
d77114b7 13701 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
13702 vty_out(vty,
13703 " received (name: %s,domain name: %s)",
60466a63
QY
13704 p->hostname ? p->hostname
13705 : "n/a",
13706 p->domainname ? p->domainname
13707 : "n/a");
d77114b7
MK
13708 } else {
13709 vty_out(vty, " not received");
13710 }
13711
13712 vty_out(vty, "\n");
13713
61bfbd51 13714 /* Graceful Restart */
d62a17ae 13715 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
13716 || CHECK_FLAG(p->cap,
13717 PEER_CAP_RESTART_ADV)) {
13718 vty_out(vty,
61bfbd51 13719 " Graceful Restart Capability:");
d62a17ae 13720 if (CHECK_FLAG(p->cap,
13721 PEER_CAP_RESTART_ADV))
13722 vty_out(vty, " advertised");
13723 if (CHECK_FLAG(p->cap,
13724 PEER_CAP_RESTART_RCV))
13725 vty_out(vty, " %sreceived",
13726 CHECK_FLAG(
13727 p->cap,
13728 PEER_CAP_RESTART_ADV)
13729 ? "and "
13730 : "");
13731 vty_out(vty, "\n");
13732
13733 if (CHECK_FLAG(p->cap,
13734 PEER_CAP_RESTART_RCV)) {
13735 int restart_af_count = 0;
13736
13737 vty_out(vty,
13738 " Remote Restart timer is %d seconds\n",
13739 p->v_gr_restart);
13740 vty_out(vty,
13741 " Address families by peer:\n ");
13742
05c7a1cc
QY
13743 FOREACH_AFI_SAFI (afi, safi)
13744 if (CHECK_FLAG(
13745 p->af_cap
13746 [afi]
13747 [safi],
13748 PEER_CAP_RESTART_AF_RCV)) {
13749 vty_out(vty,
13750 "%s%s(%s)",
13751 restart_af_count
13752 ? ", "
13753 : "",
5cb5f4d0 13754 get_afi_safi_str(
05c7a1cc 13755 afi,
5cb5f4d0
DD
13756 safi,
13757 false),
05c7a1cc
QY
13758 CHECK_FLAG(
13759 p->af_cap
13760 [afi]
13761 [safi],
13762 PEER_CAP_RESTART_AF_PRESERVE_RCV)
13763 ? "preserved"
13764 : "not preserved");
13765 restart_af_count++;
13766 }
d62a17ae 13767 if (!restart_af_count)
13768 vty_out(vty, "none");
13769 vty_out(vty, "\n");
13770 }
2986cac2 13771 } /* Gracefull Restart */
d62a17ae 13772 }
13773 }
13774 }
13775
13776 /* graceful restart information */
d62a17ae 13777 json_object *json_grace = NULL;
13778 json_object *json_grace_send = NULL;
13779 json_object *json_grace_recv = NULL;
13780 int eor_send_af_count = 0;
13781 int eor_receive_af_count = 0;
13782
13783 if (use_json) {
13784 json_grace = json_object_new_object();
13785 json_grace_send = json_object_new_object();
13786 json_grace_recv = json_object_new_object();
13787
36235319
QY
13788 if ((p->status == Established)
13789 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
05c7a1cc
QY
13790 FOREACH_AFI_SAFI (afi, safi) {
13791 if (CHECK_FLAG(p->af_sflags[afi][safi],
36235319 13792 PEER_STATUS_EOR_SEND)) {
05c7a1cc
QY
13793 json_object_boolean_true_add(
13794 json_grace_send,
5cb5f4d0
DD
13795 get_afi_safi_str(afi,
13796 safi,
13797 true));
05c7a1cc 13798 eor_send_af_count++;
d62a17ae 13799 }
13800 }
05c7a1cc
QY
13801 FOREACH_AFI_SAFI (afi, safi) {
13802 if (CHECK_FLAG(
36235319
QY
13803 p->af_sflags[afi][safi],
13804 PEER_STATUS_EOR_RECEIVED)) {
05c7a1cc
QY
13805 json_object_boolean_true_add(
13806 json_grace_recv,
5cb5f4d0
DD
13807 get_afi_safi_str(afi,
13808 safi,
13809 true));
05c7a1cc 13810 eor_receive_af_count++;
d62a17ae 13811 }
13812 }
13813 }
36235319
QY
13814 json_object_object_add(json_grace, "endOfRibSend",
13815 json_grace_send);
13816 json_object_object_add(json_grace, "endOfRibRecv",
13817 json_grace_recv);
d62a17ae 13818
d62a17ae 13819
13820 if (p->t_gr_restart)
13821 json_object_int_add(json_grace,
13822 "gracefulRestartTimerMsecs",
13823 thread_timer_remain_second(
13824 p->t_gr_restart)
13825 * 1000);
13826
13827 if (p->t_gr_stale)
13828 json_object_int_add(
13829 json_grace,
13830 "gracefulStalepathTimerMsecs",
13831 thread_timer_remain_second(
13832 p->t_gr_stale)
13833 * 1000);
2986cac2 13834 /* more gr info in new format */
13835 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json,
36235319 13836 json_grace);
d62a17ae 13837 json_object_object_add(
13838 json_neigh, "gracefulRestartInfo", json_grace);
13839 } else {
2089dd80 13840 vty_out(vty, " Graceful restart information:\n");
36235319
QY
13841 if ((p->status == Established)
13842 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 13843
d62a17ae 13844 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
13845 FOREACH_AFI_SAFI (afi, safi) {
13846 if (CHECK_FLAG(p->af_sflags[afi][safi],
13847 PEER_STATUS_EOR_SEND)) {
13848 vty_out(vty, "%s%s",
13849 eor_send_af_count ? ", "
13850 : "",
36235319
QY
13851 get_afi_safi_str(
13852 afi, safi,
13853 false));
05c7a1cc 13854 eor_send_af_count++;
d62a17ae 13855 }
13856 }
13857 vty_out(vty, "\n");
13858 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
13859 FOREACH_AFI_SAFI (afi, safi) {
13860 if (CHECK_FLAG(
13861 p->af_sflags[afi][safi],
13862 PEER_STATUS_EOR_RECEIVED)) {
13863 vty_out(vty, "%s%s",
13864 eor_receive_af_count
13865 ? ", "
13866 : "",
5cb5f4d0
DD
13867 get_afi_safi_str(afi,
13868 safi,
13869 false));
05c7a1cc 13870 eor_receive_af_count++;
d62a17ae 13871 }
13872 }
13873 vty_out(vty, "\n");
13874 }
13875
13876 if (p->t_gr_restart)
13877 vty_out(vty,
13878 " The remaining time of restart timer is %ld\n",
13879 thread_timer_remain_second(
13880 p->t_gr_restart));
13881
13882 if (p->t_gr_stale)
13883 vty_out(vty,
13884 " The remaining time of stalepath timer is %ld\n",
13885 thread_timer_remain_second(
13886 p->t_gr_stale));
2986cac2 13887
13888 /* more gr info in new format */
13889 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
d62a17ae 13890 }
2986cac2 13891
d62a17ae 13892 if (use_json) {
13893 json_object *json_stat = NULL;
13894 json_stat = json_object_new_object();
13895 /* Packet counts. */
43aa5965
QY
13896
13897 atomic_size_t outq_count, inq_count;
13898 outq_count = atomic_load_explicit(&p->obuf->count,
13899 memory_order_relaxed);
13900 inq_count = atomic_load_explicit(&p->ibuf->count,
13901 memory_order_relaxed);
13902
13903 json_object_int_add(json_stat, "depthInq",
13904 (unsigned long)inq_count);
d62a17ae 13905 json_object_int_add(json_stat, "depthOutq",
43aa5965 13906 (unsigned long)outq_count);
0112e9e0
QY
13907 json_object_int_add(json_stat, "opensSent",
13908 atomic_load_explicit(&p->open_out,
13909 memory_order_relaxed));
13910 json_object_int_add(json_stat, "opensRecv",
13911 atomic_load_explicit(&p->open_in,
13912 memory_order_relaxed));
d62a17ae 13913 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
13914 atomic_load_explicit(&p->notify_out,
13915 memory_order_relaxed));
d62a17ae 13916 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
13917 atomic_load_explicit(&p->notify_in,
13918 memory_order_relaxed));
13919 json_object_int_add(json_stat, "updatesSent",
13920 atomic_load_explicit(&p->update_out,
13921 memory_order_relaxed));
13922 json_object_int_add(json_stat, "updatesRecv",
13923 atomic_load_explicit(&p->update_in,
13924 memory_order_relaxed));
d62a17ae 13925 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
13926 atomic_load_explicit(&p->keepalive_out,
13927 memory_order_relaxed));
d62a17ae 13928 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
13929 atomic_load_explicit(&p->keepalive_in,
13930 memory_order_relaxed));
d62a17ae 13931 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
13932 atomic_load_explicit(&p->refresh_out,
13933 memory_order_relaxed));
d62a17ae 13934 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
13935 atomic_load_explicit(&p->refresh_in,
13936 memory_order_relaxed));
d62a17ae 13937 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
13938 atomic_load_explicit(&p->dynamic_cap_out,
13939 memory_order_relaxed));
d62a17ae 13940 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
13941 atomic_load_explicit(&p->dynamic_cap_in,
13942 memory_order_relaxed));
13943 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
13944 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 13945 json_object_object_add(json_neigh, "messageStats", json_stat);
13946 } else {
43aa5965
QY
13947 atomic_size_t outq_count, inq_count;
13948 outq_count = atomic_load_explicit(&p->obuf->count,
13949 memory_order_relaxed);
13950 inq_count = atomic_load_explicit(&p->ibuf->count,
13951 memory_order_relaxed);
13952
d62a17ae 13953 /* Packet counts. */
13954 vty_out(vty, " Message statistics:\n");
43aa5965
QY
13955 vty_out(vty, " Inq depth is %zu\n", inq_count);
13956 vty_out(vty, " Outq depth is %zu\n", outq_count);
d62a17ae 13957 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
13958 vty_out(vty, " Opens: %10d %10d\n",
13959 atomic_load_explicit(&p->open_out,
13960 memory_order_relaxed),
13961 atomic_load_explicit(&p->open_in,
13962 memory_order_relaxed));
13963 vty_out(vty, " Notifications: %10d %10d\n",
13964 atomic_load_explicit(&p->notify_out,
13965 memory_order_relaxed),
13966 atomic_load_explicit(&p->notify_in,
13967 memory_order_relaxed));
13968 vty_out(vty, " Updates: %10d %10d\n",
13969 atomic_load_explicit(&p->update_out,
13970 memory_order_relaxed),
13971 atomic_load_explicit(&p->update_in,
13972 memory_order_relaxed));
13973 vty_out(vty, " Keepalives: %10d %10d\n",
13974 atomic_load_explicit(&p->keepalive_out,
13975 memory_order_relaxed),
13976 atomic_load_explicit(&p->keepalive_in,
13977 memory_order_relaxed));
13978 vty_out(vty, " Route Refresh: %10d %10d\n",
13979 atomic_load_explicit(&p->refresh_out,
13980 memory_order_relaxed),
13981 atomic_load_explicit(&p->refresh_in,
13982 memory_order_relaxed));
d62a17ae 13983 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
13984 atomic_load_explicit(&p->dynamic_cap_out,
13985 memory_order_relaxed),
13986 atomic_load_explicit(&p->dynamic_cap_in,
13987 memory_order_relaxed));
13988 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
13989 PEER_TOTAL_RX(p));
d62a17ae 13990 }
13991
13992 if (use_json) {
13993 /* advertisement-interval */
13994 json_object_int_add(json_neigh,
13995 "minBtwnAdvertisementRunsTimerMsecs",
13996 p->v_routeadv * 1000);
13997
13998 /* Update-source. */
13999 if (p->update_if || p->update_source) {
14000 if (p->update_if)
14001 json_object_string_add(json_neigh,
14002 "updateSource",
14003 p->update_if);
14004 else if (p->update_source)
14005 json_object_string_add(
14006 json_neigh, "updateSource",
14007 sockunion2str(p->update_source, buf1,
14008 SU_ADDRSTRLEN));
14009 }
14010 } else {
14011 /* advertisement-interval */
14012 vty_out(vty,
14013 " Minimum time between advertisement runs is %d seconds\n",
14014 p->v_routeadv);
14015
14016 /* Update-source. */
14017 if (p->update_if || p->update_source) {
14018 vty_out(vty, " Update source is ");
14019 if (p->update_if)
14020 vty_out(vty, "%s", p->update_if);
14021 else if (p->update_source)
14022 vty_out(vty, "%s",
14023 sockunion2str(p->update_source, buf1,
14024 SU_ADDRSTRLEN));
14025 vty_out(vty, "\n");
14026 }
14027
14028 vty_out(vty, "\n");
14029 }
14030
14031 /* Address Family Information */
14032 json_object *json_hold = NULL;
14033
14034 if (use_json)
14035 json_hold = json_object_new_object();
14036
05c7a1cc
QY
14037 FOREACH_AFI_SAFI (afi, safi)
14038 if (p->afc[afi][safi])
14039 bgp_show_peer_afi(vty, p, afi, safi, use_json,
14040 json_hold);
d62a17ae 14041
14042 if (use_json) {
14043 json_object_object_add(json_neigh, "addressFamilyInfo",
14044 json_hold);
14045 json_object_int_add(json_neigh, "connectionsEstablished",
14046 p->established);
14047 json_object_int_add(json_neigh, "connectionsDropped",
14048 p->dropped);
14049 } else
14050 vty_out(vty, " Connections established %d; dropped %d\n",
14051 p->established, p->dropped);
14052
14053 if (!p->last_reset) {
14054 if (use_json)
14055 json_object_string_add(json_neigh, "lastReset",
14056 "never");
14057 else
14058 vty_out(vty, " Last reset never\n");
14059 } else {
14060 if (use_json) {
14061 time_t uptime;
a2700b50 14062 struct tm tm;
d62a17ae 14063
14064 uptime = bgp_clock();
14065 uptime -= p->resettime;
a2700b50
MS
14066 gmtime_r(&uptime, &tm);
14067
d62a17ae 14068 json_object_int_add(json_neigh, "lastResetTimerMsecs",
a2700b50
MS
14069 (tm.tm_sec * 1000)
14070 + (tm.tm_min * 60000)
14071 + (tm.tm_hour * 3600000));
3577f1c5 14072 bgp_show_peer_reset(NULL, p, json_neigh, true);
d62a17ae 14073 } else {
14074 vty_out(vty, " Last reset %s, ",
14075 peer_uptime(p->resettime, timebuf,
14076 BGP_UPTIME_LEN, 0, NULL));
14077
3577f1c5 14078 bgp_show_peer_reset(vty, p, NULL, false);
d62a17ae 14079 if (p->last_reset_cause_size) {
14080 msg = p->last_reset_cause;
14081 vty_out(vty,
14082 " Message received that caused BGP to send a NOTIFICATION:\n ");
14083 for (i = 1; i <= p->last_reset_cause_size;
14084 i++) {
14085 vty_out(vty, "%02X", *msg++);
14086
14087 if (i != p->last_reset_cause_size) {
14088 if (i % 16 == 0) {
14089 vty_out(vty, "\n ");
14090 } else if (i % 4 == 0) {
14091 vty_out(vty, " ");
14092 }
14093 }
14094 }
14095 vty_out(vty, "\n");
14096 }
14097 }
14098 }
14099
14100 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
14101 if (use_json)
14102 json_object_boolean_true_add(json_neigh,
14103 "prefixesConfigExceedMax");
14104 else
14105 vty_out(vty,
14106 " Peer had exceeded the max. no. of prefixes configured.\n");
14107
14108 if (p->t_pmax_restart) {
14109 if (use_json) {
14110 json_object_boolean_true_add(
14111 json_neigh, "reducePrefixNumFrom");
14112 json_object_int_add(json_neigh,
14113 "restartInTimerMsec",
14114 thread_timer_remain_second(
14115 p->t_pmax_restart)
14116 * 1000);
14117 } else
14118 vty_out(vty,
14119 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
14120 p->host, thread_timer_remain_second(
14121 p->t_pmax_restart));
d62a17ae 14122 } else {
14123 if (use_json)
14124 json_object_boolean_true_add(
14125 json_neigh,
14126 "reducePrefixNumAndClearIpBgp");
14127 else
14128 vty_out(vty,
14129 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
14130 p->host);
14131 }
14132 }
14133
14134 /* EBGP Multihop and GTSM */
14135 if (p->sort != BGP_PEER_IBGP) {
14136 if (use_json) {
e2521429 14137 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14138 json_object_int_add(json_neigh,
14139 "externalBgpNbrMaxHopsAway",
14140 p->gtsm_hops);
c8d6f0d6 14141 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 14142 json_object_int_add(json_neigh,
14143 "externalBgpNbrMaxHopsAway",
14144 p->ttl);
14145 } else {
e2521429 14146 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14147 vty_out(vty,
14148 " External BGP neighbor may be up to %d hops away.\n",
14149 p->gtsm_hops);
c8d6f0d6 14150 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 14151 vty_out(vty,
14152 " External BGP neighbor may be up to %d hops away.\n",
14153 p->ttl);
14154 }
14155 } else {
e2521429 14156 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED) {
d62a17ae 14157 if (use_json)
14158 json_object_int_add(json_neigh,
14159 "internalBgpNbrMaxHopsAway",
14160 p->gtsm_hops);
14161 else
14162 vty_out(vty,
14163 " Internal BGP neighbor may be up to %d hops away.\n",
14164 p->gtsm_hops);
14165 }
14166 }
14167
14168 /* Local address. */
14169 if (p->su_local) {
14170 if (use_json) {
14171 json_object_string_add(json_neigh, "hostLocal",
14172 sockunion2str(p->su_local, buf1,
14173 SU_ADDRSTRLEN));
14174 json_object_int_add(json_neigh, "portLocal",
14175 ntohs(p->su_local->sin.sin_port));
14176 } else
14177 vty_out(vty, "Local host: %s, Local port: %d\n",
14178 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
14179 ntohs(p->su_local->sin.sin_port));
14180 }
14181
14182 /* Remote address. */
14183 if (p->su_remote) {
14184 if (use_json) {
14185 json_object_string_add(json_neigh, "hostForeign",
14186 sockunion2str(p->su_remote, buf1,
14187 SU_ADDRSTRLEN));
14188 json_object_int_add(json_neigh, "portForeign",
14189 ntohs(p->su_remote->sin.sin_port));
14190 } else
14191 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
14192 sockunion2str(p->su_remote, buf1,
14193 SU_ADDRSTRLEN),
14194 ntohs(p->su_remote->sin.sin_port));
14195 }
14196
14197 /* Nexthop display. */
14198 if (p->su_local) {
14199 if (use_json) {
14200 json_object_string_add(json_neigh, "nexthop",
14201 inet_ntop(AF_INET,
14202 &p->nexthop.v4, buf1,
14203 sizeof(buf1)));
14204 json_object_string_add(json_neigh, "nexthopGlobal",
14205 inet_ntop(AF_INET6,
14206 &p->nexthop.v6_global,
14207 buf1, sizeof(buf1)));
14208 json_object_string_add(json_neigh, "nexthopLocal",
14209 inet_ntop(AF_INET6,
14210 &p->nexthop.v6_local,
14211 buf1, sizeof(buf1)));
14212 if (p->shared_network)
14213 json_object_string_add(json_neigh,
14214 "bgpConnection",
14215 "sharedNetwork");
14216 else
14217 json_object_string_add(json_neigh,
14218 "bgpConnection",
14219 "nonSharedNetwork");
14220 } else {
14221 vty_out(vty, "Nexthop: %s\n",
14222 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
14223 sizeof(buf1)));
14224 vty_out(vty, "Nexthop global: %s\n",
14225 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
14226 sizeof(buf1)));
14227 vty_out(vty, "Nexthop local: %s\n",
14228 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
14229 sizeof(buf1)));
14230 vty_out(vty, "BGP connection: %s\n",
14231 p->shared_network ? "shared network"
14232 : "non shared network");
14233 }
14234 }
14235
14236 /* Timer information. */
14237 if (use_json) {
14238 json_object_int_add(json_neigh, "connectRetryTimer",
14239 p->v_connect);
14240 if (p->status == Established && p->rtt)
14241 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14242 p->rtt);
14243 if (p->t_start)
14244 json_object_int_add(
14245 json_neigh, "nextStartTimerDueInMsecs",
14246 thread_timer_remain_second(p->t_start) * 1000);
14247 if (p->t_connect)
14248 json_object_int_add(
14249 json_neigh, "nextConnectTimerDueInMsecs",
14250 thread_timer_remain_second(p->t_connect)
14251 * 1000);
14252 if (p->t_routeadv) {
14253 json_object_int_add(json_neigh, "mraiInterval",
14254 p->v_routeadv);
14255 json_object_int_add(
14256 json_neigh, "mraiTimerExpireInMsecs",
14257 thread_timer_remain_second(p->t_routeadv)
14258 * 1000);
14259 }
14260 if (p->password)
14261 json_object_int_add(json_neigh, "authenticationEnabled",
14262 1);
14263
14264 if (p->t_read)
14265 json_object_string_add(json_neigh, "readThread", "on");
14266 else
14267 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
14268
14269 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 14270 json_object_string_add(json_neigh, "writeThread", "on");
14271 else
14272 json_object_string_add(json_neigh, "writeThread",
14273 "off");
14274 } else {
14275 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14276 p->v_connect);
14277 if (p->status == Established && p->rtt)
14278 vty_out(vty, "Estimated round trip time: %d ms\n",
14279 p->rtt);
14280 if (p->t_start)
14281 vty_out(vty, "Next start timer due in %ld seconds\n",
14282 thread_timer_remain_second(p->t_start));
14283 if (p->t_connect)
14284 vty_out(vty, "Next connect timer due in %ld seconds\n",
14285 thread_timer_remain_second(p->t_connect));
14286 if (p->t_routeadv)
14287 vty_out(vty,
14288 "MRAI (interval %u) timer expires in %ld seconds\n",
14289 p->v_routeadv,
14290 thread_timer_remain_second(p->t_routeadv));
14291 if (p->password)
14292 vty_out(vty, "Peer Authentication Enabled\n");
14293
cac9e917 14294 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
49507a6f
QY
14295 p->t_read ? "on" : "off",
14296 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14297 ? "on"
cac9e917 14298 : "off", p->fd);
d62a17ae 14299 }
14300
14301 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14302 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14303 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14304
14305 if (!use_json)
14306 vty_out(vty, "\n");
14307
14308 /* BFD information. */
14309 bgp_bfd_show_info(vty, p, use_json, json_neigh);
14310
14311 if (use_json) {
14312 if (p->conf_if) /* Configured interface name. */
14313 json_object_object_add(json, p->conf_if, json_neigh);
14314 else /* Configured IP address. */
14315 json_object_object_add(json, p->host, json_neigh);
14316 }
14317}
14318
36235319
QY
14319static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14320 enum show_type type,
14321 union sockunion *su,
14322 const char *conf_if, afi_t afi,
74a630b6 14323 bool use_json)
2986cac2 14324{
14325 struct listnode *node, *nnode;
14326 struct peer *peer;
14327 int find = 0;
14328 safi_t safi = SAFI_UNICAST;
74a630b6 14329 json_object *json = NULL;
2986cac2 14330 json_object *json_neighbor = NULL;
14331
74a630b6
NT
14332 if (use_json) {
14333 json = json_object_new_object();
14334 json_neighbor = json_object_new_object();
14335 }
14336
2986cac2 14337 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14338
14339 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14340 continue;
14341
14342 if ((peer->afc[afi][safi]) == 0)
14343 continue;
14344
2ba1fe69 14345 if (type == show_all) {
2986cac2 14346 bgp_show_peer_gr_status(vty, peer, use_json,
13909c4f 14347 json_neighbor);
2986cac2 14348
74a630b6 14349 if (use_json) {
13909c4f
DS
14350 json_object_object_add(json, peer->host,
14351 json_neighbor);
74a630b6
NT
14352 json_neighbor = NULL;
14353 }
2986cac2 14354
2ba1fe69 14355 } else if (type == show_peer) {
2986cac2 14356 if (conf_if) {
14357 if ((peer->conf_if
13909c4f
DS
14358 && !strcmp(peer->conf_if, conf_if))
14359 || (peer->hostname
2986cac2 14360 && !strcmp(peer->hostname, conf_if))) {
14361 find = 1;
13909c4f
DS
14362 bgp_show_peer_gr_status(vty, peer,
14363 use_json,
14364 json_neighbor);
2986cac2 14365 }
14366 } else {
14367 if (sockunion_same(&peer->su, su)) {
14368 find = 1;
13909c4f
DS
14369 bgp_show_peer_gr_status(vty, peer,
14370 use_json,
14371 json_neighbor);
2986cac2 14372 }
14373 }
13909c4f
DS
14374 if (use_json && find)
14375 json_object_object_add(json, peer->host,
14376 json_neighbor);
2986cac2 14377 }
14378
74a630b6
NT
14379 if (find) {
14380 json_neighbor = NULL;
2986cac2 14381 break;
74a630b6 14382 }
2986cac2 14383 }
14384
14385 if (type == show_peer && !find) {
14386 if (use_json)
13909c4f 14387 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
2986cac2 14388 else
14389 vty_out(vty, "%% No such neighbor\n");
14390 }
14391 if (use_json) {
13909c4f
DS
14392 vty_out(vty, "%s\n",
14393 json_object_to_json_string_ext(
14394 json, JSON_C_TO_STRING_PRETTY));
74a630b6
NT
14395
14396 if (json_neighbor)
14397 json_object_free(json_neighbor);
14398 json_object_free(json);
2986cac2 14399 } else {
14400 vty_out(vty, "\n");
14401 }
14402
14403 return CMD_SUCCESS;
14404}
14405
d62a17ae 14406static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14407 enum show_type type, union sockunion *su,
9f049418 14408 const char *conf_if, bool use_json,
d62a17ae 14409 json_object *json)
14410{
14411 struct listnode *node, *nnode;
14412 struct peer *peer;
14413 int find = 0;
9f049418 14414 bool nbr_output = false;
d1927ebe
AS
14415 afi_t afi = AFI_MAX;
14416 safi_t safi = SAFI_MAX;
14417
14418 if (type == show_ipv4_peer || type == show_ipv4_all) {
14419 afi = AFI_IP;
14420 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14421 afi = AFI_IP6;
14422 }
d62a17ae 14423
14424 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14425 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14426 continue;
14427
14428 switch (type) {
14429 case show_all:
14430 bgp_show_peer(vty, peer, use_json, json);
9f049418 14431 nbr_output = true;
d62a17ae 14432 break;
14433 case show_peer:
14434 if (conf_if) {
14435 if ((peer->conf_if
14436 && !strcmp(peer->conf_if, conf_if))
14437 || (peer->hostname
14438 && !strcmp(peer->hostname, conf_if))) {
14439 find = 1;
14440 bgp_show_peer(vty, peer, use_json,
14441 json);
14442 }
14443 } else {
14444 if (sockunion_same(&peer->su, su)) {
14445 find = 1;
14446 bgp_show_peer(vty, peer, use_json,
14447 json);
14448 }
14449 }
14450 break;
d1927ebe
AS
14451 case show_ipv4_peer:
14452 case show_ipv6_peer:
14453 FOREACH_SAFI (safi) {
14454 if (peer->afc[afi][safi]) {
14455 if (conf_if) {
14456 if ((peer->conf_if
14457 && !strcmp(peer->conf_if, conf_if))
14458 || (peer->hostname
14459 && !strcmp(peer->hostname, conf_if))) {
14460 find = 1;
14461 bgp_show_peer(vty, peer, use_json,
14462 json);
14463 break;
14464 }
14465 } else {
14466 if (sockunion_same(&peer->su, su)) {
14467 find = 1;
14468 bgp_show_peer(vty, peer, use_json,
14469 json);
14470 break;
14471 }
14472 }
14473 }
14474 }
14475 break;
14476 case show_ipv4_all:
14477 case show_ipv6_all:
14478 FOREACH_SAFI (safi) {
14479 if (peer->afc[afi][safi]) {
14480 bgp_show_peer(vty, peer, use_json, json);
14481 nbr_output = true;
14482 break;
14483 }
14484 }
14485 break;
d62a17ae 14486 }
14487 }
14488
d1927ebe
AS
14489 if ((type == show_peer || type == show_ipv4_peer ||
14490 type == show_ipv6_peer) && !find) {
d62a17ae 14491 if (use_json)
14492 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14493 else
88b7d255 14494 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 14495 }
14496
d1927ebe
AS
14497 if (type != show_peer && type != show_ipv4_peer &&
14498 type != show_ipv6_peer && !nbr_output && !use_json)
94d4c685 14499 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 14500
d62a17ae 14501 if (use_json) {
996c9314
LB
14502 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14503 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 14504 } else {
14505 vty_out(vty, "\n");
14506 }
14507
14508 return CMD_SUCCESS;
14509}
14510
36235319
QY
14511static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14512 enum show_type type,
14513 const char *ip_str,
14514 afi_t afi, bool use_json)
2986cac2 14515{
14516
14517 int ret;
14518 struct bgp *bgp;
14519 union sockunion su;
2986cac2 14520
14521 bgp = bgp_get_default();
14522
13909c4f
DS
14523 if (!bgp)
14524 return;
2986cac2 14525
13909c4f
DS
14526 if (!use_json)
14527 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
14528 NULL);
2986cac2 14529
13909c4f
DS
14530 if (ip_str) {
14531 ret = str2sockunion(ip_str, &su);
14532 if (ret < 0)
13909c4f 14533 bgp_show_neighbor_graceful_restart(
74a630b6
NT
14534 vty, bgp, type, NULL, ip_str, afi, use_json);
14535 else
14536 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14537 NULL, afi, use_json);
13909c4f
DS
14538 } else
14539 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
74a630b6 14540 afi, use_json);
2986cac2 14541}
14542
d62a17ae 14543static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
14544 enum show_type type,
14545 const char *ip_str,
9f049418 14546 bool use_json)
d62a17ae 14547{
0291c246
MK
14548 struct listnode *node, *nnode;
14549 struct bgp *bgp;
71aedaa3 14550 union sockunion su;
0291c246 14551 json_object *json = NULL;
71aedaa3 14552 int ret, is_first = 1;
9f049418 14553 bool nbr_output = false;
d62a17ae 14554
14555 if (use_json)
14556 vty_out(vty, "{\n");
14557
14558 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 14559 nbr_output = true;
d62a17ae 14560 if (use_json) {
14561 if (!(json = json_object_new_object())) {
af4c2728 14562 flog_err(
e50f7cfd 14563 EC_BGP_JSON_MEM_ERROR,
d62a17ae 14564 "Unable to allocate memory for JSON object");
14565 vty_out(vty,
14566 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14567 return;
14568 }
14569
14570 json_object_int_add(json, "vrfId",
14571 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
14572 ? -1
14573 : (int64_t)bgp->vrf_id);
d62a17ae 14574 json_object_string_add(
14575 json, "vrfName",
14576 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14577 ? VRF_DEFAULT_NAME
d62a17ae 14578 : bgp->name);
14579
14580 if (!is_first)
14581 vty_out(vty, ",\n");
14582 else
14583 is_first = 0;
14584
14585 vty_out(vty, "\"%s\":",
14586 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14587 ? VRF_DEFAULT_NAME
d62a17ae 14588 : bgp->name);
14589 } else {
14590 vty_out(vty, "\nInstance %s:\n",
14591 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14592 ? VRF_DEFAULT_NAME
d62a17ae 14593 : bgp->name);
14594 }
71aedaa3 14595
d1927ebe
AS
14596 if (type == show_peer || type == show_ipv4_peer ||
14597 type == show_ipv6_peer) {
71aedaa3
DS
14598 ret = str2sockunion(ip_str, &su);
14599 if (ret < 0)
14600 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14601 use_json, json);
14602 else
14603 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14604 use_json, json);
14605 } else {
d1927ebe 14606 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
71aedaa3
DS
14607 use_json, json);
14608 }
b77004d6 14609 json_object_free(json);
121067e9 14610 json = NULL;
d62a17ae 14611 }
14612
3e78a6ce 14613 if (use_json)
d62a17ae 14614 vty_out(vty, "}\n");
9f049418
DS
14615 else if (!nbr_output)
14616 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 14617}
14618
14619static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14620 enum show_type type, const char *ip_str,
9f049418 14621 bool use_json)
d62a17ae 14622{
14623 int ret;
14624 struct bgp *bgp;
14625 union sockunion su;
14626 json_object *json = NULL;
14627
14628 if (name) {
14629 if (strmatch(name, "all")) {
71aedaa3
DS
14630 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14631 use_json);
d62a17ae 14632 return CMD_SUCCESS;
14633 } else {
14634 bgp = bgp_lookup_by_name(name);
14635 if (!bgp) {
14636 if (use_json) {
14637 json = json_object_new_object();
d62a17ae 14638 vty_out(vty, "%s\n",
14639 json_object_to_json_string_ext(
14640 json,
14641 JSON_C_TO_STRING_PRETTY));
14642 json_object_free(json);
14643 } else
14644 vty_out(vty,
9f049418 14645 "%% BGP instance not found\n");
d62a17ae 14646
14647 return CMD_WARNING;
14648 }
14649 }
14650 } else {
14651 bgp = bgp_get_default();
14652 }
14653
14654 if (bgp) {
14655 json = json_object_new_object();
14656 if (ip_str) {
14657 ret = str2sockunion(ip_str, &su);
14658 if (ret < 0)
14659 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14660 use_json, json);
14661 else
14662 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14663 use_json, json);
14664 } else {
14665 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
14666 json);
14667 }
14668 json_object_free(json);
ca61fd25
DS
14669 } else {
14670 if (use_json)
14671 vty_out(vty, "{}\n");
14672 else
14673 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 14674 }
14675
14676 return CMD_SUCCESS;
4fb25c53
DW
14677}
14678
2986cac2 14679
14680
14681/* "show [ip] bgp neighbors graceful-restart" commands. */
14682DEFUN (show_ip_bgp_neighbors_gracrful_restart,
14683 show_ip_bgp_neighbors_graceful_restart_cmd,
14684 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
14685 SHOW_STR
14686 BGP_STR
14687 IP_STR
14688 IPV6_STR
14689 NEIGHBOR_STR
14690 "Neighbor to display information about\n"
14691 "Neighbor to display information about\n"
14692 "Neighbor on BGP configured interface\n"
14693 GR_SHOW
14694 JSON_STR)
14695{
14696 char *sh_arg = NULL;
14697 enum show_type sh_type;
14698 int idx = 0;
14699 afi_t afi = AFI_MAX;
2986cac2 14700 bool uj = use_json(argc, argv);
14701
36235319 14702 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
2986cac2 14703 afi = AFI_MAX;
14704
14705 idx++;
14706
14707 if (argv_find(argv, argc, "A.B.C.D", &idx)
14708 || argv_find(argv, argc, "X:X::X:X", &idx)
14709 || argv_find(argv, argc, "WORD", &idx)) {
14710 sh_type = show_peer;
14711 sh_arg = argv[idx]->arg;
14712 } else
14713 sh_type = show_all;
14714
14715 if (!argv_find(argv, argc, "graceful-restart", &idx))
14716 return CMD_SUCCESS;
14717
14718
36235319
QY
14719 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
14720 afi, uj);
2986cac2 14721}
14722
716b2d8a 14723/* "show [ip] bgp neighbors" commands. */
718e3744 14724DEFUN (show_ip_bgp_neighbors,
14725 show_ip_bgp_neighbors_cmd,
24345e82 14726 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 14727 SHOW_STR
14728 IP_STR
14729 BGP_STR
f2a8972b 14730 BGP_INSTANCE_HELP_STR
8c3deaae
QY
14731 "Address Family\n"
14732 "Address Family\n"
718e3744 14733 "Detailed information on TCP and BGP neighbor connections\n"
14734 "Neighbor to display information about\n"
a80beece 14735 "Neighbor to display information about\n"
91d37724 14736 "Neighbor on BGP configured interface\n"
9973d184 14737 JSON_STR)
718e3744 14738{
d62a17ae 14739 char *vrf = NULL;
14740 char *sh_arg = NULL;
14741 enum show_type sh_type;
d1927ebe 14742 afi_t afi = AFI_MAX;
718e3744 14743
9f049418 14744 bool uj = use_json(argc, argv);
718e3744 14745
d62a17ae 14746 int idx = 0;
718e3744 14747
9a8bdf1c
PG
14748 /* [<vrf> VIEWVRFNAME] */
14749 if (argv_find(argv, argc, "vrf", &idx)) {
14750 vrf = argv[idx + 1]->arg;
14751 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14752 vrf = NULL;
14753 } else if (argv_find(argv, argc, "view", &idx))
14754 /* [<view> VIEWVRFNAME] */
d62a17ae 14755 vrf = argv[idx + 1]->arg;
718e3744 14756
d62a17ae 14757 idx++;
d1927ebe
AS
14758
14759 if (argv_find(argv, argc, "ipv4", &idx)) {
14760 sh_type = show_ipv4_all;
14761 afi = AFI_IP;
14762 } else if (argv_find(argv, argc, "ipv6", &idx)) {
14763 sh_type = show_ipv6_all;
14764 afi = AFI_IP6;
14765 } else {
14766 sh_type = show_all;
14767 }
14768
d62a17ae 14769 if (argv_find(argv, argc, "A.B.C.D", &idx)
14770 || argv_find(argv, argc, "X:X::X:X", &idx)
14771 || argv_find(argv, argc, "WORD", &idx)) {
14772 sh_type = show_peer;
14773 sh_arg = argv[idx]->arg;
d1927ebe
AS
14774 }
14775
14776 if (sh_type == show_peer && afi == AFI_IP) {
14777 sh_type = show_ipv4_peer;
14778 } else if (sh_type == show_peer && afi == AFI_IP6) {
14779 sh_type = show_ipv6_peer;
14780 }
856ca177 14781
d62a17ae 14782 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 14783}
14784
716b2d8a 14785/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 14786 paths' and `show ip mbgp paths'. Those functions results are the
14787 same.*/
f412b39a 14788DEFUN (show_ip_bgp_paths,
718e3744 14789 show_ip_bgp_paths_cmd,
46f296b4 14790 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 14791 SHOW_STR
14792 IP_STR
14793 BGP_STR
46f296b4 14794 BGP_SAFI_HELP_STR
718e3744 14795 "Path information\n")
14796{
d62a17ae 14797 vty_out(vty, "Address Refcnt Path\n");
14798 aspath_print_all_vty(vty);
14799 return CMD_SUCCESS;
718e3744 14800}
14801
718e3744 14802#include "hash.h"
14803
e3b78da8 14804static void community_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 14805 struct vty *vty)
718e3744 14806{
d62a17ae 14807 struct community *com;
718e3744 14808
e3b78da8 14809 com = (struct community *)bucket->data;
3f65c5b1 14810 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 14811 community_str(com, false));
718e3744 14812}
14813
14814/* Show BGP's community internal data. */
f412b39a 14815DEFUN (show_ip_bgp_community_info,
718e3744 14816 show_ip_bgp_community_info_cmd,
bec37ba5 14817 "show [ip] bgp community-info",
718e3744 14818 SHOW_STR
14819 IP_STR
14820 BGP_STR
14821 "List all bgp community information\n")
14822{
d62a17ae 14823 vty_out(vty, "Address Refcnt Community\n");
718e3744 14824
d62a17ae 14825 hash_iterate(community_hash(),
e3b78da8 14826 (void (*)(struct hash_bucket *,
d62a17ae 14827 void *))community_show_all_iterator,
14828 vty);
718e3744 14829
d62a17ae 14830 return CMD_SUCCESS;
718e3744 14831}
14832
e3b78da8 14833static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 14834 struct vty *vty)
57d187bc 14835{
d62a17ae 14836 struct lcommunity *lcom;
57d187bc 14837
e3b78da8 14838 lcom = (struct lcommunity *)bucket->data;
3f65c5b1 14839 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 14840 lcommunity_str(lcom, false));
57d187bc
JS
14841}
14842
14843/* Show BGP's community internal data. */
14844DEFUN (show_ip_bgp_lcommunity_info,
14845 show_ip_bgp_lcommunity_info_cmd,
14846 "show ip bgp large-community-info",
14847 SHOW_STR
14848 IP_STR
14849 BGP_STR
14850 "List all bgp large-community information\n")
14851{
d62a17ae 14852 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 14853
d62a17ae 14854 hash_iterate(lcommunity_hash(),
e3b78da8 14855 (void (*)(struct hash_bucket *,
d62a17ae 14856 void *))lcommunity_show_all_iterator,
14857 vty);
57d187bc 14858
d62a17ae 14859 return CMD_SUCCESS;
57d187bc 14860}
2986cac2 14861/* Graceful Restart */
14862
14863static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
36235319
QY
14864 struct bgp *bgp,
14865 bool use_json,
14866 json_object *json)
2986cac2 14867{
57d187bc
JS
14868
14869
2986cac2 14870 vty_out(vty, "\n%s", SHOW_GR_HEADER);
14871
7318ae88 14872 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
2986cac2 14873
14874 switch (bgp_global_gr_mode) {
14875
14876 case GLOBAL_HELPER:
13909c4f 14877 vty_out(vty, "Global BGP GR Mode : Helper\n");
2986cac2 14878 break;
14879
14880 case GLOBAL_GR:
13909c4f 14881 vty_out(vty, "Global BGP GR Mode : Restart\n");
2986cac2 14882 break;
14883
14884 case GLOBAL_DISABLE:
13909c4f 14885 vty_out(vty, "Global BGP GR Mode : Disable\n");
2986cac2 14886 break;
14887
14888 case GLOBAL_INVALID:
2986cac2 14889 vty_out(vty,
2ba1fe69 14890 "Global BGP GR Mode Invalid\n");
2986cac2 14891 break;
14892 }
14893 vty_out(vty, "\n");
14894}
14895
36235319
QY
14896static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
14897 enum show_type type,
14898 const char *ip_str,
14899 afi_t afi, bool use_json)
2986cac2 14900{
14901 if ((afi == AFI_MAX) && (ip_str == NULL)) {
14902 afi = AFI_IP;
14903
14904 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
14905
36235319
QY
14906 bgp_show_neighbor_graceful_restart_vty(
14907 vty, type, ip_str, afi, use_json);
2986cac2 14908 afi++;
14909 }
14910 } else if (afi != AFI_MAX) {
36235319
QY
14911 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
14912 use_json);
2986cac2 14913 } else {
14914 return CMD_ERR_INCOMPLETE;
14915 }
14916
14917 return CMD_SUCCESS;
14918}
14919/* Graceful Restart */
14920
f412b39a 14921DEFUN (show_ip_bgp_attr_info,
718e3744 14922 show_ip_bgp_attr_info_cmd,
bec37ba5 14923 "show [ip] bgp attribute-info",
718e3744 14924 SHOW_STR
14925 IP_STR
14926 BGP_STR
14927 "List all bgp attribute information\n")
14928{
d62a17ae 14929 attr_show_all(vty);
14930 return CMD_SUCCESS;
718e3744 14931}
6b0655a2 14932
03915806
CS
14933static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
14934 afi_t afi, safi_t safi,
14935 bool use_json, json_object *json)
53089bec 14936{
14937 struct bgp *bgp;
14938 struct listnode *node;
14939 char *vname;
14940 char buf1[INET6_ADDRSTRLEN];
14941 char *ecom_str;
14942 vpn_policy_direction_t dir;
14943
03915806 14944 if (json) {
b46dfd20
DS
14945 json_object *json_import_vrfs = NULL;
14946 json_object *json_export_vrfs = NULL;
14947
b46dfd20
DS
14948 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14949
53089bec 14950 if (!bgp) {
b46dfd20
DS
14951 vty_out(vty, "%s\n",
14952 json_object_to_json_string_ext(
14953 json,
14954 JSON_C_TO_STRING_PRETTY));
14955 json_object_free(json);
14956
53089bec 14957 return CMD_WARNING;
14958 }
b46dfd20 14959
94d4c685
DS
14960 /* Provide context for the block */
14961 json_object_string_add(json, "vrf", name ? name : "default");
14962 json_object_string_add(json, "afiSafi",
5cb5f4d0 14963 get_afi_safi_str(afi, safi, true));
94d4c685 14964
b46dfd20
DS
14965 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14966 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
14967 json_object_string_add(json, "importFromVrfs", "none");
14968 json_object_string_add(json, "importRts", "none");
14969 } else {
6ce24e52
DS
14970 json_import_vrfs = json_object_new_array();
14971
b46dfd20
DS
14972 for (ALL_LIST_ELEMENTS_RO(
14973 bgp->vpn_policy[afi].import_vrf,
14974 node, vname))
14975 json_object_array_add(json_import_vrfs,
14976 json_object_new_string(vname));
14977
b20875ea
CS
14978 json_object_object_add(json, "importFromVrfs",
14979 json_import_vrfs);
b46dfd20 14980 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
14981 if (bgp->vpn_policy[afi].rtlist[dir]) {
14982 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14983 bgp->vpn_policy[afi].rtlist[dir],
14984 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
14985 json_object_string_add(json, "importRts",
14986 ecom_str);
14987 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14988 } else
14989 json_object_string_add(json, "importRts",
14990 "none");
b46dfd20
DS
14991 }
14992
14993 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14994 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
14995 json_object_string_add(json, "exportToVrfs", "none");
14996 json_object_string_add(json, "routeDistinguisher",
14997 "none");
14998 json_object_string_add(json, "exportRts", "none");
14999 } else {
6ce24e52
DS
15000 json_export_vrfs = json_object_new_array();
15001
b46dfd20
DS
15002 for (ALL_LIST_ELEMENTS_RO(
15003 bgp->vpn_policy[afi].export_vrf,
15004 node, vname))
15005 json_object_array_add(json_export_vrfs,
15006 json_object_new_string(vname));
15007 json_object_object_add(json, "exportToVrfs",
15008 json_export_vrfs);
15009 json_object_string_add(json, "routeDistinguisher",
15010 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
15011 buf1, RD_ADDRSTRLEN));
15012
15013 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
15014 if (bgp->vpn_policy[afi].rtlist[dir]) {
15015 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15016 bgp->vpn_policy[afi].rtlist[dir],
15017 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
15018 json_object_string_add(json, "exportRts",
15019 ecom_str);
15020 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15021 } else
15022 json_object_string_add(json, "exportRts",
15023 "none");
b46dfd20
DS
15024 }
15025
03915806
CS
15026 if (use_json) {
15027 vty_out(vty, "%s\n",
15028 json_object_to_json_string_ext(json,
b46dfd20 15029 JSON_C_TO_STRING_PRETTY));
03915806
CS
15030 json_object_free(json);
15031 }
53089bec 15032 } else {
b46dfd20
DS
15033 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15034
53089bec 15035 if (!bgp) {
b46dfd20 15036 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 15037 return CMD_WARNING;
15038 }
53089bec 15039
b46dfd20
DS
15040 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15041 BGP_CONFIG_VRF_TO_VRF_IMPORT))
15042 vty_out(vty,
15043 "This VRF is not importing %s routes from any other VRF\n",
5cb5f4d0 15044 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15045 else {
15046 vty_out(vty,
15047 "This VRF is importing %s routes from the following VRFs:\n",
5cb5f4d0 15048 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15049
15050 for (ALL_LIST_ELEMENTS_RO(
15051 bgp->vpn_policy[afi].import_vrf,
15052 node, vname))
15053 vty_out(vty, " %s\n", vname);
15054
15055 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
15056 ecom_str = NULL;
15057 if (bgp->vpn_policy[afi].rtlist[dir]) {
15058 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15059 bgp->vpn_policy[afi].rtlist[dir],
15060 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea 15061 vty_out(vty, "Import RT(s): %s\n", ecom_str);
b46dfd20 15062
b20875ea
CS
15063 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15064 } else
15065 vty_out(vty, "Import RT(s):\n");
53089bec 15066 }
53089bec 15067
b46dfd20
DS
15068 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15069 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15070 vty_out(vty,
15071 "This VRF is not exporting %s routes to any other VRF\n",
5cb5f4d0 15072 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15073 else {
15074 vty_out(vty,
04c9077f 15075 "This VRF is exporting %s routes to the following VRFs:\n",
5cb5f4d0 15076 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15077
15078 for (ALL_LIST_ELEMENTS_RO(
15079 bgp->vpn_policy[afi].export_vrf,
15080 node, vname))
15081 vty_out(vty, " %s\n", vname);
15082
15083 vty_out(vty, "RD: %s\n",
15084 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
15085 buf1, RD_ADDRSTRLEN));
15086
15087 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
15088 if (bgp->vpn_policy[afi].rtlist[dir]) {
15089 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15090 bgp->vpn_policy[afi].rtlist[dir],
15091 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
15092 vty_out(vty, "Export RT: %s\n", ecom_str);
15093 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15094 } else
15095 vty_out(vty, "Import RT(s):\n");
53089bec 15096 }
53089bec 15097 }
15098
15099 return CMD_SUCCESS;
15100}
15101
03915806
CS
15102static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
15103 safi_t safi, bool use_json)
15104{
15105 struct listnode *node, *nnode;
15106 struct bgp *bgp;
15107 char *vrf_name = NULL;
15108 json_object *json = NULL;
15109 json_object *json_vrf = NULL;
15110 json_object *json_vrfs = NULL;
15111
15112 if (use_json) {
15113 json = json_object_new_object();
15114 json_vrfs = json_object_new_object();
15115 }
15116
15117 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15118
15119 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
15120 vrf_name = bgp->name;
15121
15122 if (use_json) {
15123 json_vrf = json_object_new_object();
15124 } else {
15125 vty_out(vty, "\nInstance %s:\n",
15126 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15127 ? VRF_DEFAULT_NAME : bgp->name);
15128 }
15129 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
15130 if (use_json) {
15131 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15132 json_object_object_add(json_vrfs,
15133 VRF_DEFAULT_NAME, json_vrf);
15134 else
15135 json_object_object_add(json_vrfs, vrf_name,
15136 json_vrf);
15137 }
15138 }
15139
15140 if (use_json) {
15141 json_object_object_add(json, "vrfs", json_vrfs);
15142 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
15143 JSON_C_TO_STRING_PRETTY));
15144 json_object_free(json);
15145 }
15146
15147 return CMD_SUCCESS;
15148}
15149
53089bec 15150/* "show [ip] bgp route-leak" command. */
15151DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
15152 show_ip_bgp_route_leak_cmd,
15153 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
15154 SHOW_STR
15155 IP_STR
15156 BGP_STR
15157 BGP_INSTANCE_HELP_STR
15158 BGP_AFI_HELP_STR
15159 BGP_SAFI_HELP_STR
15160 "Route leaking information\n"
15161 JSON_STR)
53089bec 15162{
15163 char *vrf = NULL;
15164 afi_t afi = AFI_MAX;
15165 safi_t safi = SAFI_MAX;
15166
9f049418 15167 bool uj = use_json(argc, argv);
53089bec 15168 int idx = 0;
03915806 15169 json_object *json = NULL;
53089bec 15170
15171 /* show [ip] bgp */
15172 if (argv_find(argv, argc, "ip", &idx)) {
15173 afi = AFI_IP;
15174 safi = SAFI_UNICAST;
15175 }
15176 /* [vrf VIEWVRFNAME] */
15177 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
15178 vty_out(vty,
15179 "%% This command is not applicable to BGP views\n");
53089bec 15180 return CMD_WARNING;
15181 }
15182
9a8bdf1c
PG
15183 if (argv_find(argv, argc, "vrf", &idx)) {
15184 vrf = argv[idx + 1]->arg;
15185 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15186 vrf = NULL;
15187 }
53089bec 15188 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15189 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15190 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15191 }
15192
15193 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
15194 vty_out(vty,
15195 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 15196 return CMD_WARNING;
15197 }
15198
03915806
CS
15199 if (vrf && strmatch(vrf, "all"))
15200 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15201
15202 if (uj)
15203 json = json_object_new_object();
15204
15205 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
53089bec 15206}
15207
d62a17ae 15208static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
15209 safi_t safi)
f186de26 15210{
d62a17ae 15211 struct listnode *node, *nnode;
15212 struct bgp *bgp;
f186de26 15213
d62a17ae 15214 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15215 vty_out(vty, "\nInstance %s:\n",
15216 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 15217 ? VRF_DEFAULT_NAME
d62a17ae 15218 : bgp->name);
15219 update_group_show(bgp, afi, safi, vty, 0);
15220 }
f186de26 15221}
15222
d62a17ae 15223static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
15224 int safi, uint64_t subgrp_id)
4fb25c53 15225{
d62a17ae 15226 struct bgp *bgp;
4fb25c53 15227
d62a17ae 15228 if (name) {
15229 if (strmatch(name, "all")) {
15230 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
15231 return CMD_SUCCESS;
15232 } else {
15233 bgp = bgp_lookup_by_name(name);
15234 }
15235 } else {
15236 bgp = bgp_get_default();
15237 }
4fb25c53 15238
d62a17ae 15239 if (bgp)
15240 update_group_show(bgp, afi, safi, vty, subgrp_id);
15241 return CMD_SUCCESS;
4fb25c53
DW
15242}
15243
8fe8a7f6
DS
15244DEFUN (show_ip_bgp_updgrps,
15245 show_ip_bgp_updgrps_cmd,
c1a44e43 15246 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 15247 SHOW_STR
15248 IP_STR
15249 BGP_STR
15250 BGP_INSTANCE_HELP_STR
c9e571b4 15251 BGP_AFI_HELP_STR
9bedbb1e 15252 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
15253 "Detailed info about dynamic update groups\n"
15254 "Specific subgroup to display detailed info for\n")
8386ac43 15255{
d62a17ae 15256 char *vrf = NULL;
15257 afi_t afi = AFI_IP6;
15258 safi_t safi = SAFI_UNICAST;
15259 uint64_t subgrp_id = 0;
15260
15261 int idx = 0;
15262
15263 /* show [ip] bgp */
15264 if (argv_find(argv, argc, "ip", &idx))
15265 afi = AFI_IP;
9a8bdf1c
PG
15266 /* [<vrf> VIEWVRFNAME] */
15267 if (argv_find(argv, argc, "vrf", &idx)) {
15268 vrf = argv[idx + 1]->arg;
15269 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15270 vrf = NULL;
15271 } else if (argv_find(argv, argc, "view", &idx))
15272 /* [<view> VIEWVRFNAME] */
15273 vrf = argv[idx + 1]->arg;
d62a17ae 15274 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15275 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15276 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15277 }
5bf15956 15278
d62a17ae 15279 /* get subgroup id, if provided */
15280 idx = argc - 1;
15281 if (argv[idx]->type == VARIABLE_TKN)
15282 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 15283
d62a17ae 15284 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
15285}
15286
f186de26 15287DEFUN (show_bgp_instance_all_ipv6_updgrps,
15288 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 15289 "show [ip] bgp <view|vrf> all update-groups",
f186de26 15290 SHOW_STR
716b2d8a 15291 IP_STR
f186de26 15292 BGP_STR
15293 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 15294 "Detailed info about dynamic update groups\n")
f186de26 15295{
d62a17ae 15296 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
15297 return CMD_SUCCESS;
f186de26 15298}
15299
43d3f4fc
DS
15300DEFUN (show_bgp_l2vpn_evpn_updgrps,
15301 show_bgp_l2vpn_evpn_updgrps_cmd,
15302 "show [ip] bgp l2vpn evpn update-groups",
15303 SHOW_STR
15304 IP_STR
15305 BGP_STR
15306 "l2vpn address family\n"
15307 "evpn sub-address family\n"
15308 "Detailed info about dynamic update groups\n")
15309{
15310 char *vrf = NULL;
15311 uint64_t subgrp_id = 0;
15312
15313 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
15314 return CMD_SUCCESS;
15315}
15316
5bf15956
DW
15317DEFUN (show_bgp_updgrps_stats,
15318 show_bgp_updgrps_stats_cmd,
716b2d8a 15319 "show [ip] bgp update-groups statistics",
3f9c7369 15320 SHOW_STR
716b2d8a 15321 IP_STR
3f9c7369 15322 BGP_STR
0c7b1b01 15323 "Detailed info about dynamic update groups\n"
3f9c7369
DS
15324 "Statistics\n")
15325{
d62a17ae 15326 struct bgp *bgp;
3f9c7369 15327
d62a17ae 15328 bgp = bgp_get_default();
15329 if (bgp)
15330 update_group_show_stats(bgp, vty);
3f9c7369 15331
d62a17ae 15332 return CMD_SUCCESS;
3f9c7369
DS
15333}
15334
8386ac43 15335DEFUN (show_bgp_instance_updgrps_stats,
15336 show_bgp_instance_updgrps_stats_cmd,
18c57037 15337 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 15338 SHOW_STR
716b2d8a 15339 IP_STR
8386ac43 15340 BGP_STR
15341 BGP_INSTANCE_HELP_STR
0c7b1b01 15342 "Detailed info about dynamic update groups\n"
8386ac43 15343 "Statistics\n")
15344{
d62a17ae 15345 int idx_word = 3;
15346 struct bgp *bgp;
8386ac43 15347
d62a17ae 15348 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15349 if (bgp)
15350 update_group_show_stats(bgp, vty);
8386ac43 15351
d62a17ae 15352 return CMD_SUCCESS;
8386ac43 15353}
15354
d62a17ae 15355static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15356 afi_t afi, safi_t safi,
15357 const char *what, uint64_t subgrp_id)
3f9c7369 15358{
d62a17ae 15359 struct bgp *bgp;
8386ac43 15360
d62a17ae 15361 if (name)
15362 bgp = bgp_lookup_by_name(name);
15363 else
15364 bgp = bgp_get_default();
8386ac43 15365
d62a17ae 15366 if (bgp) {
15367 if (!strcmp(what, "advertise-queue"))
15368 update_group_show_adj_queue(bgp, afi, safi, vty,
15369 subgrp_id);
15370 else if (!strcmp(what, "advertised-routes"))
15371 update_group_show_advertised(bgp, afi, safi, vty,
15372 subgrp_id);
15373 else if (!strcmp(what, "packet-queue"))
15374 update_group_show_packet_queue(bgp, afi, safi, vty,
15375 subgrp_id);
15376 }
3f9c7369
DS
15377}
15378
dc64bdec
QY
15379DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15380 show_ip_bgp_instance_updgrps_adj_s_cmd,
15381 "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",
15382 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15383 BGP_SAFI_HELP_STR
15384 "Detailed info about dynamic update groups\n"
15385 "Specific subgroup to display info for\n"
15386 "Advertisement queue\n"
15387 "Announced routes\n"
15388 "Packet queue\n")
3f9c7369 15389{
dc64bdec
QY
15390 uint64_t subgrp_id = 0;
15391 afi_t afiz;
15392 safi_t safiz;
15393 if (sgid)
15394 subgrp_id = strtoull(sgid, NULL, 10);
15395
15396 if (!ip && !afi)
15397 afiz = AFI_IP6;
15398 if (!ip && afi)
15399 afiz = bgp_vty_afi_from_str(afi);
15400 if (ip && !afi)
15401 afiz = AFI_IP;
15402 if (ip && afi) {
15403 afiz = bgp_vty_afi_from_str(afi);
15404 if (afiz != AFI_IP)
15405 vty_out(vty,
15406 "%% Cannot specify both 'ip' and 'ipv6'\n");
15407 return CMD_WARNING;
15408 }
d62a17ae 15409
dc64bdec 15410 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 15411
dc64bdec 15412 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 15413 return CMD_SUCCESS;
15414}
15415
d62a17ae 15416static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
15417{
15418 struct listnode *node, *nnode;
15419 struct prefix *range;
15420 struct peer *conf;
15421 struct peer *peer;
d62a17ae 15422 afi_t afi;
15423 safi_t safi;
15424 const char *peer_status;
15425 const char *af_str;
15426 int lr_count;
15427 int dynamic;
15428 int af_cfgd;
15429
15430 conf = group->conf;
15431
15432 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
6cde4b45 15433 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
3b61f610 15434 group->name, conf->as);
d62a17ae 15435 } else if (conf->as_type == AS_INTERNAL) {
6cde4b45 15436 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
3b61f610 15437 group->name, group->bgp->as);
d62a17ae 15438 } else {
15439 vty_out(vty, "\nBGP peer-group %s\n", group->name);
15440 }
f14e6fdb 15441
d62a17ae 15442 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
15443 vty_out(vty, " Peer-group type is internal\n");
15444 else
15445 vty_out(vty, " Peer-group type is external\n");
15446
15447 /* Display AFs configured. */
15448 vty_out(vty, " Configured address-families:");
05c7a1cc
QY
15449 FOREACH_AFI_SAFI (afi, safi) {
15450 if (conf->afc[afi][safi]) {
15451 af_cfgd = 1;
5cb5f4d0 15452 vty_out(vty, " %s;", get_afi_safi_str(afi, safi, false));
d62a17ae 15453 }
05c7a1cc 15454 }
d62a17ae 15455 if (!af_cfgd)
15456 vty_out(vty, " none\n");
15457 else
15458 vty_out(vty, "\n");
15459
15460 /* Display listen ranges (for dynamic neighbors), if any */
15461 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
15462 if (afi == AFI_IP)
15463 af_str = "IPv4";
15464 else if (afi == AFI_IP6)
15465 af_str = "IPv6";
15466 else
15467 af_str = "???";
15468 lr_count = listcount(group->listen_range[afi]);
15469 if (lr_count) {
15470 vty_out(vty, " %d %s listen range(s)\n", lr_count,
15471 af_str);
15472
15473
15474 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
2dbe669b
DA
15475 nnode, range))
15476 vty_out(vty, " %pFX\n", range);
d62a17ae 15477 }
15478 }
f14e6fdb 15479
d62a17ae 15480 /* Display group members and their status */
15481 if (listcount(group->peer)) {
15482 vty_out(vty, " Peer-group members:\n");
15483 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
cb9196e7
DS
15484 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15485 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 15486 peer_status = "Idle (Admin)";
15487 else if (CHECK_FLAG(peer->sflags,
15488 PEER_STATUS_PREFIX_OVERFLOW))
15489 peer_status = "Idle (PfxCt)";
15490 else
15491 peer_status = lookup_msg(bgp_status_msg,
15492 peer->status, NULL);
15493
15494 dynamic = peer_dynamic_neighbor(peer);
15495 vty_out(vty, " %s %s %s \n", peer->host,
15496 dynamic ? "(dynamic)" : "", peer_status);
15497 }
15498 }
f14e6fdb 15499
d62a17ae 15500 return CMD_SUCCESS;
15501}
15502
ff9959b0
QY
15503static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
15504 const char *group_name)
d62a17ae 15505{
ff9959b0 15506 struct bgp *bgp;
d62a17ae 15507 struct listnode *node, *nnode;
15508 struct peer_group *group;
ff9959b0
QY
15509 bool found = false;
15510
15511 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15512
15513 if (!bgp) {
9f049418 15514 vty_out(vty, "%% BGP instance not found\n");
ff9959b0
QY
15515 return CMD_WARNING;
15516 }
d62a17ae 15517
15518 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
15519 if (group_name) {
15520 if (strmatch(group->name, group_name)) {
d62a17ae 15521 bgp_show_one_peer_group(vty, group);
ff9959b0
QY
15522 found = true;
15523 break;
d62a17ae 15524 }
ff9959b0
QY
15525 } else {
15526 bgp_show_one_peer_group(vty, group);
d62a17ae 15527 }
f14e6fdb 15528 }
f14e6fdb 15529
ff9959b0 15530 if (group_name && !found)
d62a17ae 15531 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 15532
d62a17ae 15533 return CMD_SUCCESS;
f14e6fdb
DS
15534}
15535
f14e6fdb
DS
15536DEFUN (show_ip_bgp_peer_groups,
15537 show_ip_bgp_peer_groups_cmd,
18c57037 15538 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
f14e6fdb
DS
15539 SHOW_STR
15540 IP_STR
15541 BGP_STR
8386ac43 15542 BGP_INSTANCE_HELP_STR
d6e3c605
QY
15543 "Detailed information on BGP peer groups\n"
15544 "Peer group name\n")
f14e6fdb 15545{
d62a17ae 15546 char *vrf, *pg;
d62a17ae 15547 int idx = 0;
f14e6fdb 15548
a4d82a8a
PZ
15549 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
15550 : NULL;
d62a17ae 15551 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 15552
ff9959b0 15553 return bgp_show_peer_group_vty(vty, vrf, pg);
f14e6fdb 15554}
3f9c7369 15555
d6e3c605 15556
718e3744 15557/* Redistribute VTY commands. */
15558
37a87b8f
CS
15559DEFUN_YANG (bgp_redistribute_ipv4,
15560 bgp_redistribute_ipv4_cmd,
15561 "redistribute " FRR_IP_REDIST_STR_BGPD,
15562 "Redistribute information from another routing protocol\n"
15563 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 15564{
d62a17ae 15565 int idx_protocol = 1;
37a87b8f 15566 char base_xpath[XPATH_MAXLEN];
718e3744 15567
37a87b8f
CS
15568 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15569 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15570 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15571 argv[idx_protocol]->text, "0");
15572
15573 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
7f323236 15574
37a87b8f 15575 return nb_cli_apply_changes(vty, base_xpath);
718e3744 15576}
15577
d62a17ae 15578ALIAS_HIDDEN(
15579 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
15580 "redistribute " FRR_IP_REDIST_STR_BGPD,
15581 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 15582
37a87b8f
CS
15583DEFUN_YANG (bgp_redistribute_ipv4_rmap,
15584 bgp_redistribute_ipv4_rmap_cmd,
15585 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15586 "Redistribute information from another routing protocol\n"
15587 FRR_IP_REDIST_HELP_STR_BGPD
15588 "Route map reference\n"
15589 "Pointer to route-map entries\n")
718e3744 15590{
d62a17ae 15591 int idx_protocol = 1;
15592 int idx_word = 3;
37a87b8f
CS
15593 char base_xpath[XPATH_MAXLEN];
15594
15595 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15596 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15597 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15598 argv[idx_protocol]->text, "0");
718e3744 15599
37a87b8f
CS
15600 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15601 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15602 argv[idx_word]->arg);
15603
15604 return nb_cli_apply_changes(vty, base_xpath);
718e3744 15605}
15606
d62a17ae 15607ALIAS_HIDDEN(
15608 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
15609 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15610 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15611 "Route map reference\n"
15612 "Pointer to route-map entries\n")
596c17ba 15613
37a87b8f
CS
15614DEFUN_YANG (bgp_redistribute_ipv4_metric,
15615 bgp_redistribute_ipv4_metric_cmd,
15616 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15617 "Redistribute information from another routing protocol\n"
15618 FRR_IP_REDIST_HELP_STR_BGPD
15619 "Metric for redistributed routes\n"
15620 "Default metric\n")
718e3744 15621{
d62a17ae 15622 int idx_protocol = 1;
15623 int idx_number = 3;
37a87b8f
CS
15624 char base_xpath[XPATH_MAXLEN];
15625
15626 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15627 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15628 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15629 argv[idx_protocol]->text, "0");
d62a17ae 15630
37a87b8f
CS
15631 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15632 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15633 argv[idx_number]->arg);
15634
15635 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15636}
15637
15638ALIAS_HIDDEN(
15639 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
15640 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15641 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15642 "Metric for redistributed routes\n"
15643 "Default metric\n")
596c17ba 15644
37a87b8f
CS
15645DEFUN_YANG(
15646 bgp_redistribute_ipv4_rmap_metric,
15647 bgp_redistribute_ipv4_rmap_metric_cmd,
15648 "redistribute " FRR_IP_REDIST_STR_BGPD
15649 " route-map WORD metric (0-4294967295)",
15650 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15651 "Route map reference\n"
15652 "Pointer to route-map entries\n"
15653 "Metric for redistributed routes\n"
15654 "Default metric\n")
718e3744 15655{
d62a17ae 15656 int idx_protocol = 1;
15657 int idx_word = 3;
15658 int idx_number = 5;
37a87b8f
CS
15659 char base_xpath[XPATH_MAXLEN];
15660
15661 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15662 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15663 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15664 argv[idx_protocol]->text, "0");
15665
15666 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15667 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15668 argv[idx_word]->arg);
15669 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15670 argv[idx_number]->arg);
d62a17ae 15671
37a87b8f 15672 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15673}
15674
15675ALIAS_HIDDEN(
15676 bgp_redistribute_ipv4_rmap_metric,
15677 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
15678 "redistribute " FRR_IP_REDIST_STR_BGPD
15679 " route-map WORD metric (0-4294967295)",
15680 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15681 "Route map reference\n"
15682 "Pointer to route-map entries\n"
15683 "Metric for redistributed routes\n"
15684 "Default metric\n")
596c17ba 15685
37a87b8f
CS
15686DEFUN_YANG(
15687 bgp_redistribute_ipv4_metric_rmap,
15688 bgp_redistribute_ipv4_metric_rmap_cmd,
15689 "redistribute " FRR_IP_REDIST_STR_BGPD
15690 " metric (0-4294967295) route-map WORD",
15691 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15692 "Metric for redistributed routes\n"
15693 "Default metric\n"
15694 "Route map reference\n"
15695 "Pointer to route-map entries\n")
718e3744 15696{
d62a17ae 15697 int idx_protocol = 1;
d62a17ae 15698 int idx_word = 5;
37a87b8f
CS
15699 int idx_number = 3;
15700 char base_xpath[XPATH_MAXLEN];
15701
15702 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15703 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15704 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15705 argv[idx_protocol]->text, "0");
15706
15707 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15708 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15709 argv[idx_number]->arg);
15710 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15711 argv[idx_word]->arg);
d62a17ae 15712
37a87b8f 15713 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15714}
15715
15716ALIAS_HIDDEN(
15717 bgp_redistribute_ipv4_metric_rmap,
15718 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
15719 "redistribute " FRR_IP_REDIST_STR_BGPD
15720 " metric (0-4294967295) route-map WORD",
15721 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15722 "Metric for redistributed routes\n"
15723 "Default metric\n"
15724 "Route map reference\n"
15725 "Pointer to route-map entries\n")
596c17ba 15726
37a87b8f
CS
15727DEFUN_YANG (bgp_redistribute_ipv4_ospf,
15728 bgp_redistribute_ipv4_ospf_cmd,
15729 "redistribute <ospf|table> (1-65535)",
15730 "Redistribute information from another routing protocol\n"
15731 "Open Shortest Path First (OSPFv2)\n"
15732 "Non-main Kernel Routing Table\n"
15733 "Instance ID/Table ID\n")
7c8ff89e 15734{
37a87b8f 15735 int idx_protocol = 1;
d62a17ae 15736 int idx_number = 2;
37a87b8f 15737 char base_xpath[XPATH_MAXLEN];
7c8ff89e 15738
37a87b8f
CS
15739 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15740 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15741 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15742 argv[idx_protocol]->text, argv[idx_number]->arg);
7a4bb9c5 15743
37a87b8f 15744 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
7a4bb9c5 15745
37a87b8f 15746 return nb_cli_apply_changes(vty, base_xpath);
7c8ff89e
DS
15747}
15748
d62a17ae 15749ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
15750 "redistribute <ospf|table> (1-65535)",
15751 "Redistribute information from another routing protocol\n"
15752 "Open Shortest Path First (OSPFv2)\n"
15753 "Non-main Kernel Routing Table\n"
15754 "Instance ID/Table ID\n")
596c17ba 15755
37a87b8f
CS
15756DEFUN_YANG (bgp_redistribute_ipv4_ospf_rmap,
15757 bgp_redistribute_ipv4_ospf_rmap_cmd,
15758 "redistribute <ospf|table> (1-65535) route-map WORD",
15759 "Redistribute information from another routing protocol\n"
15760 "Open Shortest Path First (OSPFv2)\n"
15761 "Non-main Kernel Routing Table\n"
15762 "Instance ID/Table ID\n"
15763 "Route map reference\n"
15764 "Pointer to route-map entries\n")
7c8ff89e 15765{
37a87b8f 15766 int idx_protocol = 1;
d62a17ae 15767 int idx_number = 2;
15768 int idx_word = 4;
37a87b8f
CS
15769 char base_xpath[XPATH_MAXLEN];
15770
15771 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15772 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15773 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15774 argv[idx_protocol]->text, argv[idx_number]->arg);
15775
15776 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15777
15778 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15779 argv[idx_word]->arg);
d62a17ae 15780
37a87b8f 15781 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15782}
15783
15784ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
15785 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
15786 "redistribute <ospf|table> (1-65535) route-map WORD",
15787 "Redistribute information from another routing protocol\n"
15788 "Open Shortest Path First (OSPFv2)\n"
15789 "Non-main Kernel Routing Table\n"
15790 "Instance ID/Table ID\n"
15791 "Route map reference\n"
15792 "Pointer to route-map entries\n")
596c17ba 15793
37a87b8f
CS
15794DEFUN_YANG(bgp_redistribute_ipv4_ospf_metric,
15795 bgp_redistribute_ipv4_ospf_metric_cmd,
15796 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15797 "Redistribute information from another routing protocol\n"
15798 "Open Shortest Path First (OSPFv2)\n"
15799 "Non-main Kernel Routing Table\n"
15800 "Instance ID/Table ID\n"
15801 "Metric for redistributed routes\n"
15802 "Default metric\n")
7c8ff89e 15803{
37a87b8f 15804 int idx_protocol = 1;
d62a17ae 15805 int idx_number = 2;
15806 int idx_number_2 = 4;
37a87b8f
CS
15807 char base_xpath[XPATH_MAXLEN];
15808
15809 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15810 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15811 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15812 argv[idx_protocol]->text, argv[idx_number]->arg);
15813
15814 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 15815
37a87b8f
CS
15816 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15817 argv[idx_number_2]->arg);
d62a17ae 15818
37a87b8f 15819 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15820}
15821
15822ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
15823 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
15824 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15825 "Redistribute information from another routing protocol\n"
15826 "Open Shortest Path First (OSPFv2)\n"
15827 "Non-main Kernel Routing Table\n"
15828 "Instance ID/Table ID\n"
15829 "Metric for redistributed routes\n"
15830 "Default metric\n")
596c17ba 15831
37a87b8f
CS
15832DEFUN_YANG(
15833 bgp_redistribute_ipv4_ospf_rmap_metric,
15834 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
15835 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15836 "Redistribute information from another routing protocol\n"
15837 "Open Shortest Path First (OSPFv2)\n"
15838 "Non-main Kernel Routing Table\n"
15839 "Instance ID/Table ID\n"
15840 "Route map reference\n"
15841 "Pointer to route-map entries\n"
15842 "Metric for redistributed routes\n"
15843 "Default metric\n")
7c8ff89e 15844{
37a87b8f 15845 int idx_protocol = 1;
d62a17ae 15846 int idx_number = 2;
15847 int idx_word = 4;
15848 int idx_number_2 = 6;
37a87b8f
CS
15849 char base_xpath[XPATH_MAXLEN];
15850
15851 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15852 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15853 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15854 argv[idx_protocol]->text, argv[idx_number]->arg);
15855
15856 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 15857
37a87b8f
CS
15858 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15859 argv[idx_word]->arg);
15860 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15861 argv[idx_number_2]->arg);
d62a17ae 15862
37a87b8f 15863 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15864}
15865
15866ALIAS_HIDDEN(
15867 bgp_redistribute_ipv4_ospf_rmap_metric,
15868 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
15869 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15870 "Redistribute information from another routing protocol\n"
15871 "Open Shortest Path First (OSPFv2)\n"
15872 "Non-main Kernel Routing Table\n"
15873 "Instance ID/Table ID\n"
15874 "Route map reference\n"
15875 "Pointer to route-map entries\n"
15876 "Metric for redistributed routes\n"
15877 "Default metric\n")
596c17ba 15878
37a87b8f
CS
15879DEFUN_YANG(
15880 bgp_redistribute_ipv4_ospf_metric_rmap,
15881 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
15882 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15883 "Redistribute information from another routing protocol\n"
15884 "Open Shortest Path First (OSPFv2)\n"
15885 "Non-main Kernel Routing Table\n"
15886 "Instance ID/Table ID\n"
15887 "Metric for redistributed routes\n"
15888 "Default metric\n"
15889 "Route map reference\n"
15890 "Pointer to route-map entries\n")
7c8ff89e 15891{
37a87b8f 15892 int idx_protocol = 1;
d62a17ae 15893 int idx_number = 2;
15894 int idx_number_2 = 4;
15895 int idx_word = 6;
37a87b8f
CS
15896 char base_xpath[XPATH_MAXLEN];
15897
15898 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15899 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15900 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15901 argv[idx_protocol]->text, argv[idx_number]->arg);
15902
15903 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 15904
37a87b8f
CS
15905 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15906 argv[idx_number_2]->arg);
15907 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15908 argv[idx_word]->arg);
d62a17ae 15909
37a87b8f 15910 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15911}
15912
15913ALIAS_HIDDEN(
15914 bgp_redistribute_ipv4_ospf_metric_rmap,
15915 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
15916 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15917 "Redistribute information from another routing protocol\n"
15918 "Open Shortest Path First (OSPFv2)\n"
15919 "Non-main Kernel Routing Table\n"
15920 "Instance ID/Table ID\n"
15921 "Metric for redistributed routes\n"
15922 "Default metric\n"
15923 "Route map reference\n"
15924 "Pointer to route-map entries\n")
596c17ba 15925
37a87b8f
CS
15926DEFUN_YANG (no_bgp_redistribute_ipv4_ospf,
15927 no_bgp_redistribute_ipv4_ospf_cmd,
15928 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
15929 NO_STR
15930 "Redistribute information from another routing protocol\n"
15931 "Open Shortest Path First (OSPFv2)\n"
15932 "Non-main Kernel Routing Table\n"
15933 "Instance ID/Table ID\n"
15934 "Metric for redistributed routes\n"
15935 "Default metric\n"
15936 "Route map reference\n"
15937 "Pointer to route-map entries\n")
7c8ff89e 15938{
37a87b8f 15939 int idx_protocol = 2;
d62a17ae 15940 int idx_number = 3;
37a87b8f 15941 char base_xpath[XPATH_MAXLEN];
d62a17ae 15942
37a87b8f
CS
15943 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15944 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15945 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15946 argv[idx_protocol]->text, argv[idx_number]->arg);
15947
15948 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
d62a17ae 15949
37a87b8f 15950 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15951}
15952
15953ALIAS_HIDDEN(
15954 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
e27957c0 15955 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 15956 NO_STR
15957 "Redistribute information from another routing protocol\n"
15958 "Open Shortest Path First (OSPFv2)\n"
15959 "Non-main Kernel Routing Table\n"
15960 "Instance ID/Table ID\n"
15961 "Metric for redistributed routes\n"
15962 "Default metric\n"
15963 "Route map reference\n"
15964 "Pointer to route-map entries\n")
596c17ba 15965
37a87b8f
CS
15966DEFUN_YANG (no_bgp_redistribute_ipv4,
15967 no_bgp_redistribute_ipv4_cmd,
15968 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
15969 NO_STR
15970 "Redistribute information from another routing protocol\n"
15971 FRR_IP_REDIST_HELP_STR_BGPD
15972 "Metric for redistributed routes\n"
15973 "Default metric\n"
15974 "Route map reference\n"
15975 "Pointer to route-map entries\n")
718e3744 15976{
d62a17ae 15977 int idx_protocol = 2;
37a87b8f 15978 char base_xpath[XPATH_MAXLEN];
d62a17ae 15979
37a87b8f
CS
15980 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15981 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15982 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15983 argv[idx_protocol]->text, "0");
15984
15985 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
15986
15987 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15988}
15989
15990ALIAS_HIDDEN(
15991 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
15992 "no redistribute " FRR_IP_REDIST_STR_BGPD
e27957c0 15993 " [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 15994 NO_STR
15995 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15996 "Metric for redistributed routes\n"
15997 "Default metric\n"
15998 "Route map reference\n"
15999 "Pointer to route-map entries\n")
596c17ba 16000
37a87b8f
CS
16001DEFUN_YANG (bgp_redistribute_ipv6,
16002 bgp_redistribute_ipv6_cmd,
16003 "redistribute " FRR_IP6_REDIST_STR_BGPD,
16004 "Redistribute information from another routing protocol\n"
16005 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 16006{
d62a17ae 16007 int idx_protocol = 1;
37a87b8f 16008 char base_xpath[XPATH_MAXLEN];
718e3744 16009
37a87b8f
CS
16010 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16011 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16012 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16013 argv[idx_protocol]->text, "0");
16014
16015 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
718e3744 16016
37a87b8f 16017 return nb_cli_apply_changes(vty, base_xpath);
718e3744 16018}
16019
37a87b8f
CS
16020DEFUN_YANG (bgp_redistribute_ipv6_rmap,
16021 bgp_redistribute_ipv6_rmap_cmd,
16022 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
16023 "Redistribute information from another routing protocol\n"
16024 FRR_IP6_REDIST_HELP_STR_BGPD
16025 "Route map reference\n"
16026 "Pointer to route-map entries\n")
718e3744 16027{
d62a17ae 16028 int idx_protocol = 1;
16029 int idx_word = 3;
37a87b8f
CS
16030 char base_xpath[XPATH_MAXLEN];
16031
16032 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16033 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16034 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16035 argv[idx_protocol]->text, "0");
718e3744 16036
37a87b8f
CS
16037 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16038 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16039 argv[idx_word]->arg);
16040
16041 return nb_cli_apply_changes(vty, base_xpath);
718e3744 16042}
16043
37a87b8f 16044DEFUN_YANG (bgp_redistribute_ipv6_metric,
718e3744 16045 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 16046 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 16047 "Redistribute information from another routing protocol\n"
ab0181ee 16048 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 16049 "Metric for redistributed routes\n"
16050 "Default metric\n")
16051{
d62a17ae 16052 int idx_protocol = 1;
16053 int idx_number = 3;
37a87b8f
CS
16054 char base_xpath[XPATH_MAXLEN];
16055
16056 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16057 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16058 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16059 argv[idx_protocol]->text, "0");
718e3744 16060
37a87b8f
CS
16061 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16062 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16063 argv[idx_number]->arg);
16064
16065 return nb_cli_apply_changes(vty, base_xpath);
718e3744 16066}
16067
37a87b8f
CS
16068DEFUN_YANG(
16069 bgp_redistribute_ipv6_rmap_metric,
16070 bgp_redistribute_ipv6_rmap_metric_cmd,
16071 "redistribute " FRR_IP6_REDIST_STR_BGPD
16072 " route-map WORD metric (0-4294967295)",
16073 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
16074 "Route map reference\n"
16075 "Pointer to route-map entries\n"
16076 "Metric for redistributed routes\n"
16077 "Default metric\n")
718e3744 16078{
d62a17ae 16079 int idx_protocol = 1;
16080 int idx_word = 3;
16081 int idx_number = 5;
37a87b8f
CS
16082 char base_xpath[XPATH_MAXLEN];
16083
16084 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16085 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16086 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16087 argv[idx_protocol]->text, "0");
718e3744 16088
37a87b8f
CS
16089 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16090 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16091 argv[idx_word]->arg);
16092 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16093 argv[idx_number]->arg);
16094
16095 return nb_cli_apply_changes(vty, base_xpath);
718e3744 16096}
16097
37a87b8f
CS
16098DEFUN_YANG(
16099 bgp_redistribute_ipv6_metric_rmap,
16100 bgp_redistribute_ipv6_metric_rmap_cmd,
16101 "redistribute " FRR_IP6_REDIST_STR_BGPD
16102 " metric (0-4294967295) route-map WORD",
16103 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
16104 "Metric for redistributed routes\n"
16105 "Default metric\n"
16106 "Route map reference\n"
16107 "Pointer to route-map entries\n")
718e3744 16108{
d62a17ae 16109 int idx_protocol = 1;
d62a17ae 16110 int idx_word = 5;
37a87b8f
CS
16111 int idx_number = 3;
16112 char base_xpath[XPATH_MAXLEN];
16113
16114 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16115 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16116 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16117 argv[idx_protocol]->text, "0");
718e3744 16118
37a87b8f
CS
16119 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16120 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16121 argv[idx_number]->arg);
16122 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16123 argv[idx_word]->arg);
16124
16125 return nb_cli_apply_changes(vty, base_xpath);
718e3744 16126}
16127
37a87b8f
CS
16128DEFUN_YANG(
16129 no_bgp_redistribute_ipv6,
16130 no_bgp_redistribute_ipv6_cmd,
16131 "no redistribute " FRR_IP6_REDIST_STR_BGPD
16132 " [{metric (0-4294967295)|route-map WORD}]",
16133 NO_STR
16134 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
16135 "Metric for redistributed routes\n"
16136 "Default metric\n"
16137 "Route map reference\n"
16138 "Pointer to route-map entries\n")
718e3744 16139{
d62a17ae 16140 int idx_protocol = 2;
37a87b8f 16141 char base_xpath[XPATH_MAXLEN];
718e3744 16142
37a87b8f
CS
16143 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16144 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16145 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16146 argv[idx_protocol]->text, "0");
16147
16148 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
16149
16150 return nb_cli_apply_changes(vty, base_xpath);
16151}
718e3744 16152
37a87b8f
CS
16153void cli_show_bgp_global_afi_safi_ip_unicast_redistribution_list(
16154 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
16155{
16156 uint32_t instance = 0;
16157
16158 vty_out(vty, " redistribute %s",
16159 yang_dnode_get_string(dnode, "./route-type"));
16160 if ((instance = yang_dnode_get_uint16(dnode, "./route-instance")))
16161 vty_out(vty, " %d", instance);
16162 if (yang_dnode_exists(dnode, "./metric"))
16163 vty_out(vty, " metric %u",
16164 yang_dnode_get_uint32(dnode, "./metric"));
16165 if (yang_dnode_exists(dnode, "./rmap-policy-import"))
16166 vty_out(vty, " route-map %s",
16167 yang_dnode_get_string(dnode, "./rmap-policy-import"));
16168 vty_out(vty, "\n");
d62a17ae 16169}
16170
dd65f45e
DL
16171static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16172 afi_t afi, safi_t safi)
d62a17ae 16173{
16174 int i;
16175
16176 /* Unicast redistribution only. */
16177 if (safi != SAFI_UNICAST)
2b791107 16178 return;
d62a17ae 16179
16180 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16181 /* Redistribute BGP does not make sense. */
16182 if (i != ZEBRA_ROUTE_BGP) {
16183 struct list *red_list;
16184 struct listnode *node;
16185 struct bgp_redist *red;
16186
16187 red_list = bgp->redist[afi][i];
16188 if (!red_list)
16189 continue;
16190
16191 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 16192 /* "redistribute" configuration. */
16193 vty_out(vty, " redistribute %s",
16194 zebra_route_string(i));
16195 if (red->instance)
16196 vty_out(vty, " %d", red->instance);
16197 if (red->redist_metric_flag)
16198 vty_out(vty, " metric %u",
16199 red->redist_metric);
16200 if (red->rmap.name)
16201 vty_out(vty, " route-map %s",
16202 red->rmap.name);
16203 vty_out(vty, "\n");
16204 }
16205 }
16206 }
718e3744 16207}
6b0655a2 16208
dd65f45e
DL
16209/* peer-group helpers for config-write */
16210
16211static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
16212{
16213 if (!peer_group_active(peer)) {
16214 if (CHECK_FLAG(peer->flags_invert, flag))
16215 return !CHECK_FLAG(peer->flags, flag);
16216 else
16217 return !!CHECK_FLAG(peer->flags, flag);
16218 }
16219
16220 return !!CHECK_FLAG(peer->flags_override, flag);
16221}
16222
16223static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16224 uint32_t flag)
16225{
16226 if (!peer_group_active(peer)) {
16227 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16228 return !peer_af_flag_check(peer, afi, safi, flag);
16229 else
16230 return !!peer_af_flag_check(peer, afi, safi, flag);
16231 }
16232
16233 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16234}
16235
16236static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16237 uint8_t type, int direct)
16238{
16239 struct bgp_filter *filter;
16240
16241 if (peer_group_active(peer))
16242 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16243 type);
16244
16245 filter = &peer->filter[afi][safi];
16246 switch (type) {
16247 case PEER_FT_DISTRIBUTE_LIST:
16248 return !!(filter->dlist[direct].name);
16249 case PEER_FT_FILTER_LIST:
16250 return !!(filter->aslist[direct].name);
16251 case PEER_FT_PREFIX_LIST:
16252 return !!(filter->plist[direct].name);
16253 case PEER_FT_ROUTE_MAP:
16254 return !!(filter->map[direct].name);
16255 case PEER_FT_UNSUPPRESS_MAP:
16256 return !!(filter->usmap.name);
7f7940e6
MK
16257 case PEER_FT_ADVERTISE_MAP:
16258 return !!(filter->advmap.aname
16259 && ((filter->advmap.condition == direct)
16260 && filter->advmap.cname));
dd65f45e
DL
16261 default:
16262 return false;
16263 }
16264}
16265
16266/* Return true if the addpath type is set for peer and different from
16267 * peer-group.
16268 */
3dc339cd
DA
16269static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16270 safi_t safi)
dd65f45e
DL
16271{
16272 enum bgp_addpath_strat type, g_type;
16273
16274 type = peer->addpath_type[afi][safi];
16275
16276 if (type != BGP_ADDPATH_NONE) {
16277 if (peer_group_active(peer)) {
16278 g_type = peer->group->conf->addpath_type[afi][safi];
16279
16280 if (type != g_type)
3dc339cd 16281 return true;
dd65f45e 16282 else
3dc339cd 16283 return false;
dd65f45e
DL
16284 }
16285
3dc339cd 16286 return true;
dd65f45e
DL
16287 }
16288
3dc339cd 16289 return false;
dd65f45e
DL
16290}
16291
b9c7bc5a 16292/* This is part of the address-family block (unicast only) */
dd65f45e 16293static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
16294 afi_t afi)
16295{
b9c7bc5a 16296 int indent = 2;
ddb5b488 16297
8a066a70 16298 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
ae6a6fb4
DS
16299 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16300 BGP_CONFIG_VRF_TO_VRF_IMPORT))
8a066a70
PG
16301 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16302 bgp->vpn_policy[afi]
bb4f6190 16303 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
16304 else
16305 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16306 bgp->vpn_policy[afi]
16307 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16308 }
12a844a5
DS
16309 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16310 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16311 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16312 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16313 return;
16314
e70e9f8e
PZ
16315 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16316 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16317
16318 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16319
16320 } else {
16321 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16322 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16323 bgp->vpn_policy[afi].tovpn_label);
16324 }
ddb5b488
PZ
16325 }
16326 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16327 BGP_VPN_POLICY_TOVPN_RD_SET)) {
16328 char buf[RD_ADDRSTRLEN];
b9c7bc5a 16329 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
16330 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
16331 sizeof(buf)));
16332 }
16333 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16334 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
16335
16336 char buf[PREFIX_STRLEN];
16337 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
16338 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
16339 sizeof(buf))) {
16340
b9c7bc5a
PZ
16341 vty_out(vty, "%*snexthop vpn export %s\n",
16342 indent, "", buf);
ddb5b488
PZ
16343 }
16344 }
16345 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
16346 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
16347 && ecommunity_cmp(
16348 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16349 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16350
16351 char *b = ecommunity_ecom2str(
16352 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16353 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16354 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
16355 XFREE(MTYPE_ECOMMUNITY_STR, b);
16356 } else {
16357 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16358 char *b = ecommunity_ecom2str(
16359 bgp->vpn_policy[afi]
16360 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16361 ECOMMUNITY_FORMAT_ROUTE_MAP,
16362 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16363 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
16364 XFREE(MTYPE_ECOMMUNITY_STR, b);
16365 }
16366 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16367 char *b = ecommunity_ecom2str(
16368 bgp->vpn_policy[afi]
16369 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16370 ECOMMUNITY_FORMAT_ROUTE_MAP,
16371 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16372 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
16373 XFREE(MTYPE_ECOMMUNITY_STR, b);
16374 }
16375 }
bb4f6190
DS
16376
16377 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 16378 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
16379 bgp->vpn_policy[afi]
16380 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 16381
301ad80a
PG
16382 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16383 char *b = ecommunity_ecom2str(
16384 bgp->vpn_policy[afi]
16385 .import_redirect_rtlist,
16386 ECOMMUNITY_FORMAT_ROUTE_MAP,
16387 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 16388
9a659715
PG
16389 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16390 != ECOMMUNITY_SIZE)
c6423c31 16391 vty_out(vty, "%*srt6 redirect import %s\n",
9a659715
PG
16392 indent, "", b);
16393 else
16394 vty_out(vty, "%*srt redirect import %s\n",
16395 indent, "", b);
301ad80a
PG
16396 XFREE(MTYPE_ECOMMUNITY_STR, b);
16397 }
ddb5b488
PZ
16398}
16399
dd65f45e
DL
16400static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
16401 afi_t afi, safi_t safi)
16402{
16403 struct bgp_filter *filter;
16404 char *addr;
16405
16406 addr = peer->host;
16407 filter = &peer->filter[afi][safi];
16408
16409 /* distribute-list. */
16410 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16411 FILTER_IN))
16412 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
16413 filter->dlist[FILTER_IN].name);
16414
16415 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16416 FILTER_OUT))
16417 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
16418 filter->dlist[FILTER_OUT].name);
16419
16420 /* prefix-list. */
16421 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16422 FILTER_IN))
16423 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
16424 filter->plist[FILTER_IN].name);
16425
16426 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16427 FILTER_OUT))
16428 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
16429 filter->plist[FILTER_OUT].name);
16430
16431 /* route-map. */
16432 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
16433 vty_out(vty, " neighbor %s route-map %s in\n", addr,
16434 filter->map[RMAP_IN].name);
16435
16436 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
16437 RMAP_OUT))
16438 vty_out(vty, " neighbor %s route-map %s out\n", addr,
16439 filter->map[RMAP_OUT].name);
16440
16441 /* unsuppress-map */
16442 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
16443 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
16444 filter->usmap.name);
16445
7f7940e6
MK
16446 /* advertise-map : always applied in OUT direction*/
16447 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16448 CONDITION_NON_EXIST))
16449 vty_out(vty,
16450 " neighbor %s advertise-map %s non-exist-map %s\n",
16451 addr, filter->advmap.aname, filter->advmap.cname);
16452
16453 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16454 CONDITION_EXIST))
16455 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
16456 addr, filter->advmap.aname, filter->advmap.cname);
16457
dd65f45e
DL
16458 /* filter-list. */
16459 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16460 FILTER_IN))
16461 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
16462 filter->aslist[FILTER_IN].name);
16463
16464 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16465 FILTER_OUT))
16466 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
16467 filter->aslist[FILTER_OUT].name);
16468}
16469
16470/* BGP peer configuration display function. */
16471static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
16472 struct peer *peer)
16473{
16474 struct peer *g_peer = NULL;
16475 char buf[SU_ADDRSTRLEN];
16476 char *addr;
16477 int if_pg_printed = false;
16478 int if_ras_printed = false;
16479
16480 /* Skip dynamic neighbors. */
16481 if (peer_dynamic_neighbor(peer))
16482 return;
16483
16484 if (peer->conf_if)
16485 addr = peer->conf_if;
16486 else
16487 addr = peer->host;
16488
16489 /************************************
16490 ****** Global to the neighbor ******
16491 ************************************/
16492 if (peer->conf_if) {
16493 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
16494 vty_out(vty, " neighbor %s interface v6only", addr);
16495 else
16496 vty_out(vty, " neighbor %s interface", addr);
16497
16498 if (peer_group_active(peer)) {
16499 vty_out(vty, " peer-group %s", peer->group->name);
16500 if_pg_printed = true;
16501 } else if (peer->as_type == AS_SPECIFIED) {
16502 vty_out(vty, " remote-as %u", peer->as);
16503 if_ras_printed = true;
16504 } else if (peer->as_type == AS_INTERNAL) {
16505 vty_out(vty, " remote-as internal");
16506 if_ras_printed = true;
16507 } else if (peer->as_type == AS_EXTERNAL) {
16508 vty_out(vty, " remote-as external");
16509 if_ras_printed = true;
16510 }
16511
16512 vty_out(vty, "\n");
16513 }
16514
16515 /* remote-as and peer-group */
16516 /* peer is a member of a peer-group */
16517 if (peer_group_active(peer)) {
16518 g_peer = peer->group->conf;
16519
16520 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
16521 if (peer->as_type == AS_SPECIFIED) {
16522 vty_out(vty, " neighbor %s remote-as %u\n",
16523 addr, peer->as);
16524 } else if (peer->as_type == AS_INTERNAL) {
16525 vty_out(vty,
16526 " neighbor %s remote-as internal\n",
16527 addr);
16528 } else if (peer->as_type == AS_EXTERNAL) {
16529 vty_out(vty,
16530 " neighbor %s remote-as external\n",
16531 addr);
16532 }
16533 }
16534
16535 /* For swpX peers we displayed the peer-group
16536 * via 'neighbor swpX interface peer-group PGNAME' */
16537 if (!if_pg_printed)
16538 vty_out(vty, " neighbor %s peer-group %s\n", addr,
16539 peer->group->name);
16540 }
16541
16542 /* peer is NOT a member of a peer-group */
16543 else {
16544 /* peer is a peer-group, declare the peer-group */
16545 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
16546 vty_out(vty, " neighbor %s peer-group\n", addr);
16547 }
16548
16549 if (!if_ras_printed) {
16550 if (peer->as_type == AS_SPECIFIED) {
16551 vty_out(vty, " neighbor %s remote-as %u\n",
16552 addr, peer->as);
16553 } else if (peer->as_type == AS_INTERNAL) {
16554 vty_out(vty,
16555 " neighbor %s remote-as internal\n",
16556 addr);
16557 } else if (peer->as_type == AS_EXTERNAL) {
16558 vty_out(vty,
16559 " neighbor %s remote-as external\n",
16560 addr);
16561 }
16562 }
16563 }
16564
16565 /* local-as */
16566 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
16567 vty_out(vty, " neighbor %s local-as %u", addr,
16568 peer->change_local_as);
16569 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
16570 vty_out(vty, " no-prepend");
16571 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
16572 vty_out(vty, " replace-as");
16573 vty_out(vty, "\n");
16574 }
16575
16576 /* description */
16577 if (peer->desc) {
16578 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
16579 }
16580
16581 /* shutdown */
16582 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
16583 if (peer->tx_shutdown_message)
16584 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
16585 peer->tx_shutdown_message);
16586 else
16587 vty_out(vty, " neighbor %s shutdown\n", addr);
16588 }
16589
8336c896
DA
16590 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
16591 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
16592 peer->rtt_expected, peer->rtt_keepalive_conf);
16593
dd65f45e
DL
16594 /* bfd */
16595 if (peer->bfd_info) {
16596 if (!peer_group_active(peer) || !g_peer->bfd_info) {
16597 bgp_bfd_peer_config_write(vty, peer, addr);
16598 }
16599 }
16600
16601 /* password */
16602 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
16603 vty_out(vty, " neighbor %s password %s\n", addr,
16604 peer->password);
16605
16606 /* neighbor solo */
16607 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
16608 if (!peer_group_active(peer)) {
16609 vty_out(vty, " neighbor %s solo\n", addr);
16610 }
16611 }
16612
16613 /* BGP port */
16614 if (peer->port != BGP_PORT_DEFAULT) {
16615 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
16616 }
16617
16618 /* Local interface name */
16619 if (peer->ifname) {
16620 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
16621 }
16622
16623 /* passive */
16624 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
16625 vty_out(vty, " neighbor %s passive\n", addr);
16626
16627 /* ebgp-multihop */
16628 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
e2521429
DA
16629 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
16630 && peer->ttl == MAXTTL)) {
dd65f45e
DL
16631 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
16632 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
16633 peer->ttl);
16634 }
16635 }
16636
16637 /* ttl-security hops */
e2521429 16638 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
dd65f45e
DL
16639 if (!peer_group_active(peer)
16640 || g_peer->gtsm_hops != peer->gtsm_hops) {
16641 vty_out(vty, " neighbor %s ttl-security hops %d\n",
16642 addr, peer->gtsm_hops);
16643 }
16644 }
16645
16646 /* disable-connected-check */
16647 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
16648 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
16649
16650 /* enforce-first-as */
16651 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
16652 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
16653
16654 /* update-source */
16655 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
16656 if (peer->update_source)
16657 vty_out(vty, " neighbor %s update-source %s\n", addr,
16658 sockunion2str(peer->update_source, buf,
16659 SU_ADDRSTRLEN));
16660 else if (peer->update_if)
16661 vty_out(vty, " neighbor %s update-source %s\n", addr,
16662 peer->update_if);
16663 }
16664
16665 /* advertisement-interval */
16666 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
16667 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
16668 peer->routeadv);
16669
16670 /* timers */
16671 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
16672 vty_out(vty, " neighbor %s timers %u %u\n", addr,
16673 peer->keepalive, peer->holdtime);
16674
16675 /* timers connect */
16676 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
16677 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16678 peer->connect);
5d5393b9
DL
16679 /* need special-case handling for changed default values due to
16680 * config profile / version (because there is no "timers bgp connect"
16681 * command, we need to save this per-peer :/)
16682 */
16683 else if (!peer_group_active(peer) && !peer->connect &&
16684 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
16685 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16686 peer->bgp->default_connect_retry);
dd65f45e 16687
d43114f3
DS
16688 /* timers delayopen */
16689 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
16690 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16691 peer->delayopen);
16692 /* Save config even though flag is not set if default values have been
16693 * changed
16694 */
16695 else if (!peer_group_active(peer) && !peer->delayopen
16696 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
16697 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16698 peer->bgp->default_delayopen);
16699
dd65f45e
DL
16700 /* capability dynamic */
16701 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
16702 vty_out(vty, " neighbor %s capability dynamic\n", addr);
16703
16704 /* capability extended-nexthop */
16705 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
16706 if (!peer->conf_if) {
16707 if (CHECK_FLAG(peer->flags_invert,
16708 PEER_FLAG_CAPABILITY_ENHE))
16709 vty_out(vty,
16710 " no neighbor %s capability extended-nexthop\n",
16711 addr);
16712 else
16713 vty_out(vty,
16714 " neighbor %s capability extended-nexthop\n",
16715 addr);
16716 }
16717 }
16718
16719 /* dont-capability-negotiation */
16720 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
16721 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
16722
16723 /* override-capability */
16724 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
16725 vty_out(vty, " neighbor %s override-capability\n", addr);
16726
16727 /* strict-capability-match */
16728 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
16729 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
16730
16731 /* Sender side AS path loop detection. */
16732 if (peer->as_path_loop_detection)
16733 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
16734 addr);
cfd47646 16735
16736 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 16737 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
cfd47646 16738
16739 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 16740 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
cfd47646 16741 vty_out(vty,
16742 " neighbor %s graceful-restart-helper\n", addr);
13909c4f
DS
16743 } else if (CHECK_FLAG(
16744 peer->peer_gr_new_status_flag,
16745 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
cfd47646 16746 vty_out(vty,
16747 " neighbor %s graceful-restart\n", addr);
13909c4f
DS
16748 } else if (
16749 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
16750 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
16751 && !(CHECK_FLAG(
16752 peer->peer_gr_new_status_flag,
16753 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
16754 vty_out(vty, " neighbor %s graceful-restart-disable\n",
16755 addr);
cfd47646 16756 }
16757 }
dd65f45e
DL
16758}
16759
16760/* BGP peer configuration display function. */
16761static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
16762 struct peer *peer, afi_t afi, safi_t safi)
16763{
16764 struct peer *g_peer = NULL;
16765 char *addr;
16766 bool flag_scomm, flag_secomm, flag_slcomm;
16767
16768 /* Skip dynamic neighbors. */
16769 if (peer_dynamic_neighbor(peer))
16770 return;
16771
16772 if (peer->conf_if)
16773 addr = peer->conf_if;
16774 else
16775 addr = peer->host;
16776
16777 /************************************
16778 ****** Per AF to the neighbor ******
16779 ************************************/
16780 if (peer_group_active(peer)) {
16781 g_peer = peer->group->conf;
16782
16783 /* If the peer-group is active but peer is not, print a 'no
16784 * activate' */
16785 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
16786 vty_out(vty, " no neighbor %s activate\n", addr);
16787 }
16788
16789 /* If the peer-group is not active but peer is, print an
16790 'activate' */
16791 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
16792 vty_out(vty, " neighbor %s activate\n", addr);
16793 }
16794 } else {
16795 if (peer->afc[afi][safi]) {
16796 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
892fedb6
DA
16797 if (CHECK_FLAG(bgp->flags,
16798 BGP_FLAG_NO_DEFAULT_IPV4)) {
dd65f45e
DL
16799 vty_out(vty, " neighbor %s activate\n",
16800 addr);
16801 }
16802 } else
16803 vty_out(vty, " neighbor %s activate\n", addr);
16804 } else {
16805 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
892fedb6
DA
16806 if (!CHECK_FLAG(bgp->flags,
16807 BGP_FLAG_NO_DEFAULT_IPV4)) {
dd65f45e
DL
16808 vty_out(vty,
16809 " no neighbor %s activate\n",
16810 addr);
16811 }
16812 }
16813 }
16814 }
16815
16816 /* addpath TX knobs */
16817 if (peergroup_af_addpath_check(peer, afi, safi)) {
16818 switch (peer->addpath_type[afi][safi]) {
16819 case BGP_ADDPATH_ALL:
16820 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
16821 addr);
16822 break;
16823 case BGP_ADDPATH_BEST_PER_AS:
16824 vty_out(vty,
16825 " neighbor %s addpath-tx-bestpath-per-AS\n",
16826 addr);
16827 break;
16828 case BGP_ADDPATH_MAX:
16829 case BGP_ADDPATH_NONE:
16830 break;
16831 }
16832 }
16833
16834 /* ORF capability. */
16835 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
16836 || peergroup_af_flag_check(peer, afi, safi,
16837 PEER_FLAG_ORF_PREFIX_RM)) {
16838 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
16839
16840 if (peergroup_af_flag_check(peer, afi, safi,
16841 PEER_FLAG_ORF_PREFIX_SM)
16842 && peergroup_af_flag_check(peer, afi, safi,
16843 PEER_FLAG_ORF_PREFIX_RM))
16844 vty_out(vty, " both");
16845 else if (peergroup_af_flag_check(peer, afi, safi,
16846 PEER_FLAG_ORF_PREFIX_SM))
16847 vty_out(vty, " send");
16848 else
16849 vty_out(vty, " receive");
16850 vty_out(vty, "\n");
16851 }
16852
dd65f45e
DL
16853 /* Route reflector client. */
16854 if (peergroup_af_flag_check(peer, afi, safi,
16855 PEER_FLAG_REFLECTOR_CLIENT)) {
16856 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
16857 }
16858
16859 /* next-hop-self force */
16860 if (peergroup_af_flag_check(peer, afi, safi,
16861 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
16862 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
16863 }
16864
16865 /* next-hop-self */
16866 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
16867 vty_out(vty, " neighbor %s next-hop-self\n", addr);
16868 }
16869
16870 /* remove-private-AS */
16871 if (peergroup_af_flag_check(peer, afi, safi,
16872 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
16873 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
16874 addr);
16875 }
16876
16877 else if (peergroup_af_flag_check(peer, afi, safi,
16878 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
16879 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
16880 addr);
16881 }
16882
16883 else if (peergroup_af_flag_check(peer, afi, safi,
16884 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
16885 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
16886 }
16887
16888 else if (peergroup_af_flag_check(peer, afi, safi,
16889 PEER_FLAG_REMOVE_PRIVATE_AS)) {
16890 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
16891 }
16892
16893 /* as-override */
16894 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
16895 vty_out(vty, " neighbor %s as-override\n", addr);
16896 }
16897
16898 /* send-community print. */
16899 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
16900 PEER_FLAG_SEND_COMMUNITY);
16901 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
16902 PEER_FLAG_SEND_EXT_COMMUNITY);
16903 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
16904 PEER_FLAG_SEND_LARGE_COMMUNITY);
16905
16906 if (flag_scomm && flag_secomm && flag_slcomm) {
16907 vty_out(vty, " no neighbor %s send-community all\n", addr);
16908 } else {
16909 if (flag_scomm)
16910 vty_out(vty, " no neighbor %s send-community\n", addr);
16911 if (flag_secomm)
16912 vty_out(vty,
16913 " no neighbor %s send-community extended\n",
16914 addr);
16915
16916 if (flag_slcomm)
16917 vty_out(vty, " no neighbor %s send-community large\n",
16918 addr);
16919 }
16920
16921 /* Default information */
16922 if (peergroup_af_flag_check(peer, afi, safi,
16923 PEER_FLAG_DEFAULT_ORIGINATE)) {
16924 vty_out(vty, " neighbor %s default-originate", addr);
16925
16926 if (peer->default_rmap[afi][safi].name)
16927 vty_out(vty, " route-map %s",
16928 peer->default_rmap[afi][safi].name);
16929
16930 vty_out(vty, "\n");
16931 }
16932
16933 /* Soft reconfiguration inbound. */
16934 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
16935 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
16936 addr);
16937 }
16938
16939 /* maximum-prefix. */
16940 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
6cde4b45 16941 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
dd65f45e
DL
16942 peer->pmax[afi][safi]);
16943
16944 if (peer->pmax_threshold[afi][safi]
16945 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
16946 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
16947 if (peer_af_flag_check(peer, afi, safi,
16948 PEER_FLAG_MAX_PREFIX_WARNING))
16949 vty_out(vty, " warning-only");
16950 if (peer->pmax_restart[afi][safi])
16951 vty_out(vty, " restart %u",
16952 peer->pmax_restart[afi][safi]);
9cbd06e0
DA
16953 if (peer_af_flag_check(peer, afi, safi,
16954 PEER_FLAG_MAX_PREFIX_FORCE))
16955 vty_out(vty, " force");
dd65f45e
DL
16956
16957 vty_out(vty, "\n");
16958 }
16959
fde246e8
DA
16960 /* maximum-prefix-out */
16961 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
6cde4b45 16962 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
fde246e8
DA
16963 addr, peer->pmax_out[afi][safi]);
16964
dd65f45e
DL
16965 /* Route server client. */
16966 if (peergroup_af_flag_check(peer, afi, safi,
16967 PEER_FLAG_RSERVER_CLIENT)) {
16968 vty_out(vty, " neighbor %s route-server-client\n", addr);
16969 }
16970
16971 /* Nexthop-local unchanged. */
16972 if (peergroup_af_flag_check(peer, afi, safi,
16973 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
16974 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
16975 }
16976
16977 /* allowas-in <1-10> */
16978 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
16979 if (peer_af_flag_check(peer, afi, safi,
16980 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
16981 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
16982 } else if (peer->allowas_in[afi][safi] == 3) {
16983 vty_out(vty, " neighbor %s allowas-in\n", addr);
16984 } else {
16985 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
16986 peer->allowas_in[afi][safi]);
16987 }
16988 }
16989
16990 /* weight */
16991 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
16992 vty_out(vty, " neighbor %s weight %lu\n", addr,
16993 peer->weight[afi][safi]);
16994
16995 /* Filter. */
16996 bgp_config_write_filter(vty, peer, afi, safi);
16997
16998 /* atribute-unchanged. */
16999 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
17000 || (safi != SAFI_EVPN
17001 && peer_af_flag_check(peer, afi, safi,
17002 PEER_FLAG_NEXTHOP_UNCHANGED))
17003 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
17004
17005 if (!peer_group_active(peer)
17006 || peergroup_af_flag_check(peer, afi, safi,
17007 PEER_FLAG_AS_PATH_UNCHANGED)
17008 || peergroup_af_flag_check(peer, afi, safi,
17009 PEER_FLAG_NEXTHOP_UNCHANGED)
17010 || peergroup_af_flag_check(peer, afi, safi,
17011 PEER_FLAG_MED_UNCHANGED)) {
17012
17013 vty_out(vty,
17014 " neighbor %s attribute-unchanged%s%s%s\n",
17015 addr,
17016 peer_af_flag_check(peer, afi, safi,
17017 PEER_FLAG_AS_PATH_UNCHANGED)
17018 ? " as-path"
17019 : "",
17020 peer_af_flag_check(peer, afi, safi,
17021 PEER_FLAG_NEXTHOP_UNCHANGED)
17022 ? " next-hop"
17023 : "",
17024 peer_af_flag_check(peer, afi, safi,
17025 PEER_FLAG_MED_UNCHANGED)
17026 ? " med"
17027 : "");
17028 }
17029 }
17030}
17031
17032/* Address family based peer configuration display. */
17033static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
17034 safi_t safi)
17035{
17036 struct peer *peer;
17037 struct peer_group *group;
17038 struct listnode *node, *nnode;
17039
17040
17041 vty_frame(vty, " !\n address-family ");
17042 if (afi == AFI_IP) {
17043 if (safi == SAFI_UNICAST)
17044 vty_frame(vty, "ipv4 unicast");
17045 else if (safi == SAFI_LABELED_UNICAST)
17046 vty_frame(vty, "ipv4 labeled-unicast");
17047 else if (safi == SAFI_MULTICAST)
17048 vty_frame(vty, "ipv4 multicast");
17049 else if (safi == SAFI_MPLS_VPN)
17050 vty_frame(vty, "ipv4 vpn");
17051 else if (safi == SAFI_ENCAP)
17052 vty_frame(vty, "ipv4 encap");
17053 else if (safi == SAFI_FLOWSPEC)
17054 vty_frame(vty, "ipv4 flowspec");
17055 } else if (afi == AFI_IP6) {
17056 if (safi == SAFI_UNICAST)
17057 vty_frame(vty, "ipv6 unicast");
17058 else if (safi == SAFI_LABELED_UNICAST)
17059 vty_frame(vty, "ipv6 labeled-unicast");
17060 else if (safi == SAFI_MULTICAST)
17061 vty_frame(vty, "ipv6 multicast");
17062 else if (safi == SAFI_MPLS_VPN)
17063 vty_frame(vty, "ipv6 vpn");
17064 else if (safi == SAFI_ENCAP)
17065 vty_frame(vty, "ipv6 encap");
17066 else if (safi == SAFI_FLOWSPEC)
17067 vty_frame(vty, "ipv6 flowspec");
17068 } else if (afi == AFI_L2VPN) {
17069 if (safi == SAFI_EVPN)
17070 vty_frame(vty, "l2vpn evpn");
17071 }
17072 vty_frame(vty, "\n");
17073
17074 bgp_config_write_distance(vty, bgp, afi, safi);
17075
17076 bgp_config_write_network(vty, bgp, afi, safi);
17077
17078 bgp_config_write_redistribute(vty, bgp, afi, safi);
17079
8a4e7fe6
DA
17080 /* BGP flag dampening. */
17081 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
0221327c
DS
17082 bgp_config_write_damp(vty, bgp, afi, safi);
17083 for (ALL_LIST_ELEMENTS_RO(bgp->group, node, group))
17084 if (peer_af_flag_check(group->conf, afi, safi,
17085 PEER_FLAG_CONFIG_DAMPENING))
17086 bgp_config_write_peer_damp(vty, group->conf, afi, safi);
17087 for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer))
17088 if (peer_af_flag_check(peer, afi, safi,
17089 PEER_FLAG_CONFIG_DAMPENING))
17090 bgp_config_write_peer_damp(vty, peer, afi, safi);
8a4e7fe6 17091
dd65f45e
DL
17092 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
17093 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
17094
17095 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17096 /* Skip dynamic neighbors. */
17097 if (peer_dynamic_neighbor(peer))
17098 continue;
17099
17100 /* Do not display doppelganger peers */
17101 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17102 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
17103 }
17104
17105 bgp_config_write_maxpaths(vty, bgp, afi, safi);
17106 bgp_config_write_table_map(vty, bgp, afi, safi);
17107
17108 if (safi == SAFI_EVPN)
17109 bgp_config_write_evpn_info(vty, bgp, afi, safi);
17110
17111 if (safi == SAFI_FLOWSPEC)
17112 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
17113
17114 if (safi == SAFI_UNICAST) {
17115 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
17116 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17117 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
17118
17119 vty_out(vty, " export vpn\n");
17120 }
17121 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17122 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
17123
17124 vty_out(vty, " import vpn\n");
17125 }
17126 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17127 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
17128 char *name;
17129
17130 for (ALL_LIST_ELEMENTS_RO(
17131 bgp->vpn_policy[afi].import_vrf, node,
17132 name))
17133 vty_out(vty, " import vrf %s\n", name);
17134 }
17135 }
17136
17137 vty_endframe(vty, " exit-address-family\n");
17138}
17139
17140int bgp_config_write(struct vty *vty)
17141{
17142 struct bgp *bgp;
17143 struct peer_group *group;
17144 struct peer *peer;
17145 struct listnode *node, *nnode;
17146 struct listnode *mnode, *mnnode;
17147
17148 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
17149 vty_out(vty, "bgp route-map delay-timer %u\n",
17150 bm->rmap_update_timer);
17151
d70583f7
D
17152 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
17153 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17154 if (bm->v_update_delay != bm->v_establish_wait)
17155 vty_out(vty, " %d", bm->v_establish_wait);
17156 vty_out(vty, "\n");
17157 }
17158
9acb67cb
DS
17159 if (bm->wait_for_fib)
17160 vty_out(vty, "bgp suppress-fib-pending\n");
17161
05bd726c 17162 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17163 vty_out(vty, "bgp graceful-shutdown\n");
17164
c163f297
DS
17165 /* No-RIB (Zebra) option flag configuration */
17166 if (bgp_option_check(BGP_OPT_NO_FIB))
17167 vty_out(vty, "bgp no-rib\n");
17168
ec0acb80 17169 if (!CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
e46723a5
DS
17170 vty_out(vty, "no bgp send-extra-data zebra\n");
17171
dd65f45e
DL
17172 /* BGP configuration. */
17173 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17174
17175 /* skip all auto created vrf as they dont have user config */
17176 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17177 continue;
17178
17179 /* Router bgp ASN */
17180 vty_out(vty, "router bgp %u", bgp->as);
17181
17182 if (bgp->name)
17183 vty_out(vty, " %s %s",
17184 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17185 ? "view" : "vrf", bgp->name);
17186 vty_out(vty, "\n");
17187
17188 /* BGP fast-external-failover. */
17189 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17190 vty_out(vty, " no bgp fast-external-failover\n");
17191
17192 /* BGP router ID. */
3a6290bd 17193 if (bgp->router_id_static.s_addr != INADDR_ANY)
23d0a753
DA
17194 vty_out(vty, " bgp router-id %pI4\n",
17195 &bgp->router_id_static);
dd65f45e 17196
c208c586
S
17197 /* Suppress fib pending */
17198 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17199 vty_out(vty, " bgp suppress-fib-pending\n");
17200
dd65f45e 17201 /* BGP log-neighbor-changes. */
892fedb6 17202 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
5d5393b9 17203 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
dd65f45e 17204 vty_out(vty, " %sbgp log-neighbor-changes\n",
892fedb6
DA
17205 CHECK_FLAG(bgp->flags,
17206 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
dd65f45e
DL
17207 ? ""
17208 : "no ");
17209
17210 /* BGP configuration. */
892fedb6 17211 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
dd65f45e
DL
17212 vty_out(vty, " bgp always-compare-med\n");
17213
17214 /* RFC8212 default eBGP policy. */
1d3fdccf
DA
17215 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17216 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17217 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17218 CHECK_FLAG(bgp->flags,
17219 BGP_FLAG_EBGP_REQUIRES_POLICY)
17220 ? ""
17221 : "no ");
dd65f45e
DL
17222
17223 /* draft-ietf-idr-deprecate-as-set-confed-set */
7f972cd8 17224 if (bgp->reject_as_sets)
dd65f45e
DL
17225 vty_out(vty, " bgp reject-as-sets\n");
17226
2adac256
DA
17227 /* Suppress duplicate updates if the route actually not changed
17228 */
17229 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17230 != SAVE_BGP_SUPPRESS_DUPLICATES)
17231 vty_out(vty, " %sbgp suppress-duplicates\n",
17232 CHECK_FLAG(bgp->flags,
17233 BGP_FLAG_SUPPRESS_DUPLICATES)
17234 ? ""
17235 : "no ");
17236
dd65f45e 17237 /* BGP default ipv4-unicast. */
892fedb6 17238 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4))
dd65f45e
DL
17239 vty_out(vty, " no bgp default ipv4-unicast\n");
17240
17241 /* BGP default local-preference. */
17242 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17243 vty_out(vty, " bgp default local-preference %u\n",
17244 bgp->default_local_pref);
17245
17246 /* BGP default show-hostname */
892fedb6 17247 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
5d5393b9 17248 != SAVE_BGP_SHOW_HOSTNAME)
dd65f45e 17249 vty_out(vty, " %sbgp default show-hostname\n",
892fedb6 17250 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
dd65f45e
DL
17251 ? ""
17252 : "no ");
17253
aef999a2
DA
17254 /* BGP default show-nexthop-hostname */
17255 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17256 != SAVE_BGP_SHOW_HOSTNAME)
17257 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17258 CHECK_FLAG(bgp->flags,
17259 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17260 ? ""
17261 : "no ");
17262
dd65f45e
DL
17263 /* BGP default subgroup-pkt-queue-max. */
17264 if (bgp->default_subgroup_pkt_queue_max
17265 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
17266 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
17267 bgp->default_subgroup_pkt_queue_max);
17268
17269 /* BGP client-to-client reflection. */
892fedb6 17270 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
dd65f45e
DL
17271 vty_out(vty, " no bgp client-to-client reflection\n");
17272
17273 /* BGP cluster ID. */
17274 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
23d0a753
DA
17275 vty_out(vty, " bgp cluster-id %pI4\n",
17276 &bgp->cluster_id);
dd65f45e
DL
17277
17278 /* Disable ebgp connected nexthop check */
892fedb6 17279 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
dd65f45e
DL
17280 vty_out(vty,
17281 " bgp disable-ebgp-connected-route-check\n");
17282
17283 /* Confederation identifier*/
17284 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
17285 vty_out(vty, " bgp confederation identifier %u\n",
17286 bgp->confed_id);
17287
17288 /* Confederation peer */
17289 if (bgp->confed_peers_cnt > 0) {
17290 int i;
17291
17292 vty_out(vty, " bgp confederation peers");
17293
17294 for (i = 0; i < bgp->confed_peers_cnt; i++)
17295 vty_out(vty, " %u", bgp->confed_peers[i]);
17296
17297 vty_out(vty, "\n");
17298 }
17299
17300 /* BGP deterministic-med. */
892fedb6 17301 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
5d5393b9 17302 != SAVE_BGP_DETERMINISTIC_MED)
dd65f45e 17303 vty_out(vty, " %sbgp deterministic-med\n",
892fedb6
DA
17304 CHECK_FLAG(bgp->flags,
17305 BGP_FLAG_DETERMINISTIC_MED)
dd65f45e
DL
17306 ? ""
17307 : "no ");
17308
17309 /* BGP update-delay. */
17310 bgp_config_write_update_delay(vty, bgp);
17311
17312 if (bgp->v_maxmed_onstartup
17313 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
17314 vty_out(vty, " bgp max-med on-startup %u",
17315 bgp->v_maxmed_onstartup);
17316 if (bgp->maxmed_onstartup_value
17317 != BGP_MAXMED_VALUE_DEFAULT)
17318 vty_out(vty, " %u",
17319 bgp->maxmed_onstartup_value);
17320 vty_out(vty, "\n");
17321 }
17322 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
17323 vty_out(vty, " bgp max-med administrative");
17324 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
17325 vty_out(vty, " %u", bgp->maxmed_admin_value);
17326 vty_out(vty, "\n");
17327 }
17328
17329 /* write quanta */
17330 bgp_config_write_wpkt_quanta(vty, bgp);
17331 /* read quanta */
17332 bgp_config_write_rpkt_quanta(vty, bgp);
17333
17334 /* coalesce time */
17335 bgp_config_write_coalesce_time(vty, bgp);
17336
05bd726c 17337 /* BGP per-instance graceful-shutdown */
17338 /* BGP-wide settings and per-instance settings are mutually
17339 * exclusive.
17340 */
17341 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17342 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
17343 vty_out(vty, " bgp graceful-shutdown\n");
17344
dd65f45e
DL
17345 /* BGP graceful-restart. */
17346 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
17347 vty_out(vty,
17348 " bgp graceful-restart stalepath-time %u\n",
17349 bgp->stalepath_time);
cfd47646 17350
dd65f45e
DL
17351 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
17352 vty_out(vty, " bgp graceful-restart restart-time %u\n",
17353 bgp->restart_time);
cfd47646 17354
17355 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
17356 vty_out(vty,
17357 " bgp graceful-restart select-defer-time %u\n",
17358 bgp->select_defer_time);
17359
17360 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
dd65f45e
DL
17361 vty_out(vty, " bgp graceful-restart\n");
17362
cfd47646 17363 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
17364 vty_out(vty, " bgp graceful-restart-disable\n");
17365
dd65f45e 17366 /* BGP graceful-restart Preserve State F bit. */
892fedb6 17367 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
dd65f45e
DL
17368 vty_out(vty,
17369 " bgp graceful-restart preserve-fw-state\n");
17370
dc95985f 17371 /* Stale timer for RIB */
17372 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
17373 vty_out(vty,
17374 " bgp graceful-restart rib-stale-time %u\n",
17375 bgp->rib_stale_time);
17376
dd65f45e 17377 /* BGP bestpath method. */
892fedb6 17378 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
dd65f45e 17379 vty_out(vty, " bgp bestpath as-path ignore\n");
892fedb6 17380 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
dd65f45e
DL
17381 vty_out(vty, " bgp bestpath as-path confed\n");
17382
892fedb6
DA
17383 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
17384 if (CHECK_FLAG(bgp->flags,
17385 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
dd65f45e
DL
17386 vty_out(vty,
17387 " bgp bestpath as-path multipath-relax as-set\n");
17388 } else {
17389 vty_out(vty,
17390 " bgp bestpath as-path multipath-relax\n");
17391 }
17392 }
17393
892fedb6 17394 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
dd65f45e
DL
17395 vty_out(vty,
17396 " bgp route-reflector allow-outbound-policy\n");
17397 }
892fedb6 17398 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
dd65f45e 17399 vty_out(vty, " bgp bestpath compare-routerid\n");
892fedb6
DA
17400 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
17401 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
dd65f45e 17402 vty_out(vty, " bgp bestpath med");
892fedb6 17403 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
dd65f45e 17404 vty_out(vty, " confed");
892fedb6
DA
17405 if (CHECK_FLAG(bgp->flags,
17406 BGP_FLAG_MED_MISSING_AS_WORST))
dd65f45e
DL
17407 vty_out(vty, " missing-as-worst");
17408 vty_out(vty, "\n");
17409 }
17410
f7e1c681 17411 /* Link bandwidth handling. */
17412 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
17413 vty_out(vty, " bgp bestpath bandwidth ignore\n");
17414 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
17415 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
17416 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
17417 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
17418
dd65f45e 17419 /* BGP network import check. */
892fedb6 17420 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
5d5393b9 17421 != SAVE_BGP_IMPORT_CHECK)
dd65f45e 17422 vty_out(vty, " %sbgp network import-check\n",
892fedb6 17423 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
dd65f45e
DL
17424 ? ""
17425 : "no ");
17426
17427 /* BGP timers configuration. */
5d5393b9
DL
17428 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
17429 && bgp->default_holdtime != SAVE_BGP_HOLDTIME)
dd65f45e
DL
17430 vty_out(vty, " timers bgp %u %u\n",
17431 bgp->default_keepalive, bgp->default_holdtime);
17432
17433 /* peer-group */
17434 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
17435 bgp_config_write_peer_global(vty, bgp, group->conf);
17436 }
17437
17438 /* Normal neighbor configuration. */
17439 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17440 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17441 bgp_config_write_peer_global(vty, bgp, peer);
17442 }
17443
17444 /* listen range and limit for dynamic BGP neighbors */
17445 bgp_config_write_listen(vty, bgp);
17446
17447 /*
17448 * BGP default autoshutdown neighbors
17449 *
17450 * This must be placed after any peer and peer-group
17451 * configuration, to avoid setting all peers to shutdown after
17452 * a daemon restart, which is undesired behavior. (see #2286)
17453 */
17454 if (bgp->autoshutdown)
17455 vty_out(vty, " bgp default shutdown\n");
17456
9cf59432
DS
17457 /* BGP instance administrative shutdown */
17458 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
17459 vty_out(vty, " bgp shutdown\n");
17460
dd65f45e
DL
17461 /* IPv4 unicast configuration. */
17462 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
17463
17464 /* IPv4 multicast configuration. */
17465 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
17466
17467 /* IPv4 labeled-unicast configuration. */
17468 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
17469
17470 /* IPv4 VPN configuration. */
17471 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
17472
17473 /* ENCAPv4 configuration. */
17474 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
17475
17476 /* FLOWSPEC v4 configuration. */
17477 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
17478
17479 /* IPv6 unicast configuration. */
17480 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
17481
17482 /* IPv6 multicast configuration. */
17483 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
17484
17485 /* IPv6 labeled-unicast configuration. */
17486 bgp_config_write_family(vty, bgp, AFI_IP6,
17487 SAFI_LABELED_UNICAST);
17488
17489 /* IPv6 VPN configuration. */
17490 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
17491
17492 /* ENCAPv6 configuration. */
17493 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
17494
17495 /* FLOWSPEC v6 configuration. */
17496 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
17497
17498 /* EVPN configuration. */
17499 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
17500
17501 hook_call(bgp_inst_config_write, bgp, vty);
17502
49e5a4a0 17503#ifdef ENABLE_BGP_VNC
dd65f45e
DL
17504 bgp_rfapi_cfg_write(vty, bgp);
17505#endif
17506
17507 vty_out(vty, "!\n");
17508 }
17509 return 0;
17510}
17511
ddb5b488 17512
718e3744 17513/* BGP node structure. */
d62a17ae 17514static struct cmd_node bgp_node = {
f4b8291f 17515 .name = "bgp",
62b346ee 17516 .node = BGP_NODE,
24389580 17517 .parent_node = CONFIG_NODE,
62b346ee 17518 .prompt = "%s(config-router)# ",
612c2c15 17519 .config_write = bgp_config_write,
718e3744 17520};
17521
d62a17ae 17522static struct cmd_node bgp_ipv4_unicast_node = {
f4b8291f 17523 .name = "bgp ipv4 unicast",
62b346ee 17524 .node = BGP_IPV4_NODE,
24389580 17525 .parent_node = BGP_NODE,
62b346ee 17526 .prompt = "%s(config-router-af)# ",
718e3744 17527};
17528
d62a17ae 17529static struct cmd_node bgp_ipv4_multicast_node = {
f4b8291f 17530 .name = "bgp ipv4 multicast",
62b346ee 17531 .node = BGP_IPV4M_NODE,
24389580 17532 .parent_node = BGP_NODE,
62b346ee 17533 .prompt = "%s(config-router-af)# ",
718e3744 17534};
17535
d62a17ae 17536static struct cmd_node bgp_ipv4_labeled_unicast_node = {
f4b8291f 17537 .name = "bgp ipv4 labeled unicast",
62b346ee 17538 .node = BGP_IPV4L_NODE,
24389580 17539 .parent_node = BGP_NODE,
62b346ee 17540 .prompt = "%s(config-router-af)# ",
f51bae9c
DS
17541};
17542
d62a17ae 17543static struct cmd_node bgp_ipv6_unicast_node = {
f4b8291f 17544 .name = "bgp ipv6",
62b346ee 17545 .node = BGP_IPV6_NODE,
24389580 17546 .parent_node = BGP_NODE,
62b346ee 17547 .prompt = "%s(config-router-af)# ",
718e3744 17548};
17549
d62a17ae 17550static struct cmd_node bgp_ipv6_multicast_node = {
f4b8291f 17551 .name = "bgp ipv6 multicast",
62b346ee 17552 .node = BGP_IPV6M_NODE,
24389580 17553 .parent_node = BGP_NODE,
62b346ee 17554 .prompt = "%s(config-router-af)# ",
25ffbdc1 17555};
17556
d62a17ae 17557static struct cmd_node bgp_ipv6_labeled_unicast_node = {
f4b8291f 17558 .name = "bgp ipv6 labeled unicast",
62b346ee 17559 .node = BGP_IPV6L_NODE,
24389580 17560 .parent_node = BGP_NODE,
62b346ee 17561 .prompt = "%s(config-router-af)# ",
f51bae9c
DS
17562};
17563
62b346ee 17564static struct cmd_node bgp_vpnv4_node = {
f4b8291f 17565 .name = "bgp vpnv4",
62b346ee 17566 .node = BGP_VPNV4_NODE,
24389580 17567 .parent_node = BGP_NODE,
62b346ee 17568 .prompt = "%s(config-router-af)# ",
62b346ee 17569};
6b0655a2 17570
62b346ee 17571static struct cmd_node bgp_vpnv6_node = {
f4b8291f 17572 .name = "bgp vpnv6",
62b346ee 17573 .node = BGP_VPNV6_NODE,
24389580 17574 .parent_node = BGP_NODE,
62b346ee 17575 .prompt = "%s(config-router-af-vpnv6)# ",
62b346ee 17576};
8ecd3266 17577
62b346ee 17578static struct cmd_node bgp_evpn_node = {
f4b8291f 17579 .name = "bgp evpn",
62b346ee 17580 .node = BGP_EVPN_NODE,
24389580 17581 .parent_node = BGP_NODE,
62b346ee 17582 .prompt = "%s(config-router-evpn)# ",
62b346ee 17583};
4e0b7b6d 17584
62b346ee 17585static struct cmd_node bgp_evpn_vni_node = {
f4b8291f 17586 .name = "bgp evpn vni",
62b346ee 17587 .node = BGP_EVPN_VNI_NODE,
24389580 17588 .parent_node = BGP_EVPN_NODE,
62b346ee 17589 .prompt = "%s(config-router-af-vni)# ",
62b346ee 17590};
90e60aa7 17591
62b346ee 17592static struct cmd_node bgp_flowspecv4_node = {
f4b8291f 17593 .name = "bgp ipv4 flowspec",
62b346ee 17594 .node = BGP_FLOWSPECV4_NODE,
24389580 17595 .parent_node = BGP_NODE,
62b346ee 17596 .prompt = "%s(config-router-af)# ",
62b346ee 17597};
7c40bf39 17598
62b346ee 17599static struct cmd_node bgp_flowspecv6_node = {
f4b8291f 17600 .name = "bgp ipv6 flowspec",
62b346ee 17601 .node = BGP_FLOWSPECV6_NODE,
24389580 17602 .parent_node = BGP_NODE,
62b346ee 17603 .prompt = "%s(config-router-af-vpnv6)# ",
62b346ee 17604};
7c40bf39 17605
d62a17ae 17606static void community_list_vty(void);
1f8ae70b 17607
d62a17ae 17608static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 17609{
d62a17ae 17610 struct bgp *bgp;
17611 struct peer *peer;
d62a17ae 17612 struct listnode *lnbgp, *lnpeer;
b8a815e5 17613
d62a17ae 17614 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17615 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
17616 /* only provide suggestions on the appropriate input
17617 * token type,
17618 * they'll otherwise show up multiple times */
17619 enum cmd_token_type match_type;
17620 char *name = peer->host;
d48ed3e0 17621
d62a17ae 17622 if (peer->conf_if) {
17623 match_type = VARIABLE_TKN;
17624 name = peer->conf_if;
17625 } else if (strchr(peer->host, ':'))
17626 match_type = IPV6_TKN;
17627 else
17628 match_type = IPV4_TKN;
d48ed3e0 17629
d62a17ae 17630 if (token->type != match_type)
17631 continue;
d48ed3e0 17632
d62a17ae 17633 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
17634 }
d62a17ae 17635 }
b8a815e5
DL
17636}
17637
17638static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 17639 {.varname = "neighbor", .completions = bgp_ac_neighbor},
17640 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 17641 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 17642 {.completions = NULL}};
17643
47a306a0
DS
17644static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
17645{
17646 struct bgp *bgp;
17647 struct peer_group *group;
17648 struct listnode *lnbgp, *lnpeer;
17649
17650 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17651 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
17652 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
17653 group->name));
17654 }
17655}
17656
17657static const struct cmd_variable_handler bgp_var_peergroup[] = {
17658 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
17659 {.completions = NULL} };
17660
d62a17ae 17661void bgp_vty_init(void)
17662{
17663 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 17664 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 17665
17666 /* Install bgp top node. */
612c2c15
DL
17667 install_node(&bgp_node);
17668 install_node(&bgp_ipv4_unicast_node);
17669 install_node(&bgp_ipv4_multicast_node);
17670 install_node(&bgp_ipv4_labeled_unicast_node);
17671 install_node(&bgp_ipv6_unicast_node);
17672 install_node(&bgp_ipv6_multicast_node);
17673 install_node(&bgp_ipv6_labeled_unicast_node);
17674 install_node(&bgp_vpnv4_node);
17675 install_node(&bgp_vpnv6_node);
17676 install_node(&bgp_evpn_node);
17677 install_node(&bgp_evpn_vni_node);
17678 install_node(&bgp_flowspecv4_node);
17679 install_node(&bgp_flowspecv6_node);
d62a17ae 17680
17681 /* Install default VTY commands to new nodes. */
17682 install_default(BGP_NODE);
17683 install_default(BGP_IPV4_NODE);
17684 install_default(BGP_IPV4M_NODE);
17685 install_default(BGP_IPV4L_NODE);
17686 install_default(BGP_IPV6_NODE);
17687 install_default(BGP_IPV6M_NODE);
17688 install_default(BGP_IPV6L_NODE);
17689 install_default(BGP_VPNV4_NODE);
17690 install_default(BGP_VPNV6_NODE);
7c40bf39 17691 install_default(BGP_FLOWSPECV4_NODE);
17692 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 17693 install_default(BGP_EVPN_NODE);
17694 install_default(BGP_EVPN_VNI_NODE);
17695
8029b216
AK
17696 /* "bgp local-mac" hidden commands. */
17697 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
17698 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
17699
9acb67cb
DS
17700 /* "bgp suppress-fib-pending" global */
17701 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
17702
d62a17ae 17703 /* bgp route-map delay-timer commands. */
17704 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
17705 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17706
d70583f7
D
17707 /* global bgp update-delay command */
17708 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
17709 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
17710
05bd726c 17711 /* global bgp graceful-shutdown command */
17712 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
17713 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
17714
d62a17ae 17715 /* Dummy commands (Currently not supported) */
17716 install_element(BGP_NODE, &no_synchronization_cmd);
17717 install_element(BGP_NODE, &no_auto_summary_cmd);
17718
17719 /* "router bgp" commands. */
17720 install_element(CONFIG_NODE, &router_bgp_cmd);
17721
17722 /* "no router bgp" commands. */
17723 install_element(CONFIG_NODE, &no_router_bgp_cmd);
17724
17725 /* "bgp router-id" commands. */
17726 install_element(BGP_NODE, &bgp_router_id_cmd);
17727 install_element(BGP_NODE, &no_bgp_router_id_cmd);
17728
c208c586
S
17729 /* "bgp suppress-fib-pending" command */
17730 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
17731
d62a17ae 17732 /* "bgp cluster-id" commands. */
17733 install_element(BGP_NODE, &bgp_cluster_id_cmd);
17734 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
17735
c163f297
DS
17736 /* "bgp no-rib" commands. */
17737 install_element(CONFIG_NODE, &bgp_norib_cmd);
17738 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
17739
e46723a5
DS
17740 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
17741
d62a17ae 17742 /* "bgp confederation" commands. */
17743 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
17744 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
17745
17746 /* "bgp confederation peers" commands. */
17747 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
17748 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
17749
17750 /* bgp max-med command */
17751 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
17752 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
17753 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
17754 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
17755 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
17756
17757 /* bgp disable-ebgp-connected-nh-check */
17758 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
17759 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
17760
17761 /* bgp update-delay command */
17762 install_element(BGP_NODE, &bgp_update_delay_cmd);
17763 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
d62a17ae 17764
17765 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
555e09d4 17766 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
d62a17ae 17767
17768 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
17769 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
17770
17771 /* "maximum-paths" commands. */
17772 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
17773 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
17774 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
17775 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
17776 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
17777 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
17778 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
17779 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
17780 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
17781 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
17782 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17783 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
17784 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
17785 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17786 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
17787
39edabac
PG
17788 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
17789 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
17790 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
17791 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17792 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
d62a17ae 17793 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
17794 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
17795 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
17796 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17797 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
17798
17799 /* "timers bgp" commands. */
17800 install_element(BGP_NODE, &bgp_timers_cmd);
17801 install_element(BGP_NODE, &no_bgp_timers_cmd);
17802
17803 /* route-map delay-timer commands - per instance for backwards compat.
17804 */
17805 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
17806 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17807
17808 /* "bgp client-to-client reflection" commands */
17809 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
17810 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
17811
17812 /* "bgp always-compare-med" commands */
17813 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
17814 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
17815
9dac9fc8
DA
17816 /* bgp ebgp-requires-policy */
17817 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
17818 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
17819
2adac256
DA
17820 /* bgp suppress-duplicates */
17821 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
17822 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
17823
fb29348a
DA
17824 /* bgp reject-as-sets */
17825 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
17826 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
17827
d62a17ae 17828 /* "bgp deterministic-med" commands */
17829 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
17830 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
17831
055679e9 17832 /* "bgp graceful-restart" command */
36235319
QY
17833 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
17834 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
055679e9 17835
17836 /* "bgp graceful-restart-disable" command */
36235319
QY
17837 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
17838 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
055679e9 17839
17840 /* "neighbor a:b:c:d graceful-restart" command */
36235319
QY
17841 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
17842 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
055679e9 17843
17844 /* "neighbor a:b:c:d graceful-restart-disable" command */
17845 install_element(BGP_NODE,
17846 &bgp_neighbor_graceful_restart_disable_set_cmd);
17847 install_element(BGP_NODE,
17848 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
17849
17850 /* "neighbor a:b:c:d graceful-restart-helper" command */
17851 install_element(BGP_NODE,
17852 &bgp_neighbor_graceful_restart_helper_set_cmd);
17853 install_element(BGP_NODE,
17854 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
17855
d62a17ae 17856 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
17857 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
17858 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
17859 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
cfd47646 17860 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
f009ff26 17861 install_element(BGP_NODE,
17862 &no_bgp_graceful_restart_select_defer_time_cmd);
d62a17ae 17863 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
17864 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
17865
d6e3c15b 17866 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
17867 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
dc95985f 17868 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
17869 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
d6e3c15b 17870
7f323236
DW
17871 /* "bgp graceful-shutdown" commands */
17872 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
17873 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
17874
d62a17ae 17875 /* "bgp fast-external-failover" commands */
17876 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
17877 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
17878
d62a17ae 17879 /* "bgp bestpath compare-routerid" commands */
17880 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
17881 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
17882
17883 /* "bgp bestpath as-path ignore" commands */
17884 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
17885 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
17886
17887 /* "bgp bestpath as-path confed" commands */
17888 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
17889 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
17890
17891 /* "bgp bestpath as-path multipath-relax" commands */
17892 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
17893 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
17894
17895 /* "bgp log-neighbor-changes" commands */
17896 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
17897 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
17898
17899 /* "bgp bestpath med" commands */
17900 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
17901 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
17902
f7e1c681 17903 /* "bgp bestpath bandwidth" commands */
17904 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
ad36d216 17905 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
f7e1c681 17906
d62a17ae 17907 /* "no bgp default ipv4-unicast" commands. */
17908 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
17909 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
17910
17911 /* "bgp network import-check" commands. */
17912 install_element(BGP_NODE, &bgp_network_import_check_cmd);
17913 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
17914 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
17915
17916 /* "bgp default local-preference" commands. */
17917 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
17918 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
17919
17920 /* bgp default show-hostname */
17921 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
17922 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
17923
aef999a2
DA
17924 /* bgp default show-nexthop-hostname */
17925 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
17926 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
17927
d62a17ae 17928 /* "bgp default subgroup-pkt-queue-max" commands. */
17929 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
17930 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
17931
17932 /* bgp ibgp-allow-policy-mods command */
17933 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
17934 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
17935
17936 /* "bgp listen limit" commands. */
17937 install_element(BGP_NODE, &bgp_listen_limit_cmd);
17938 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
17939
17940 /* "bgp listen range" commands. */
17941 install_element(BGP_NODE, &bgp_listen_range_cmd);
17942 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
17943
8175f54a 17944 /* "bgp default shutdown" command */
f26845f9 17945 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
9cf59432
DS
17946
17947 /* "bgp shutdown" commands */
17948 install_element(BGP_NODE, &bgp_shutdown_cmd);
8389c83a 17949 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
9cf59432 17950 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
1b6e7a88 17951 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
f26845f9 17952
d62a17ae 17953 /* "neighbor remote-as" commands. */
17954 install_element(BGP_NODE, &neighbor_remote_as_cmd);
17955 install_element(BGP_NODE, &neighbor_interface_config_cmd);
17956 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
17957 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
17958 install_element(BGP_NODE,
17959 &neighbor_interface_v6only_config_remote_as_cmd);
17960 install_element(BGP_NODE, &no_neighbor_cmd);
17961 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
17962
17963 /* "neighbor peer-group" commands. */
17964 install_element(BGP_NODE, &neighbor_peer_group_cmd);
17965 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
17966 install_element(BGP_NODE,
17967 &no_neighbor_interface_peer_group_remote_as_cmd);
17968
17969 /* "neighbor local-as" commands. */
17970 install_element(BGP_NODE, &neighbor_local_as_cmd);
17971 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
17972 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
17973 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
17974
17975 /* "neighbor solo" commands. */
17976 install_element(BGP_NODE, &neighbor_solo_cmd);
17977 install_element(BGP_NODE, &no_neighbor_solo_cmd);
17978
17979 /* "neighbor password" commands. */
17980 install_element(BGP_NODE, &neighbor_password_cmd);
17981 install_element(BGP_NODE, &no_neighbor_password_cmd);
17982
17983 /* "neighbor activate" commands. */
17984 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
17985 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
17986 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
17987 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
17988 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
17989 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
17990 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
17991 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
17992 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 17993 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
17994 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 17995 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
17996
17997 /* "no neighbor activate" commands. */
17998 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
17999 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
18000 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
18001 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
18002 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
18003 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
18004 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
18005 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
18006 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 18007 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
18008 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 18009 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
18010
18011 /* "neighbor peer-group" set commands. */
18012 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
18013 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18014 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
18015 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18016 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
18017 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
18018 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18019 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 18020 install_element(BGP_FLOWSPECV4_NODE,
18021 &neighbor_set_peer_group_hidden_cmd);
18022 install_element(BGP_FLOWSPECV6_NODE,
18023 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 18024
18025 /* "no neighbor peer-group unset" commands. */
18026 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
18027 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18028 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18029 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18030 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18031 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18032 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18033 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 18034 install_element(BGP_FLOWSPECV4_NODE,
18035 &no_neighbor_set_peer_group_hidden_cmd);
18036 install_element(BGP_FLOWSPECV6_NODE,
18037 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 18038
18039 /* "neighbor softreconfiguration inbound" commands.*/
18040 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
18041 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
18042 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
18043 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18044 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
18045 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18046 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
18047 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18048 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
18049 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18050 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
18051 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18052 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
18053 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18054 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
18055 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18056 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
18057 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 18058 install_element(BGP_FLOWSPECV4_NODE,
18059 &neighbor_soft_reconfiguration_cmd);
18060 install_element(BGP_FLOWSPECV4_NODE,
18061 &no_neighbor_soft_reconfiguration_cmd);
18062 install_element(BGP_FLOWSPECV6_NODE,
18063 &neighbor_soft_reconfiguration_cmd);
18064 install_element(BGP_FLOWSPECV6_NODE,
18065 &no_neighbor_soft_reconfiguration_cmd);
616c6ee8
PG
18066 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
18067 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 18068
18069 /* "neighbor attribute-unchanged" commands. */
18070 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
18071 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
18072 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
18073 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
18074 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
18075 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
18076 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
18077 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
18078 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
18079 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
18080 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
18081 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
18082 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
18083 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
18084 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
18085 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
18086 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
18087 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
18088
18089 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
18090 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
18091
18092 /* "nexthop-local unchanged" commands */
18093 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
18094 install_element(BGP_IPV6_NODE,
18095 &no_neighbor_nexthop_local_unchanged_cmd);
18096
18097 /* "neighbor next-hop-self" commands. */
18098 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
18099 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
18100 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
18101 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
18102 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
18103 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
18104 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
18105 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
18106 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
18107 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
18108 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
18109 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
18110 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
18111 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
18112 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
18113 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
18114 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
18115 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
18116 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
18117 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 18118
18119 /* "neighbor next-hop-self force" commands. */
18120 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
18121 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
1bc4e531
DA
18122 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18123 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18124 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
18125 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18126 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18127 install_element(BGP_IPV4_NODE,
18128 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18129 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
18130 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18131 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18132 install_element(BGP_IPV4M_NODE,
18133 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18134 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
18135 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18136 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18137 install_element(BGP_IPV4L_NODE,
18138 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18139 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
18140 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18141 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18142 install_element(BGP_IPV6_NODE,
18143 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18144 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
18145 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18146 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18147 install_element(BGP_IPV6M_NODE,
18148 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18149 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
18150 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18151 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18152 install_element(BGP_IPV6L_NODE,
18153 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18154 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
18155 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18156 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18157 install_element(BGP_VPNV4_NODE,
18158 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18159 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
18160 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18161 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18162 install_element(BGP_VPNV6_NODE,
18163 &no_neighbor_nexthop_self_all_hidden_cmd);
be7e1fa3
MS
18164 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
18165 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
d62a17ae 18166
18167 /* "neighbor as-override" commands. */
18168 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
18169 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
18170 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
18171 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
18172 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
18173 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
18174 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
18175 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
18176 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
18177 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
18178 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
18179 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
18180 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
18181 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
18182 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
18183 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
18184 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
18185 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
18186
18187 /* "neighbor remove-private-AS" commands. */
18188 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
18189 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
18190 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
18191 install_element(BGP_NODE,
18192 &no_neighbor_remove_private_as_all_hidden_cmd);
18193 install_element(BGP_NODE,
18194 &neighbor_remove_private_as_replace_as_hidden_cmd);
18195 install_element(BGP_NODE,
18196 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
18197 install_element(BGP_NODE,
18198 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
18199 install_element(
18200 BGP_NODE,
18201 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
18202 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
18203 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
18204 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
18205 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18206 install_element(BGP_IPV4_NODE,
18207 &neighbor_remove_private_as_replace_as_cmd);
18208 install_element(BGP_IPV4_NODE,
18209 &no_neighbor_remove_private_as_replace_as_cmd);
18210 install_element(BGP_IPV4_NODE,
18211 &neighbor_remove_private_as_all_replace_as_cmd);
18212 install_element(BGP_IPV4_NODE,
18213 &no_neighbor_remove_private_as_all_replace_as_cmd);
18214 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
18215 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
18216 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
18217 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
18218 install_element(BGP_IPV4M_NODE,
18219 &neighbor_remove_private_as_replace_as_cmd);
18220 install_element(BGP_IPV4M_NODE,
18221 &no_neighbor_remove_private_as_replace_as_cmd);
18222 install_element(BGP_IPV4M_NODE,
18223 &neighbor_remove_private_as_all_replace_as_cmd);
18224 install_element(BGP_IPV4M_NODE,
18225 &no_neighbor_remove_private_as_all_replace_as_cmd);
18226 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
18227 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
18228 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
18229 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
18230 install_element(BGP_IPV4L_NODE,
18231 &neighbor_remove_private_as_replace_as_cmd);
18232 install_element(BGP_IPV4L_NODE,
18233 &no_neighbor_remove_private_as_replace_as_cmd);
18234 install_element(BGP_IPV4L_NODE,
18235 &neighbor_remove_private_as_all_replace_as_cmd);
18236 install_element(BGP_IPV4L_NODE,
18237 &no_neighbor_remove_private_as_all_replace_as_cmd);
18238 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
18239 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
18240 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
18241 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18242 install_element(BGP_IPV6_NODE,
18243 &neighbor_remove_private_as_replace_as_cmd);
18244 install_element(BGP_IPV6_NODE,
18245 &no_neighbor_remove_private_as_replace_as_cmd);
18246 install_element(BGP_IPV6_NODE,
18247 &neighbor_remove_private_as_all_replace_as_cmd);
18248 install_element(BGP_IPV6_NODE,
18249 &no_neighbor_remove_private_as_all_replace_as_cmd);
18250 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
18251 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
18252 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
18253 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
18254 install_element(BGP_IPV6M_NODE,
18255 &neighbor_remove_private_as_replace_as_cmd);
18256 install_element(BGP_IPV6M_NODE,
18257 &no_neighbor_remove_private_as_replace_as_cmd);
18258 install_element(BGP_IPV6M_NODE,
18259 &neighbor_remove_private_as_all_replace_as_cmd);
18260 install_element(BGP_IPV6M_NODE,
18261 &no_neighbor_remove_private_as_all_replace_as_cmd);
18262 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
18263 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
18264 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
18265 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
18266 install_element(BGP_IPV6L_NODE,
18267 &neighbor_remove_private_as_replace_as_cmd);
18268 install_element(BGP_IPV6L_NODE,
18269 &no_neighbor_remove_private_as_replace_as_cmd);
18270 install_element(BGP_IPV6L_NODE,
18271 &neighbor_remove_private_as_all_replace_as_cmd);
18272 install_element(BGP_IPV6L_NODE,
18273 &no_neighbor_remove_private_as_all_replace_as_cmd);
18274 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
18275 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
18276 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
18277 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18278 install_element(BGP_VPNV4_NODE,
18279 &neighbor_remove_private_as_replace_as_cmd);
18280 install_element(BGP_VPNV4_NODE,
18281 &no_neighbor_remove_private_as_replace_as_cmd);
18282 install_element(BGP_VPNV4_NODE,
18283 &neighbor_remove_private_as_all_replace_as_cmd);
18284 install_element(BGP_VPNV4_NODE,
18285 &no_neighbor_remove_private_as_all_replace_as_cmd);
18286 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
18287 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
18288 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
18289 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18290 install_element(BGP_VPNV6_NODE,
18291 &neighbor_remove_private_as_replace_as_cmd);
18292 install_element(BGP_VPNV6_NODE,
18293 &no_neighbor_remove_private_as_replace_as_cmd);
18294 install_element(BGP_VPNV6_NODE,
18295 &neighbor_remove_private_as_all_replace_as_cmd);
18296 install_element(BGP_VPNV6_NODE,
18297 &no_neighbor_remove_private_as_all_replace_as_cmd);
18298
18299 /* "neighbor send-community" commands.*/
18300 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
18301 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
18302 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
18303 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
18304 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
18305 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
18306 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
18307 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
18308 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
18309 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
18310 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
18311 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
18312 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
18313 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
18314 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
18315 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
18316 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
18317 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
18318 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
18319 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
18320 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
18321 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
18322 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
18323 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
18324 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
18325 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
18326 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
18327 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
18328 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
18329 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
18330 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
18331 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
18332 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
18333 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
18334 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
18335 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
18336
18337 /* "neighbor route-reflector" commands.*/
18338 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
18339 install_element(BGP_NODE,
18340 &no_neighbor_route_reflector_client_hidden_cmd);
18341 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
18342 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
18343 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
18344 install_element(BGP_IPV4M_NODE,
18345 &no_neighbor_route_reflector_client_cmd);
18346 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
18347 install_element(BGP_IPV4L_NODE,
18348 &no_neighbor_route_reflector_client_cmd);
18349 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
18350 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
18351 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
18352 install_element(BGP_IPV6M_NODE,
18353 &no_neighbor_route_reflector_client_cmd);
18354 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
18355 install_element(BGP_IPV6L_NODE,
18356 &no_neighbor_route_reflector_client_cmd);
18357 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
18358 install_element(BGP_VPNV4_NODE,
18359 &no_neighbor_route_reflector_client_cmd);
18360 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
18361 install_element(BGP_VPNV6_NODE,
18362 &no_neighbor_route_reflector_client_cmd);
7c40bf39 18363 install_element(BGP_FLOWSPECV4_NODE,
18364 &neighbor_route_reflector_client_cmd);
18365 install_element(BGP_FLOWSPECV4_NODE,
18366 &no_neighbor_route_reflector_client_cmd);
18367 install_element(BGP_FLOWSPECV6_NODE,
18368 &neighbor_route_reflector_client_cmd);
18369 install_element(BGP_FLOWSPECV6_NODE,
18370 &no_neighbor_route_reflector_client_cmd);
d62a17ae 18371 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
18372 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
18373
18374 /* "neighbor route-server" commands.*/
18375 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
18376 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
18377 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
18378 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
18379 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
18380 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
18381 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
18382 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
18383 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
18384 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
18385 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
18386 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
18387 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
18388 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
18389 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
18390 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
18391 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
18392 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
18393 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
18394 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 18395 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
18396 install_element(BGP_FLOWSPECV4_NODE,
18397 &no_neighbor_route_server_client_cmd);
18398 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
18399 install_element(BGP_FLOWSPECV6_NODE,
18400 &no_neighbor_route_server_client_cmd);
d62a17ae 18401
18402 /* "neighbor addpath-tx-all-paths" commands.*/
18403 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
18404 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
18405 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18406 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18407 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18408 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18409 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18410 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18411 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18412 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18413 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18414 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18415 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18416 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18417 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18418 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18419 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18420 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18421
18422 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
18423 install_element(BGP_NODE,
18424 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18425 install_element(BGP_NODE,
18426 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18427 install_element(BGP_IPV4_NODE,
18428 &neighbor_addpath_tx_bestpath_per_as_cmd);
18429 install_element(BGP_IPV4_NODE,
18430 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18431 install_element(BGP_IPV4M_NODE,
18432 &neighbor_addpath_tx_bestpath_per_as_cmd);
18433 install_element(BGP_IPV4M_NODE,
18434 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18435 install_element(BGP_IPV4L_NODE,
18436 &neighbor_addpath_tx_bestpath_per_as_cmd);
18437 install_element(BGP_IPV4L_NODE,
18438 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18439 install_element(BGP_IPV6_NODE,
18440 &neighbor_addpath_tx_bestpath_per_as_cmd);
18441 install_element(BGP_IPV6_NODE,
18442 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18443 install_element(BGP_IPV6M_NODE,
18444 &neighbor_addpath_tx_bestpath_per_as_cmd);
18445 install_element(BGP_IPV6M_NODE,
18446 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18447 install_element(BGP_IPV6L_NODE,
18448 &neighbor_addpath_tx_bestpath_per_as_cmd);
18449 install_element(BGP_IPV6L_NODE,
18450 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18451 install_element(BGP_VPNV4_NODE,
18452 &neighbor_addpath_tx_bestpath_per_as_cmd);
18453 install_element(BGP_VPNV4_NODE,
18454 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18455 install_element(BGP_VPNV6_NODE,
18456 &neighbor_addpath_tx_bestpath_per_as_cmd);
18457 install_element(BGP_VPNV6_NODE,
18458 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18459
2b31007c
RZ
18460 /* "neighbor sender-as-path-loop-detection" commands. */
18461 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
18462 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
18463
d62a17ae 18464 /* "neighbor passive" commands. */
18465 install_element(BGP_NODE, &neighbor_passive_cmd);
18466 install_element(BGP_NODE, &no_neighbor_passive_cmd);
18467
18468
18469 /* "neighbor shutdown" commands. */
18470 install_element(BGP_NODE, &neighbor_shutdown_cmd);
18471 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
18472 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
18473 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
8336c896
DA
18474 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
18475 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
d62a17ae 18476
18477 /* "neighbor capability extended-nexthop" commands.*/
18478 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
18479 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
18480
18481 /* "neighbor capability orf prefix-list" commands.*/
18482 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
18483 install_element(BGP_NODE,
18484 &no_neighbor_capability_orf_prefix_hidden_cmd);
18485 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
18486 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
18487 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
18488 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18489 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
18490 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18491 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
18492 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
18493 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
18494 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18495 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
18496 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18497
18498 /* "neighbor capability dynamic" commands.*/
18499 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
18500 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
18501
18502 /* "neighbor dont-capability-negotiate" commands. */
18503 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
18504 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
18505
18506 /* "neighbor ebgp-multihop" commands. */
18507 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
18508 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
18509 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
18510
18511 /* "neighbor disable-connected-check" commands. */
18512 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
18513 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
18514
47cbc09b
PM
18515 /* "neighbor enforce-first-as" commands. */
18516 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
18517 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
18518
d62a17ae 18519 /* "neighbor description" commands. */
18520 install_element(BGP_NODE, &neighbor_description_cmd);
18521 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 18522 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 18523
18524 /* "neighbor update-source" commands. "*/
18525 install_element(BGP_NODE, &neighbor_update_source_cmd);
18526 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
18527
18528 /* "neighbor default-originate" commands. */
18529 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
18530 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
18531 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
18532 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
18533 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
18534 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
18535 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
18536 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
18537 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
18538 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
18539 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
18540 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
18541 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
18542 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
18543 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
18544 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
18545 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
18546 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
18547 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
18548 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
18549 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
18550
18551 /* "neighbor port" commands. */
18552 install_element(BGP_NODE, &neighbor_port_cmd);
18553 install_element(BGP_NODE, &no_neighbor_port_cmd);
18554
18555 /* "neighbor weight" commands. */
18556 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
18557 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
18558
18559 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
18560 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
18561 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
18562 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
18563 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
18564 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
18565 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
18566 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
18567 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
18568 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
18569 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
18570 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
18571 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
18572 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
18573 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
18574 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
18575
18576 /* "neighbor override-capability" commands. */
18577 install_element(BGP_NODE, &neighbor_override_capability_cmd);
18578 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
18579
18580 /* "neighbor strict-capability-match" commands. */
18581 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
18582 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
18583
18584 /* "neighbor timers" commands. */
18585 install_element(BGP_NODE, &neighbor_timers_cmd);
18586 install_element(BGP_NODE, &no_neighbor_timers_cmd);
18587
18588 /* "neighbor timers connect" commands. */
18589 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
18590 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
18591
d43114f3
DS
18592 /* "neighbor timers delayopen" commands. */
18593 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
18594 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
18595
d62a17ae 18596 /* "neighbor advertisement-interval" commands. */
18597 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
18598 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
18599
18600 /* "neighbor interface" commands. */
18601 install_element(BGP_NODE, &neighbor_interface_cmd);
18602 install_element(BGP_NODE, &no_neighbor_interface_cmd);
18603
18604 /* "neighbor distribute" commands. */
18605 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
18606 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
18607 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
18608 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
18609 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
18610 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
18611 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
18612 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
18613 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
18614 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
18615 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
18616 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
18617 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
18618 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
18619 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
18620 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
18621 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
18622 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
18623
18624 /* "neighbor prefix-list" commands. */
18625 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
d62a17ae 18626 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
d62a17ae 18627 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
d62a17ae 18628 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
d62a17ae 18629 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
d62a17ae 18630 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
d62a17ae 18631 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
d62a17ae 18632 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
d62a17ae 18633 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
7c40bf39 18634 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
7c40bf39 18635 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
d62a17ae 18636
18637 /* "neighbor filter-list" commands. */
18638 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
18639 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
18640 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
18641 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
18642 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
18643 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
18644 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
18645 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
18646 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
18647 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
18648 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
18649 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
18650 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
18651 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
18652 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
18653 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
18654 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
18655 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 18656 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
18657 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
18658 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
18659 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 18660
18661 /* "neighbor route-map" commands. */
18662 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
18663 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
18664 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
d62a17ae 18665 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
d62a17ae 18666 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
d62a17ae 18667 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
d62a17ae 18668 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
d62a17ae 18669 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
d62a17ae 18670 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
d62a17ae 18671 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
7c40bf39 18672 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
7c40bf39 18673 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
d37ba549 18674 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
d62a17ae 18675
18676 /* "neighbor unsuppress-map" commands. */
18677 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
18678 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
18679 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
18680 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
18681 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
18682 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
18683 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
18684 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
18685 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
18686 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
18687 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
18688 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
18689 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
18690 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
18691 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
18692 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
18693 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
18694 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
18695
7f7940e6
MK
18696 /* "neighbor advertise-map" commands. */
18697 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
7f7940e6 18698 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18699 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18700 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18701 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18702 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18703 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18704 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18705 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18706
fde246e8
DA
18707 /* neighbor maximum-prefix-out commands. */
18708 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
18709 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
18710 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
18711 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18712 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
18713 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18714 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
18715 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18716 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
18717 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18718 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
18719 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18720 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
18721 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18722 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
18723 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18724 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
18725 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18726
d62a17ae 18727 /* "neighbor maximum-prefix" commands. */
18728 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
18729 install_element(BGP_NODE,
18730 &neighbor_maximum_prefix_threshold_hidden_cmd);
18731 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
18732 install_element(BGP_NODE,
18733 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
18734 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
18735 install_element(BGP_NODE,
18736 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
18737 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
18738 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
18739 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18740 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18741 install_element(BGP_IPV4_NODE,
18742 &neighbor_maximum_prefix_threshold_warning_cmd);
18743 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18744 install_element(BGP_IPV4_NODE,
18745 &neighbor_maximum_prefix_threshold_restart_cmd);
18746 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
18747 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
18748 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18749 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
18750 install_element(BGP_IPV4M_NODE,
18751 &neighbor_maximum_prefix_threshold_warning_cmd);
18752 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
18753 install_element(BGP_IPV4M_NODE,
18754 &neighbor_maximum_prefix_threshold_restart_cmd);
18755 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
18756 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
18757 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18758 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
18759 install_element(BGP_IPV4L_NODE,
18760 &neighbor_maximum_prefix_threshold_warning_cmd);
18761 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
18762 install_element(BGP_IPV4L_NODE,
18763 &neighbor_maximum_prefix_threshold_restart_cmd);
18764 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
18765 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
18766 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18767 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18768 install_element(BGP_IPV6_NODE,
18769 &neighbor_maximum_prefix_threshold_warning_cmd);
18770 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18771 install_element(BGP_IPV6_NODE,
18772 &neighbor_maximum_prefix_threshold_restart_cmd);
18773 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
18774 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
18775 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18776 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
18777 install_element(BGP_IPV6M_NODE,
18778 &neighbor_maximum_prefix_threshold_warning_cmd);
18779 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
18780 install_element(BGP_IPV6M_NODE,
18781 &neighbor_maximum_prefix_threshold_restart_cmd);
18782 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
18783 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
18784 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18785 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
18786 install_element(BGP_IPV6L_NODE,
18787 &neighbor_maximum_prefix_threshold_warning_cmd);
18788 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
18789 install_element(BGP_IPV6L_NODE,
18790 &neighbor_maximum_prefix_threshold_restart_cmd);
18791 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
18792 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
18793 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18794 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18795 install_element(BGP_VPNV4_NODE,
18796 &neighbor_maximum_prefix_threshold_warning_cmd);
18797 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18798 install_element(BGP_VPNV4_NODE,
18799 &neighbor_maximum_prefix_threshold_restart_cmd);
18800 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
18801 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
18802 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18803 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18804 install_element(BGP_VPNV6_NODE,
18805 &neighbor_maximum_prefix_threshold_warning_cmd);
18806 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18807 install_element(BGP_VPNV6_NODE,
18808 &neighbor_maximum_prefix_threshold_restart_cmd);
18809 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
18810
18811 /* "neighbor allowas-in" */
18812 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
18813 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
18814 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
18815 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
18816 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
18817 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
18818 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
18819 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
18820 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
18821 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
18822 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
18823 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
18824 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
18825 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
18826 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
18827 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
18828 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
18829 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
18830 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
18831 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
18832
0221327c
DS
18833 /* "neighbor dampening" commands. */
18834 install_element(BGP_NODE, &neighbor_damp_cmd);
18835 install_element(BGP_NODE, &no_neighbor_damp_cmd);
18836 install_element(BGP_IPV4_NODE, &neighbor_damp_cmd);
18837 install_element(BGP_IPV4_NODE, &no_neighbor_damp_cmd);
18838 install_element(BGP_IPV4M_NODE, &neighbor_damp_cmd);
18839 install_element(BGP_IPV4M_NODE, &no_neighbor_damp_cmd);
18840 install_element(BGP_IPV4L_NODE, &neighbor_damp_cmd);
18841 install_element(BGP_IPV4L_NODE, &no_neighbor_damp_cmd);
18842 install_element(BGP_IPV6_NODE, &neighbor_damp_cmd);
18843 install_element(BGP_IPV6_NODE, &no_neighbor_damp_cmd);
18844 install_element(BGP_IPV6M_NODE, &neighbor_damp_cmd);
18845 install_element(BGP_IPV6M_NODE, &no_neighbor_damp_cmd);
18846 install_element(BGP_IPV6L_NODE, &neighbor_damp_cmd);
18847 install_element(BGP_IPV6L_NODE, &no_neighbor_damp_cmd);
18848 install_element(VIEW_NODE, &show_ip_bgp_neighbor_damp_param_cmd);
18849
d62a17ae 18850 /* address-family commands. */
18851 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
18852 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 18853#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 18854 install_element(BGP_NODE, &address_family_vpnv4_cmd);
18855 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 18856#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 18857
d62a17ae 18858 install_element(BGP_NODE, &address_family_evpn_cmd);
18859
18860 /* "exit-address-family" command. */
18861 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
18862 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
18863 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
18864 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
18865 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
18866 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
18867 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
18868 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 18869 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
18870 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 18871 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
18872
18873 /* "clear ip bgp commands" */
18874 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
18875
18876 /* clear ip bgp prefix */
18877 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
18878 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
18879 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
18880
18881 /* "show [ip] bgp summary" commands. */
18882 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 18883 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 18884 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 18885 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 18886 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
18887 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 18888 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
18889
18890 /* "show [ip] bgp neighbors" commands. */
18891 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
18892
36235319 18893 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
2986cac2 18894
d62a17ae 18895 /* "show [ip] bgp peer-group" commands. */
18896 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
18897
18898 /* "show [ip] bgp paths" commands. */
18899 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
18900
18901 /* "show [ip] bgp community" commands. */
18902 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
18903
18904 /* "show ip bgp large-community" commands. */
18905 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
18906 /* "show [ip] bgp attribute-info" commands. */
18907 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 18908 /* "show [ip] bgp route-leak" command */
18909 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 18910
18911 /* "redistribute" commands. */
18912 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
18913 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
18914 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
18915 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
18916 install_element(BGP_NODE,
18917 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
18918 install_element(BGP_NODE,
18919 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
18920 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
18921 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
18922 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
18923 install_element(BGP_NODE,
18924 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
18925 install_element(BGP_NODE,
18926 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
18927 install_element(BGP_NODE,
18928 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
18929 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
18930 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
18931 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
18932 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
18933 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
18934 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
18935 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
18936 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
18937 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
18938 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
18939 install_element(BGP_IPV4_NODE,
18940 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
18941 install_element(BGP_IPV4_NODE,
18942 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
18943 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
18944 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
18945 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
18946 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
18947 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
18948 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
18949
b9c7bc5a
PZ
18950 /* import|export vpn [route-map WORD] */
18951 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
18952 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 18953
12a844a5
DS
18954 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
18955 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
18956
d62a17ae 18957 /* ttl_security commands */
18958 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
18959 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
18960
18961 /* "show [ip] bgp memory" commands. */
18962 install_element(VIEW_NODE, &show_bgp_memory_cmd);
18963
acf71666
MK
18964 /* "show bgp martian next-hop" */
18965 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
18966
48ecf8f5
DS
18967 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
18968
d62a17ae 18969 /* "show [ip] bgp views" commands. */
18970 install_element(VIEW_NODE, &show_bgp_views_cmd);
18971
18972 /* "show [ip] bgp vrfs" commands. */
18973 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
18974
18975 /* Community-list. */
18976 community_list_vty();
ddb5b488
PZ
18977
18978 /* vpn-policy commands */
b9c7bc5a
PZ
18979 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
18980 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
18981 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
18982 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
18983 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
18984 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
18985 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
18986 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
18987 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
18988 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
18989 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
18990 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 18991
301ad80a
PG
18992 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
18993 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
18994
b9c7bc5a
PZ
18995 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
18996 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
18997 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
18998 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
b9c7bc5a
PZ
18999 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
19000 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
19001 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
19002 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
19003 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
19004 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
718e3744 19005}
6b0655a2 19006
718e3744 19007#include "memory.h"
19008#include "bgp_regex.h"
19009#include "bgp_clist.h"
19010#include "bgp_ecommunity.h"
19011
19012/* VTY functions. */
19013
19014/* Direction value to string conversion. */
d62a17ae 19015static const char *community_direct_str(int direct)
19016{
19017 switch (direct) {
19018 case COMMUNITY_DENY:
19019 return "deny";
19020 case COMMUNITY_PERMIT:
19021 return "permit";
19022 default:
19023 return "unknown";
19024 }
718e3744 19025}
19026
19027/* Display error string. */
d62a17ae 19028static void community_list_perror(struct vty *vty, int ret)
19029{
19030 switch (ret) {
19031 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
19032 vty_out(vty, "%% Can't find community-list\n");
19033 break;
19034 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
19035 vty_out(vty, "%% Malformed community-list value\n");
19036 break;
19037 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
19038 vty_out(vty,
19039 "%% Community name conflict, previously defined as standard community\n");
19040 break;
19041 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
19042 vty_out(vty,
19043 "%% Community name conflict, previously defined as expanded community\n");
19044 break;
19045 }
718e3744 19046}
19047
5bf15956
DW
19048/* "community-list" keyword help string. */
19049#define COMMUNITY_LIST_STR "Add a community list entry\n"
19050
7336e101
SP
19051/*community-list standard */
19052DEFUN (community_list_standard,
19053 bgp_community_list_standard_cmd,
2f8cc0e5 19054 "bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101 19055 BGP_STR
718e3744 19056 COMMUNITY_LIST_STR
19057 "Community list number (standard)\n"
5bf15956 19058 "Add an standard community-list entry\n"
718e3744 19059 "Community list name\n"
2f8cc0e5
DA
19060 "Sequence number of an entry\n"
19061 "Sequence number\n"
718e3744 19062 "Specify community to reject\n"
19063 "Specify community to accept\n"
19064 COMMUNITY_VAL_STR)
19065{
d62a17ae 19066 char *cl_name_or_number = NULL;
2f8cc0e5 19067 char *seq = NULL;
d62a17ae 19068 int direct = 0;
19069 int style = COMMUNITY_LIST_STANDARD;
d62a17ae 19070 int idx = 0;
7336e101 19071
2f8cc0e5
DA
19072 argv_find(argv, argc, "(1-4294967295)", &idx);
19073 if (idx)
19074 seq = argv[idx]->arg;
19075
19076 idx = 0;
d62a17ae 19077 argv_find(argv, argc, "(1-99)", &idx);
19078 argv_find(argv, argc, "WORD", &idx);
19079 cl_name_or_number = argv[idx]->arg;
19080 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19081 : COMMUNITY_DENY;
19082 argv_find(argv, argc, "AA:NN", &idx);
19083 char *str = argv_concat(argv, argc, idx);
42f914d4 19084
2f8cc0e5
DA
19085 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19086 direct, style);
42f914d4 19087
d62a17ae 19088 XFREE(MTYPE_TMP, str);
42f914d4 19089
d62a17ae 19090 if (ret < 0) {
19091 /* Display error string. */
19092 community_list_perror(vty, ret);
19093 return CMD_WARNING_CONFIG_FAILED;
19094 }
42f914d4 19095
d62a17ae 19096 return CMD_SUCCESS;
718e3744 19097}
19098
7336e101
SP
19099DEFUN (no_community_list_standard_all,
19100 no_bgp_community_list_standard_all_cmd,
2f8cc0e5 19101 "no bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19102 NO_STR
19103 BGP_STR
19104 COMMUNITY_LIST_STR
19105 "Community list number (standard)\n"
19106 "Add an standard community-list entry\n"
19107 "Community list name\n"
2f8cc0e5
DA
19108 "Sequence number of an entry\n"
19109 "Sequence number\n"
7336e101
SP
19110 "Specify community to reject\n"
19111 "Specify community to accept\n"
19112 COMMUNITY_VAL_STR)
718e3744 19113{
d62a17ae 19114 char *cl_name_or_number = NULL;
174b5cb9 19115 char *str = NULL;
d62a17ae 19116 int direct = 0;
19117 int style = COMMUNITY_LIST_STANDARD;
2f8cc0e5 19118 char *seq = NULL;
d62a17ae 19119 int idx = 0;
7336e101 19120
2f8cc0e5
DA
19121 argv_find(argv, argc, "(1-4294967295)", &idx);
19122 if (idx)
19123 seq = argv[idx]->arg;
19124
19125 idx = 0;
174b5cb9
DA
19126 argv_find(argv, argc, "permit", &idx);
19127 argv_find(argv, argc, "deny", &idx);
19128
19129 if (idx) {
19130 direct = argv_find(argv, argc, "permit", &idx)
19131 ? COMMUNITY_PERMIT
19132 : COMMUNITY_DENY;
19133
19134 idx = 0;
19135 argv_find(argv, argc, "AA:NN", &idx);
19136 str = argv_concat(argv, argc, idx);
19137 }
19138
19139 idx = 0;
d62a17ae 19140 argv_find(argv, argc, "(1-99)", &idx);
19141 argv_find(argv, argc, "WORD", &idx);
19142 cl_name_or_number = argv[idx]->arg;
42f914d4 19143
2f8cc0e5 19144 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 19145 direct, style);
42f914d4 19146
d62a17ae 19147 XFREE(MTYPE_TMP, str);
daf9ddbb 19148
d62a17ae 19149 if (ret < 0) {
19150 community_list_perror(vty, ret);
19151 return CMD_WARNING_CONFIG_FAILED;
19152 }
42f914d4 19153
d62a17ae 19154 return CMD_SUCCESS;
718e3744 19155}
7336e101 19156
174b5cb9
DA
19157ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
19158 "no bgp community-list <(1-99)|standard WORD>",
19159 NO_STR BGP_STR COMMUNITY_LIST_STR
19160 "Community list number (standard)\n"
19161 "Add an standard community-list entry\n"
19162 "Community list name\n")
19163
7336e101
SP
19164/*community-list expanded */
19165DEFUN (community_list_expanded_all,
19166 bgp_community_list_expanded_all_cmd,
2f8cc0e5 19167 "bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19168 BGP_STR
19169 COMMUNITY_LIST_STR
718e3744 19170 "Community list number (expanded)\n"
5bf15956 19171 "Add an expanded community-list entry\n"
718e3744 19172 "Community list name\n"
2f8cc0e5
DA
19173 "Sequence number of an entry\n"
19174 "Sequence number\n"
718e3744 19175 "Specify community to reject\n"
19176 "Specify community to accept\n"
19177 COMMUNITY_VAL_STR)
19178{
d62a17ae 19179 char *cl_name_or_number = NULL;
2f8cc0e5 19180 char *seq = NULL;
d62a17ae 19181 int direct = 0;
19182 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 19183 int idx = 0;
7b9a4750 19184
2f8cc0e5
DA
19185 argv_find(argv, argc, "(1-4294967295)", &idx);
19186 if (idx)
19187 seq = argv[idx]->arg;
19188
19189 idx = 0;
19190
d62a17ae 19191 argv_find(argv, argc, "(100-500)", &idx);
19192 argv_find(argv, argc, "WORD", &idx);
19193 cl_name_or_number = argv[idx]->arg;
19194 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19195 : COMMUNITY_DENY;
19196 argv_find(argv, argc, "AA:NN", &idx);
19197 char *str = argv_concat(argv, argc, idx);
42f914d4 19198
2f8cc0e5
DA
19199 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19200 direct, style);
42f914d4 19201
d62a17ae 19202 XFREE(MTYPE_TMP, str);
42f914d4 19203
d62a17ae 19204 if (ret < 0) {
19205 /* Display error string. */
19206 community_list_perror(vty, ret);
19207 return CMD_WARNING_CONFIG_FAILED;
19208 }
42f914d4 19209
d62a17ae 19210 return CMD_SUCCESS;
718e3744 19211}
19212
7336e101
SP
19213DEFUN (no_community_list_expanded_all,
19214 no_bgp_community_list_expanded_all_cmd,
2f8cc0e5 19215 "no bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19216 NO_STR
19217 BGP_STR
19218 COMMUNITY_LIST_STR
19219 "Community list number (expanded)\n"
19220 "Add an expanded community-list entry\n"
19221 "Community list name\n"
2f8cc0e5
DA
19222 "Sequence number of an entry\n"
19223 "Sequence number\n"
7336e101
SP
19224 "Specify community to reject\n"
19225 "Specify community to accept\n"
19226 COMMUNITY_VAL_STR)
718e3744 19227{
d62a17ae 19228 char *cl_name_or_number = NULL;
2f8cc0e5 19229 char *seq = NULL;
174b5cb9 19230 char *str = NULL;
d62a17ae 19231 int direct = 0;
19232 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 19233 int idx = 0;
174b5cb9 19234
2f8cc0e5
DA
19235 argv_find(argv, argc, "(1-4294967295)", &idx);
19236 if (idx)
19237 seq = argv[idx]->arg;
19238
19239 idx = 0;
174b5cb9
DA
19240 argv_find(argv, argc, "permit", &idx);
19241 argv_find(argv, argc, "deny", &idx);
19242
19243 if (idx) {
19244 direct = argv_find(argv, argc, "permit", &idx)
19245 ? COMMUNITY_PERMIT
19246 : COMMUNITY_DENY;
19247
19248 idx = 0;
19249 argv_find(argv, argc, "AA:NN", &idx);
19250 str = argv_concat(argv, argc, idx);
7336e101 19251 }
174b5cb9
DA
19252
19253 idx = 0;
d62a17ae 19254 argv_find(argv, argc, "(100-500)", &idx);
19255 argv_find(argv, argc, "WORD", &idx);
19256 cl_name_or_number = argv[idx]->arg;
42f914d4 19257
2f8cc0e5 19258 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 19259 direct, style);
42f914d4 19260
d62a17ae 19261 XFREE(MTYPE_TMP, str);
daf9ddbb 19262
d62a17ae 19263 if (ret < 0) {
19264 community_list_perror(vty, ret);
19265 return CMD_WARNING_CONFIG_FAILED;
19266 }
42f914d4 19267
d62a17ae 19268 return CMD_SUCCESS;
718e3744 19269}
19270
36d4bb44
EB
19271ALIAS(no_community_list_expanded_all,
19272 no_bgp_community_list_expanded_all_list_cmd,
174b5cb9 19273 "no bgp community-list <(100-500)|expanded WORD>",
36d4bb44 19274 NO_STR BGP_STR COMMUNITY_LIST_STR
174b5cb9
DA
19275 "Community list number (expanded)\n"
19276 "Add an expanded community-list entry\n"
19277 "Community list name\n")
19278
8d9b8ed9
PM
19279/* Return configuration string of community-list entry. */
19280static const char *community_list_config_str(struct community_entry *entry)
19281{
19282 const char *str;
19283
19284 if (entry->any)
19285 str = "";
19286 else {
19287 if (entry->style == COMMUNITY_LIST_STANDARD)
19288 str = community_str(entry->u.com, false);
19289 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
19290 str = lcommunity_str(entry->u.lcom, false);
19291 else
19292 str = entry->config;
19293 }
19294 return str;
19295}
19296
d62a17ae 19297static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 19298{
d62a17ae 19299 struct community_entry *entry;
718e3744 19300
d62a17ae 19301 for (entry = list->head; entry; entry = entry->next) {
19302 if (entry == list->head) {
19303 if (all_digit(list->name))
19304 vty_out(vty, "Community %s list %s\n",
19305 entry->style == COMMUNITY_LIST_STANDARD
19306 ? "standard"
19307 : "(expanded) access",
19308 list->name);
19309 else
19310 vty_out(vty, "Named Community %s list %s\n",
19311 entry->style == COMMUNITY_LIST_STANDARD
19312 ? "standard"
19313 : "expanded",
19314 list->name);
19315 }
19316 if (entry->any)
19317 vty_out(vty, " %s\n",
19318 community_direct_str(entry->direct));
19319 else
19320 vty_out(vty, " %s %s\n",
19321 community_direct_str(entry->direct),
8d9b8ed9 19322 community_list_config_str(entry));
d62a17ae 19323 }
718e3744 19324}
19325
7336e101
SP
19326DEFUN (show_community_list,
19327 show_bgp_community_list_cmd,
19328 "show bgp community-list",
718e3744 19329 SHOW_STR
7336e101 19330 BGP_STR
718e3744 19331 "List community-list\n")
19332{
d62a17ae 19333 struct community_list *list;
19334 struct community_list_master *cm;
718e3744 19335
d62a17ae 19336 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
19337 if (!cm)
19338 return CMD_SUCCESS;
718e3744 19339
d62a17ae 19340 for (list = cm->num.head; list; list = list->next)
19341 community_list_show(vty, list);
718e3744 19342
d62a17ae 19343 for (list = cm->str.head; list; list = list->next)
19344 community_list_show(vty, list);
718e3744 19345
d62a17ae 19346 return CMD_SUCCESS;
718e3744 19347}
19348
7336e101
SP
19349DEFUN (show_community_list_arg,
19350 show_bgp_community_list_arg_cmd,
960b69b9 19351 "show bgp community-list <(1-500)|WORD> detail",
7336e101
SP
19352 SHOW_STR
19353 BGP_STR
718e3744 19354 "List community-list\n"
19355 "Community-list number\n"
960b69b9 19356 "Community-list name\n"
19357 "Detailed information on community-list\n")
718e3744 19358{
d62a17ae 19359 int idx_comm_list = 3;
19360 struct community_list *list;
718e3744 19361
e237b0d2 19362 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 19363 COMMUNITY_LIST_MASTER);
19364 if (!list) {
19365 vty_out(vty, "%% Can't find community-list\n");
19366 return CMD_WARNING;
19367 }
718e3744 19368
d62a17ae 19369 community_list_show(vty, list);
718e3744 19370
d62a17ae 19371 return CMD_SUCCESS;
718e3744 19372}
6b0655a2 19373
57d187bc
JS
19374/*
19375 * Large Community code.
19376 */
d62a17ae 19377static int lcommunity_list_set_vty(struct vty *vty, int argc,
19378 struct cmd_token **argv, int style,
19379 int reject_all_digit_name)
19380{
19381 int ret;
19382 int direct;
19383 char *str;
19384 int idx = 0;
19385 char *cl_name;
2f8cc0e5
DA
19386 char *seq = NULL;
19387
947073e3 19388 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5 19389 seq = argv[idx]->arg;
d62a17ae 19390
2f8cc0e5 19391 idx = 0;
d62a17ae 19392 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19393 : COMMUNITY_DENY;
19394
19395 /* All digit name check. */
19396 idx = 0;
19397 argv_find(argv, argc, "WORD", &idx);
19398 argv_find(argv, argc, "(1-99)", &idx);
19399 argv_find(argv, argc, "(100-500)", &idx);
19400 cl_name = argv[idx]->arg;
19401 if (reject_all_digit_name && all_digit(cl_name)) {
19402 vty_out(vty, "%% Community name cannot have all digits\n");
19403 return CMD_WARNING_CONFIG_FAILED;
19404 }
19405
19406 idx = 0;
19407 argv_find(argv, argc, "AA:BB:CC", &idx);
19408 argv_find(argv, argc, "LINE", &idx);
19409 /* Concat community string argument. */
19410 if (idx)
19411 str = argv_concat(argv, argc, idx);
19412 else
19413 str = NULL;
19414
2f8cc0e5 19415 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
d62a17ae 19416
19417 /* Free temporary community list string allocated by
19418 argv_concat(). */
0a22ddfb 19419 XFREE(MTYPE_TMP, str);
d62a17ae 19420
19421 if (ret < 0) {
19422 community_list_perror(vty, ret);
19423 return CMD_WARNING_CONFIG_FAILED;
19424 }
19425 return CMD_SUCCESS;
19426}
19427
19428static int lcommunity_list_unset_vty(struct vty *vty, int argc,
19429 struct cmd_token **argv, int style)
19430{
19431 int ret;
19432 int direct = 0;
19433 char *str = NULL;
19434 int idx = 0;
2f8cc0e5 19435 char *seq = NULL;
d62a17ae 19436
947073e3 19437 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5 19438 seq = argv[idx]->arg;
d62a17ae 19439
2f8cc0e5 19440 idx = 0;
d62a17ae 19441 argv_find(argv, argc, "permit", &idx);
19442 argv_find(argv, argc, "deny", &idx);
19443
19444 if (idx) {
19445 /* Check the list direct. */
19446 if (strncmp(argv[idx]->arg, "p", 1) == 0)
19447 direct = COMMUNITY_PERMIT;
19448 else
19449 direct = COMMUNITY_DENY;
19450
19451 idx = 0;
19452 argv_find(argv, argc, "LINE", &idx);
19453 argv_find(argv, argc, "AA:AA:NN", &idx);
19454 /* Concat community string argument. */
19455 str = argv_concat(argv, argc, idx);
19456 }
19457
19458 idx = 0;
19459 argv_find(argv, argc, "(1-99)", &idx);
19460 argv_find(argv, argc, "(100-500)", &idx);
19461 argv_find(argv, argc, "WORD", &idx);
19462
19463 /* Unset community list. */
2f8cc0e5 19464 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
d62a17ae 19465 style);
19466
19467 /* Free temporary community list string allocated by
19468 argv_concat(). */
0a22ddfb 19469 XFREE(MTYPE_TMP, str);
d62a17ae 19470
19471 if (ret < 0) {
19472 community_list_perror(vty, ret);
19473 return CMD_WARNING_CONFIG_FAILED;
19474 }
19475
19476 return CMD_SUCCESS;
57d187bc
JS
19477}
19478
19479/* "large-community-list" keyword help string. */
19480#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
19481#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
19482
7336e101
SP
19483DEFUN (lcommunity_list_standard,
19484 bgp_lcommunity_list_standard_cmd,
2f8cc0e5 19485 "bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
19486 BGP_STR
19487 LCOMMUNITY_LIST_STR
19488 "Large Community list number (standard)\n"
2f8cc0e5
DA
19489 "Sequence number of an entry\n"
19490 "Sequence number\n"
7336e101
SP
19491 "Specify large community to reject\n"
19492 "Specify large community to accept\n"
19493 LCOMMUNITY_VAL_STR)
52951b63 19494{
d62a17ae 19495 return lcommunity_list_set_vty(vty, argc, argv,
19496 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
19497}
19498
7336e101
SP
19499DEFUN (lcommunity_list_expanded,
19500 bgp_lcommunity_list_expanded_cmd,
2f8cc0e5 19501 "bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
19502 BGP_STR
19503 LCOMMUNITY_LIST_STR
19504 "Large Community list number (expanded)\n"
2f8cc0e5
DA
19505 "Sequence number of an entry\n"
19506 "Sequence number\n"
7336e101
SP
19507 "Specify large community to reject\n"
19508 "Specify large community to accept\n"
19509 "An ordered list as a regular-expression\n")
57d187bc 19510{
d62a17ae 19511 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 19512 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
19513}
19514
7336e101
SP
19515DEFUN (lcommunity_list_name_standard,
19516 bgp_lcommunity_list_name_standard_cmd,
2f8cc0e5 19517 "bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
19518 BGP_STR
19519 LCOMMUNITY_LIST_STR
19520 "Specify standard large-community-list\n"
19521 "Large Community list name\n"
2f8cc0e5
DA
19522 "Sequence number of an entry\n"
19523 "Sequence number\n"
7336e101
SP
19524 "Specify large community to reject\n"
19525 "Specify large community to accept\n"
19526 LCOMMUNITY_VAL_STR)
52951b63 19527{
d62a17ae 19528 return lcommunity_list_set_vty(vty, argc, argv,
19529 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
19530}
19531
7336e101
SP
19532DEFUN (lcommunity_list_name_expanded,
19533 bgp_lcommunity_list_name_expanded_cmd,
2f8cc0e5 19534 "bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
19535 BGP_STR
19536 LCOMMUNITY_LIST_STR
19537 "Specify expanded large-community-list\n"
19538 "Large Community list name\n"
2f8cc0e5
DA
19539 "Sequence number of an entry\n"
19540 "Sequence number\n"
7336e101
SP
19541 "Specify large community to reject\n"
19542 "Specify large community to accept\n"
19543 "An ordered list as a regular-expression\n")
57d187bc 19544{
d62a17ae 19545 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 19546 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
19547}
19548
4378f57c
DA
19549DEFUN (no_lcommunity_list_all,
19550 no_bgp_lcommunity_list_all_cmd,
7336e101
SP
19551 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
19552 NO_STR
19553 BGP_STR
19554 LCOMMUNITY_LIST_STR
19555 "Large Community list number (standard)\n"
19556 "Large Community list number (expanded)\n"
19557 "Large Community list name\n")
57d187bc 19558{
7336e101
SP
19559 return lcommunity_list_unset_vty(vty, argc, argv,
19560 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
19561}
19562
4378f57c
DA
19563DEFUN (no_lcommunity_list_name_standard_all,
19564 no_bgp_lcommunity_list_name_standard_all_cmd,
19565 "no bgp large-community-list standard WORD",
19566 NO_STR
19567 BGP_STR
19568 LCOMMUNITY_LIST_STR
19569 "Specify standard large-community-list\n"
19570 "Large Community list name\n")
19571{
19572 return lcommunity_list_unset_vty(vty, argc, argv,
19573 LARGE_COMMUNITY_LIST_STANDARD);
19574}
19575
7336e101
SP
19576DEFUN (no_lcommunity_list_name_expanded_all,
19577 no_bgp_lcommunity_list_name_expanded_all_cmd,
19578 "no bgp large-community-list expanded WORD",
19579 NO_STR
19580 BGP_STR
19581 LCOMMUNITY_LIST_STR
19582 "Specify expanded large-community-list\n"
19583 "Large Community list name\n")
57d187bc 19584{
d62a17ae 19585 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19586 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
19587}
19588
7336e101
SP
19589DEFUN (no_lcommunity_list_standard,
19590 no_bgp_lcommunity_list_standard_cmd,
2f8cc0e5 19591 "no bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
19592 NO_STR
19593 BGP_STR
19594 LCOMMUNITY_LIST_STR
19595 "Large Community list number (standard)\n"
2f8cc0e5
DA
19596 "Sequence number of an entry\n"
19597 "Sequence number\n"
7336e101
SP
19598 "Specify large community to reject\n"
19599 "Specify large community to accept\n"
19600 LCOMMUNITY_VAL_STR)
57d187bc 19601{
d62a17ae 19602 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19603 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
19604}
19605
7336e101
SP
19606DEFUN (no_lcommunity_list_expanded,
19607 no_bgp_lcommunity_list_expanded_cmd,
2f8cc0e5 19608 "no bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
19609 NO_STR
19610 BGP_STR
19611 LCOMMUNITY_LIST_STR
19612 "Large Community list number (expanded)\n"
2f8cc0e5
DA
19613 "Sequence number of an entry\n"
19614 "Sequence number\n"
7336e101
SP
19615 "Specify large community to reject\n"
19616 "Specify large community to accept\n"
19617 "An ordered list as a regular-expression\n")
57d187bc 19618{
d62a17ae 19619 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19620 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
19621}
19622
7336e101
SP
19623DEFUN (no_lcommunity_list_name_standard,
19624 no_bgp_lcommunity_list_name_standard_cmd,
2f8cc0e5 19625 "no bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
19626 NO_STR
19627 BGP_STR
19628 LCOMMUNITY_LIST_STR
19629 "Specify standard large-community-list\n"
19630 "Large Community list name\n"
2f8cc0e5
DA
19631 "Sequence number of an entry\n"
19632 "Sequence number\n"
7336e101
SP
19633 "Specify large community to reject\n"
19634 "Specify large community to accept\n"
19635 LCOMMUNITY_VAL_STR)
57d187bc 19636{
d62a17ae 19637 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19638 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
19639}
19640
7336e101
SP
19641DEFUN (no_lcommunity_list_name_expanded,
19642 no_bgp_lcommunity_list_name_expanded_cmd,
2f8cc0e5 19643 "no bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
19644 NO_STR
19645 BGP_STR
19646 LCOMMUNITY_LIST_STR
19647 "Specify expanded large-community-list\n"
19648 "Large community list name\n"
2f8cc0e5
DA
19649 "Sequence number of an entry\n"
19650 "Sequence number\n"
7336e101
SP
19651 "Specify large community to reject\n"
19652 "Specify large community to accept\n"
19653 "An ordered list as a regular-expression\n")
57d187bc 19654{
d62a17ae 19655 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19656 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
19657}
19658
d62a17ae 19659static void lcommunity_list_show(struct vty *vty, struct community_list *list)
19660{
19661 struct community_entry *entry;
19662
19663 for (entry = list->head; entry; entry = entry->next) {
19664 if (entry == list->head) {
19665 if (all_digit(list->name))
19666 vty_out(vty, "Large community %s list %s\n",
169b72c8 19667 entry->style ==
19668 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 19669 ? "standard"
19670 : "(expanded) access",
19671 list->name);
19672 else
19673 vty_out(vty,
19674 "Named large community %s list %s\n",
169b72c8 19675 entry->style ==
19676 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 19677 ? "standard"
19678 : "expanded",
19679 list->name);
19680 }
19681 if (entry->any)
19682 vty_out(vty, " %s\n",
19683 community_direct_str(entry->direct));
19684 else
19685 vty_out(vty, " %s %s\n",
19686 community_direct_str(entry->direct),
8d9b8ed9 19687 community_list_config_str(entry));
d62a17ae 19688 }
57d187bc
JS
19689}
19690
7336e101
SP
19691DEFUN (show_lcommunity_list,
19692 show_bgp_lcommunity_list_cmd,
19693 "show bgp large-community-list",
57d187bc 19694 SHOW_STR
7336e101 19695 BGP_STR
57d187bc
JS
19696 "List large-community list\n")
19697{
d62a17ae 19698 struct community_list *list;
19699 struct community_list_master *cm;
57d187bc 19700
d62a17ae 19701 cm = community_list_master_lookup(bgp_clist,
19702 LARGE_COMMUNITY_LIST_MASTER);
19703 if (!cm)
19704 return CMD_SUCCESS;
57d187bc 19705
d62a17ae 19706 for (list = cm->num.head; list; list = list->next)
19707 lcommunity_list_show(vty, list);
57d187bc 19708
d62a17ae 19709 for (list = cm->str.head; list; list = list->next)
19710 lcommunity_list_show(vty, list);
57d187bc 19711
d62a17ae 19712 return CMD_SUCCESS;
57d187bc
JS
19713}
19714
7336e101
SP
19715DEFUN (show_lcommunity_list_arg,
19716 show_bgp_lcommunity_list_arg_cmd,
960b69b9 19717 "show bgp large-community-list <(1-500)|WORD> detail",
7336e101
SP
19718 SHOW_STR
19719 BGP_STR
57d187bc 19720 "List large-community list\n"
960b69b9 19721 "Large-community-list number\n"
19722 "Large-community-list name\n"
19723 "Detailed information on large-community-list\n")
57d187bc 19724{
d62a17ae 19725 struct community_list *list;
57d187bc 19726
e237b0d2 19727 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
d62a17ae 19728 LARGE_COMMUNITY_LIST_MASTER);
19729 if (!list) {
960b69b9 19730 vty_out(vty, "%% Can't find large-community-list\n");
d62a17ae 19731 return CMD_WARNING;
19732 }
57d187bc 19733
d62a17ae 19734 lcommunity_list_show(vty, list);
57d187bc 19735
d62a17ae 19736 return CMD_SUCCESS;
57d187bc
JS
19737}
19738
718e3744 19739/* "extcommunity-list" keyword help string. */
19740#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
19741#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
19742
7336e101
SP
19743DEFUN (extcommunity_list_standard,
19744 bgp_extcommunity_list_standard_cmd,
2f8cc0e5 19745 "bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101 19746 BGP_STR
718e3744 19747 EXTCOMMUNITY_LIST_STR
19748 "Extended Community list number (standard)\n"
718e3744 19749 "Specify standard extcommunity-list\n"
5bf15956 19750 "Community list name\n"
2f8cc0e5
DA
19751 "Sequence number of an entry\n"
19752 "Sequence number\n"
718e3744 19753 "Specify community to reject\n"
19754 "Specify community to accept\n"
19755 EXTCOMMUNITY_VAL_STR)
19756{
d62a17ae 19757 int style = EXTCOMMUNITY_LIST_STANDARD;
19758 int direct = 0;
19759 char *cl_number_or_name = NULL;
2f8cc0e5 19760 char *seq = NULL;
42f914d4 19761
d62a17ae 19762 int idx = 0;
7b9a4750 19763
d62a17ae 19764 argv_find(argv, argc, "(1-99)", &idx);
19765 argv_find(argv, argc, "WORD", &idx);
19766 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 19767
409148f6 19768 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5
DA
19769 seq = argv[idx]->arg;
19770
d62a17ae 19771 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19772 : COMMUNITY_DENY;
19773 argv_find(argv, argc, "AA:NN", &idx);
19774 char *str = argv_concat(argv, argc, idx);
42f914d4 19775
2f8cc0e5 19776 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 19777 direct, style);
42f914d4 19778
d62a17ae 19779 XFREE(MTYPE_TMP, str);
42f914d4 19780
d62a17ae 19781 if (ret < 0) {
19782 community_list_perror(vty, ret);
19783 return CMD_WARNING_CONFIG_FAILED;
19784 }
42f914d4 19785
d62a17ae 19786 return CMD_SUCCESS;
718e3744 19787}
19788
7336e101
SP
19789DEFUN (extcommunity_list_name_expanded,
19790 bgp_extcommunity_list_name_expanded_cmd,
2f8cc0e5 19791 "bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
19792 BGP_STR
19793 EXTCOMMUNITY_LIST_STR
5bf15956 19794 "Extended Community list number (expanded)\n"
718e3744 19795 "Specify expanded extcommunity-list\n"
19796 "Extended Community list name\n"
2f8cc0e5
DA
19797 "Sequence number of an entry\n"
19798 "Sequence number\n"
718e3744 19799 "Specify community to reject\n"
19800 "Specify community to accept\n"
19801 "An ordered list as a regular-expression\n")
19802{
d62a17ae 19803 int style = EXTCOMMUNITY_LIST_EXPANDED;
19804 int direct = 0;
19805 char *cl_number_or_name = NULL;
2f8cc0e5 19806 char *seq = NULL;
d62a17ae 19807 int idx = 0;
7336e101 19808
d62a17ae 19809 argv_find(argv, argc, "(100-500)", &idx);
19810 argv_find(argv, argc, "WORD", &idx);
19811 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 19812
409148f6 19813 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5
DA
19814 seq = argv[idx]->arg;
19815
d62a17ae 19816 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19817 : COMMUNITY_DENY;
19818 argv_find(argv, argc, "LINE", &idx);
19819 char *str = argv_concat(argv, argc, idx);
42f914d4 19820
2f8cc0e5 19821 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 19822 direct, style);
42f914d4 19823
d62a17ae 19824 XFREE(MTYPE_TMP, str);
42f914d4 19825
d62a17ae 19826 if (ret < 0) {
19827 community_list_perror(vty, ret);
19828 return CMD_WARNING_CONFIG_FAILED;
19829 }
42f914d4 19830
d62a17ae 19831 return CMD_SUCCESS;
718e3744 19832}
19833
7336e101
SP
19834DEFUN (no_extcommunity_list_standard_all,
19835 no_bgp_extcommunity_list_standard_all_cmd,
2f8cc0e5 19836 "no bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19837 NO_STR
19838 BGP_STR
19839 EXTCOMMUNITY_LIST_STR
813d4307 19840 "Extended Community list number (standard)\n"
718e3744 19841 "Specify standard extcommunity-list\n"
5bf15956 19842 "Community list name\n"
2f8cc0e5
DA
19843 "Sequence number of an entry\n"
19844 "Sequence number\n"
718e3744 19845 "Specify community to reject\n"
19846 "Specify community to accept\n"
19847 EXTCOMMUNITY_VAL_STR)
19848{
d62a17ae 19849 int style = EXTCOMMUNITY_LIST_STANDARD;
19850 int direct = 0;
19851 char *cl_number_or_name = NULL;
d4455c89 19852 char *str = NULL;
2f8cc0e5 19853 char *seq = NULL;
d62a17ae 19854 int idx = 0;
d4455c89 19855
409148f6 19856 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5
DA
19857 seq = argv[idx]->arg;
19858
19859 idx = 0;
d4455c89
DA
19860 argv_find(argv, argc, "permit", &idx);
19861 argv_find(argv, argc, "deny", &idx);
d4455c89
DA
19862 if (idx) {
19863 direct = argv_find(argv, argc, "permit", &idx)
19864 ? COMMUNITY_PERMIT
19865 : COMMUNITY_DENY;
19866
19867 idx = 0;
19868 argv_find(argv, argc, "AA:NN", &idx);
19869 str = argv_concat(argv, argc, idx);
19870 }
19871
19872 idx = 0;
d62a17ae 19873 argv_find(argv, argc, "(1-99)", &idx);
19874 argv_find(argv, argc, "WORD", &idx);
19875 cl_number_or_name = argv[idx]->arg;
42f914d4 19876
d62a17ae 19877 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 19878 seq, direct, style);
42f914d4 19879
d62a17ae 19880 XFREE(MTYPE_TMP, str);
42f914d4 19881
d62a17ae 19882 if (ret < 0) {
19883 community_list_perror(vty, ret);
19884 return CMD_WARNING_CONFIG_FAILED;
19885 }
42f914d4 19886
d62a17ae 19887 return CMD_SUCCESS;
718e3744 19888}
19889
d4455c89
DA
19890ALIAS(no_extcommunity_list_standard_all,
19891 no_bgp_extcommunity_list_standard_all_list_cmd,
19892 "no bgp extcommunity-list <(1-99)|standard WORD>",
36d4bb44 19893 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
19894 "Extended Community list number (standard)\n"
19895 "Specify standard extcommunity-list\n"
19896 "Community list name\n")
19897
7336e101
SP
19898DEFUN (no_extcommunity_list_expanded_all,
19899 no_bgp_extcommunity_list_expanded_all_cmd,
2f8cc0e5 19900 "no bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
19901 NO_STR
19902 BGP_STR
19903 EXTCOMMUNITY_LIST_STR
718e3744 19904 "Extended Community list number (expanded)\n"
718e3744 19905 "Specify expanded extcommunity-list\n"
5bf15956 19906 "Extended Community list name\n"
2f8cc0e5
DA
19907 "Sequence number of an entry\n"
19908 "Sequence number\n"
718e3744 19909 "Specify community to reject\n"
19910 "Specify community to accept\n"
19911 "An ordered list as a regular-expression\n")
19912{
d62a17ae 19913 int style = EXTCOMMUNITY_LIST_EXPANDED;
19914 int direct = 0;
19915 char *cl_number_or_name = NULL;
d4455c89 19916 char *str = NULL;
2f8cc0e5 19917 char *seq = NULL;
d62a17ae 19918 int idx = 0;
d4455c89 19919
409148f6 19920 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5
DA
19921 seq = argv[idx]->arg;
19922
19923 idx = 0;
d4455c89
DA
19924 argv_find(argv, argc, "permit", &idx);
19925 argv_find(argv, argc, "deny", &idx);
19926
19927 if (idx) {
19928 direct = argv_find(argv, argc, "permit", &idx)
19929 ? COMMUNITY_PERMIT
19930 : COMMUNITY_DENY;
19931
19932 idx = 0;
19933 argv_find(argv, argc, "LINE", &idx);
19934 str = argv_concat(argv, argc, idx);
19935 }
19936
19937 idx = 0;
d62a17ae 19938 argv_find(argv, argc, "(100-500)", &idx);
19939 argv_find(argv, argc, "WORD", &idx);
19940 cl_number_or_name = argv[idx]->arg;
42f914d4 19941
d62a17ae 19942 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 19943 seq, direct, style);
42f914d4 19944
d62a17ae 19945 XFREE(MTYPE_TMP, str);
42f914d4 19946
d62a17ae 19947 if (ret < 0) {
19948 community_list_perror(vty, ret);
19949 return CMD_WARNING_CONFIG_FAILED;
19950 }
42f914d4 19951
d62a17ae 19952 return CMD_SUCCESS;
718e3744 19953}
19954
d4455c89
DA
19955ALIAS(no_extcommunity_list_expanded_all,
19956 no_bgp_extcommunity_list_expanded_all_list_cmd,
19957 "no bgp extcommunity-list <(100-500)|expanded WORD>",
36d4bb44 19958 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
19959 "Extended Community list number (expanded)\n"
19960 "Specify expanded extcommunity-list\n"
19961 "Extended Community list name\n")
19962
d62a17ae 19963static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 19964{
d62a17ae 19965 struct community_entry *entry;
718e3744 19966
d62a17ae 19967 for (entry = list->head; entry; entry = entry->next) {
19968 if (entry == list->head) {
19969 if (all_digit(list->name))
19970 vty_out(vty, "Extended community %s list %s\n",
19971 entry->style == EXTCOMMUNITY_LIST_STANDARD
19972 ? "standard"
19973 : "(expanded) access",
19974 list->name);
19975 else
19976 vty_out(vty,
19977 "Named extended community %s list %s\n",
19978 entry->style == EXTCOMMUNITY_LIST_STANDARD
19979 ? "standard"
19980 : "expanded",
19981 list->name);
19982 }
19983 if (entry->any)
19984 vty_out(vty, " %s\n",
19985 community_direct_str(entry->direct));
19986 else
19987 vty_out(vty, " %s %s\n",
19988 community_direct_str(entry->direct),
8d9b8ed9 19989 community_list_config_str(entry));
d62a17ae 19990 }
718e3744 19991}
19992
7336e101
SP
19993DEFUN (show_extcommunity_list,
19994 show_bgp_extcommunity_list_cmd,
19995 "show bgp extcommunity-list",
718e3744 19996 SHOW_STR
7336e101 19997 BGP_STR
718e3744 19998 "List extended-community list\n")
19999{
d62a17ae 20000 struct community_list *list;
20001 struct community_list_master *cm;
718e3744 20002
d62a17ae 20003 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20004 if (!cm)
20005 return CMD_SUCCESS;
718e3744 20006
d62a17ae 20007 for (list = cm->num.head; list; list = list->next)
20008 extcommunity_list_show(vty, list);
718e3744 20009
d62a17ae 20010 for (list = cm->str.head; list; list = list->next)
20011 extcommunity_list_show(vty, list);
718e3744 20012
d62a17ae 20013 return CMD_SUCCESS;
718e3744 20014}
20015
7336e101
SP
20016DEFUN (show_extcommunity_list_arg,
20017 show_bgp_extcommunity_list_arg_cmd,
960b69b9 20018 "show bgp extcommunity-list <(1-500)|WORD> detail",
7336e101
SP
20019 SHOW_STR
20020 BGP_STR
718e3744 20021 "List extended-community list\n"
20022 "Extcommunity-list number\n"
960b69b9 20023 "Extcommunity-list name\n"
20024 "Detailed information on extcommunity-list\n")
718e3744 20025{
d62a17ae 20026 int idx_comm_list = 3;
20027 struct community_list *list;
718e3744 20028
e237b0d2 20029 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 20030 EXTCOMMUNITY_LIST_MASTER);
20031 if (!list) {
20032 vty_out(vty, "%% Can't find extcommunity-list\n");
20033 return CMD_WARNING;
20034 }
718e3744 20035
d62a17ae 20036 extcommunity_list_show(vty, list);
718e3744 20037
d62a17ae 20038 return CMD_SUCCESS;
718e3744 20039}
6b0655a2 20040
718e3744 20041/* Display community-list and extcommunity-list configuration. */
d62a17ae 20042static int community_list_config_write(struct vty *vty)
20043{
20044 struct community_list *list;
20045 struct community_entry *entry;
20046 struct community_list_master *cm;
20047 int write = 0;
20048
20049 /* Community-list. */
20050 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20051
20052 for (list = cm->num.head; list; list = list->next)
20053 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20054 vty_out(vty,
20055 "bgp community-list %s seq %" PRId64 " %s %s\n",
20056 list->name, entry->seq,
d62a17ae 20057 community_direct_str(entry->direct),
20058 community_list_config_str(entry));
20059 write++;
20060 }
20061 for (list = cm->str.head; list; list = list->next)
20062 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20063 vty_out(vty,
20064 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
d62a17ae 20065 entry->style == COMMUNITY_LIST_STANDARD
20066 ? "standard"
20067 : "expanded",
2f8cc0e5
DA
20068 list->name, entry->seq,
20069 community_direct_str(entry->direct),
d62a17ae 20070 community_list_config_str(entry));
20071 write++;
20072 }
20073
20074 /* Extcommunity-list. */
20075 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20076
20077 for (list = cm->num.head; list; list = list->next)
20078 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20079 vty_out(vty,
20080 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
20081 list->name, entry->seq,
20082 community_direct_str(entry->direct),
d62a17ae 20083 community_list_config_str(entry));
20084 write++;
20085 }
20086 for (list = cm->str.head; list; list = list->next)
20087 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20088 vty_out(vty,
6cde4b45 20089 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
d62a17ae 20090 entry->style == EXTCOMMUNITY_LIST_STANDARD
20091 ? "standard"
20092 : "expanded",
2f8cc0e5
DA
20093 list->name, entry->seq,
20094 community_direct_str(entry->direct),
d62a17ae 20095 community_list_config_str(entry));
20096 write++;
20097 }
20098
20099
20100 /* lcommunity-list. */
20101 cm = community_list_master_lookup(bgp_clist,
20102 LARGE_COMMUNITY_LIST_MASTER);
20103
20104 for (list = cm->num.head; list; list = list->next)
20105 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20106 vty_out(vty,
6cde4b45 20107 "bgp large-community-list %s seq %" PRId64" %s %s\n",
2f8cc0e5
DA
20108 list->name, entry->seq,
20109 community_direct_str(entry->direct),
d62a17ae 20110 community_list_config_str(entry));
20111 write++;
20112 }
20113 for (list = cm->str.head; list; list = list->next)
20114 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20115 vty_out(vty,
6cde4b45 20116 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
2f8cc0e5 20117
d62a17ae 20118 entry->style == LARGE_COMMUNITY_LIST_STANDARD
20119 ? "standard"
20120 : "expanded",
2f8cc0e5 20121 list->name, entry->seq, community_direct_str(entry->direct),
d62a17ae 20122 community_list_config_str(entry));
20123 write++;
20124 }
20125
20126 return write;
20127}
20128
612c2c15 20129static int community_list_config_write(struct vty *vty);
d62a17ae 20130static struct cmd_node community_list_node = {
f4b8291f 20131 .name = "community list",
62b346ee
DL
20132 .node = COMMUNITY_LIST_NODE,
20133 .prompt = "",
612c2c15 20134 .config_write = community_list_config_write,
718e3744 20135};
20136
d62a17ae 20137static void community_list_vty(void)
20138{
612c2c15 20139 install_node(&community_list_node);
d62a17ae 20140
20141 /* Community-list. */
7336e101
SP
20142 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
20143 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
20144 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 20145 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 20146 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 20147 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
20148 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
20149 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 20150
20151 /* Extcommunity-list. */
7336e101
SP
20152 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
20153 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
20154 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
d4455c89
DA
20155 install_element(CONFIG_NODE,
20156 &no_bgp_extcommunity_list_standard_all_list_cmd);
7336e101 20157 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
d4455c89
DA
20158 install_element(CONFIG_NODE,
20159 &no_bgp_extcommunity_list_expanded_all_list_cmd);
7336e101
SP
20160 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
20161 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 20162
20163 /* Large Community List */
7336e101 20164 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
7336e101
SP
20165 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
20166 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
7336e101 20167 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
4378f57c
DA
20168 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
20169 install_element(CONFIG_NODE,
20170 &no_bgp_lcommunity_list_name_standard_all_cmd);
7336e101
SP
20171 install_element(CONFIG_NODE,
20172 &no_bgp_lcommunity_list_name_expanded_all_cmd);
20173 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
20174 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
20175 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
20176 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
20177 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
20178 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
5bf15956 20179}