]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
bgpd: remove duplicated checks from CLI
[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"
6f4eacf3 27#include "lib/printfrr.h"
718e3744 28#include "prefix.h"
29#include "plist.h"
30#include "buffer.h"
31#include "linklist.h"
32#include "stream.h"
33#include "thread.h"
34#include "log.h"
3b8b1855 35#include "memory.h"
1c0d8808 36#include "lib_vty.h"
4bf6a362 37#include "hash.h"
3f9c7369 38#include "queue.h"
039f3a34 39#include "filter.h"
5d5ba018 40#include "frrstr.h"
718e3744 41
42#include "bgpd/bgpd.h"
48ecf8f5 43#include "bgpd/bgp_attr_evpn.h"
4bf6a362 44#include "bgpd/bgp_advertise.h"
718e3744 45#include "bgpd/bgp_attr.h"
46#include "bgpd/bgp_aspath.h"
47#include "bgpd/bgp_community.h"
4bf6a362 48#include "bgpd/bgp_ecommunity.h"
57d187bc 49#include "bgpd/bgp_lcommunity.h"
4bf6a362 50#include "bgpd/bgp_damp.h"
718e3744 51#include "bgpd/bgp_debug.h"
14454c9f 52#include "bgpd/bgp_errors.h"
e0701b79 53#include "bgpd/bgp_fsm.h"
4bf6a362 54#include "bgpd/bgp_nexthop.h"
718e3744 55#include "bgpd/bgp_open.h"
4bf6a362 56#include "bgpd/bgp_regex.h"
718e3744 57#include "bgpd/bgp_route.h"
c016b6c7 58#include "bgpd/bgp_mplsvpn.h"
718e3744 59#include "bgpd/bgp_zebra.h"
fee0f4c6 60#include "bgpd/bgp_table.h"
94f2b392 61#include "bgpd/bgp_vty.h"
165b5fff 62#include "bgpd/bgp_mpath.h"
cb1faec9 63#include "bgpd/bgp_packet.h"
3f9c7369 64#include "bgpd/bgp_updgrp.h"
c43ed2e4 65#include "bgpd/bgp_bfd.h"
555e09d4 66#include "bgpd/bgp_io.h"
94c2f693 67#include "bgpd/bgp_evpn.h"
dd65f45e 68#include "bgpd/bgp_evpn_vty.h"
b5e140c8 69#include "bgpd/bgp_evpn_mh.h"
dcc68b5e 70#include "bgpd/bgp_addpath.h"
48ecf8f5 71#include "bgpd/bgp_mac.h"
dd65f45e 72#include "bgpd/bgp_flowspec.h"
49e5a4a0 73#ifdef ENABLE_BGP_VNC
dd65f45e
DL
74#include "bgpd/rfapi/bgp_rfapi_cfg.h"
75#endif
76
ff8a8a7a
CS
77#include "northbound.h"
78#include "northbound_cli.h"
79#include "bgpd/bgp_nb.h"
80
81
5d5393b9 82FRR_CFG_DEFAULT_BOOL(BGP_IMPORT_CHECK,
62282e83
DS
83 {
84 .val_bool = false,
85 .match_profile = "traditional",
86 .match_version = "< 7.4",
87 },
88 { .val_bool = true },
67b0f40c 89);
5d5393b9 90FRR_CFG_DEFAULT_BOOL(BGP_SHOW_HOSTNAME,
4c1458b5
DL
91 { .val_bool = true, .match_profile = "datacenter", },
92 { .val_bool = false },
67b0f40c 93);
aef999a2
DA
94FRR_CFG_DEFAULT_BOOL(BGP_SHOW_NEXTHOP_HOSTNAME,
95 { .val_bool = true, .match_profile = "datacenter", },
96 { .val_bool = false },
67b0f40c 97);
5d5393b9 98FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
4c1458b5
DL
99 { .val_bool = true, .match_profile = "datacenter", },
100 { .val_bool = false },
67b0f40c 101);
5d5393b9 102FRR_CFG_DEFAULT_BOOL(BGP_DETERMINISTIC_MED,
4c1458b5
DL
103 { .val_bool = true, .match_profile = "datacenter", },
104 { .val_bool = false },
67b0f40c 105);
5d5393b9
DL
106FRR_CFG_DEFAULT_ULONG(BGP_CONNECT_RETRY,
107 { .val_ulong = 10, .match_profile = "datacenter", },
108 { .val_ulong = 120 },
67b0f40c 109);
5d5393b9
DL
110FRR_CFG_DEFAULT_ULONG(BGP_HOLDTIME,
111 { .val_ulong = 9, .match_profile = "datacenter", },
112 { .val_ulong = 180 },
67b0f40c 113);
5d5393b9
DL
114FRR_CFG_DEFAULT_ULONG(BGP_KEEPALIVE,
115 { .val_ulong = 3, .match_profile = "datacenter", },
116 { .val_ulong = 60 },
67b0f40c 117);
1d3fdccf
DA
118FRR_CFG_DEFAULT_BOOL(BGP_EBGP_REQUIRES_POLICY,
119 { .val_bool = false, .match_profile = "datacenter", },
120 { .val_bool = false, .match_version = "< 7.4", },
121 { .val_bool = true },
67b0f40c 122);
2adac256
DA
123FRR_CFG_DEFAULT_BOOL(BGP_SUPPRESS_DUPLICATES,
124 { .val_bool = false, .match_version = "< 7.6", },
125 { .val_bool = true },
67b0f40c 126);
5d5393b9 127
dd65f45e
DL
128DEFINE_HOOK(bgp_inst_config_write,
129 (struct bgp *bgp, struct vty *vty),
8451921b
DL
130 (bgp, vty));
131DEFINE_HOOK(bgp_snmp_update_last_changed, (struct bgp *bgp), (bgp));
718e3744 132
36235319
QY
133#define GR_NO_OPER \
134 "The Graceful Restart No Operation was executed as cmd same as previous one."
135#define GR_INVALID \
136 "The Graceful Restart command used is not valid at this moment."
d62a17ae 137static struct peer_group *listen_range_exists(struct bgp *bgp,
138 struct prefix *range, int exact);
139
055679e9 140/* Show BGP peer's information. */
141enum show_type {
142 show_all,
143 show_peer,
144 show_ipv4_all,
145 show_ipv6_all,
146 show_ipv4_peer,
147 show_ipv6_peer
148};
149
36235319
QY
150static struct peer_group *listen_range_exists(struct bgp *bgp,
151 struct prefix *range, int exact);
2986cac2 152
36235319
QY
153static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
154 struct bgp *bgp,
155 bool use_json,
156 json_object *json);
2986cac2 157
36235319
QY
158static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
159 enum show_type type,
160 const char *ip_str,
161 afi_t afi, bool use_json);
2986cac2 162
f4b8ec07
CS
163static int peer_and_group_lookup_nb(struct vty *vty, const char *peer_str,
164 char *base_xpath, int xpath_len,
165 char *abs_xpath);
166
d62a17ae 167static enum node_type bgp_node_type(afi_t afi, safi_t safi)
168{
169 switch (afi) {
170 case AFI_IP:
171 switch (safi) {
172 case SAFI_UNICAST:
173 return BGP_IPV4_NODE;
d62a17ae 174 case SAFI_MULTICAST:
175 return BGP_IPV4M_NODE;
d62a17ae 176 case SAFI_LABELED_UNICAST:
177 return BGP_IPV4L_NODE;
d62a17ae 178 case SAFI_MPLS_VPN:
179 return BGP_VPNV4_NODE;
7c40bf39 180 case SAFI_FLOWSPEC:
181 return BGP_FLOWSPECV4_NODE;
5c525538
RW
182 default:
183 /* not expected */
184 return BGP_IPV4_NODE;
d62a17ae 185 }
186 break;
187 case AFI_IP6:
188 switch (safi) {
189 case SAFI_UNICAST:
190 return BGP_IPV6_NODE;
d62a17ae 191 case SAFI_MULTICAST:
192 return BGP_IPV6M_NODE;
d62a17ae 193 case SAFI_LABELED_UNICAST:
194 return BGP_IPV6L_NODE;
d62a17ae 195 case SAFI_MPLS_VPN:
196 return BGP_VPNV6_NODE;
7c40bf39 197 case SAFI_FLOWSPEC:
198 return BGP_FLOWSPECV6_NODE;
5c525538
RW
199 default:
200 /* not expected */
201 return BGP_IPV4_NODE;
d62a17ae 202 }
203 break;
204 case AFI_L2VPN:
205 return BGP_EVPN_NODE;
b26f891d 206 case AFI_UNSPEC:
d62a17ae 207 case AFI_MAX:
208 // We should never be here but to clarify the switch statement..
209 return BGP_IPV4_NODE;
d62a17ae 210 }
211
212 // Impossible to happen
213 return BGP_IPV4_NODE;
f51bae9c 214}
20eb8864 215
5cb5f4d0
DD
216static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
217{
7d0d37de
DS
218 if (afi == AFI_IP) {
219 if (safi == SAFI_UNICAST)
220 return "IPv4 Unicast";
221 if (safi == SAFI_MULTICAST)
222 return "IPv4 Multicast";
223 if (safi == SAFI_LABELED_UNICAST)
224 return "IPv4 Labeled Unicast";
225 if (safi == SAFI_MPLS_VPN)
226 return "IPv4 VPN";
227 if (safi == SAFI_ENCAP)
228 return "IPv4 Encap";
229 if (safi == SAFI_FLOWSPEC)
230 return "IPv4 Flowspec";
231 } else if (afi == AFI_IP6) {
232 if (safi == SAFI_UNICAST)
233 return "IPv6 Unicast";
234 if (safi == SAFI_MULTICAST)
235 return "IPv6 Multicast";
236 if (safi == SAFI_LABELED_UNICAST)
237 return "IPv6 Labeled Unicast";
238 if (safi == SAFI_MPLS_VPN)
239 return "IPv6 VPN";
240 if (safi == SAFI_ENCAP)
241 return "IPv6 Encap";
242 if (safi == SAFI_FLOWSPEC)
243 return "IPv6 Flowspec";
244 } else if (afi == AFI_L2VPN) {
245 if (safi == SAFI_EVPN)
246 return "L2VPN EVPN";
247 }
248
249 return "Unknown";
5cb5f4d0
DD
250}
251
252/*
253 * Please note that we have intentionally camelCased
254 * the return strings here. So if you want
255 * to use this function, please ensure you
256 * are doing this within json output
257 */
258static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
259{
7d0d37de
DS
260 if (afi == AFI_IP) {
261 if (safi == SAFI_UNICAST)
262 return "ipv4Unicast";
263 if (safi == SAFI_MULTICAST)
264 return "ipv4Multicast";
265 if (safi == SAFI_LABELED_UNICAST)
266 return "ipv4LabeledUnicast";
267 if (safi == SAFI_MPLS_VPN)
268 return "ipv4Vpn";
269 if (safi == SAFI_ENCAP)
270 return "ipv4Encap";
271 if (safi == SAFI_FLOWSPEC)
272 return "ipv4Flowspec";
273 } else if (afi == AFI_IP6) {
274 if (safi == SAFI_UNICAST)
275 return "ipv6Unicast";
276 if (safi == SAFI_MULTICAST)
277 return "ipv6Multicast";
278 if (safi == SAFI_LABELED_UNICAST)
279 return "ipv6LabeledUnicast";
280 if (safi == SAFI_MPLS_VPN)
281 return "ipv6Vpn";
282 if (safi == SAFI_ENCAP)
283 return "ipv6Encap";
284 if (safi == SAFI_FLOWSPEC)
285 return "ipv6Flowspec";
286 } else if (afi == AFI_L2VPN) {
287 if (safi == SAFI_EVPN)
288 return "l2VpnEvpn";
289 }
290
291 return "Unknown";
5cb5f4d0
DD
292}
293
37a87b8f
CS
294/* return string maps to afi-safi specific container names
295 * defined in bgp yang file.
296 */
297const char *bgp_afi_safi_get_container_str(afi_t afi, safi_t safi)
298{
7d0d37de
DS
299 if (afi == AFI_IP) {
300 if (safi == SAFI_UNICAST)
301 return "ipv4-unicast";
302 if (safi == SAFI_MULTICAST)
303 return "ipv4-multicast";
304 if (safi == SAFI_LABELED_UNICAST)
305 return "ipv4-labeled-unicast";
306 if (safi == SAFI_MPLS_VPN)
307 return "l3vpn-ipv4-unicast";
308 if (safi == SAFI_FLOWSPEC)
309 return "ipv4-flowspec";
310 } else if (afi == AFI_IP6) {
311 if (safi == SAFI_UNICAST)
312 return "ipv6-unicast";
313 if (safi == SAFI_MULTICAST)
314 return "ipv6-multicast";
315 if (safi == SAFI_LABELED_UNICAST)
316 return "ipv6-labeled-unicast";
317 if (safi == SAFI_MPLS_VPN)
318 return "l3vpn-ipv6-unicast";
319 if (safi == SAFI_FLOWSPEC)
320 return "ipv6-flowspec";
321 } else if (afi == AFI_L2VPN) {
322 if (safi == SAFI_EVPN)
323 return "l2vpn-evpn";
324 }
325
326 return "Unknown";
37a87b8f
CS
327}
328
718e3744 329/* Utility function to get address family from current node. */
d62a17ae 330afi_t bgp_node_afi(struct vty *vty)
331{
332 afi_t afi;
333 switch (vty->node) {
334 case BGP_IPV6_NODE:
335 case BGP_IPV6M_NODE:
336 case BGP_IPV6L_NODE:
337 case BGP_VPNV6_NODE:
7c40bf39 338 case BGP_FLOWSPECV6_NODE:
d62a17ae 339 afi = AFI_IP6;
340 break;
341 case BGP_EVPN_NODE:
342 afi = AFI_L2VPN;
343 break;
344 default:
345 afi = AFI_IP;
346 break;
347 }
348 return afi;
718e3744 349}
350
351/* Utility function to get subsequent address family from current
352 node. */
d62a17ae 353safi_t bgp_node_safi(struct vty *vty)
354{
355 safi_t safi;
356 switch (vty->node) {
357 case BGP_VPNV4_NODE:
358 case BGP_VPNV6_NODE:
359 safi = SAFI_MPLS_VPN;
360 break;
361 case BGP_IPV4M_NODE:
362 case BGP_IPV6M_NODE:
363 safi = SAFI_MULTICAST;
364 break;
365 case BGP_EVPN_NODE:
366 safi = SAFI_EVPN;
367 break;
368 case BGP_IPV4L_NODE:
369 case BGP_IPV6L_NODE:
370 safi = SAFI_LABELED_UNICAST;
371 break;
7c40bf39 372 case BGP_FLOWSPECV4_NODE:
373 case BGP_FLOWSPECV6_NODE:
374 safi = SAFI_FLOWSPEC;
375 break;
d62a17ae 376 default:
377 safi = SAFI_UNICAST;
378 break;
379 }
380 return safi;
718e3744 381}
382
55f91488
QY
383/**
384 * Converts an AFI in string form to afi_t
385 *
386 * @param afi string, one of
387 * - "ipv4"
388 * - "ipv6"
81cf0de5 389 * - "l2vpn"
55f91488
QY
390 * @return the corresponding afi_t
391 */
d62a17ae 392afi_t bgp_vty_afi_from_str(const char *afi_str)
393{
394 afi_t afi = AFI_MAX; /* unknown */
395 if (strmatch(afi_str, "ipv4"))
396 afi = AFI_IP;
397 else if (strmatch(afi_str, "ipv6"))
398 afi = AFI_IP6;
81cf0de5
CS
399 else if (strmatch(afi_str, "l2vpn"))
400 afi = AFI_L2VPN;
d62a17ae 401 return afi;
402}
403
404int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
405 afi_t *afi)
406{
407 int ret = 0;
408 if (argv_find(argv, argc, "ipv4", index)) {
409 ret = 1;
410 if (afi)
411 *afi = AFI_IP;
412 } else if (argv_find(argv, argc, "ipv6", index)) {
413 ret = 1;
414 if (afi)
415 *afi = AFI_IP6;
8688b3e7
DS
416 } else if (argv_find(argv, argc, "l2vpn", index)) {
417 ret = 1;
418 if (afi)
419 *afi = AFI_L2VPN;
d62a17ae 420 }
421 return ret;
46f296b4
LB
422}
423
375a2e67 424/* supports <unicast|multicast|vpn|labeled-unicast> */
d62a17ae 425safi_t bgp_vty_safi_from_str(const char *safi_str)
426{
427 safi_t safi = SAFI_MAX; /* unknown */
428 if (strmatch(safi_str, "multicast"))
429 safi = SAFI_MULTICAST;
430 else if (strmatch(safi_str, "unicast"))
431 safi = SAFI_UNICAST;
432 else if (strmatch(safi_str, "vpn"))
433 safi = SAFI_MPLS_VPN;
81cf0de5
CS
434 else if (strmatch(safi_str, "evpn"))
435 safi = SAFI_EVPN;
d62a17ae 436 else if (strmatch(safi_str, "labeled-unicast"))
437 safi = SAFI_LABELED_UNICAST;
7c40bf39 438 else if (strmatch(safi_str, "flowspec"))
439 safi = SAFI_FLOWSPEC;
d62a17ae 440 return safi;
441}
442
443int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
444 safi_t *safi)
445{
446 int ret = 0;
447 if (argv_find(argv, argc, "unicast", index)) {
448 ret = 1;
449 if (safi)
450 *safi = SAFI_UNICAST;
451 } else if (argv_find(argv, argc, "multicast", index)) {
452 ret = 1;
453 if (safi)
454 *safi = SAFI_MULTICAST;
455 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
456 ret = 1;
457 if (safi)
458 *safi = SAFI_LABELED_UNICAST;
459 } else if (argv_find(argv, argc, "vpn", index)) {
460 ret = 1;
461 if (safi)
462 *safi = SAFI_MPLS_VPN;
8688b3e7
DS
463 } else if (argv_find(argv, argc, "evpn", index)) {
464 ret = 1;
465 if (safi)
466 *safi = SAFI_EVPN;
7c40bf39 467 } else if (argv_find(argv, argc, "flowspec", index)) {
468 ret = 1;
469 if (safi)
470 *safi = SAFI_FLOWSPEC;
d62a17ae 471 }
472 return ret;
46f296b4
LB
473}
474
5d5393b9
DL
475int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
476 enum bgp_instance_type inst_type)
477{
478 int ret = bgp_get(bgp, as, name, inst_type);
479
480 if (ret == BGP_CREATED) {
481 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
d43114f3 482 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
5d5393b9
DL
483
484 if (DFLT_BGP_IMPORT_CHECK)
892fedb6 485 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
5d5393b9 486 if (DFLT_BGP_SHOW_HOSTNAME)
892fedb6 487 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
aef999a2
DA
488 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
489 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
5d5393b9 490 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
892fedb6 491 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
5d5393b9 492 if (DFLT_BGP_DETERMINISTIC_MED)
892fedb6 493 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
1d3fdccf
DA
494 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
495 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2adac256
DA
496 if (DFLT_BGP_SUPPRESS_DUPLICATES)
497 SET_FLAG((*bgp)->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
5d5393b9
DL
498
499 ret = BGP_SUCCESS;
500 }
501 return ret;
502}
503
7eeee51e 504/*
f212a857 505 * bgp_vty_find_and_parse_afi_safi_bgp
7eeee51e 506 *
f212a857
DS
507 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
508 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
7eeee51e
DS
509 * to appropriate values for the calling function. This is to allow the
510 * calling function to make decisions appropriate for the show command
511 * that is being parsed.
512 *
513 * The show commands are generally of the form:
d62a17ae 514 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
515 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
7eeee51e
DS
516 *
517 * Since we use argv_find if the show command in particular doesn't have:
518 * [ip]
18c57037 519 * [<view|vrf> VIEWVRFNAME]
375a2e67 520 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
7eeee51e
DS
521 * The command parsing should still be ok.
522 *
523 * vty -> The vty for the command so we can output some useful data in
524 * the event of a parse error in the vrf.
525 * argv -> The command tokens
526 * argc -> How many command tokens we have
d62a17ae 527 * idx -> The current place in the command, generally should be 0 for this
528 * function
7eeee51e
DS
529 * afi -> The parsed afi if it was included in the show command, returned here
530 * safi -> The parsed safi if it was included in the show command, returned here
f212a857 531 * bgp -> Pointer to the bgp data structure we need to fill in.
52e5b8c4 532 * use_json -> json is configured or not
7eeee51e
DS
533 *
534 * The function returns the correct location in the parse tree for the
535 * last token found.
0e37c258
DS
536 *
537 * Returns 0 for failure to parse correctly, else the idx position of where
538 * it found the last token.
7eeee51e 539 */
d62a17ae 540int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
541 struct cmd_token **argv, int argc,
542 int *idx, afi_t *afi, safi_t *safi,
9f049418 543 struct bgp **bgp, bool use_json)
d62a17ae 544{
545 char *vrf_name = NULL;
546
547 assert(afi);
548 assert(safi);
549 assert(bgp);
550
551 if (argv_find(argv, argc, "ip", idx))
552 *afi = AFI_IP;
553
9a8bdf1c 554 if (argv_find(argv, argc, "view", idx))
d62a17ae 555 vrf_name = argv[*idx + 1]->arg;
9a8bdf1c
PG
556 else if (argv_find(argv, argc, "vrf", idx)) {
557 vrf_name = argv[*idx + 1]->arg;
558 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
559 vrf_name = NULL;
560 }
561 if (vrf_name) {
d62a17ae 562 if (strmatch(vrf_name, "all"))
563 *bgp = NULL;
564 else {
565 *bgp = bgp_lookup_by_name(vrf_name);
566 if (!*bgp) {
52e5b8c4
SP
567 if (use_json) {
568 json_object *json = NULL;
569 json = json_object_new_object();
570 json_object_string_add(
571 json, "warning",
572 "View/Vrf is unknown");
573 vty_out(vty, "%s\n",
574 json_object_to_json_string_ext(json,
575 JSON_C_TO_STRING_PRETTY));
576 json_object_free(json);
577 }
ca61fd25
DS
578 else
579 vty_out(vty, "View/Vrf %s is unknown\n",
580 vrf_name);
d62a17ae 581 *idx = 0;
582 return 0;
583 }
584 }
585 } else {
586 *bgp = bgp_get_default();
587 if (!*bgp) {
52e5b8c4
SP
588 if (use_json) {
589 json_object *json = NULL;
590 json = json_object_new_object();
591 json_object_string_add(
592 json, "warning",
593 "Default BGP instance not found");
594 vty_out(vty, "%s\n",
595 json_object_to_json_string_ext(json,
596 JSON_C_TO_STRING_PRETTY));
597 json_object_free(json);
598 }
ca61fd25
DS
599 else
600 vty_out(vty,
601 "Default BGP instance not found\n");
d62a17ae 602 *idx = 0;
603 return 0;
604 }
605 }
606
607 if (argv_find_and_parse_afi(argv, argc, idx, afi))
608 argv_find_and_parse_safi(argv, argc, idx, safi);
609
610 *idx += 1;
611 return *idx;
612}
613
f4b8ec07 614bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
d62a17ae 615{
616 struct interface *ifp = NULL;
617
618 if (su->sa.sa_family == AF_INET)
619 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
620 else if (su->sa.sa_family == AF_INET6)
621 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
622 su->sin6.sin6_scope_id,
623 bgp->vrf_id);
624
625 if (ifp)
3dc339cd 626 return true;
d62a17ae 627
3dc339cd 628 return false;
718e3744 629}
630
718e3744 631/* Utility function for looking up peer or peer group. */
f14e6fdb
DS
632/* This is used only for configuration, so disallow if attempted on
633 * a dynamic neighbor.
634 */
d62a17ae 635struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
636{
637 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
638 int ret;
639 union sockunion su;
640 struct peer *peer = NULL;
641 struct peer_group *group = NULL;
642
643 if (!bgp) {
644 return NULL;
645 }
646
647 ret = str2sockunion(peer_str, &su);
648 if (ret == 0) {
649 /* IP address, locate peer. */
650 peer = peer_lookup(bgp, &su);
651 } else {
652 /* Not IP, could match either peer configured on interface or a
653 * group. */
654 peer = peer_lookup_by_conf_if(bgp, peer_str);
655 if (!peer)
656 group = peer_group_lookup(bgp, peer_str);
657 }
658
659 if (peer) {
660 if (peer_dynamic_neighbor(peer)) {
661 vty_out(vty,
662 "%% Operation not allowed on a dynamic neighbor\n");
663 return NULL;
664 }
665
666 return peer;
667 }
668
669 if (group)
670 return group->conf;
671
672 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
673
674 return NULL;
675}
676
f4b8ec07
CS
677int bgp_nb_errmsg_return(char *errmsg, size_t errmsg_len, int ret)
678{
679 const char *str = NULL;
680
681 switch (ret) {
682 case BGP_ERR_INVALID_VALUE:
683 str = "Invalid value";
684 break;
685 case BGP_ERR_INVALID_FLAG:
686 str = "Invalid flag";
687 break;
688 case BGP_ERR_PEER_GROUP_SHUTDOWN:
689 str = "Peer-group has been shutdown. Activate the peer-group first";
690 break;
691 case BGP_ERR_PEER_FLAG_CONFLICT:
692 str = "Can't set override-capability and strict-capability-match at the same time";
693 break;
694 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
695 str = "Specify remote-as or peer-group remote AS first";
696 break;
697 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
698 str = "Cannot change the peer-group. Deconfigure first";
699 break;
700 case BGP_ERR_PEER_GROUP_MISMATCH:
701 str = "Peer is not a member of this peer-group";
702 break;
703 case BGP_ERR_PEER_FILTER_CONFLICT:
704 str = "Prefix/distribute list can not co-exist";
705 break;
706 case BGP_ERR_NOT_INTERNAL_PEER:
707 str = "Invalid command. Not an internal neighbor";
708 break;
709 case BGP_ERR_REMOVE_PRIVATE_AS:
710 str = "remove-private-AS cannot be configured for IBGP peers";
711 break;
712 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
713 str = "Local-AS allowed only for EBGP peers";
714 break;
715 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
716 str = "Cannot have local-as same as BGP AS number";
717 break;
718 case BGP_ERR_TCPSIG_FAILED:
719 str = "Error while applying TCP-Sig to session(s)";
720 break;
721 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
722 str = "ebgp-multihop and ttl-security cannot be configured together";
723 break;
724 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
725 str = "ttl-security only allowed for EBGP peers";
726 break;
727 case BGP_ERR_AS_OVERRIDE:
728 str = "as-override cannot be configured for IBGP peers";
729 break;
730 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
731 str = "Invalid limit for number of dynamic neighbors";
732 break;
733 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
734 str = "Dynamic neighbor listen range already exists";
735 break;
736 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
737 str = "Operation not allowed on a dynamic neighbor";
738 break;
739 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
740 str = "Operation not allowed on a directly connected neighbor";
741 break;
742 case BGP_ERR_PEER_SAFI_CONFLICT:
a59803d0 743 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
f4b8ec07
CS
744 break;
745 case BGP_ERR_GR_INVALID_CMD:
746 str = "The Graceful Restart command used is not valid at this moment.";
747 break;
748 case BGP_ERR_GR_OPERATION_FAILED:
749 str = "The Graceful Restart Operation failed due to an err.";
750 break;
751 case BGP_GR_NO_OPERATION:
752 str = GR_NO_OPER;
753 break;
754 case BGP_ERR_PEER_GROUP_MEMBER:
755 str = "Peer-group member cannot override remote-as of peer-group";
756 break;
757 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
758 str = "Peer-group members must be all internal or all external";
759 break;
760 }
761 if (str) {
762 snprintf(errmsg, errmsg_len, "%s", str);
763 return -1;
764 }
765
766 return 0;
767}
768
d62a17ae 769int bgp_vty_return(struct vty *vty, int ret)
770{
771 const char *str = NULL;
772
773 switch (ret) {
774 case BGP_ERR_INVALID_VALUE:
775 str = "Invalid value";
776 break;
777 case BGP_ERR_INVALID_FLAG:
778 str = "Invalid flag";
779 break;
780 case BGP_ERR_PEER_GROUP_SHUTDOWN:
781 str = "Peer-group has been shutdown. Activate the peer-group first";
782 break;
783 case BGP_ERR_PEER_FLAG_CONFLICT:
784 str = "Can't set override-capability and strict-capability-match at the same time";
785 break;
786 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
787 str = "Specify remote-as or peer-group remote AS first";
788 break;
789 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
790 str = "Cannot change the peer-group. Deconfigure first";
791 break;
792 case BGP_ERR_PEER_GROUP_MISMATCH:
793 str = "Peer is not a member of this peer-group";
794 break;
795 case BGP_ERR_PEER_FILTER_CONFLICT:
796 str = "Prefix/distribute list can not co-exist";
797 break;
798 case BGP_ERR_NOT_INTERNAL_PEER:
799 str = "Invalid command. Not an internal neighbor";
800 break;
801 case BGP_ERR_REMOVE_PRIVATE_AS:
802 str = "remove-private-AS cannot be configured for IBGP peers";
803 break;
804 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
805 str = "Local-AS allowed only for EBGP peers";
806 break;
807 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
808 str = "Cannot have local-as same as BGP AS number";
809 break;
810 case BGP_ERR_TCPSIG_FAILED:
811 str = "Error while applying TCP-Sig to session(s)";
812 break;
813 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
814 str = "ebgp-multihop and ttl-security cannot be configured together";
815 break;
816 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
817 str = "ttl-security only allowed for EBGP peers";
818 break;
819 case BGP_ERR_AS_OVERRIDE:
820 str = "as-override cannot be configured for IBGP peers";
821 break;
822 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
823 str = "Invalid limit for number of dynamic neighbors";
824 break;
825 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
826 str = "Dynamic neighbor listen range already exists";
827 break;
828 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
829 str = "Operation not allowed on a dynamic neighbor";
830 break;
831 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
832 str = "Operation not allowed on a directly connected neighbor";
833 break;
834 case BGP_ERR_PEER_SAFI_CONFLICT:
a59803d0 835 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
055679e9 836 break;
837 case BGP_ERR_GR_INVALID_CMD:
838 str = "The Graceful Restart command used is not valid at this moment.";
839 break;
840 case BGP_ERR_GR_OPERATION_FAILED:
841 str = "The Graceful Restart Operation failed due to an err.";
842 break;
843 case BGP_GR_NO_OPERATION:
844 str = GR_NO_OPER;
d62a17ae 845 break;
846 }
847 if (str) {
848 vty_out(vty, "%% %s\n", str);
849 return CMD_WARNING_CONFIG_FAILED;
850 }
851 return CMD_SUCCESS;
718e3744 852}
853
7aafcaca 854/* BGP clear sort. */
d62a17ae 855enum clear_sort {
856 clear_all,
857 clear_peer,
858 clear_group,
859 clear_external,
860 clear_as
7aafcaca
DS
861};
862
ff8a8a7a
CS
863static void bgp_clear_vty_error(struct peer *peer, afi_t afi, safi_t safi,
864 int error, char *errmsg, size_t errmsg_len)
d62a17ae 865{
866 switch (error) {
867 case BGP_ERR_AF_UNCONFIGURED:
ff8a8a7a
CS
868 snprintf(errmsg, errmsg_len,
869 "%%BGP: Enable %s address family for the neighbor %s",
870 get_afi_safi_str(afi, safi, false), peer->host);
d62a17ae 871 break;
872 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
ff8a8a7a
CS
873 snprintf(
874 errmsg, errmsg_len,
875 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig",
d62a17ae 876 peer->host);
877 break;
878 default:
879 break;
880 }
7aafcaca
DS
881}
882
dc912615 883static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
c368171c 884 struct listnode **nnode, enum bgp_clear_type stype)
dc912615
DS
885{
886 int ret = 0;
2adac256 887 struct peer_af *paf;
dc912615
DS
888
889 /* if afi/.safi not specified, spin thru all of them */
890 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
891 afi_t tmp_afi;
892 safi_t tmp_safi;
893
894 FOREACH_AFI_SAFI (tmp_afi, tmp_safi) {
2adac256
DA
895 paf = peer_af_find(peer, tmp_afi, tmp_safi);
896 if (paf && paf->subgroup)
897 SET_FLAG(paf->subgroup->sflags,
898 SUBGRP_STATUS_FORCE_UPDATES);
899
dc912615
DS
900 if (!peer->afc[tmp_afi][tmp_safi])
901 continue;
902
903 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 904 ret = peer_clear(peer, nnode);
dc912615
DS
905 else
906 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
907 stype);
908 }
909 /* if afi specified and safi not, spin thru safis on this afi */
910 } else if (safi == SAFI_UNSPEC) {
911 safi_t tmp_safi;
912
913 for (tmp_safi = SAFI_UNICAST;
914 tmp_safi < SAFI_MAX; tmp_safi++) {
915 if (!peer->afc[afi][tmp_safi])
916 continue;
917
2adac256
DA
918 paf = peer_af_find(peer, afi, tmp_safi);
919 if (paf && paf->subgroup)
920 SET_FLAG(paf->subgroup->sflags,
921 SUBGRP_STATUS_FORCE_UPDATES);
922
dc912615 923 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 924 ret = peer_clear(peer, nnode);
dc912615
DS
925 else
926 ret = peer_clear_soft(peer, afi,
927 tmp_safi, stype);
928 }
929 /* both afi/safi specified, let the caller know if not defined */
930 } else {
931 if (!peer->afc[afi][safi])
932 return 1;
933
2adac256
DA
934 paf = peer_af_find(peer, afi, safi);
935 if (paf && paf->subgroup)
936 SET_FLAG(paf->subgroup->sflags,
937 SUBGRP_STATUS_FORCE_UPDATES);
938
dc912615 939 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 940 ret = peer_clear(peer, nnode);
dc912615
DS
941 else
942 ret = peer_clear_soft(peer, afi, safi, stype);
943 }
944
945 return ret;
946}
947
7aafcaca 948/* `clear ip bgp' functions. */
ff8a8a7a 949static int bgp_clear(struct bgp *bgp, afi_t afi, safi_t safi,
d62a17ae 950 enum clear_sort sort, enum bgp_clear_type stype,
ff8a8a7a 951 const char *arg, char *errmsg, size_t errmsg_len)
d62a17ae 952{
dc912615 953 int ret = 0;
3ae8bfa5 954 bool found = false;
d62a17ae 955 struct peer *peer;
dc95985f 956
957 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
d62a17ae 958
959 /* Clear all neighbors. */
960 /*
961 * Pass along pointer to next node to peer_clear() when walking all
3ae8bfa5
PM
962 * nodes on the BGP instance as that may get freed if it is a
963 * doppelganger
d62a17ae 964 */
965 if (sort == clear_all) {
966 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dc95985f 967
968 bgp_peer_gr_flags_update(peer);
969
36235319 970 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
dc95985f 971 gr_router_detected = true;
972
c368171c 973 ret = bgp_peer_clear(peer, afi, safi, &nnode,
dc912615 974 stype);
d62a17ae 975
976 if (ret < 0)
ff8a8a7a
CS
977 bgp_clear_vty_error(peer, afi, safi, ret,
978 errmsg, errmsg_len);
dc95985f 979 }
980
36235319
QY
981 if (gr_router_detected
982 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 983 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
984 } else if (!gr_router_detected
985 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 986 bgp_zebra_send_capabilities(bgp, true);
04b6bdc0 987 }
d62a17ae 988
989 /* This is to apply read-only mode on this clear. */
990 if (stype == BGP_CLEAR_SOFT_NONE)
991 bgp->update_delay_over = 0;
992
993 return CMD_SUCCESS;
7aafcaca
DS
994 }
995
3ae8bfa5 996 /* Clear specified neighbor. */
d62a17ae 997 if (sort == clear_peer) {
998 union sockunion su;
d62a17ae 999
1000 /* Make sockunion for lookup. */
1001 ret = str2sockunion(arg, &su);
1002 if (ret < 0) {
1003 peer = peer_lookup_by_conf_if(bgp, arg);
1004 if (!peer) {
1005 peer = peer_lookup_by_hostname(bgp, arg);
1006 if (!peer) {
ff8a8a7a
CS
1007 snprintf(
1008 errmsg, errmsg_len,
1009 "Malformed address or name: %s",
d62a17ae 1010 arg);
1011 return CMD_WARNING;
1012 }
1013 }
1014 } else {
1015 peer = peer_lookup(bgp, &su);
1016 if (!peer) {
ff8a8a7a
CS
1017 snprintf(errmsg, errmsg_len,
1018 "%%BGP: Unknown neighbor - \"%s\"",
1019 arg);
d62a17ae 1020 return CMD_WARNING;
1021 }
1022 }
7aafcaca 1023
dc95985f 1024 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1025 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1026
dc912615
DS
1027 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1028
1029 /* if afi/safi not defined for this peer, let caller know */
1030 if (ret == 1)
3ae8bfa5 1031 ret = BGP_ERR_AF_UNCONFIGURED;
7aafcaca 1032
d62a17ae 1033 if (ret < 0)
ff8a8a7a
CS
1034 bgp_clear_vty_error(peer, afi, safi, ret, errmsg,
1035 errmsg_len);
7aafcaca 1036
d62a17ae 1037 return CMD_SUCCESS;
7aafcaca 1038 }
7aafcaca 1039
3ae8bfa5 1040 /* Clear all neighbors belonging to a specific peer-group. */
d62a17ae 1041 if (sort == clear_group) {
1042 struct peer_group *group;
7aafcaca 1043
d62a17ae 1044 group = peer_group_lookup(bgp, arg);
1045 if (!group) {
ff8a8a7a
CS
1046 snprintf(errmsg, errmsg_len,
1047 "%%BGP: No such peer-group %s", arg);
d62a17ae 1048 return CMD_WARNING;
1049 }
1050
1051 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
c368171c 1052 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 1053
d62a17ae 1054 if (ret < 0)
ff8a8a7a
CS
1055 bgp_clear_vty_error(peer, afi, safi, ret,
1056 errmsg, errmsg_len);
3ae8bfa5
PM
1057 else
1058 found = true;
d62a17ae 1059 }
3ae8bfa5
PM
1060
1061 if (!found)
ff8a8a7a
CS
1062 snprintf(
1063 errmsg, errmsg_len,
1064 "%%BGP: No %s peer belonging to peer-group %s is configured",
5cb5f4d0 1065 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1066
d62a17ae 1067 return CMD_SUCCESS;
7aafcaca 1068 }
7aafcaca 1069
3ae8bfa5 1070 /* Clear all external (eBGP) neighbors. */
d62a17ae 1071 if (sort == clear_external) {
1072 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1073 if (peer->sort == BGP_PEER_IBGP)
1074 continue;
7aafcaca 1075
dc95985f 1076 bgp_peer_gr_flags_update(peer);
1077
36235319 1078 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 1079 gr_router_detected = true;
dc95985f 1080
c368171c 1081 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 1082
d62a17ae 1083 if (ret < 0)
ff8a8a7a
CS
1084 bgp_clear_vty_error(peer, afi, safi, ret,
1085 errmsg, errmsg_len);
3ae8bfa5
PM
1086 else
1087 found = true;
d62a17ae 1088 }
3ae8bfa5 1089
36235319
QY
1090 if (gr_router_detected
1091 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1092 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1093 } else if (!gr_router_detected
1094 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1095 bgp_zebra_send_capabilities(bgp, true);
1096 }
1097
3ae8bfa5 1098 if (!found)
ff8a8a7a
CS
1099 snprintf(errmsg, errmsg_len,
1100 "%%BGP: No external %s peer is configured",
1101 get_afi_safi_str(afi, safi, false));
3ae8bfa5 1102
d62a17ae 1103 return CMD_SUCCESS;
1104 }
1105
3ae8bfa5 1106 /* Clear all neighbors belonging to a specific AS. */
d62a17ae 1107 if (sort == clear_as) {
3ae8bfa5 1108 as_t as = strtoul(arg, NULL, 10);
d62a17ae 1109
1110 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1111 if (peer->as != as)
1112 continue;
1113
dc95985f 1114 bgp_peer_gr_flags_update(peer);
1115
36235319 1116 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 1117 gr_router_detected = true;
dc95985f 1118
c368171c 1119 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
d62a17ae 1120
1121 if (ret < 0)
ff8a8a7a
CS
1122 bgp_clear_vty_error(peer, afi, safi, ret,
1123 errmsg, errmsg_len);
3ae8bfa5
PM
1124 else
1125 found = true;
d62a17ae 1126 }
3ae8bfa5 1127
36235319
QY
1128 if (gr_router_detected
1129 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1130 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1131 } else if (!gr_router_detected
1132 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1133 bgp_zebra_send_capabilities(bgp, true);
1134 }
1135
3ae8bfa5 1136 if (!found)
ff8a8a7a
CS
1137 snprintf(errmsg, errmsg_len,
1138 "%%BGP: No %s peer is configured with AS %s",
1139 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1140
d62a17ae 1141 return CMD_SUCCESS;
1142 }
1143
1144 return CMD_SUCCESS;
1145}
1146
ff8a8a7a
CS
1147static int bgp_clear_vty(const char *name, afi_t afi, safi_t safi,
1148 enum clear_sort sort, enum bgp_clear_type stype,
1149 const char *arg, char *errmsg, size_t errmsg_len)
d62a17ae 1150{
1151 struct bgp *bgp;
1152
1153 /* BGP structure lookup. */
1154 if (name) {
1155 bgp = bgp_lookup_by_name(name);
1156 if (bgp == NULL) {
ff8a8a7a
CS
1157 snprintf(errmsg, errmsg_len,
1158 "Can't find BGP instance %s", name);
d62a17ae 1159 return CMD_WARNING;
1160 }
1161 } else {
1162 bgp = bgp_get_default();
1163 if (bgp == NULL) {
ff8a8a7a
CS
1164 snprintf(errmsg, errmsg_len,
1165 "No BGP process is configured");
d62a17ae 1166 return CMD_WARNING;
1167 }
1168 }
1169
ff8a8a7a 1170 return bgp_clear(bgp, afi, safi, sort, stype, arg, errmsg, errmsg_len);
7aafcaca
DS
1171}
1172
1173/* clear soft inbound */
ff8a8a7a 1174int bgp_clear_star_soft_in(const char *name, char *errmsg, size_t errmsg_len)
7aafcaca 1175{
99b3ebd3
NS
1176 afi_t afi;
1177 safi_t safi;
ff8a8a7a
CS
1178 int ret;
1179
1180 FOREACH_AFI_SAFI (afi, safi) {
1181 ret = bgp_clear_vty(name, afi, safi, clear_all,
1182 BGP_CLEAR_SOFT_IN, NULL, errmsg,
1183 errmsg_len);
1184 if (ret != CMD_SUCCESS)
1185 return -1;
1186 }
99b3ebd3 1187
ff8a8a7a 1188 return 0;
7aafcaca
DS
1189}
1190
1191/* clear soft outbound */
ff8a8a7a 1192int bgp_clear_star_soft_out(const char *name, char *errmsg, size_t errmsg_len)
7aafcaca 1193{
99b3ebd3
NS
1194 afi_t afi;
1195 safi_t safi;
ff8a8a7a 1196 int ret;
99b3ebd3 1197
ff8a8a7a
CS
1198 FOREACH_AFI_SAFI (afi, safi) {
1199 ret = bgp_clear_vty(name, afi, safi, clear_all,
1200 BGP_CLEAR_SOFT_OUT, NULL, errmsg,
1201 errmsg_len);
1202 if (ret != CMD_SUCCESS)
1203 return -1;
1204 }
1205
1206 return 0;
7aafcaca
DS
1207}
1208
1209
f787d7a0 1210#ifndef VTYSH_EXTRACT_PL
2e4c2296 1211#include "bgpd/bgp_vty_clippy.c"
f787d7a0
DL
1212#endif
1213
8029b216
AK
1214DEFUN_HIDDEN (bgp_local_mac,
1215 bgp_local_mac_cmd,
093e3f23 1216 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
8029b216
AK
1217 BGP_STR
1218 "Local MAC config\n"
1219 "VxLAN Network Identifier\n"
1220 "VNI number\n"
1221 "local mac\n"
1222 "mac address\n"
1223 "mac-mobility sequence\n"
1224 "seq number\n")
1225{
1226 int rv;
1227 vni_t vni;
1228 struct ethaddr mac;
1229 struct ipaddr ip;
1230 uint32_t seq;
1231 struct bgp *bgp;
1232
1233 vni = strtoul(argv[3]->arg, NULL, 10);
1234 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1235 vty_out(vty, "%% Malformed MAC address\n");
1236 return CMD_WARNING;
1237 }
1238 memset(&ip, 0, sizeof(ip));
1239 seq = strtoul(argv[7]->arg, NULL, 10);
1240
1241 bgp = bgp_get_default();
1242 if (!bgp) {
1243 vty_out(vty, "Default BGP instance is not there\n");
1244 return CMD_WARNING;
1245 }
1246
b5e140c8
AK
1247 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1248 zero_esi);
8029b216
AK
1249 if (rv < 0) {
1250 vty_out(vty, "Internal error\n");
1251 return CMD_WARNING;
1252 }
1253
1254 return CMD_SUCCESS;
1255}
1256
1257DEFUN_HIDDEN (no_bgp_local_mac,
1258 no_bgp_local_mac_cmd,
093e3f23 1259 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
8029b216
AK
1260 NO_STR
1261 BGP_STR
1262 "Local MAC config\n"
1263 "VxLAN Network Identifier\n"
1264 "VNI number\n"
1265 "local mac\n"
1266 "mac address\n")
1267{
1268 int rv;
1269 vni_t vni;
1270 struct ethaddr mac;
1271 struct ipaddr ip;
1272 struct bgp *bgp;
1273
1274 vni = strtoul(argv[4]->arg, NULL, 10);
1275 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1276 vty_out(vty, "%% Malformed MAC address\n");
1277 return CMD_WARNING;
1278 }
1279 memset(&ip, 0, sizeof(ip));
1280
1281 bgp = bgp_get_default();
1282 if (!bgp) {
1283 vty_out(vty, "Default BGP instance is not there\n");
1284 return CMD_WARNING;
1285 }
1286
ec0ab544 1287 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
8029b216
AK
1288 if (rv < 0) {
1289 vty_out(vty, "Internal error\n");
1290 return CMD_WARNING;
1291 }
1292
1293 return CMD_SUCCESS;
1294}
1295
718e3744 1296DEFUN (no_synchronization,
1297 no_synchronization_cmd,
1298 "no synchronization",
1299 NO_STR
1300 "Perform IGP synchronization\n")
1301{
d62a17ae 1302 return CMD_SUCCESS;
718e3744 1303}
1304
1305DEFUN (no_auto_summary,
1306 no_auto_summary_cmd,
1307 "no auto-summary",
1308 NO_STR
1309 "Enable automatic network number summarization\n")
1310{
d62a17ae 1311 return CMD_SUCCESS;
718e3744 1312}
3d515fd9 1313
718e3744 1314/* "router bgp" commands. */
ff8a8a7a
CS
1315DEFUN_YANG_NOSH(router_bgp,
1316 router_bgp_cmd,
1317 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1318 ROUTER_STR BGP_STR AS_STR BGP_INSTANCE_HELP_STR)
718e3744 1319{
d62a17ae 1320 int idx_asn = 2;
1321 int idx_view_vrf = 3;
1322 int idx_vrf = 4;
ff8a8a7a 1323 int ret = CMD_SUCCESS;
d62a17ae 1324 as_t as;
1325 struct bgp *bgp;
1326 const char *name = NULL;
ff8a8a7a 1327 char as_str[12] = {'\0'};
d62a17ae 1328 enum bgp_instance_type inst_type;
ff8a8a7a 1329 char base_xpath[XPATH_MAXLEN];
d62a17ae 1330
1331 // "router bgp" without an ASN
1332 if (argc == 2) {
1333 // Pending: Make VRF option available for ASN less config
1334 bgp = bgp_get_default();
1335
1336 if (bgp == NULL) {
1337 vty_out(vty, "%% No BGP process is configured\n");
1338 return CMD_WARNING_CONFIG_FAILED;
1339 }
1340
1341 if (listcount(bm->bgp) > 1) {
996c9314 1342 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1343 return CMD_WARNING_CONFIG_FAILED;
1344 }
ff8a8a7a
CS
1345
1346 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
5ce106b7 1347 "frr-bgp:bgp", "bgp", VRF_DEFAULT_NAME);
ff8a8a7a
CS
1348
1349 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
1350 snprintf(as_str, 12, "%d", bgp->as);
87ce2564
CS
1351 nb_cli_enqueue_change(vty, "./global/local-as", NB_OP_MODIFY,
1352 as_str);
ff8a8a7a 1353 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW) {
87ce2564
CS
1354 nb_cli_enqueue_change(vty,
1355 "./global/instance-type-view",
ff8a8a7a
CS
1356 NB_OP_MODIFY, "true");
1357 }
1358
a5ab756f 1359 nb_cli_pending_commit_check(vty);
ff8a8a7a
CS
1360 ret = nb_cli_apply_changes(vty, base_xpath);
1361 if (ret == CMD_SUCCESS) {
1362 VTY_PUSH_XPATH(BGP_NODE, base_xpath);
1363
1364 /*
1365 * For backward compatibility with old commands we still
1366 * need to use the qobj infrastructure.
1367 */
1368 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1369 }
1370 return ret;
d62a17ae 1371 }
1372
1373 // "router bgp X"
1374 else {
d62a17ae 1375
ff8a8a7a 1376 as = strtoul(argv[idx_asn]->arg, NULL, 10);
d62a17ae 1377 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1378 if (argc > 3) {
1379 name = argv[idx_vrf]->arg;
1380
9a8bdf1c
PG
1381 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1382 if (strmatch(name, VRF_DEFAULT_NAME))
1383 name = NULL;
1384 else
1385 inst_type = BGP_INSTANCE_TYPE_VRF;
ff8a8a7a 1386 } else if (!strcmp(argv[idx_view_vrf]->text, "view")) {
d62a17ae 1387 inst_type = BGP_INSTANCE_TYPE_VIEW;
ff8a8a7a 1388 }
d62a17ae 1389 }
ff8a8a7a
CS
1390 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1391 "frr-bgp:bgp", "bgp", name ? name : VRF_DEFAULT_NAME);
1392
1393 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
87ce2564 1394 nb_cli_enqueue_change(vty, "./global/local-as", NB_OP_MODIFY,
ff8a8a7a
CS
1395 argv[idx_asn]->arg);
1396 if (inst_type == BGP_INSTANCE_TYPE_VIEW) {
87ce2564
CS
1397 nb_cli_enqueue_change(vty,
1398 "./global/instance-type-view",
ff8a8a7a 1399 NB_OP_MODIFY, "true");
d62a17ae 1400 }
1401
ff8a8a7a
CS
1402 nb_cli_pending_commit_check(vty);
1403 ret = nb_cli_apply_changes(vty, base_xpath);
1404 if (ret == CMD_SUCCESS) {
1405 VTY_PUSH_XPATH(BGP_NODE, base_xpath);
3bd70bf8 1406
ff8a8a7a
CS
1407 /*
1408 * For backward compatibility with old commands we still
1409 * need to use the qobj infrastructure.
1410 */
1411 bgp = bgp_lookup(as, name);
1412 if (bgp)
1413 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1414 }
d62a17ae 1415 }
1416
ff8a8a7a 1417 return ret;
718e3744 1418}
1419
718e3744 1420/* "no router bgp" commands. */
ff8a8a7a
CS
1421DEFUN_YANG(no_router_bgp,
1422 no_router_bgp_cmd,
1423 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1424 NO_STR ROUTER_STR BGP_STR AS_STR BGP_INSTANCE_HELP_STR)
718e3744 1425{
d62a17ae 1426 int idx_vrf = 5;
d62a17ae 1427 const char *name = NULL;
ff8a8a7a 1428 char base_xpath[XPATH_MAXLEN];
4b63e358 1429 const struct lyd_node *bgp_glb_dnode;
718e3744 1430
d62a17ae 1431 // "no router bgp" without an ASN
1432 if (argc == 3) {
1433 // Pending: Make VRF option available for ASN less config
4b63e358
CS
1434 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1435 "frr-bgp:bgp", "bgp", VRF_DEFAULT_NAME);
718e3744 1436
4b63e358
CS
1437 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
1438 base_xpath);
1439 if (!bgp_glb_dnode) {
d62a17ae 1440 vty_out(vty, "%% No BGP process is configured\n");
1441 return CMD_WARNING_CONFIG_FAILED;
1442 }
7fb21a9f 1443
d62a17ae 1444 if (listcount(bm->bgp) > 1) {
996c9314 1445 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1446 return CMD_WARNING_CONFIG_FAILED;
1447 }
1448 } else {
d62a17ae 1449 if (argc > 4)
1450 name = argv[idx_vrf]->arg;
45d1d7c9
IR
1451 else
1452 name = VRF_DEFAULT_NAME;
7fb21a9f 1453
45d1d7c9
IR
1454 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1455 "frr-bgp:bgp", "bgp", name);
d62a17ae 1456 }
718e3744 1457
ff8a8a7a 1458 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
718e3744 1459
ff8a8a7a 1460 return nb_cli_apply_changes(vty, base_xpath);
718e3744 1461}
1462
ff8a8a7a
CS
1463void cli_show_router_bgp(struct vty *vty, struct lyd_node *dnode,
1464 bool show_defaults)
1465{
1466 const struct lyd_node *vrf_dnode;
1467 const char *vrf_name;
1468 as_t as;
6b0655a2 1469
ff8a8a7a
CS
1470 vrf_dnode = yang_dnode_get_parent(dnode, "control-plane-protocol");
1471 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
5e42cb2f 1472 as = yang_dnode_get_uint32(dnode, "./global/local-as");
718e3744 1473
ff8a8a7a
CS
1474 vty_out(vty, "!\n");
1475 vty_out(vty, "router bgp %u", as);
1476 if (!strmatch(vrf_name, VRF_DEFAULT_NAME))
1477 vty_out(vty, " vrf %s", vrf_name);
1478 vty_out(vty, "\n");
718e3744 1479}
1480
ff8a8a7a
CS
1481/* BGP router-id. */
1482
1483DEFPY_YANG(bgp_router_id, bgp_router_id_cmd, "bgp router-id A.B.C.D",
1484 BGP_STR
1485 "Override configured router identifier\n"
1486 "Manually configured router identifier\n")
718e3744 1487{
87ce2564
CS
1488 nb_cli_enqueue_change(vty, "./global/router-id", NB_OP_MODIFY,
1489 router_id_str);
718e3744 1490
ff8a8a7a
CS
1491 return nb_cli_apply_changes(vty, NULL);
1492}
718e3744 1493
ff8a8a7a
CS
1494DEFPY_YANG(no_bgp_router_id, no_bgp_router_id_cmd, "no bgp router-id [A.B.C.D]",
1495 NO_STR BGP_STR
1496 "Override configured router identifier\n"
1497 "Manually configured router identifier\n")
1498{
87ce2564 1499 nb_cli_enqueue_change(vty, "./global/router-id", NB_OP_DESTROY,
ff8a8a7a 1500 router_id_str ? router_id_str : NULL);
718e3744 1501
ff8a8a7a 1502 return nb_cli_apply_changes(vty, NULL);
718e3744 1503}
1504
ff8a8a7a
CS
1505void cli_show_router_bgp_router_id(struct vty *vty, struct lyd_node *dnode,
1506 bool show_defaults)
1507{
1508 vty_out(vty, " bgp router-id %s\n", yang_dnode_get_string(dnode, NULL));
1509}
6b0655a2 1510
9acb67cb
DS
1511DEFPY (bgp_global_suppress_fib_pending,
1512 bgp_global_suppress_fib_pending_cmd,
1513 "[no] bgp suppress-fib-pending",
1514 NO_STR
1515 BGP_STR
1516 "Advertise only routes that are programmed in kernel to peers globally\n")
1517{
1518 bm_wait_for_fib_set(!no);
1519
1520 return CMD_SUCCESS;
1521}
1522
c208c586
S
1523DEFPY (bgp_suppress_fib_pending,
1524 bgp_suppress_fib_pending_cmd,
1525 "[no] bgp suppress-fib-pending",
1526 NO_STR
1527 BGP_STR
1528 "Advertise only routes that are programmed in kernel to peers\n")
1529{
1530 VTY_DECLVAR_CONTEXT(bgp, bgp);
1531
1532 bgp_suppress_fib_pending_set(bgp, !no);
1533 return CMD_SUCCESS;
1534}
1535
1536
718e3744 1537/* BGP Cluster ID. */
ff8a8a7a
CS
1538DEFUN_YANG(bgp_cluster_id,
1539 bgp_cluster_id_cmd,
1540 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1541 BGP_STR
1542 "Configure Route-Reflector Cluster-id\n"
1543 "Route-Reflector Cluster-id in IP address format\n"
1544 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1545{
d62a17ae 1546 int idx_ipv4 = 2;
718e3744 1547
87ce2564
CS
1548 nb_cli_enqueue_change(
1549 vty, "./global/route-reflector/route-reflector-cluster-id",
1550 NB_OP_MODIFY, argv[idx_ipv4]->arg);
718e3744 1551
ff8a8a7a 1552 return nb_cli_apply_changes(vty, NULL);
718e3744 1553}
1554
ff8a8a7a
CS
1555DEFUN_YANG(no_bgp_cluster_id,
1556 no_bgp_cluster_id_cmd,
1557 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1558 NO_STR BGP_STR
1559 "Configure Route-Reflector Cluster-id\n"
1560 "Route-Reflector Cluster-id in IP address format\n"
1561 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1562{
87ce2564
CS
1563 nb_cli_enqueue_change(
1564 vty, "./global/route-reflector/route-reflector-cluster-id",
1565 NB_OP_DESTROY, NULL);
718e3744 1566
ff8a8a7a 1567 return nb_cli_apply_changes(vty, NULL);
718e3744 1568}
1569
c163f297
DS
1570DEFPY (bgp_norib,
1571 bgp_norib_cmd,
1572 "bgp no-rib",
1573 BGP_STR
1574 "Disable BGP route installation to RIB (Zebra)\n")
1575{
1576 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1577 vty_out(vty,
1578 "%% No-RIB option is already set, nothing to do here.\n");
1579 return CMD_SUCCESS;
1580 }
1581
1582 bgp_option_norib_set_runtime();
1583
1584 return CMD_SUCCESS;
1585}
1586
1587DEFPY (no_bgp_norib,
1588 no_bgp_norib_cmd,
1589 "no bgp no-rib",
1590 NO_STR
1591 BGP_STR
1592 "Disable BGP route installation to RIB (Zebra)\n")
1593{
1594 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1595 vty_out(vty,
1596 "%% No-RIB option is not set, nothing to do here.\n");
1597 return CMD_SUCCESS;
1598 }
1599
1600 bgp_option_norib_unset_runtime();
1601
1602 return CMD_SUCCESS;
1603}
1604
e46723a5
DS
1605DEFPY (no_bgp_send_extra_data,
1606 no_bgp_send_extra_data_cmd,
1607 "[no] bgp send-extra-data zebra",
1608 NO_STR
1609 BGP_STR
1610 "Extra data to Zebra for display/use\n"
1611 "To zebra\n")
1612{
ec0acb80
DA
1613 if (no)
1614 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1615 else
1616 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
e46723a5
DS
1617
1618 return CMD_SUCCESS;
1619}
1620
ff8a8a7a
CS
1621DEFUN_YANG(bgp_confederation_identifier,
1622 bgp_confederation_identifier_cmd,
1623 "bgp confederation identifier (1-4294967295)",
1624 "BGP specific commands\n"
1625 "AS confederation parameters\n"
1626 "AS number\n"
1627 "Set routing domain confederation AS\n")
718e3744 1628{
d62a17ae 1629 int idx_number = 3;
718e3744 1630
87ce2564
CS
1631 nb_cli_enqueue_change(vty, "./global/confederation/identifier",
1632 NB_OP_MODIFY, argv[idx_number]->arg);
718e3744 1633
ff8a8a7a 1634 return nb_cli_apply_changes(vty, NULL);
718e3744 1635}
1636
ff8a8a7a
CS
1637DEFUN_YANG(no_bgp_confederation_identifier,
1638 no_bgp_confederation_identifier_cmd,
1639 "no bgp confederation identifier [(1-4294967295)]",
1640 NO_STR
1641 "BGP specific commands\n"
1642 "AS confederation parameters\n"
1643 "AS number\n"
1644 "Set routing domain confederation AS\n")
718e3744 1645{
87ce2564
CS
1646 nb_cli_enqueue_change(vty, "./global/confederation/identifier",
1647 NB_OP_DESTROY, NULL);
718e3744 1648
ff8a8a7a 1649 return nb_cli_apply_changes(vty, NULL);
718e3744 1650}
1651
ff8a8a7a
CS
1652void cli_show_router_bgp_confederation_identifier(struct vty *vty,
1653 struct lyd_node *dnode,
1654 bool show_defaults)
1655{
1656 vty_out(vty, " bgp confederation identifier %u\n",
1657 yang_dnode_get_uint32(dnode, NULL));
1658}
1659
1660DEFUN_YANG(bgp_confederation_peers,
1661 bgp_confederation_peers_cmd,
1662 "bgp confederation peers (1-4294967295)...",
1663 "BGP specific commands\n"
1664 "AS confederation parameters\n"
1665 "Peer ASs in BGP confederation\n" AS_STR)
718e3744 1666{
d62a17ae 1667 int idx_asn = 3;
d62a17ae 1668 int i;
718e3744 1669
ff8a8a7a 1670 for (i = idx_asn; i < argc; i++)
87ce2564 1671 nb_cli_enqueue_change(vty, "./global/confederation/member-as",
ff8a8a7a 1672 NB_OP_CREATE, argv[i]->arg);
718e3744 1673
ff8a8a7a 1674 return nb_cli_apply_changes(vty, NULL);
718e3744 1675}
1676
ff8a8a7a
CS
1677DEFUN_YANG(no_bgp_confederation_peers,
1678 no_bgp_confederation_peers_cmd,
1679 "no bgp confederation peers (1-4294967295)...",
1680 NO_STR
1681 "BGP specific commands\n"
1682 "AS confederation parameters\n"
1683 "Peer ASs in BGP confederation\n" AS_STR)
718e3744 1684{
d62a17ae 1685 int idx_asn = 4;
d62a17ae 1686 int i;
718e3744 1687
ff8a8a7a 1688 for (i = idx_asn; i < argc; i++)
87ce2564 1689 nb_cli_enqueue_change(vty, "./global/confederation/member-as",
ff8a8a7a 1690 NB_OP_DESTROY, argv[i]->arg);
0b2aa3a0 1691
ff8a8a7a
CS
1692 return nb_cli_apply_changes(vty, NULL);
1693}
1694
1695void cli_show_router_bgp_confederation_member_as(struct vty *vty,
1696 struct lyd_node *dnode,
1697 bool show_defaults)
1698{
1699 vty_out(vty, " bgp confederation peers %u \n",
1700 yang_dnode_get_uint32(dnode, NULL));
718e3744 1701}
6b0655a2 1702
5e242b0d
DS
1703/**
1704 * Central routine for maximum-paths configuration.
1705 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1706 * @set: 1 for setting values, 0 for removing the max-paths config.
1707 */
37a87b8f
CS
1708int bgp_maxpaths_config_vty(struct bgp *bgp, afi_t afi, safi_t safi,
1709 int peer_type, uint16_t maxpaths, uint16_t options,
1710 int set, char *errmsg, size_t errmsg_len)
d62a17ae 1711{
d62a17ae 1712 int ret;
d62a17ae 1713
1714 if (set) {
d62a17ae 1715 if (maxpaths > multipath_num) {
37a87b8f
CS
1716 snprintf(
1717 errmsg, errmsg_len,
d62a17ae 1718 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1719 maxpaths, multipath_num);
1720 return CMD_WARNING_CONFIG_FAILED;
1721 }
1722 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1723 options);
1724 } else
1725 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1726
1727 if (ret < 0) {
37a87b8f
CS
1728 snprintf(
1729 errmsg, errmsg_len,
d62a17ae 1730 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1731 (set == 1) ? "" : "un",
1732 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1733 maxpaths, afi, safi);
1734 return CMD_WARNING_CONFIG_FAILED;
1735 }
1736
1737 bgp_recalculate_all_bestpaths(bgp);
1738
1739 return CMD_SUCCESS;
165b5fff
JB
1740}
1741
ff8a8a7a
CS
1742void cli_show_router_bgp_med_config(struct vty *vty, struct lyd_node *dnode,
1743 bool show_defaults)
abc920f8 1744{
ff8a8a7a
CS
1745 if (yang_dnode_get_bool(dnode, "./enable-med-admin")) {
1746 uint32_t med_admin_val;
abc920f8 1747
ff8a8a7a
CS
1748 vty_out(vty, " bgp max-med administrative");
1749 if ((med_admin_val =
1750 yang_dnode_get_uint32(dnode, "./max-med-admin"))
1751 != BGP_MAXMED_VALUE_DEFAULT)
1752 vty_out(vty, " %u", med_admin_val);
1753 vty_out(vty, "\n");
1754 }
abc920f8 1755
ff8a8a7a
CS
1756 if (yang_dnode_exists(dnode, "./max-med-onstart-up-time")) {
1757 uint32_t onstartup_val;
abc920f8 1758
ff8a8a7a
CS
1759 vty_out(vty, " bgp max-med on-startup %u",
1760 yang_dnode_get_uint32(dnode,
1761 "./max-med-onstart-up-time"));
1762 onstartup_val = yang_dnode_get_uint32(
1763 dnode, "./max-med-onstart-up-value");
1764 if (onstartup_val != BGP_MAXMED_VALUE_DEFAULT)
1765 vty_out(vty, " %u", onstartup_val);
1766
1767 vty_out(vty, "\n");
1768 }
abc920f8
DS
1769}
1770
ff8a8a7a
CS
1771DEFUN_YANG(bgp_maxmed_admin,
1772 bgp_maxmed_admin_cmd,
1773 "bgp max-med administrative ",
1774 BGP_STR
1775 "Advertise routes with max-med\n"
1776 "Administratively applied, for an indefinite period\n")
1777{
87ce2564 1778 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
ff8a8a7a
CS
1779 NB_OP_MODIFY, "true");
1780
1781 return nb_cli_apply_changes(vty, NULL);
1782}
1783
1784DEFUN_YANG(bgp_maxmed_admin_medv,
1785 bgp_maxmed_admin_medv_cmd,
1786 "bgp max-med administrative (0-4294967295)",
1787 BGP_STR
1788 "Advertise routes with max-med\n"
1789 "Administratively applied, for an indefinite period\n"
1790 "Max MED value to be used\n")
abc920f8 1791{
d62a17ae 1792 int idx_number = 3;
abc920f8 1793
87ce2564 1794 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
ff8a8a7a 1795 NB_OP_MODIFY, "true");
abc920f8 1796
87ce2564
CS
1797 nb_cli_enqueue_change(vty, "./global/med-config/max-med-admin",
1798 NB_OP_MODIFY, argv[idx_number]->arg);
abc920f8 1799
ff8a8a7a 1800 return nb_cli_apply_changes(vty, NULL);
abc920f8
DS
1801}
1802
ff8a8a7a
CS
1803DEFUN_YANG(no_bgp_maxmed_admin,
1804 no_bgp_maxmed_admin_cmd,
1805 "no bgp max-med administrative [(0-4294967295)]",
1806 NO_STR BGP_STR
1807 "Advertise routes with max-med\n"
1808 "Administratively applied, for an indefinite period\n"
1809 "Max MED value to be used\n")
abc920f8 1810{
87ce2564 1811 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
ff8a8a7a 1812 NB_OP_MODIFY, "false");
abc920f8 1813
87ce2564
CS
1814 nb_cli_enqueue_change(vty, "./global/med-config/max-med-admin",
1815 NB_OP_MODIFY, NULL);
ff8a8a7a
CS
1816
1817 return nb_cli_apply_changes(vty, NULL);
abc920f8
DS
1818}
1819
37a87b8f
CS
1820DEFUN_YANG (bgp_maxmed_onstartup,
1821 bgp_maxmed_onstartup_cmd,
1822 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1823 BGP_STR
1824 "Advertise routes with max-med\n"
1825 "Effective on a startup\n"
1826 "Time (seconds) period for max-med\n"
1827 "Max MED value to be used\n")
abc920f8 1828{
d62a17ae 1829 int idx = 0;
4668a151 1830
d62a17ae 1831 argv_find(argv, argc, "(5-86400)", &idx);
87ce2564
CS
1832 nb_cli_enqueue_change(vty,
1833 "./global/med-config/max-med-onstart-up-time",
ff8a8a7a
CS
1834 NB_OP_MODIFY, argv[idx]->arg);
1835
d62a17ae 1836 if (argv_find(argv, argc, "(0-4294967295)", &idx))
87ce2564
CS
1837 nb_cli_enqueue_change(
1838 vty, "./global/med-config/max-med-onstart-up-value",
1839 NB_OP_MODIFY, argv[idx]->arg);
d62a17ae 1840 else
87ce2564
CS
1841 nb_cli_enqueue_change(
1842 vty, "./global/med-config/max-med-onstart-up-value",
1843 NB_OP_MODIFY, NULL);
abc920f8 1844
ff8a8a7a 1845 return nb_cli_apply_changes(vty, NULL);
abc920f8
DS
1846}
1847
37a87b8f
CS
1848DEFUN_YANG (no_bgp_maxmed_onstartup,
1849 no_bgp_maxmed_onstartup_cmd,
1850 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1851 NO_STR BGP_STR
1852 "Advertise routes with max-med\n"
1853 "Effective on a startup\n"
1854 "Time (seconds) period for max-med\n"
1855 "Max MED value to be used\n")
abc920f8 1856{
87ce2564
CS
1857 nb_cli_enqueue_change(vty,
1858 "./global/med-config/max-med-onstart-up-time",
ff8a8a7a 1859 NB_OP_DESTROY, NULL);
abc920f8 1860
87ce2564
CS
1861 nb_cli_enqueue_change(vty,
1862 "./global/med-config/max-med-onstart-up-value",
ff8a8a7a 1863 NB_OP_MODIFY, NULL);
abc920f8 1864
ff8a8a7a 1865 return nb_cli_apply_changes(vty, NULL);
abc920f8
DS
1866}
1867
d70583f7
D
1868static int bgp_global_update_delay_config_vty(struct vty *vty,
1869 uint16_t update_delay,
1870 uint16_t establish_wait)
1871{
1872 struct listnode *node, *nnode;
1873 struct bgp *bgp;
1874 bool vrf_cfg = false;
1875
1876 /*
1877 * See if update-delay is set per-vrf and warn user to delete it
1878 * Note that we only need to check this if this is the first time
1879 * setting the global config.
1880 */
1881 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
1882 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1883 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1884 vty_out(vty,
1885 "%% update-delay configuration found in vrf %s\n",
1886 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
1887 ? VRF_DEFAULT_NAME
1888 : bgp->name);
1889 vrf_cfg = true;
1890 }
1891 }
1892 }
1893
1894 if (vrf_cfg) {
1895 vty_out(vty,
1896 "%%Failed: global update-delay config not permitted\n");
1897 return CMD_WARNING;
1898 }
1899
1900 if (!establish_wait) { /* update-delay <delay> */
1901 bm->v_update_delay = update_delay;
1902 bm->v_establish_wait = bm->v_update_delay;
1903 } else {
1904 /* update-delay <delay> <establish-wait> */
1905 if (update_delay < establish_wait) {
1906 vty_out(vty,
1907 "%%Failed: update-delay less than the establish-wait!\n");
1908 return CMD_WARNING_CONFIG_FAILED;
1909 }
1910
1911 bm->v_update_delay = update_delay;
1912 bm->v_establish_wait = establish_wait;
1913 }
1914
1915 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1916 bgp->v_update_delay = bm->v_update_delay;
1917 bgp->v_establish_wait = bm->v_establish_wait;
1918 }
1919
1920 return CMD_SUCCESS;
1921}
1922
1923static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
1924{
1925 struct listnode *node, *nnode;
1926 struct bgp *bgp;
1927
1928 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
1929 bm->v_establish_wait = bm->v_update_delay;
1930
1931 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1932 bgp->v_update_delay = bm->v_update_delay;
1933 bgp->v_establish_wait = bm->v_establish_wait;
1934 }
1935
1936 return CMD_SUCCESS;
1937}
1938
1939static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
1940 uint16_t establish_wait)
f188f2c4 1941{
d62a17ae 1942 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 1943
d70583f7
D
1944 /* if configured globally, per-instance config is not allowed */
1945 if (bm->v_update_delay) {
1946 vty_out(vty,
1947 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
1948 return CMD_WARNING_CONFIG_FAILED;
1949 }
1950
f188f2c4 1951
d70583f7 1952 if (!establish_wait) /* update-delay <delay> */
d62a17ae 1953 {
1954 bgp->v_update_delay = update_delay;
1955 bgp->v_establish_wait = bgp->v_update_delay;
1956 return CMD_SUCCESS;
1957 }
f188f2c4 1958
d62a17ae 1959 /* update-delay <delay> <establish-wait> */
d62a17ae 1960 if (update_delay < establish_wait) {
1961 vty_out(vty,
1962 "%%Failed: update-delay less than the establish-wait!\n");
1963 return CMD_WARNING_CONFIG_FAILED;
1964 }
f188f2c4 1965
d62a17ae 1966 bgp->v_update_delay = update_delay;
1967 bgp->v_establish_wait = establish_wait;
f188f2c4 1968
d62a17ae 1969 return CMD_SUCCESS;
f188f2c4
DS
1970}
1971
d62a17ae 1972static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 1973{
d62a17ae 1974 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 1975
d70583f7
D
1976 /* If configured globally, cannot remove from one bgp instance */
1977 if (bm->v_update_delay) {
1978 vty_out(vty,
1979 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
1980 return CMD_WARNING_CONFIG_FAILED;
1981 }
d62a17ae 1982 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1983 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 1984
d62a17ae 1985 return CMD_SUCCESS;
f188f2c4
DS
1986}
1987
2b791107 1988void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 1989{
d70583f7
D
1990 /* If configured globally, no need to display per-instance value */
1991 if (bgp->v_update_delay != bm->v_update_delay) {
d62a17ae 1992 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1993 if (bgp->v_update_delay != bgp->v_establish_wait)
1994 vty_out(vty, " %d", bgp->v_establish_wait);
1995 vty_out(vty, "\n");
1996 }
f188f2c4
DS
1997}
1998
d70583f7
D
1999/* Global update-delay configuration */
2000DEFPY (bgp_global_update_delay,
2001 bgp_global_update_delay_cmd,
2002 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2003 BGP_STR
2004 "Force initial delay for best-path and updates for all bgp instances\n"
2005 "Max delay in seconds\n"
2006 "Establish wait in seconds\n")
2007{
2008 return bgp_global_update_delay_config_vty(vty, delay, wait);
2009}
f188f2c4 2010
d70583f7
D
2011/* Global update-delay deconfiguration */
2012DEFPY (no_bgp_global_update_delay,
2013 no_bgp_global_update_delay_cmd,
2014 "no bgp update-delay [(0-3600) [(1-3600)]]",
2015 NO_STR
2016 BGP_STR
f188f2c4 2017 "Force initial delay for best-path and updates\n"
d70583f7
D
2018 "Max delay in seconds\n"
2019 "Establish wait in seconds\n")
f188f2c4 2020{
d70583f7 2021 return bgp_global_update_delay_deconfig_vty(vty);
f188f2c4
DS
2022}
2023
d70583f7
D
2024/* Update-delay configuration */
2025
2026DEFPY (bgp_update_delay,
2027 bgp_update_delay_cmd,
2028 "update-delay (0-3600)$delay [(1-3600)$wait]",
f188f2c4 2029 "Force initial delay for best-path and updates\n"
d70583f7
D
2030 "Max delay in seconds\n"
2031 "Establish wait in seconds\n")
f188f2c4 2032{
d70583f7 2033 return bgp_update_delay_config_vty(vty, delay, wait);
f188f2c4
DS
2034}
2035
2036/* Update-delay deconfiguration */
d70583f7 2037DEFPY (no_bgp_update_delay,
f188f2c4 2038 no_bgp_update_delay_cmd,
838758ac
DW
2039 "no update-delay [(0-3600) [(1-3600)]]",
2040 NO_STR
f188f2c4 2041 "Force initial delay for best-path and updates\n"
d70583f7
D
2042 "Max delay in seconds\n"
2043 "Establish wait in seconds\n")
f188f2c4 2044{
d62a17ae 2045 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
2046}
2047
5e242b0d 2048
ff8a8a7a 2049int bgp_wpkt_quanta_config_vty(struct bgp *bgp, uint32_t quanta, bool set)
cb1faec9 2050{
8fa7732f
QY
2051 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2052 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
555e09d4
QY
2053
2054 return CMD_SUCCESS;
2055}
2056
ff8a8a7a 2057int bgp_rpkt_quanta_config_vty(struct bgp *bgp, uint32_t quanta, bool set)
555e09d4 2058{
8fa7732f
QY
2059 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2060 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
cb1faec9 2061
d62a17ae 2062 return CMD_SUCCESS;
cb1faec9
DS
2063}
2064
2b791107 2065void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 2066{
555e09d4
QY
2067 uint32_t quanta =
2068 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2069 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 2070 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
2071}
2072
555e09d4
QY
2073void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2074{
2075 uint32_t quanta =
2076 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2077 if (quanta != BGP_READ_PACKET_MAX)
152456fe 2078 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 2079}
cb1faec9 2080
8fa7732f
QY
2081/* Packet quanta configuration
2082 *
2083 * XXX: The value set here controls the size of a stack buffer in the IO
2084 * thread. When changing these limits be careful to prevent stack overflow.
2085 *
2086 * Furthermore, the maximums used here should correspond to
2087 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2088 */
37a87b8f
CS
2089DEFPY_YANG (bgp_wpkt_quanta,
2090 bgp_wpkt_quanta_cmd,
2091 "[no] write-quanta (1-64)$quanta",
2092 NO_STR
2093 "How many packets to write to peer socket per run\n"
2094 "Number of packets\n")
ff8a8a7a
CS
2095{
2096 if (!no)
2097 nb_cli_enqueue_change(
2098 vty,
87ce2564 2099 "./global/global-neighbor-config/packet-quanta-config/wpkt-quanta",
ff8a8a7a
CS
2100 NB_OP_MODIFY, quanta_str);
2101 else
2102 nb_cli_enqueue_change(
2103 vty,
87ce2564 2104 "./global/global-neighbor-config/packet-quanta-config/wpkt-quanta",
ff8a8a7a
CS
2105 NB_OP_MODIFY, NULL);
2106
2107 return nb_cli_apply_changes(vty, NULL);
2108}
2109
37a87b8f
CS
2110DEFPY_YANG (bgp_rpkt_quanta,
2111 bgp_rpkt_quanta_cmd,
2112 "[no] read-quanta (1-10)$quanta",
2113 NO_STR
2114 "How many packets to read from peer socket per I/O cycle\n"
2115 "Number of packets\n")
ff8a8a7a
CS
2116{
2117 if (!no)
2118 nb_cli_enqueue_change(
2119 vty,
87ce2564 2120 "./global/global-neighbor-config/packet-quanta-config/rpkt-quanta",
ff8a8a7a
CS
2121 NB_OP_MODIFY, quanta_str);
2122 else
2123 nb_cli_enqueue_change(
2124 vty,
87ce2564 2125 "./global/global-neighbor-config/packet-quanta-config/rpkt-quanta",
ff8a8a7a 2126 NB_OP_MODIFY, NULL);
cb1faec9 2127
ff8a8a7a 2128 return nb_cli_apply_changes(vty, NULL);
555e09d4
QY
2129}
2130
2b791107 2131void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 2132{
37a333fe 2133 if (!bgp->heuristic_coalesce)
d62a17ae 2134 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
2135}
2136
ff8a8a7a
CS
2137void cli_show_router_global_update_group_config_coalesce_time(
2138 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
3f9c7369 2139{
ff8a8a7a
CS
2140 vty_out(vty, " coalesce-time %u\n", yang_dnode_get_uint32(dnode, NULL));
2141}
2142
4668a151 2143
37a87b8f
CS
2144DEFUN_YANG (bgp_coalesce_time,
2145 bgp_coalesce_time_cmd,
2146 "coalesce-time (0-4294967295)",
2147 "Subgroup coalesce timer\n"
2148 "Subgroup coalesce timer value (in ms)\n")
ff8a8a7a 2149{
d62a17ae 2150 int idx = 0;
ff8a8a7a 2151
d62a17ae 2152 argv_find(argv, argc, "(0-4294967295)", &idx);
87ce2564
CS
2153 nb_cli_enqueue_change(
2154 vty, "./global/global-update-group-config/coalesce-time",
2155 NB_OP_MODIFY, argv[idx]->arg);
ff8a8a7a
CS
2156
2157 return nb_cli_apply_changes(vty, NULL);
3f9c7369
DS
2158}
2159
ff8a8a7a
CS
2160DEFUN_YANG(no_bgp_coalesce_time,
2161 no_bgp_coalesce_time_cmd,
2162 "no coalesce-time (0-4294967295)",
2163 NO_STR
2164 "Subgroup coalesce timer\n"
2165 "Subgroup coalesce timer value (in ms)\n")
3f9c7369 2166{
87ce2564
CS
2167 nb_cli_enqueue_change(
2168 vty, "./global/global-update-group-config/coalesce-time",
2169 NB_OP_MODIFY, NULL);
4668a151 2170
ff8a8a7a 2171 return nb_cli_apply_changes(vty, NULL);
3f9c7369
DS
2172}
2173
5e242b0d 2174/* Maximum-paths configuration */
37a87b8f
CS
2175DEFUN_YANG (bgp_maxpaths,
2176 bgp_maxpaths_cmd,
2177 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2178 "Forward packets over multiple paths\n"
2179 "Number of paths\n")
5e242b0d 2180{
d62a17ae 2181 int idx_number = 1;
37a87b8f
CS
2182 char base_xpath[XPATH_MAXLEN];
2183 afi_t afi;
2184 safi_t safi;
2185
2186 afi = bgp_node_afi(vty);
2187 safi = bgp_node_safi(vty);
2188
2189 snprintf(
2190 base_xpath, sizeof(base_xpath),
2191 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ebgp/maximum-paths",
2192 yang_afi_safi_value2identity(afi, safi),
2193 bgp_afi_safi_get_container_str(afi, safi));
2194
2195 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2196 argv[idx_number]->arg);
2197
2198 return nb_cli_apply_changes(vty, NULL);
2199}
2200
2201void cli_show_bgp_global_afi_safi_unicast_use_multiple_paths_ebgp_maximum_paths(
2202 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
2203{
2204 vty_out(vty, " maximum-paths %d\n",
2205 yang_dnode_get_uint16(dnode, NULL));
5e242b0d
DS
2206}
2207
d62a17ae 2208ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2209 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2210 "Forward packets over multiple paths\n"
2211 "Number of paths\n")
596c17ba 2212
37a87b8f
CS
2213DEFUN_YANG (bgp_maxpaths_ibgp,
2214 bgp_maxpaths_ibgp_cmd,
2215 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2216 "Forward packets over multiple paths\n"
2217 "iBGP-multipath\n"
2218 "Number of paths\n")
165b5fff 2219{
d62a17ae 2220 int idx_number = 2;
37a87b8f
CS
2221 char base_xpath[XPATH_MAXLEN];
2222 afi_t afi;
2223 safi_t safi;
2224
2225 afi = bgp_node_afi(vty);
2226 safi = bgp_node_safi(vty);
2227
2228 snprintf(
2229 base_xpath, sizeof(base_xpath),
2230 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2231 yang_afi_safi_value2identity(afi, safi),
2232 bgp_afi_safi_get_container_str(afi, safi));
2233
2234 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2235 argv[idx_number]->arg);
2236
2237 return nb_cli_apply_changes(vty, NULL);
5e242b0d 2238}
165b5fff 2239
d62a17ae 2240ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2241 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2242 "Forward packets over multiple paths\n"
2243 "iBGP-multipath\n"
2244 "Number of paths\n")
596c17ba 2245
37a87b8f
CS
2246DEFUN_YANG (bgp_maxpaths_ibgp_cluster,
2247 bgp_maxpaths_ibgp_cluster_cmd,
2248 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2249 "Forward packets over multiple paths\n"
2250 "iBGP-multipath\n"
2251 "Number of paths\n"
2252 "Match the cluster length\n")
5e242b0d 2253{
d62a17ae 2254 int idx_number = 2;
37a87b8f
CS
2255 char base_xpath[XPATH_MAXLEN];
2256 afi_t afi;
2257 safi_t safi;
2258
2259 afi = bgp_node_afi(vty);
2260 safi = bgp_node_safi(vty);
2261
2262 snprintf(
2263 base_xpath, sizeof(base_xpath),
2264 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2265 yang_afi_safi_value2identity(afi, safi),
2266 bgp_afi_safi_get_container_str(afi, safi));
2267
2268 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2269 argv[idx_number]->arg);
2270
2271 snprintf(
2272 base_xpath, sizeof(base_xpath),
2273 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/cluster-length-list",
2274 yang_afi_safi_value2identity(afi, safi),
2275 bgp_afi_safi_get_container_str(afi, safi));
2276
2277 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, "true");
2278
2279 return nb_cli_apply_changes(vty, NULL);
2280}
2281
2282void cli_show_bgp_global_afi_safi_ip_unicast_use_multiple_paths_ibgp_maximum_paths(
2283 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
2284{
2285 vty_out(vty, " maximum-paths ibgp %d",
2286 yang_dnode_get_uint16(dnode, "./maximum-paths"));
2287 if (yang_dnode_get_bool(dnode, "./cluster-length-list"))
2288 vty_out(vty, " equal-cluster-length");
2289 vty_out(vty, "\n");
165b5fff
JB
2290}
2291
d62a17ae 2292ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2293 "maximum-paths ibgp " CMD_RANGE_STR(
2294 1, MULTIPATH_NUM) " equal-cluster-length",
2295 "Forward packets over multiple paths\n"
2296 "iBGP-multipath\n"
2297 "Number of paths\n"
2298 "Match the cluster length\n")
596c17ba 2299
37a87b8f
CS
2300DEFUN_YANG (no_bgp_maxpaths,
2301 no_bgp_maxpaths_cmd,
2302 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2303 NO_STR
2304 "Forward packets over multiple paths\n"
2305 "Number of paths\n")
165b5fff 2306{
37a87b8f
CS
2307 char base_xpath[XPATH_MAXLEN];
2308 afi_t afi;
2309 safi_t safi;
2310
2311 afi = bgp_node_afi(vty);
2312 safi = bgp_node_safi(vty);
2313
2314 snprintf(
2315 base_xpath, sizeof(base_xpath),
2316 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ebgp/maximum-paths",
2317 yang_afi_safi_value2identity(afi, safi),
2318 bgp_afi_safi_get_container_str(afi, safi));
2319
2320 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, NULL);
2321
2322 return nb_cli_apply_changes(vty, NULL);
165b5fff
JB
2323}
2324
d62a17ae 2325ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 2326 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 2327 "Forward packets over multiple paths\n"
2328 "Number of paths\n")
596c17ba 2329
37a87b8f
CS
2330DEFUN_YANG (no_bgp_maxpaths_ibgp,
2331 no_bgp_maxpaths_ibgp_cmd,
2332 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2333 NO_STR
2334 "Forward packets over multiple paths\n"
2335 "iBGP-multipath\n"
2336 "Number of paths\n"
2337 "Match the cluster length\n")
165b5fff 2338{
37a87b8f
CS
2339 char base_xpath[XPATH_MAXLEN];
2340 afi_t afi;
2341 safi_t safi;
2342
2343 afi = bgp_node_afi(vty);
2344 safi = bgp_node_safi(vty);
2345
2346 snprintf(
2347 base_xpath, sizeof(base_xpath),
2348 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2349 yang_afi_safi_value2identity(afi, safi),
2350 bgp_afi_safi_get_container_str(afi, safi));
2351
2352 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, NULL);
2353
2354 snprintf(
2355 base_xpath, sizeof(base_xpath),
2356 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/cluster-length-list",
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, "false");
2361
2362 return nb_cli_apply_changes(vty, NULL);
165b5fff
JB
2363}
2364
d62a17ae 2365ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2366 "no maximum-paths ibgp [" CMD_RANGE_STR(
2367 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2368 NO_STR
2369 "Forward packets over multiple paths\n"
2370 "iBGP-multipath\n"
2371 "Number of paths\n"
2372 "Match the cluster length\n")
596c17ba 2373
dd65f45e
DL
2374static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2375 afi_t afi, safi_t safi)
165b5fff 2376{
00908b7a 2377 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
d62a17ae 2378 vty_out(vty, " maximum-paths %d\n",
2379 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2380 }
165b5fff 2381
00908b7a 2382 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
d62a17ae 2383 vty_out(vty, " maximum-paths ibgp %d",
2384 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2385 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
2386 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
2387 vty_out(vty, " equal-cluster-length");
2388 vty_out(vty, "\n");
2389 }
165b5fff 2390}
6b0655a2 2391
718e3744 2392/* BGP timers. */
2393
37a87b8f
CS
2394DEFUN_YANG (bgp_timers,
2395 bgp_timers_cmd,
2396 "timers bgp (0-65535) (0-65535)",
2397 "Adjust routing timers\n"
2398 "BGP timers\n"
2399 "Keepalive interval\n"
2400 "Holdtime\n")
718e3744 2401{
d62a17ae 2402 int idx_number = 2;
2403 int idx_number_2 = 3;
718e3744 2404
87ce2564 2405 nb_cli_enqueue_change(vty, "./global/global-config-timers/keepalive",
ff8a8a7a 2406 NB_OP_MODIFY, argv[idx_number]->arg);
87ce2564 2407 nb_cli_enqueue_change(vty, "./global/global-config-timers/hold-time",
ff8a8a7a 2408 NB_OP_MODIFY, argv[idx_number_2]->arg);
718e3744 2409
ff8a8a7a
CS
2410 return nb_cli_apply_changes(vty, NULL);
2411}
718e3744 2412
37a87b8f
CS
2413DEFUN_YANG (no_bgp_timers,
2414 no_bgp_timers_cmd,
2415 "no timers bgp [(0-65535) (0-65535)]",
2416 NO_STR
2417 "Adjust routing timers\n"
2418 "BGP timers\n"
2419 "Keepalive interval\n"
2420 "Holdtime\n")
ff8a8a7a 2421{
87ce2564 2422 nb_cli_enqueue_change(vty, "./global/global-config-timers/keepalive",
ff8a8a7a 2423 NB_OP_DESTROY, NULL);
87ce2564 2424 nb_cli_enqueue_change(vty, "./global/global-config-timers/hold-time",
ff8a8a7a 2425 NB_OP_DESTROY, NULL);
718e3744 2426
ff8a8a7a 2427 return nb_cli_apply_changes(vty, NULL);
718e3744 2428}
2429
ff8a8a7a
CS
2430void cli_show_router_bgp_route_reflector(struct vty *vty,
2431 struct lyd_node *dnode,
2432 bool show_defaults)
718e3744 2433{
ff8a8a7a
CS
2434 if (yang_dnode_get_bool(dnode, "./no-client-reflect"))
2435 vty_out(vty, " no bgp client-to-client reflection\n");
718e3744 2436
ff8a8a7a
CS
2437 if (yang_dnode_get_bool(dnode, "./allow-outbound-policy"))
2438 vty_out(vty, " bgp route-reflector allow-outbound-policy\n");
2439
2440 if (yang_dnode_exists(dnode, "./route-reflector-cluster-id"))
2441 vty_out(vty, " bgp cluster-id %s\n",
2442 yang_dnode_get_string(dnode,
2443 "./route-reflector-cluster-id"));
718e3744 2444}
2445
ff8a8a7a
CS
2446DEFUN_YANG(bgp_client_to_client_reflection,
2447 bgp_client_to_client_reflection_cmd,
2448 "bgp client-to-client reflection",
2449 "BGP specific commands\n"
2450 "Configure client to client route reflection\n"
2451 "reflection of routes allowed\n")
2452{
87ce2564 2453 nb_cli_enqueue_change(vty, "./global/route-reflector/no-client-reflect",
ff8a8a7a 2454 NB_OP_MODIFY, "false");
6b0655a2 2455
ff8a8a7a
CS
2456 return nb_cli_apply_changes(vty, NULL);
2457}
2458
2459DEFUN_YANG(no_bgp_client_to_client_reflection,
2460 no_bgp_client_to_client_reflection_cmd,
2461 "no bgp client-to-client reflection",
2462 NO_STR
2463 "BGP specific commands\n"
2464 "Configure client to client route reflection\n"
2465 "reflection of routes allowed\n")
718e3744 2466{
87ce2564 2467 nb_cli_enqueue_change(vty, "./global/route-reflector/no-client-reflect",
ff8a8a7a 2468 NB_OP_MODIFY, "true");
7aafcaca 2469
ff8a8a7a 2470 return nb_cli_apply_changes(vty, NULL);
718e3744 2471}
2472
ff8a8a7a
CS
2473void cli_show_router_bgp_route_selection(struct vty *vty,
2474 struct lyd_node *dnode,
2475 bool show_defaults)
718e3744 2476{
7aafcaca 2477
ff8a8a7a
CS
2478 if (yang_dnode_get_bool(dnode, "./always-compare-med"))
2479 vty_out(vty, " bgp always-compare-med\n");
2480
2481 if (yang_dnode_get_bool(dnode, "./ignore-as-path-length"))
2482 vty_out(vty, " bgp bestpath as-path ignore\n");
2483
2484 if (yang_dnode_get_bool(dnode, "./aspath-confed"))
2485 vty_out(vty, " bgp bestpath as-path confed\n");
2486
2487 if (yang_dnode_get_bool(dnode, "./external-compare-router-id"))
2488 vty_out(vty, " bgp bestpath compare-routerid\n");
2489
2490 if (yang_dnode_get_bool(dnode, "./allow-multiple-as")) {
2491 if (yang_dnode_get_bool(dnode, "./multi-path-as-set"))
2492 vty_out(vty,
2493 " bgp bestpath as-path multipath-relax as-set\n");
2494 else
2495 vty_out(vty, " bgp bestpath as-path multipath-relax\n");
2496 }
2497
2498 if (yang_dnode_get_bool(dnode, "./deterministic-med"))
2499 vty_out(vty, " bgp deterministic-med\n");
2500
2501 if (yang_dnode_get_bool(dnode, "./confed-med")
2502 || yang_dnode_get_bool(dnode, "./missing-as-worst-med")) {
2503 vty_out(vty, " bgp bestpath med");
2504 if (yang_dnode_get_bool(dnode, "./confed-med"))
2505 vty_out(vty, " confed");
2506 if (yang_dnode_get_bool(dnode, "./missing-as-worst-med"))
2507 vty_out(vty, " missing-as-worst");
2508 vty_out(vty, "\n");
2509 }
718e3744 2510}
2511
2512/* "bgp always-compare-med" configuration. */
ff8a8a7a
CS
2513DEFUN_YANG(bgp_always_compare_med,
2514 bgp_always_compare_med_cmd,
2515 "bgp always-compare-med",
2516 "BGP specific commands\n"
2517 "Allow comparing MED from different neighbors\n")
718e3744 2518{
87ce2564
CS
2519 nb_cli_enqueue_change(
2520 vty, "./global/route-selection-options/always-compare-med",
2521 NB_OP_MODIFY, "true");
7aafcaca 2522
ff8a8a7a 2523 return nb_cli_apply_changes(vty, NULL);
718e3744 2524}
2525
ff8a8a7a
CS
2526DEFUN_YANG(no_bgp_always_compare_med,
2527 no_bgp_always_compare_med_cmd,
2528 "no bgp always-compare-med",
2529 NO_STR
2530 "BGP specific commands\n"
2531 "Allow comparing MED from different neighbors\n")
718e3744 2532{
87ce2564
CS
2533 nb_cli_enqueue_change(
2534 vty, "./global/route-selection-options/always-compare-med",
2535 NB_OP_MODIFY, "false");
7aafcaca 2536
ff8a8a7a 2537 return nb_cli_apply_changes(vty, NULL);
718e3744 2538}
6b0655a2 2539
2adac256
DA
2540DEFUN_YANG(bgp_suppress_duplicates,
2541 bgp_suppress_duplicates_cmd,
2542 "bgp suppress-duplicates",
2543 "BGP specific commands\n"
2544 "Suppress duplicate updates if the route actually not changed\n")
2545{
2546 nb_cli_enqueue_change(vty, "./global/suppress-duplicates",
2547 NB_OP_MODIFY, "true");
2548 return nb_cli_apply_changes(vty, NULL);
2549}
2550
2551DEFUN_YANG(no_bgp_suppress_duplicates,
2552 no_bgp_suppress_duplicates_cmd,
2553 "no bgp suppress-duplicates",
2554 NO_STR
2555 "BGP specific commands\n"
2556 "Suppress duplicate updates if the route actually not changed\n")
2557{
2558 nb_cli_enqueue_change(vty, "./global/suppress-duplicates",
2559 NB_OP_MODIFY, "false");
2560 return nb_cli_apply_changes(vty, NULL);
2561}
2562
2563void cli_show_router_bgp_suppress_duplicates(struct vty *vty,
2564 struct lyd_node *dnode,
2565 bool show_defaults)
2566{
2567 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SUPPRESS_DUPLICATES)
2568 vty_out(vty, " bgp suppress-duplicates\n");
2569}
2570
ff8a8a7a
CS
2571DEFUN_YANG(bgp_ebgp_requires_policy,
2572 bgp_ebgp_requires_policy_cmd,
2573 "bgp ebgp-requires-policy",
2574 "BGP specific commands\n"
2575 "Require in and out policy for eBGP peers (RFC8212)\n")
2576{
87ce2564
CS
2577 nb_cli_enqueue_change(vty, "./global/ebgp-requires-policy",
2578 NB_OP_MODIFY, "true");
ff8a8a7a
CS
2579 return nb_cli_apply_changes(vty, NULL);
2580}
9dac9fc8 2581
ff8a8a7a
CS
2582DEFUN_YANG(no_bgp_ebgp_requires_policy,
2583 no_bgp_ebgp_requires_policy_cmd,
2584 "no bgp ebgp-requires-policy",
2585 NO_STR
2586 "BGP specific commands\n"
2587 "Require in and out policy for eBGP peers (RFC8212)\n")
9dac9fc8 2588{
87ce2564
CS
2589 nb_cli_enqueue_change(vty, "./global/ebgp-requires-policy",
2590 NB_OP_MODIFY, "false");
ff8a8a7a 2591 return nb_cli_apply_changes(vty, NULL);
9dac9fc8
DA
2592}
2593
ff8a8a7a
CS
2594void cli_show_router_bgp_ebgp_requires_policy(struct vty *vty,
2595 struct lyd_node *dnode,
2596 bool show_defaults)
9dac9fc8 2597{
ff8a8a7a
CS
2598 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_EBGP_REQUIRES_POLICY)
2599 vty_out(vty, " bgp ebgp-requires-policy\n");
9dac9fc8
DA
2600}
2601
fb29348a
DA
2602DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2603 "bgp reject-as-sets",
2604 "BGP specific commands\n"
2605 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2606{
2607 VTY_DECLVAR_CONTEXT(bgp, bgp);
2608 struct listnode *node, *nnode;
2609 struct peer *peer;
2610
7f972cd8 2611 bgp->reject_as_sets = true;
fb29348a
DA
2612
2613 /* Reset existing BGP sessions to reject routes
2614 * with aspath containing AS_SET or AS_CONFED_SET.
2615 */
2616 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2617 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2618 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2619 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2620 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2621 }
2622 }
2623
2624 return CMD_SUCCESS;
2625}
2626
2627DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2628 "no bgp reject-as-sets",
2629 NO_STR
2630 "BGP specific commands\n"
2631 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2632{
2633 VTY_DECLVAR_CONTEXT(bgp, bgp);
2634 struct listnode *node, *nnode;
2635 struct peer *peer;
2636
7f972cd8 2637 bgp->reject_as_sets = false;
fb29348a
DA
2638
2639 /* Reset existing BGP sessions to reject routes
2640 * with aspath containing AS_SET or AS_CONFED_SET.
2641 */
2642 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2643 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2644 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2645 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2646 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2647 }
2648 }
2649
2650 return CMD_SUCCESS;
2651}
9dac9fc8 2652
718e3744 2653/* "bgp deterministic-med" configuration. */
ff8a8a7a 2654DEFUN_YANG (bgp_deterministic_med,
718e3744 2655 bgp_deterministic_med_cmd,
2656 "bgp deterministic-med",
2657 "BGP specific commands\n"
2658 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2659{
87ce2564
CS
2660 nb_cli_enqueue_change(
2661 vty, "./global/route-selection-options/deterministic-med",
2662 NB_OP_MODIFY, "true");
7aafcaca 2663
ff8a8a7a 2664 return nb_cli_apply_changes(vty, NULL);
718e3744 2665}
2666
ff8a8a7a 2667DEFUN_YANG (no_bgp_deterministic_med,
718e3744 2668 no_bgp_deterministic_med_cmd,
2669 "no bgp deterministic-med",
2670 NO_STR
2671 "BGP specific commands\n"
2672 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2673{
87ce2564
CS
2674 nb_cli_enqueue_change(
2675 vty, "./global/route-selection-options/deterministic-med",
2676 NB_OP_MODIFY, "false");
d62a17ae 2677
ff8a8a7a 2678 return nb_cli_apply_changes(vty, NULL);
718e3744 2679}
538621f2 2680
055679e9 2681/* "bgp graceful-restart mode" configuration. */
538621f2 2682DEFUN (bgp_graceful_restart,
2ba1fe69 2683 bgp_graceful_restart_cmd,
2684 "bgp graceful-restart",
2685 "BGP specific commands\n"
2686 GR_CMD
055679e9 2687 )
538621f2 2688{
055679e9 2689 int ret = BGP_GR_FAILURE;
2690
2691 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2692 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
dc95985f 2693
d62a17ae 2694 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2695
2696 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2697
36235319
QY
2698 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2699 ret);
5cce3f05 2700
055679e9 2701 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2702 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
dc95985f 2703 vty_out(vty,
2704 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2705 return bgp_vty_return(vty, ret);
538621f2 2706}
2707
2708DEFUN (no_bgp_graceful_restart,
2ba1fe69 2709 no_bgp_graceful_restart_cmd,
2710 "no bgp graceful-restart",
2711 NO_STR
2712 "BGP specific commands\n"
2713 NO_GR_CMD
055679e9 2714 )
538621f2 2715{
d62a17ae 2716 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2717
2718 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2719 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
055679e9 2720
2721 int ret = BGP_GR_FAILURE;
2722
2723 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2724
36235319
QY
2725 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2726 ret);
5cce3f05 2727
055679e9 2728 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2729 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
dc95985f 2730 vty_out(vty,
2731 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2732
2733 return bgp_vty_return(vty, ret);
538621f2 2734}
2735
93406d87 2736DEFUN (bgp_graceful_restart_stalepath_time,
2ba1fe69 2737 bgp_graceful_restart_stalepath_time_cmd,
2738 "bgp graceful-restart stalepath-time (1-4095)",
2739 "BGP specific commands\n"
2740 "Graceful restart capability parameters\n"
2741 "Set the max time to hold onto restarting peer's stale paths\n"
2742 "Delay value (seconds)\n")
93406d87 2743{
d62a17ae 2744 VTY_DECLVAR_CONTEXT(bgp, bgp);
2745 int idx_number = 3;
d7c0a89a 2746 uint32_t stalepath;
93406d87 2747
d62a17ae 2748 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2749 bgp->stalepath_time = stalepath;
2750 return CMD_SUCCESS;
93406d87 2751}
2752
eb6f1b41 2753DEFUN (bgp_graceful_restart_restart_time,
2ba1fe69 2754 bgp_graceful_restart_restart_time_cmd,
2755 "bgp graceful-restart restart-time (1-4095)",
2756 "BGP specific commands\n"
2757 "Graceful restart capability parameters\n"
2758 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2759 "Delay value (seconds)\n")
eb6f1b41 2760{
d62a17ae 2761 VTY_DECLVAR_CONTEXT(bgp, bgp);
2762 int idx_number = 3;
d7c0a89a 2763 uint32_t restart;
eb6f1b41 2764
d62a17ae 2765 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2766 bgp->restart_time = restart;
2767 return CMD_SUCCESS;
eb6f1b41
PG
2768}
2769
cfd47646 2770DEFUN (bgp_graceful_restart_select_defer_time,
2771 bgp_graceful_restart_select_defer_time_cmd,
2772 "bgp graceful-restart select-defer-time (0-3600)",
2773 "BGP specific commands\n"
2774 "Graceful restart capability parameters\n"
2775 "Set the time to defer the BGP route selection after restart\n"
2776 "Delay value (seconds, 0 - disable)\n")
2777{
2778 VTY_DECLVAR_CONTEXT(bgp, bgp);
2779 int idx_number = 3;
2780 uint32_t defer_time;
2781
2782 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2783 bgp->select_defer_time = defer_time;
2784 if (defer_time == 0)
892fedb6 2785 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2786 else
892fedb6 2787 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2788
2789 return CMD_SUCCESS;
2790}
2791
93406d87 2792DEFUN (no_bgp_graceful_restart_stalepath_time,
2ba1fe69 2793 no_bgp_graceful_restart_stalepath_time_cmd,
2794 "no bgp graceful-restart stalepath-time [(1-4095)]",
2795 NO_STR
2796 "BGP specific commands\n"
2797 "Graceful restart capability parameters\n"
2798 "Set the max time to hold onto restarting peer's stale paths\n"
2799 "Delay value (seconds)\n")
93406d87 2800{
d62a17ae 2801 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 2802
d62a17ae 2803 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2804 return CMD_SUCCESS;
93406d87 2805}
2806
eb6f1b41 2807DEFUN (no_bgp_graceful_restart_restart_time,
2ba1fe69 2808 no_bgp_graceful_restart_restart_time_cmd,
2809 "no bgp graceful-restart restart-time [(1-4095)]",
2810 NO_STR
2811 "BGP specific commands\n"
2812 "Graceful restart capability parameters\n"
2813 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2814 "Delay value (seconds)\n")
eb6f1b41 2815{
d62a17ae 2816 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 2817
d62a17ae 2818 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2819 return CMD_SUCCESS;
eb6f1b41
PG
2820}
2821
cfd47646 2822DEFUN (no_bgp_graceful_restart_select_defer_time,
2823 no_bgp_graceful_restart_select_defer_time_cmd,
2824 "no bgp graceful-restart select-defer-time [(0-3600)]",
2825 NO_STR
2826 "BGP specific commands\n"
2827 "Graceful restart capability parameters\n"
2828 "Set the time to defer the BGP route selection after restart\n"
2829 "Delay value (seconds)\n")
2830{
2831 VTY_DECLVAR_CONTEXT(bgp, bgp);
2832
2833 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
892fedb6 2834 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2835
2836 return CMD_SUCCESS;
2837}
2838
43fc21b3 2839DEFUN (bgp_graceful_restart_preserve_fw,
2ba1fe69 2840 bgp_graceful_restart_preserve_fw_cmd,
2841 "bgp graceful-restart preserve-fw-state",
2842 "BGP specific commands\n"
2843 "Graceful restart capability parameters\n"
2844 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2845{
d62a17ae 2846 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2847 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2848 return CMD_SUCCESS;
43fc21b3
JC
2849}
2850
2851DEFUN (no_bgp_graceful_restart_preserve_fw,
2ba1fe69 2852 no_bgp_graceful_restart_preserve_fw_cmd,
2853 "no bgp graceful-restart preserve-fw-state",
2854 NO_STR
2855 "BGP specific commands\n"
2856 "Graceful restart capability parameters\n"
2857 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2858{
d62a17ae 2859 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2860 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2861 return CMD_SUCCESS;
43fc21b3
JC
2862}
2863
055679e9 2864DEFUN (bgp_graceful_restart_disable,
2ba1fe69 2865 bgp_graceful_restart_disable_cmd,
2866 "bgp graceful-restart-disable",
2867 "BGP specific commands\n"
2868 GR_DISABLE)
055679e9 2869{
2870 int ret = BGP_GR_FAILURE;
2871
2872 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2873 zlog_debug(
2ba1fe69 2874 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
dc95985f 2875
055679e9 2876 VTY_DECLVAR_CONTEXT(bgp, bgp);
2877
2878 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
2879
dc95985f 2880 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2881 bgp->peer, ret);
5cce3f05 2882
055679e9 2883 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2884 zlog_debug(
2ba1fe69 2885 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
dc95985f 2886 vty_out(vty,
2887 "Graceful restart configuration changed, reset all peers to take effect\n");
2888
055679e9 2889 return bgp_vty_return(vty, ret);
2890}
2891
2892DEFUN (no_bgp_graceful_restart_disable,
2ba1fe69 2893 no_bgp_graceful_restart_disable_cmd,
2894 "no bgp graceful-restart-disable",
2895 NO_STR
2896 "BGP specific commands\n"
2897 NO_GR_DISABLE
055679e9 2898 )
2899{
2900 VTY_DECLVAR_CONTEXT(bgp, bgp);
2901
2902 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2903 zlog_debug(
2ba1fe69 2904 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
055679e9 2905
2906 int ret = BGP_GR_FAILURE;
2907
2908 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
2909
36235319
QY
2910 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2911 ret);
5cce3f05 2912
055679e9 2913 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2914 zlog_debug(
2ba1fe69 2915 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
dc95985f 2916 vty_out(vty,
2917 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2918
2919 return bgp_vty_return(vty, ret);
2920}
2921
2922DEFUN (bgp_neighbor_graceful_restart_set,
2ba1fe69 2923 bgp_neighbor_graceful_restart_set_cmd,
2924 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2925 NEIGHBOR_STR
2926 NEIGHBOR_ADDR_STR2
2927 GR_NEIGHBOR_CMD
055679e9 2928 )
2929{
2930 int idx_peer = 1;
2931 struct peer *peer;
2932 int ret = BGP_GR_FAILURE;
2933
dc95985f 2934 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2935
055679e9 2936 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2937 zlog_debug(
2ba1fe69 2938 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
dc95985f 2939
055679e9 2940 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2941 if (!peer)
2942 return CMD_WARNING_CONFIG_FAILED;
2943
2944 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
2945
dc95985f 2946 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2947 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2948
2949 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2950 zlog_debug(
2ba1fe69 2951 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 2952 vty_out(vty,
2953 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2954
2955 return bgp_vty_return(vty, ret);
2956}
2957
2958DEFUN (no_bgp_neighbor_graceful_restart,
2ba1fe69 2959 no_bgp_neighbor_graceful_restart_set_cmd,
2960 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2961 NO_STR
2962 NEIGHBOR_STR
2963 NEIGHBOR_ADDR_STR2
2964 NO_GR_NEIGHBOR_CMD
055679e9 2965 )
2966{
2967 int idx_peer = 2;
2968 int ret = BGP_GR_FAILURE;
2969 struct peer *peer;
2970
dc95985f 2971 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2972
055679e9 2973 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2974 if (!peer)
2975 return CMD_WARNING_CONFIG_FAILED;
2976
2977 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2978 zlog_debug(
2ba1fe69 2979 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
055679e9 2980
2981 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
2982
dc95985f 2983 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2984 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2985
2986 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2987 zlog_debug(
2ba1fe69 2988 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 2989 vty_out(vty,
2990 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2991
2992 return bgp_vty_return(vty, ret);
2993}
2994
2995DEFUN (bgp_neighbor_graceful_restart_helper_set,
2ba1fe69 2996 bgp_neighbor_graceful_restart_helper_set_cmd,
2997 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
2998 NEIGHBOR_STR
2999 NEIGHBOR_ADDR_STR2
3000 GR_NEIGHBOR_HELPER_CMD
055679e9 3001 )
3002{
3003 int idx_peer = 1;
3004 struct peer *peer;
3005 int ret = BGP_GR_FAILURE;
3006
dc95985f 3007 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3008
055679e9 3009 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3010 zlog_debug(
2ba1fe69 3011 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
dc95985f 3012
055679e9 3013 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3014
055679e9 3015 if (!peer)
3016 return CMD_WARNING_CONFIG_FAILED;
3017
3018
3019 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
5cce3f05 3020
dc95985f 3021 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3022 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
5cce3f05 3023
055679e9 3024 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3025 zlog_debug(
2ba1fe69 3026 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 3027 vty_out(vty,
3028 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3029
3030 return bgp_vty_return(vty, ret);
3031}
3032
3033DEFUN (no_bgp_neighbor_graceful_restart_helper,
2ba1fe69 3034 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3035 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3036 NO_STR
3037 NEIGHBOR_STR
3038 NEIGHBOR_ADDR_STR2
3039 NO_GR_NEIGHBOR_HELPER_CMD
055679e9 3040 )
3041{
3042 int idx_peer = 2;
3043 int ret = BGP_GR_FAILURE;
3044 struct peer *peer;
3045
dc95985f 3046 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3047
055679e9 3048 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3049 if (!peer)
3050 return CMD_WARNING_CONFIG_FAILED;
3051
3052 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3053 zlog_debug(
2ba1fe69 3054 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
055679e9 3055
36235319 3056 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
055679e9 3057
dc95985f 3058 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3059 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3060
3061 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3062 zlog_debug(
2ba1fe69 3063 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 3064 vty_out(vty,
3065 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3066
3067 return bgp_vty_return(vty, ret);
3068}
3069
3070DEFUN (bgp_neighbor_graceful_restart_disable_set,
2ba1fe69 3071 bgp_neighbor_graceful_restart_disable_set_cmd,
3072 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3073 NEIGHBOR_STR
3074 NEIGHBOR_ADDR_STR2
3075 GR_NEIGHBOR_DISABLE_CMD
055679e9 3076 )
3077{
3078 int idx_peer = 1;
3079 struct peer *peer;
3080 int ret = BGP_GR_FAILURE;
3081
dc95985f 3082 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3083
055679e9 3084 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3085 zlog_debug(
2ba1fe69 3086 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 3087
3088 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3089 if (!peer)
3090 return CMD_WARNING_CONFIG_FAILED;
3091
36235319 3092 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
055679e9 3093
3094 if (peer->bgp->t_startup)
3095 bgp_peer_gr_flags_update(peer);
3096
dc95985f 3097 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3098 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3099
055679e9 3100 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3101 zlog_debug(
2ba1fe69 3102 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3103 vty_out(vty,
3104 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3105
3106 return bgp_vty_return(vty, ret);
3107}
3108
3109DEFUN (no_bgp_neighbor_graceful_restart_disable,
2ba1fe69 3110 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3111 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3112 NO_STR
3113 NEIGHBOR_STR
3114 NEIGHBOR_ADDR_STR2
3115 NO_GR_NEIGHBOR_DISABLE_CMD
055679e9 3116 )
3117{
3118 int idx_peer = 2;
3119 int ret = BGP_GR_FAILURE;
3120 struct peer *peer;
3121
dc95985f 3122 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3123
055679e9 3124 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3125 if (!peer)
3126 return CMD_WARNING_CONFIG_FAILED;
3127
3128 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3129 zlog_debug(
2ba1fe69 3130 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 3131
3132 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3133
dc95985f 3134 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3135 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3136
3137 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3138 zlog_debug(
2ba1fe69 3139 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3140 vty_out(vty,
3141 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3142
3143 return bgp_vty_return(vty, ret);
3144}
3145
d6e3c15b 3146DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3147 bgp_graceful_restart_disable_eor_cmd,
3148 "bgp graceful-restart disable-eor",
3149 "BGP specific commands\n"
3150 "Graceful restart configuration parameters\n"
3151 "Disable EOR Check\n")
3152{
3153 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3154 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3155
d6e3c15b 3156 return CMD_SUCCESS;
3157}
3158
3159DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3160 no_bgp_graceful_restart_disable_eor_cmd,
3161 "no bgp graceful-restart disable-eor",
3162 NO_STR
3163 "BGP specific commands\n"
3164 "Graceful restart configuration parameters\n"
3165 "Disable EOR Check\n")
3166{
3167 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3168 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3169
3170 return CMD_SUCCESS;
3171}
3172
3173DEFUN (bgp_graceful_restart_rib_stale_time,
3174 bgp_graceful_restart_rib_stale_time_cmd,
3175 "bgp graceful-restart rib-stale-time (1-3600)",
3176 "BGP specific commands\n"
3177 "Graceful restart configuration parameters\n"
3178 "Specify the stale route removal timer in rib\n"
3179 "Delay value (seconds)\n")
3180{
3181 VTY_DECLVAR_CONTEXT(bgp, bgp);
3182 int idx_number = 3;
3183 uint32_t stale_time;
3184
3185 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3186 bgp->rib_stale_time = stale_time;
3187 /* Send the stale timer update message to RIB */
3188 if (bgp_zebra_stale_timer_update(bgp))
3189 return CMD_WARNING;
3190
3191 return CMD_SUCCESS;
3192}
3193
3194DEFUN (no_bgp_graceful_restart_rib_stale_time,
3195 no_bgp_graceful_restart_rib_stale_time_cmd,
3196 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3197 NO_STR
3198 "BGP specific commands\n"
3199 "Graceful restart configuration parameters\n"
3200 "Specify the stale route removal timer in rib\n"
3201 "Delay value (seconds)\n")
3202{
3203 VTY_DECLVAR_CONTEXT(bgp, bgp);
3204
3205 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3206 /* Send the stale timer update message to RIB */
3207 if (bgp_zebra_stale_timer_update(bgp))
3208 return CMD_WARNING;
3209
d6e3c15b 3210 return CMD_SUCCESS;
3211}
3212
ff8a8a7a
CS
3213static inline int bgp_initiate_graceful_shut_unshut(struct bgp *bgp,
3214 char *errmsg,
3215 size_t errmsg_len)
05bd726c 3216{
3217 bgp_static_redo_import_check(bgp);
3218 bgp_redistribute_redo(bgp);
ff8a8a7a
CS
3219 if (bgp_clear_star_soft_out(bgp->name, errmsg, errmsg_len) < 0)
3220 return -1;
3221 if (bgp_clear_star_soft_in(bgp->name, errmsg, errmsg_len) < 0)
3222 return -1;
3223
3224 return 0;
05bd726c 3225}
3226
3227static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3228{
3229 struct listnode *node, *nnode;
3230 struct bgp *bgp;
3231 bool vrf_cfg = false;
ff8a8a7a 3232 char errmsg[BUFSIZ] = {'\0'};
05bd726c 3233
3234 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3235 return CMD_SUCCESS;
3236
3237 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3238 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3239 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3240 vty_out(vty,
3241 "%% graceful-shutdown configuration found in vrf %s\n",
3242 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3243 VRF_DEFAULT_NAME : bgp->name);
3244 vrf_cfg = true;
3245 }
3246 }
3247
3248 if (vrf_cfg) {
3249 vty_out(vty,
3250 "%%Failed: global graceful-shutdown not permitted\n");
3251 return CMD_WARNING;
3252 }
3253
3254 /* Set flag globally */
3255 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3256
3257 /* Initiate processing for all BGP instances. */
ff8a8a7a
CS
3258 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3259 if (bgp_initiate_graceful_shut_unshut(bgp, errmsg,
3260 sizeof(errmsg))
3261 < 0)
3262 if (strlen(errmsg))
3263 vty_out(vty, "%s\n", errmsg);
3264 }
05bd726c 3265
3266 return CMD_SUCCESS;
3267}
3268
3269static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3270{
3271 struct listnode *node, *nnode;
3272 struct bgp *bgp;
ff8a8a7a 3273 char errmsg[BUFSIZ] = {'\0'};
05bd726c 3274
3275 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3276 return CMD_SUCCESS;
3277
3278 /* Unset flag globally */
3279 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3280
3281 /* Initiate processing for all BGP instances. */
ff8a8a7a
CS
3282 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3283 if (bgp_initiate_graceful_shut_unshut(bgp, errmsg,
3284 sizeof(errmsg))
3285 < 0)
3286 if (strlen(errmsg))
3287 vty_out(vty, "%s\n", errmsg);
3288 }
05bd726c 3289
3290 return CMD_SUCCESS;
3291}
3292
7f323236
DW
3293/* "bgp graceful-shutdown" configuration */
3294DEFUN (bgp_graceful_shutdown,
3295 bgp_graceful_shutdown_cmd,
3296 "bgp graceful-shutdown",
3297 BGP_STR
3298 "Graceful shutdown parameters\n")
3299{
05bd726c 3300 if (vty->node == CONFIG_NODE)
3301 return bgp_global_graceful_shutdown_config_vty(vty);
3302
87ce2564
CS
3303 nb_cli_enqueue_change(vty, "./global/graceful-shutdown/enable",
3304 NB_OP_MODIFY, "true");
7f323236 3305
ff8a8a7a 3306 return nb_cli_apply_changes(vty, NULL);
7f323236
DW
3307}
3308
ff8a8a7a 3309DEFUN_YANG (no_bgp_graceful_shutdown,
7f323236
DW
3310 no_bgp_graceful_shutdown_cmd,
3311 "no bgp graceful-shutdown",
3312 NO_STR
3313 BGP_STR
3314 "Graceful shutdown parameters\n")
3315{
05bd726c 3316 if (vty->node == CONFIG_NODE)
3317 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3318
87ce2564
CS
3319 nb_cli_enqueue_change(vty, "./global/graceful-shutdown/enable",
3320 NB_OP_MODIFY, "false");
05bd726c 3321
ff8a8a7a
CS
3322 return nb_cli_apply_changes(vty, NULL);
3323}
7f323236 3324
ff8a8a7a
CS
3325void cli_show_router_bgp_graceful_shutdown(struct vty *vty,
3326 struct lyd_node *dnode,
3327 bool show_defaults)
3328{
3329 if (yang_dnode_get_bool(dnode, NULL))
3330 vty_out(vty, " bgp graceful-shutdown\n");
7f323236
DW
3331}
3332
718e3744 3333/* "bgp fast-external-failover" configuration. */
ff8a8a7a 3334DEFUN_YANG (bgp_fast_external_failover,
718e3744 3335 bgp_fast_external_failover_cmd,
3336 "bgp fast-external-failover",
3337 BGP_STR
3338 "Immediately reset session if a link to a directly connected external peer goes down\n")
3339{
87ce2564
CS
3340 nb_cli_enqueue_change(vty, "./global/fast-external-failover",
3341 NB_OP_MODIFY, "false");
ff8a8a7a
CS
3342
3343 return nb_cli_apply_changes(vty, NULL);
718e3744 3344}
3345
ff8a8a7a 3346DEFUN_YANG (no_bgp_fast_external_failover,
718e3744 3347 no_bgp_fast_external_failover_cmd,
3348 "no bgp fast-external-failover",
3349 NO_STR
3350 BGP_STR
3351 "Immediately reset session if a link to a directly connected external peer goes down\n")
3352{
87ce2564
CS
3353 nb_cli_enqueue_change(vty, "./global/fast-external-failover",
3354 NB_OP_MODIFY, "true");
ff8a8a7a
CS
3355
3356 return nb_cli_apply_changes(vty, NULL);
3357}
3358
3359void cli_show_router_bgp_fast_external_failover(struct vty *vty,
3360 struct lyd_node *dnode,
3361 bool show_defaults)
3362{
3363 if (!yang_dnode_get_bool(dnode, NULL))
3364 vty_out(vty, " no bgp fast-external-failover\n");
718e3744 3365}
6b0655a2 3366
718e3744 3367/* "bgp bestpath compare-routerid" configuration. */
ff8a8a7a
CS
3368DEFUN_YANG(bgp_bestpath_compare_router_id,
3369 bgp_bestpath_compare_router_id_cmd,
3370 "bgp bestpath compare-routerid",
3371 "BGP specific commands\n"
3372 "Change the default bestpath selection\n"
3373 "Compare router-id for identical EBGP paths\n")
718e3744 3374{
ff8a8a7a 3375 nb_cli_enqueue_change(
87ce2564
CS
3376 vty,
3377 "./global/route-selection-options/external-compare-router-id",
ff8a8a7a 3378 NB_OP_MODIFY, "true");
7aafcaca 3379
ff8a8a7a 3380 return nb_cli_apply_changes(vty, NULL);
718e3744 3381}
3382
ff8a8a7a
CS
3383DEFUN_YANG(no_bgp_bestpath_compare_router_id,
3384 no_bgp_bestpath_compare_router_id_cmd,
3385 "no bgp bestpath compare-routerid",
3386 NO_STR
3387 "BGP specific commands\n"
3388 "Change the default bestpath selection\n"
3389 "Compare router-id for identical EBGP paths\n")
718e3744 3390{
ff8a8a7a 3391 nb_cli_enqueue_change(
87ce2564
CS
3392 vty,
3393 "./global/route-selection-options/external-compare-router-id",
ff8a8a7a 3394 NB_OP_MODIFY, "false");
7aafcaca 3395
ff8a8a7a 3396 return nb_cli_apply_changes(vty, NULL);
718e3744 3397}
6b0655a2 3398
718e3744 3399/* "bgp bestpath as-path ignore" configuration. */
ff8a8a7a
CS
3400DEFUN_YANG(bgp_bestpath_aspath_ignore,
3401 bgp_bestpath_aspath_ignore_cmd,
3402 "bgp bestpath as-path ignore",
3403 "BGP specific commands\n"
3404 "Change the default bestpath selection\n"
3405 "AS-path attribute\n"
3406 "Ignore as-path length in selecting a route\n")
718e3744 3407{
87ce2564
CS
3408 nb_cli_enqueue_change(
3409 vty, "./global/route-selection-options/ignore-as-path-length",
3410 NB_OP_MODIFY, "true");
7aafcaca 3411
ff8a8a7a 3412 return nb_cli_apply_changes(vty, NULL);
718e3744 3413}
3414
ff8a8a7a
CS
3415DEFUN_YANG(no_bgp_bestpath_aspath_ignore,
3416 no_bgp_bestpath_aspath_ignore_cmd,
3417 "no bgp bestpath as-path ignore",
3418 NO_STR
3419 "BGP specific commands\n"
3420 "Change the default bestpath selection\n"
3421 "AS-path attribute\n"
3422 "Ignore as-path length in selecting a route\n")
718e3744 3423{
87ce2564
CS
3424 nb_cli_enqueue_change(
3425 vty, "./global/route-selection-options/ignore-as-path-length",
3426 NB_OP_MODIFY, "false");
7aafcaca 3427
ff8a8a7a 3428 return nb_cli_apply_changes(vty, NULL);
718e3744 3429}
6b0655a2 3430
6811845b 3431/* "bgp bestpath as-path confed" configuration. */
ff8a8a7a 3432DEFUN_YANG (bgp_bestpath_aspath_confed,
6811845b 3433 bgp_bestpath_aspath_confed_cmd,
3434 "bgp bestpath as-path confed",
3435 "BGP specific commands\n"
3436 "Change the default bestpath selection\n"
3437 "AS-path attribute\n"
3438 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3439{
87ce2564
CS
3440 nb_cli_enqueue_change(vty,
3441 "./global/route-selection-options/aspath-confed",
ff8a8a7a 3442 NB_OP_MODIFY, "true");
7aafcaca 3443
ff8a8a7a 3444 return nb_cli_apply_changes(vty, NULL);
6811845b 3445}
3446
ff8a8a7a 3447DEFUN_YANG (no_bgp_bestpath_aspath_confed,
6811845b 3448 no_bgp_bestpath_aspath_confed_cmd,
3449 "no bgp bestpath as-path confed",
3450 NO_STR
3451 "BGP specific commands\n"
3452 "Change the default bestpath selection\n"
3453 "AS-path attribute\n"
3454 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3455{
87ce2564
CS
3456 nb_cli_enqueue_change(vty,
3457 "./global/route-selection-options/aspath-confed",
ff8a8a7a 3458 NB_OP_MODIFY, "false");
7aafcaca 3459
ff8a8a7a 3460 return nb_cli_apply_changes(vty, NULL);
6811845b 3461}
6b0655a2 3462
2fdd455c 3463/* "bgp bestpath as-path multipath-relax" configuration. */
ff8a8a7a 3464DEFUN_YANG (bgp_bestpath_aspath_multipath_relax,
2fdd455c 3465 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3466 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
3467 "BGP specific commands\n"
3468 "Change the default bestpath selection\n"
3469 "AS-path attribute\n"
3470 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3471 "Generate an AS_SET\n"
16fc1eec
DS
3472 "Do not generate an AS_SET\n")
3473{
d62a17ae 3474 int idx = 0;
219178b6 3475
87ce2564
CS
3476 nb_cli_enqueue_change(
3477 vty, "./global/route-selection-options/allow-multiple-as",
3478 NB_OP_MODIFY, "true");
d62a17ae 3479 if (argv_find(argv, argc, "as-set", &idx))
ff8a8a7a 3480 nb_cli_enqueue_change(
87ce2564
CS
3481 vty,
3482 "./global/route-selection-options/multi-path-as-set",
ff8a8a7a 3483 NB_OP_MODIFY, "true");
d62a17ae 3484 else
ff8a8a7a 3485 nb_cli_enqueue_change(
87ce2564
CS
3486 vty,
3487 "./global/route-selection-options/multi-path-as-set",
ff8a8a7a 3488 NB_OP_MODIFY, "false");
7aafcaca 3489
ff8a8a7a 3490 return nb_cli_apply_changes(vty, NULL);
16fc1eec
DS
3491}
3492
ff8a8a7a 3493DEFUN_YANG (no_bgp_bestpath_aspath_multipath_relax,
219178b6 3494 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3495 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
3496 NO_STR
3497 "BGP specific commands\n"
3498 "Change the default bestpath selection\n"
3499 "AS-path attribute\n"
3500 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3501 "Generate an AS_SET\n"
16fc1eec
DS
3502 "Do not generate an AS_SET\n")
3503{
87ce2564
CS
3504 nb_cli_enqueue_change(
3505 vty, "./global/route-selection-options/allow-multiple-as",
3506 NB_OP_MODIFY, "false");
3507 nb_cli_enqueue_change(
3508 vty, "./global/route-selection-options/multi-path-as-set",
3509 NB_OP_MODIFY, "false");
7aafcaca 3510
ff8a8a7a 3511 return nb_cli_apply_changes(vty, NULL);
2fdd455c 3512}
6b0655a2 3513
848973c7 3514/* "bgp log-neighbor-changes" configuration. */
ff8a8a7a
CS
3515DEFUN_YANG(bgp_log_neighbor_changes,
3516 bgp_log_neighbor_changes_cmd,
3517 "bgp log-neighbor-changes",
3518 "BGP specific commands\n"
3519 "Log neighbor up/down and reset reason\n")
848973c7 3520{
87ce2564
CS
3521 nb_cli_enqueue_change(
3522 vty, "./global/global-neighbor-config/log-neighbor-changes",
3523 NB_OP_MODIFY, "true");
ff8a8a7a
CS
3524
3525 return nb_cli_apply_changes(vty, NULL);
848973c7 3526}
3527
ff8a8a7a
CS
3528DEFUN_YANG(no_bgp_log_neighbor_changes,
3529 no_bgp_log_neighbor_changes_cmd,
3530 "no bgp log-neighbor-changes",
3531 NO_STR
3532 "BGP specific commands\n"
3533 "Log neighbor up/down and reset reason\n")
848973c7 3534{
87ce2564
CS
3535 nb_cli_enqueue_change(
3536 vty, "./global/global-neighbor-config/log-neighbor-changes",
3537 NB_OP_MODIFY, "false");
ff8a8a7a
CS
3538
3539 return nb_cli_apply_changes(vty, NULL);
848973c7 3540}
6b0655a2 3541
718e3744 3542/* "bgp bestpath med" configuration. */
ff8a8a7a 3543DEFUN_YANG (bgp_bestpath_med,
718e3744 3544 bgp_bestpath_med_cmd,
2d8c1a4d 3545 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 3546 "BGP specific commands\n"
3547 "Change the default bestpath selection\n"
3548 "MED attribute\n"
3549 "Compare MED among confederation paths\n"
838758ac
DW
3550 "Treat missing MED as the least preferred one\n"
3551 "Treat missing MED as the least preferred one\n"
3552 "Compare MED among confederation paths\n")
718e3744 3553{
d62a17ae 3554 int idx = 0;
ff8a8a7a
CS
3555 bool confed = false;
3556 bool worst_med = false;
3557
3558
d62a17ae 3559 if (argv_find(argv, argc, "confed", &idx))
ff8a8a7a
CS
3560 confed = true;
3561
87ce2564
CS
3562 nb_cli_enqueue_change(vty,
3563 "./global/route-selection-options/confed-med",
ff8a8a7a
CS
3564 NB_OP_MODIFY, confed ? "true" : "false");
3565
d62a17ae 3566 idx = 0;
3567 if (argv_find(argv, argc, "missing-as-worst", &idx))
ff8a8a7a 3568 worst_med = true;
e52702f2 3569
87ce2564
CS
3570 nb_cli_enqueue_change(
3571 vty, "./global/route-selection-options/missing-as-worst-med",
3572 NB_OP_MODIFY, worst_med ? "true" : "false");
7aafcaca 3573
ff8a8a7a 3574 return nb_cli_apply_changes(vty, NULL);
718e3744 3575}
3576
ff8a8a7a 3577DEFUN_YANG (no_bgp_bestpath_med,
718e3744 3578 no_bgp_bestpath_med_cmd,
2d8c1a4d 3579 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 3580 NO_STR
3581 "BGP specific commands\n"
3582 "Change the default bestpath selection\n"
3583 "MED attribute\n"
3584 "Compare MED among confederation paths\n"
3a2d747c
QY
3585 "Treat missing MED as the least preferred one\n"
3586 "Treat missing MED as the least preferred one\n"
3587 "Compare MED among confederation paths\n")
718e3744 3588{
d62a17ae 3589 int idx = 0;
ff8a8a7a 3590
d62a17ae 3591 if (argv_find(argv, argc, "confed", &idx))
87ce2564
CS
3592 nb_cli_enqueue_change(
3593 vty, "./global/route-selection-options/confed-med",
3594 NB_OP_MODIFY, "false");
ff8a8a7a 3595
d62a17ae 3596 idx = 0;
3597 if (argv_find(argv, argc, "missing-as-worst", &idx))
ff8a8a7a 3598 nb_cli_enqueue_change(
87ce2564
CS
3599 vty,
3600 "./global/route-selection-options/missing-as-worst-med",
ff8a8a7a 3601 NB_OP_MODIFY, "false");
718e3744 3602
ff8a8a7a 3603 return nb_cli_apply_changes(vty, NULL);
718e3744 3604}
3605
f7e1c681 3606/* "bgp bestpath bandwidth" configuration. */
3607DEFPY (bgp_bestpath_bw,
3608 bgp_bestpath_bw_cmd,
ad36d216 3609 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
f7e1c681 3610 "BGP specific commands\n"
3611 "Change the default bestpath selection\n"
3612 "Link Bandwidth attribute\n"
3613 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3614 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3615 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3616{
3617 VTY_DECLVAR_CONTEXT(bgp, bgp);
3618 afi_t afi;
3619 safi_t safi;
3620
ad36d216
DS
3621 if (!bw_cfg) {
3622 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3623 return CMD_ERR_INCOMPLETE;
f7e1c681 3624 }
ad36d216
DS
3625 if (!strcmp(bw_cfg, "ignore"))
3626 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3627 else if (!strcmp(bw_cfg, "skip-missing"))
3628 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3629 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3630 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3631 else
3632 return CMD_ERR_NO_MATCH;
f7e1c681 3633
3634 /* This config is used in route install, so redo that. */
3635 FOREACH_AFI_SAFI (afi, safi) {
3636 if (!bgp_fibupd_safi(safi))
3637 continue;
3638 bgp_zebra_announce_table(bgp, afi, safi);
3639 }
3640
3641 return CMD_SUCCESS;
3642}
3643
ad36d216
DS
3644DEFPY (no_bgp_bestpath_bw,
3645 no_bgp_bestpath_bw_cmd,
3646 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3647 NO_STR
3648 "BGP specific commands\n"
3649 "Change the default bestpath selection\n"
3650 "Link Bandwidth attribute\n"
3651 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3652 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3653 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3654{
3655 VTY_DECLVAR_CONTEXT(bgp, bgp);
3656 afi_t afi;
3657 safi_t safi;
3658
3659 bgp->lb_handling = BGP_LINK_BW_ECMP;
3660
3661 /* This config is used in route install, so redo that. */
3662 FOREACH_AFI_SAFI (afi, safi) {
3663 if (!bgp_fibupd_safi(safi))
3664 continue;
3665 bgp_zebra_announce_table(bgp, afi, safi);
3666 }
3667 return CMD_SUCCESS;
3668}
3669
718e3744 3670/* "no bgp default ipv4-unicast". */
3671DEFUN (no_bgp_default_ipv4_unicast,
3672 no_bgp_default_ipv4_unicast_cmd,
3673 "no bgp default ipv4-unicast",
3674 NO_STR
3675 "BGP specific commands\n"
3676 "Configure BGP defaults\n"
3677 "Activate ipv4-unicast for a peer by default\n")
3678{
d62a17ae 3679 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3680 SET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
d62a17ae 3681 return CMD_SUCCESS;
718e3744 3682}
3683
3684DEFUN (bgp_default_ipv4_unicast,
3685 bgp_default_ipv4_unicast_cmd,
3686 "bgp default ipv4-unicast",
3687 "BGP specific commands\n"
3688 "Configure BGP defaults\n"
3689 "Activate ipv4-unicast for a peer by default\n")
3690{
d62a17ae 3691 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3692 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
d62a17ae 3693 return CMD_SUCCESS;
718e3744 3694}
6b0655a2 3695
04b6bdc0 3696/* Display hostname in certain command outputs */
ff8a8a7a 3697DEFUN_YANG (bgp_default_show_hostname,
04b6bdc0
DW
3698 bgp_default_show_hostname_cmd,
3699 "bgp default show-hostname",
3700 "BGP specific commands\n"
3701 "Configure BGP defaults\n"
0437e105 3702 "Show hostname in certain command outputs\n")
04b6bdc0 3703{
87ce2564
CS
3704 nb_cli_enqueue_change(vty, "./global/show-hostname", NB_OP_MODIFY,
3705 "true");
ff8a8a7a
CS
3706
3707 return nb_cli_apply_changes(vty, NULL);
04b6bdc0
DW
3708}
3709
ff8a8a7a
CS
3710DEFUN_YANG(no_bgp_default_show_hostname,
3711 no_bgp_default_show_hostname_cmd,
3712 "no bgp default show-hostname",
3713 NO_STR
3714 "BGP specific commands\n"
3715 "Configure BGP defaults\n"
3716 "Show hostname in certain command outputs\n")
04b6bdc0 3717{
87ce2564
CS
3718 nb_cli_enqueue_change(vty, "./global/show-hostname", NB_OP_MODIFY,
3719 "false");
ff8a8a7a
CS
3720
3721 return nb_cli_apply_changes(vty, NULL);
3722}
3723
3724void cli_show_router_bgp_show_hostname(struct vty *vty, struct lyd_node *dnode,
3725 bool show_defaults)
3726{
3727 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SHOW_HOSTNAME)
3728 vty_out(vty, " bgp default show-hostname\n");
04b6bdc0
DW
3729}
3730
aef999a2 3731/* Display hostname in certain command outputs */
232c75cd
CS
3732DEFUN_YANG(bgp_default_show_nexthop_hostname,
3733 bgp_default_show_nexthop_hostname_cmd,
3734 "bgp default show-nexthop-hostname",
3735 "BGP specific commands\n"
3736 "Configure BGP defaults\n"
3737 "Show hostname for nexthop in certain command outputs\n")
aef999a2 3738{
87ce2564
CS
3739 nb_cli_enqueue_change(vty, "./global/show-nexthop-hostname",
3740 NB_OP_MODIFY, "true");
ff8a8a7a
CS
3741
3742 return nb_cli_apply_changes(vty, NULL);
aef999a2
DA
3743}
3744
3745DEFUN (no_bgp_default_show_nexthop_hostname,
3746 no_bgp_default_show_nexthop_hostname_cmd,
3747 "no bgp default show-nexthop-hostname",
3748 NO_STR
3749 "BGP specific commands\n"
3750 "Configure BGP defaults\n"
3751 "Show hostname for nexthop in certain command outputs\n")
3752{
87ce2564
CS
3753 nb_cli_enqueue_change(vty, "./global/show-nexthop-hostname",
3754 NB_OP_MODIFY, "false");
ff8a8a7a
CS
3755
3756 return nb_cli_apply_changes(vty, NULL);
3757}
3758
3759void cli_show_router_bgp_show_nexthop_hostname(struct vty *vty,
3760 struct lyd_node *dnode,
3761 bool show_defaults)
3762{
3763 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SHOW_HOSTNAME)
3764 vty_out(vty, " bgp default show-nexthop-hostname\n");
aef999a2
DA
3765}
3766
8233ef81 3767/* "bgp network import-check" configuration. */
ff8a8a7a
CS
3768DEFUN_YANG(bgp_network_import_check,
3769 bgp_network_import_check_cmd,
3770 "bgp network import-check",
3771 "BGP specific commands\n"
3772 "BGP network command\n"
3773 "Check BGP network route exists in IGP\n")
718e3744 3774{
87ce2564
CS
3775 nb_cli_enqueue_change(vty, "./global/import-check", NB_OP_MODIFY,
3776 "true");
078430f6 3777
ff8a8a7a 3778 return nb_cli_apply_changes(vty, NULL);
718e3744 3779}
3780
d62a17ae 3781ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3782 "bgp network import-check exact",
3783 "BGP specific commands\n"
3784 "BGP network command\n"
3785 "Check BGP network route exists in IGP\n"
3786 "Match route precisely\n")
8233ef81 3787
ff8a8a7a
CS
3788DEFUN_YANG(no_bgp_network_import_check,
3789 no_bgp_network_import_check_cmd,
3790 "no bgp network import-check",
3791 NO_STR
3792 "BGP specific commands\n"
3793 "BGP network command\n"
3794 "Check BGP network route exists in IGP\n")
718e3744 3795{
87ce2564
CS
3796 nb_cli_enqueue_change(vty, "./global/import-check", NB_OP_MODIFY,
3797 "false");
5623e905 3798
ff8a8a7a 3799 return nb_cli_apply_changes(vty, NULL);
718e3744 3800}
6b0655a2 3801
ff8a8a7a
CS
3802void cli_show_router_bgp_import_check(struct vty *vty, struct lyd_node *dnode,
3803 bool show_defaults)
718e3744 3804{
ff8a8a7a
CS
3805 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_IMPORT_CHECK)
3806 vty_out(vty, " bgp network import-check\n");
3807}
718e3744 3808
ff8a8a7a
CS
3809DEFUN_YANG(bgp_default_local_preference,
3810 bgp_default_local_preference_cmd,
3811 "bgp default local-preference (0-4294967295)",
3812 "BGP specific commands\n"
3813 "Configure BGP defaults\n"
3814 "local preference (higher=more preferred)\n"
3815 "Configure default local preference value\n")
3816{
3817 int idx_number = 3;
718e3744 3818
87ce2564 3819 nb_cli_enqueue_change(vty, "./global/local-pref", NB_OP_MODIFY,
ff8a8a7a 3820 argv[idx_number]->arg);
718e3744 3821
ff8a8a7a 3822 return nb_cli_apply_changes(vty, NULL);
718e3744 3823}
3824
ff8a8a7a
CS
3825DEFUN_YANG(no_bgp_default_local_preference,
3826 no_bgp_default_local_preference_cmd,
3827 "no bgp default local-preference [(0-4294967295)]",
3828 NO_STR
3829 "BGP specific commands\n"
3830 "Configure BGP defaults\n"
3831 "local preference (higher=more preferred)\n"
3832 "Configure default local preference value\n")
718e3744 3833{
87ce2564 3834 nb_cli_enqueue_change(vty, "./global/local-pref", NB_OP_MODIFY, NULL);
7aafcaca 3835
ff8a8a7a 3836 return nb_cli_apply_changes(vty, NULL);
718e3744 3837}
3838
ff8a8a7a
CS
3839void cli_show_router_bgp_local_pref(struct vty *vty, struct lyd_node *dnode,
3840 bool show_defaults)
3841{
3842 vty_out(vty, " bgp default local-preference %u\n",
3843 yang_dnode_get_uint32(dnode, NULL));
3844}
6b0655a2 3845
ff8a8a7a
CS
3846
3847DEFUN_YANG(bgp_default_subgroup_pkt_queue_max,
3848 bgp_default_subgroup_pkt_queue_max_cmd,
3849 "bgp default subgroup-pkt-queue-max (20-100)",
3850 "BGP specific commands\n"
3851 "Configure BGP defaults\n"
3852 "subgroup-pkt-queue-max\n"
3853 "Configure subgroup packet queue max\n")
8bd9d948 3854{
d62a17ae 3855 int idx_number = 3;
3f9c7369 3856
ff8a8a7a 3857 nb_cli_enqueue_change(
87ce2564
CS
3858 vty,
3859 "./global/global-update-group-config/subgroup-pkt-queue-size",
ff8a8a7a 3860 NB_OP_MODIFY, argv[idx_number]->arg);
3f9c7369 3861
ff8a8a7a 3862 return nb_cli_apply_changes(vty, NULL);
3f9c7369
DS
3863}
3864
ff8a8a7a
CS
3865DEFUN_YANG(no_bgp_default_subgroup_pkt_queue_max,
3866 no_bgp_default_subgroup_pkt_queue_max_cmd,
3867 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3868 NO_STR
3869 "BGP specific commands\n"
3870 "Configure BGP defaults\n"
3871 "subgroup-pkt-queue-max\n"
3872 "Configure subgroup packet queue max\n")
3f9c7369 3873{
ff8a8a7a 3874 nb_cli_enqueue_change(
87ce2564
CS
3875 vty,
3876 "./global/global-update-group-config/subgroup-pkt-queue-size",
ff8a8a7a
CS
3877 NB_OP_MODIFY, NULL);
3878
3879 return nb_cli_apply_changes(vty, NULL);
8bd9d948
DS
3880}
3881
ff8a8a7a
CS
3882void cli_show_router_global_update_group_config_subgroup_pkt_queue_size(
3883 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
3884{
3885 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
3886 yang_dnode_get_uint32(dnode, NULL));
3887}
813d4307 3888
ff8a8a7a
CS
3889DEFUN_YANG(bgp_rr_allow_outbound_policy,
3890 bgp_rr_allow_outbound_policy_cmd,
3891 "bgp route-reflector allow-outbound-policy",
3892 "BGP specific commands\n"
3893 "Allow modifications made by out route-map\n"
3894 "on ibgp neighbors\n")
8bd9d948 3895{
87ce2564
CS
3896 nb_cli_enqueue_change(vty,
3897 "./global/route-reflector/allow-outbound-policy",
ff8a8a7a 3898 NB_OP_MODIFY, "true");
8bd9d948 3899
ff8a8a7a
CS
3900 return nb_cli_apply_changes(vty, NULL);
3901}
8bd9d948 3902
ff8a8a7a
CS
3903DEFUN_YANG(no_bgp_rr_allow_outbound_policy,
3904 no_bgp_rr_allow_outbound_policy_cmd,
3905 "no bgp route-reflector allow-outbound-policy",
3906 NO_STR
3907 "BGP specific commands\n"
3908 "Allow modifications made by out route-map\n"
3909 "on ibgp neighbors\n")
3910{
87ce2564
CS
3911 nb_cli_enqueue_change(vty,
3912 "./global/route-reflector/allow-outbound-policy",
ff8a8a7a
CS
3913 NB_OP_MODIFY, "false");
3914
3915 return nb_cli_apply_changes(vty, NULL);
8bd9d948
DS
3916}
3917
ff8a8a7a
CS
3918
3919void cli_show_router_global_neighbor_config(struct vty *vty,
3920 struct lyd_node *dnode,
3921 bool show_defaults)
8bd9d948 3922{
ff8a8a7a
CS
3923 uint32_t write_quanta, read_quanta;
3924
3925 if (yang_dnode_get_bool(dnode, "./log-neighbor-changes"))
3926 vty_out(vty, " bgp log-neighbor-changes\n");
8bd9d948 3927
ff8a8a7a
CS
3928 if (yang_dnode_exists(dnode, "./dynamic-neighbors-limit")) {
3929 uint32_t listen_limit = yang_dnode_get_uint32(
3930 dnode, "./dynamic-neighbors-limit");
3931 vty_out(vty, " bgp listen limit %u\n", listen_limit);
d62a17ae 3932 }
8bd9d948 3933
ff8a8a7a
CS
3934 write_quanta = yang_dnode_get_uint32(
3935 dnode, "./packet-quanta-config/wpkt-quanta");
3936 if (write_quanta != BGP_WRITE_PACKET_MAX)
3937 vty_out(vty, " write-quanta %d\n", write_quanta);
3938
3939 read_quanta = yang_dnode_get_uint32(
3940 dnode, "./packet-quanta-config/rpkt-quanta");
3941
3942 if (read_quanta != BGP_READ_PACKET_MAX)
3943 vty_out(vty, " read-quanta %d\n", read_quanta);
8bd9d948
DS
3944}
3945
ff8a8a7a
CS
3946DEFUN_YANG(bgp_listen_limit,
3947 bgp_listen_limit_cmd,
3948 "bgp listen limit (1-5000)",
3949 "BGP specific commands\n"
3950 "BGP Dynamic Neighbors listen commands\n"
3951 "Maximum number of BGP Dynamic Neighbors that can be created\n"
3952 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 3953{
d62a17ae 3954 int idx_number = 3;
f14e6fdb 3955
ff8a8a7a 3956 nb_cli_enqueue_change(
87ce2564 3957 vty, "./global/global-neighbor-config/dynamic-neighbors-limit",
ff8a8a7a 3958 NB_OP_MODIFY, argv[idx_number]->arg);
f14e6fdb 3959
ff8a8a7a 3960 return nb_cli_apply_changes(vty, NULL);
f14e6fdb
DS
3961}
3962
ff8a8a7a
CS
3963DEFUN_YANG(no_bgp_listen_limit,
3964 no_bgp_listen_limit_cmd,
3965 "no bgp listen limit [(1-5000)]",
3966 NO_STR
3967 "BGP specific commands\n"
3968 "BGP Dynamic Neighbors listen commands\n"
3969 "Maximum number of BGP Dynamic Neighbors that can be created\n"
3970 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 3971{
ff8a8a7a 3972 nb_cli_enqueue_change(
87ce2564 3973 vty, "./global/global-neighbor-config/dynamic-neighbors-limit",
ff8a8a7a
CS
3974 NB_OP_DESTROY, NULL);
3975
3976 return nb_cli_apply_changes(vty, NULL);
f14e6fdb
DS
3977}
3978
3979
20eb8864 3980/*
3981 * Check if this listen range is already configured. Check for exact
3982 * match or overlap based on input.
3983 */
d62a17ae 3984static struct peer_group *listen_range_exists(struct bgp *bgp,
3985 struct prefix *range, int exact)
3986{
3987 struct listnode *node, *nnode;
3988 struct listnode *node1, *nnode1;
3989 struct peer_group *group;
3990 struct prefix *lr;
3991 afi_t afi;
3992 int match;
3993
3994 afi = family2afi(range->family);
3995 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
3996 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
3997 lr)) {
3998 if (exact)
3999 match = prefix_same(range, lr);
4000 else
4001 match = (prefix_match(range, lr)
4002 || prefix_match(lr, range));
4003 if (match)
4004 return group;
4005 }
4006 }
4007
4008 return NULL;
20eb8864 4009}
4010
f14e6fdb
DS
4011DEFUN (bgp_listen_range,
4012 bgp_listen_range_cmd,
d7b9898c 4013 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
f14e6fdb 4014 "BGP specific commands\n"
d7fa34c1
QY
4015 "Configure BGP dynamic neighbors listen range\n"
4016 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
4017 NEIGHBOR_ADDR_STR
4018 "Member of the peer-group\n"
4019 "Peer-group name\n")
f14e6fdb 4020{
d62a17ae 4021 VTY_DECLVAR_CONTEXT(bgp, bgp);
4022 struct prefix range;
4023 struct peer_group *group, *existing_group;
4024 afi_t afi;
4025 int ret;
4026 int idx = 0;
4027
4028 argv_find(argv, argc, "A.B.C.D/M", &idx);
4029 argv_find(argv, argc, "X:X::X:X/M", &idx);
4030 char *prefix = argv[idx]->arg;
d7b9898c 4031 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 4032 char *peergroup = argv[idx]->arg;
4033
4034 /* Convert IP prefix string to struct prefix. */
4035 ret = str2prefix(prefix, &range);
4036 if (!ret) {
4037 vty_out(vty, "%% Malformed listen range\n");
4038 return CMD_WARNING_CONFIG_FAILED;
4039 }
4040
4041 afi = family2afi(range.family);
4042
4043 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4044 vty_out(vty,
4045 "%% Malformed listen range (link-local address)\n");
4046 return CMD_WARNING_CONFIG_FAILED;
4047 }
4048
4049 apply_mask(&range);
4050
4051 /* Check if same listen range is already configured. */
4052 existing_group = listen_range_exists(bgp, &range, 1);
4053 if (existing_group) {
4054 if (strcmp(existing_group->name, peergroup) == 0)
4055 return CMD_SUCCESS;
4056 else {
4057 vty_out(vty,
4058 "%% Same listen range is attached to peer-group %s\n",
4059 existing_group->name);
4060 return CMD_WARNING_CONFIG_FAILED;
4061 }
4062 }
4063
4064 /* Check if an overlapping listen range exists. */
4065 if (listen_range_exists(bgp, &range, 0)) {
4066 vty_out(vty,
4067 "%% Listen range overlaps with existing listen range\n");
4068 return CMD_WARNING_CONFIG_FAILED;
4069 }
4070
4071 group = peer_group_lookup(bgp, peergroup);
4072 if (!group) {
4073 vty_out(vty, "%% Configure the peer-group first\n");
4074 return CMD_WARNING_CONFIG_FAILED;
4075 }
4076
4077 ret = peer_group_listen_range_add(group, &range);
4078 return bgp_vty_return(vty, ret);
f14e6fdb
DS
4079}
4080
4081DEFUN (no_bgp_listen_range,
4082 no_bgp_listen_range_cmd,
d7b9898c 4083 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
d7fa34c1 4084 NO_STR
f14e6fdb 4085 "BGP specific commands\n"
d7fa34c1
QY
4086 "Unconfigure BGP dynamic neighbors listen range\n"
4087 "Unconfigure BGP dynamic neighbors listen range\n"
4088 NEIGHBOR_ADDR_STR
4089 "Member of the peer-group\n"
4090 "Peer-group name\n")
f14e6fdb 4091{
d62a17ae 4092 VTY_DECLVAR_CONTEXT(bgp, bgp);
4093 struct prefix range;
4094 struct peer_group *group;
4095 afi_t afi;
4096 int ret;
4097 int idx = 0;
4098
4099 argv_find(argv, argc, "A.B.C.D/M", &idx);
4100 argv_find(argv, argc, "X:X::X:X/M", &idx);
4101 char *prefix = argv[idx]->arg;
21d88a71 4102 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 4103 char *peergroup = argv[idx]->arg;
4104
4105 /* Convert IP prefix string to struct prefix. */
4106 ret = str2prefix(prefix, &range);
4107 if (!ret) {
4108 vty_out(vty, "%% Malformed listen range\n");
4109 return CMD_WARNING_CONFIG_FAILED;
4110 }
4111
4112 afi = family2afi(range.family);
4113
4114 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4115 vty_out(vty,
4116 "%% Malformed listen range (link-local address)\n");
4117 return CMD_WARNING_CONFIG_FAILED;
4118 }
4119
4120 apply_mask(&range);
4121
4122 group = peer_group_lookup(bgp, peergroup);
4123 if (!group) {
4124 vty_out(vty, "%% Peer-group does not exist\n");
4125 return CMD_WARNING_CONFIG_FAILED;
4126 }
4127
4128 ret = peer_group_listen_range_del(group, &range);
4129 return bgp_vty_return(vty, ret);
4130}
4131
2b791107 4132void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 4133{
4134 struct peer_group *group;
4135 struct listnode *node, *nnode, *rnode, *nrnode;
4136 struct prefix *range;
4137 afi_t afi;
d62a17ae 4138
4139 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4140 vty_out(vty, " bgp listen limit %d\n",
4141 bgp->dynamic_neighbors_limit);
4142
4143 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4144 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4145 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4146 nrnode, range)) {
d62a17ae 4147 vty_out(vty,
2dbe669b
DA
4148 " bgp listen range %pFX peer-group %s\n",
4149 range, group->name);
d62a17ae 4150 }
4151 }
4152 }
f14e6fdb
DS
4153}
4154
4155
ff8a8a7a
CS
4156DEFUN_YANG(bgp_disable_connected_route_check,
4157 bgp_disable_connected_route_check_cmd,
4158 "bgp disable-ebgp-connected-route-check",
4159 "BGP specific commands\n"
4160 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4161{
87ce2564
CS
4162 nb_cli_enqueue_change(vty,
4163 "./global/ebgp-multihop-connected-route-check",
ff8a8a7a 4164 NB_OP_MODIFY, "true");
7aafcaca 4165
ff8a8a7a 4166 return nb_cli_apply_changes(vty, NULL);
907f92c8
DS
4167}
4168
ff8a8a7a
CS
4169DEFUN_YANG(no_bgp_disable_connected_route_check,
4170 no_bgp_disable_connected_route_check_cmd,
4171 "no bgp disable-ebgp-connected-route-check",
4172 NO_STR
4173 "BGP specific commands\n"
4174 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4175{
87ce2564
CS
4176 nb_cli_enqueue_change(vty,
4177 "./global/ebgp-multihop-connected-route-check",
ff8a8a7a 4178 NB_OP_MODIFY, "false");
d62a17ae 4179
ff8a8a7a 4180 return nb_cli_apply_changes(vty, NULL);
d62a17ae 4181}
4182
ff8a8a7a
CS
4183void cli_show_router_global_ebgp_multihop_connected_route_check(
4184 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
4185{
4186 if (yang_dnode_get_bool(dnode, NULL))
4187 vty_out(vty, " bgp disable-ebgp-connected-route-check\n");
4188}
d62a17ae 4189
ff8a8a7a
CS
4190DEFUN_YANG(bgp_default_shutdown,
4191 bgp_default_shutdown_cmd,
4192 "[no] bgp default shutdown",
4193 NO_STR BGP_STR
4194 "Configure BGP defaults\n"
4195 "Apply administrative shutdown to newly configured peers\n")
f26845f9 4196{
87ce2564 4197 nb_cli_enqueue_change(vty, "./global/default-shutdown", NB_OP_MODIFY,
ff8a8a7a
CS
4198 strmatch(argv[0]->text, "no") ? "false" : "true");
4199
4200 return nb_cli_apply_changes(vty, NULL);
4201}
4202
4203void cli_show_router_bgp_default_shutdown(struct vty *vty,
4204 struct lyd_node *dnode,
4205 bool show_defaults)
4206{
4207 if (yang_dnode_get_bool(dnode, NULL))
4208 vty_out(vty, " bgp default shutdown\n");
f26845f9
QY
4209}
4210
736b68f3
DS
4211DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4212 BGP_STR
9ddf4b81 4213 "Administrative shutdown of the BGP instance\n"
736b68f3
DS
4214 "Add a shutdown message (RFC 8203)\n"
4215 "Shutdown message\n")
9cf59432 4216{
736b68f3 4217 char *msgstr = NULL;
8389c83a 4218
9cf59432
DS
4219 VTY_DECLVAR_CONTEXT(bgp, bgp);
4220
8389c83a 4221 if (argc > 3)
f80e35b6 4222 msgstr = argv_concat(argv, argc, 3);
8389c83a
DS
4223
4224 bgp_shutdown_enable(bgp, msgstr);
4225 XFREE(MTYPE_TMP, msgstr);
9cf59432
DS
4226
4227 return CMD_SUCCESS;
4228}
4229
736b68f3 4230DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
9ddf4b81 4231 BGP_STR "Administrative shutdown of the BGP instance\n")
1e12ebbc
DS
4232{
4233 VTY_DECLVAR_CONTEXT(bgp, bgp);
4234
4235 bgp_shutdown_enable(bgp, NULL);
4236
4237 return CMD_SUCCESS;
4238}
8389c83a 4239
736b68f3 4240DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
9ddf4b81 4241 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
9cf59432
DS
4242{
4243 VTY_DECLVAR_CONTEXT(bgp, bgp);
4244
4245 bgp_shutdown_disable(bgp);
4246
4247 return CMD_SUCCESS;
4248}
4249
9ddf4b81 4250ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
1b6e7a88 4251 "no bgp shutdown message MSG...", NO_STR BGP_STR
9ddf4b81 4252 "Administrative shutdown of the BGP instance\n"
1b6e7a88 4253 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
1b6e7a88 4254
f4b8ec07
CS
4255DEFUN_YANG(neighbor_remote_as,
4256 neighbor_remote_as_cmd,
4257 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4258 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4259 "Specify a BGP neighbor\n" AS_STR
4260 "Internal BGP peer\n"
4261 "External BGP peer\n")
718e3744 4262{
d62a17ae 4263 int idx_peer = 1;
4264 int idx_remote_as = 3;
f4b8ec07
CS
4265 char base_xpath[XPATH_MAXLEN];
4266 char unnbr_xpath[XPATH_MAXLEN];
4267 char prgrp_xpath[XPATH_MAXLEN];
4268 union sockunion su;
4269 const char *as_type_str = "as-specified";
4270
4271 if (str2sockunion(argv[idx_peer]->arg, &su) < 0) {
4272 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
4273 FRR_BGP_NEIGHBOR_UNNUM_XPATH, argv[idx_peer]->arg, "");
4274
4275 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
4276 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg, "");
4277
4278 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4279 VTY_CURR_XPATH, unnbr_xpath + 1)) {
4280 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
4281 } else if (yang_dnode_exists(vty->candidate_config->dnode,
4282 "%s%s", VTY_CURR_XPATH,
4283 prgrp_xpath + 1)) {
4284 snprintf(base_xpath, sizeof(base_xpath),
4285 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg,
4286 "");
4287 } else {
4288 vty_out(vty,
4289 "%% Create the peer-group or interface first\n");
4290 return CMD_WARNING_CONFIG_FAILED;
4291 }
4292 } else {
4293 snprintf(base_xpath, sizeof(base_xpath),
4294 FRR_BGP_NEIGHBOR_NUM_XPATH, argv[idx_peer]->arg, "");
4295 }
4296
4297 if (argv[idx_remote_as]->arg[0] == 'i') {
4298 as_type_str = "internal";
4299 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4300 as_type_str = "external";
4301 } else {
4302 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4303 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4304 }
4305 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4306 NB_OP_MODIFY, as_type_str);
4307
4308 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 4309}
4310
f4b8ec07
CS
4311int peer_conf_interface_create(struct bgp *bgp, const char *conf_if, afi_t afi,
4312 safi_t safi, bool v6only,
4313 const char *peer_group_name, int as_type,
4314 as_t as, char *errmsg, size_t errmsg_len)
d62a17ae 4315{
d62a17ae 4316 struct peer *peer;
4317 struct peer_group *group;
4318 int ret = 0;
d62a17ae 4319
4320 group = peer_group_lookup(bgp, conf_if);
4321
4322 if (group) {
f4b8ec07
CS
4323 snprintf(errmsg, errmsg_len,
4324 "Name conflict with peer-group \n");
4325 return -1;
d62a17ae 4326 }
4327
4328 peer = peer_lookup_by_conf_if(bgp, conf_if);
4329 if (peer) {
f4b8ec07 4330 if (as_type != AS_UNSPECIFIED)
cc4d4ce8 4331 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
d62a17ae 4332 afi, safi);
4333 } else {
892fedb6 4334 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4)
d62a17ae 4335 && afi == AFI_IP && safi == SAFI_UNICAST)
4336 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
4337 as_type, 0, 0, NULL);
4338 else
4339 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
4340 as_type, afi, safi, NULL);
4341
4342 if (!peer) {
f4b8ec07
CS
4343 snprintf(errmsg, errmsg_len,
4344 "BGP failed to create peer\n");
4345 return -1;
d62a17ae 4346 }
4347
4348 if (v6only)
527de3dc 4349 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4350
4351 /* Request zebra to initiate IPv6 RAs on this interface. We do
4352 * this
4353 * any unnumbered peer in order to not worry about run-time
4354 * transitions
4355 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4356 * address
4357 * gets deleted later etc.)
4358 */
4359 if (peer->ifp)
4360 bgp_zebra_initiate_radv(bgp, peer);
4361 }
4362
4363 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4364 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4365 if (v6only)
527de3dc 4366 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4367 else
527de3dc 4368 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4369
4370 /* v6only flag changed. Reset bgp seesion */
4371 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4372 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4373 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4374 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4375 } else
4376 bgp_session_reset(peer);
4377 }
4378
9fb964de
PM
4379 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4380 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4381 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
dc2f50f3 4382 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
9fb964de 4383 }
d62a17ae 4384
4385 if (peer_group_name) {
4386 group = peer_group_lookup(bgp, peer_group_name);
4387 if (!group) {
f4b8ec07
CS
4388 snprintf(errmsg, errmsg_len,
4389 "Configure the peer-group first\n");
4390 return -1;
d62a17ae 4391 }
4392
8395c1f8 4393 ret = peer_group_bind(bgp, NULL, peer, group, &as);
d62a17ae 4394 }
4395
f4b8ec07 4396 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
a80beece
DS
4397}
4398
232c75cd
CS
4399DEFUN_YANG(neighbor_interface_config,
4400 neighbor_interface_config_cmd,
f4b8ec07
CS
4401 "neighbor WORD interface [peer-group PGNAME]",
4402 NEIGHBOR_STR
4403 "Interface name or neighbor tag\n"
4404 "Enable BGP on interface\n"
4405 "Member of the peer-group\n"
4406 "Peer-group name\n")
4c48cf63 4407{
d62a17ae 4408 int idx_word = 1;
4409 int idx_peer_group_word = 4;
f4b8ec07
CS
4410 char base_xpath[XPATH_MAXLEN];
4411
4412 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4413 argv[idx_word]->arg, "");
31500417 4414
f4b8ec07 4415 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 4416 if (argc > idx_peer_group_word)
f4b8ec07
CS
4417 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_MODIFY,
4418 argv[idx_peer_group_word]->arg);
4419
4420 return nb_cli_apply_changes(vty, base_xpath);
4c48cf63
DW
4421}
4422
f4b8ec07
CS
4423DEFUN_YANG(neighbor_interface_config_v6only,
4424 neighbor_interface_config_v6only_cmd,
4425 "neighbor WORD interface v6only [peer-group PGNAME]",
4426 NEIGHBOR_STR
4427 "Interface name or neighbor tag\n"
4428 "Enable BGP on interface\n"
4429 "Enable BGP with v6 link-local only\n"
4430 "Member of the peer-group\n"
4431 "Peer-group name\n")
4c48cf63 4432{
d62a17ae 4433 int idx_word = 1;
4434 int idx_peer_group_word = 5;
f4b8ec07
CS
4435 char base_xpath[XPATH_MAXLEN];
4436
4437 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4438 argv[idx_word]->arg, "");
31500417 4439
f4b8ec07 4440 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 4441 if (argc > idx_peer_group_word)
f4b8ec07
CS
4442 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_MODIFY,
4443 argv[idx_peer_group_word]->arg);
31500417 4444
f4b8ec07
CS
4445 nb_cli_enqueue_change(vty, "./v6only", NB_OP_MODIFY, "true");
4446
4447 return nb_cli_apply_changes(vty, base_xpath);
4c48cf63
DW
4448}
4449
a80beece 4450
f4b8ec07
CS
4451DEFUN_YANG(
4452 neighbor_interface_config_remote_as,
4453 neighbor_interface_config_remote_as_cmd,
4454 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4455 NEIGHBOR_STR
4456 "Interface name or neighbor tag\n"
4457 "Enable BGP on interface\n"
4458 "Specify a BGP neighbor\n" AS_STR
4459 "Internal BGP peer\n"
4460 "External BGP peer\n")
b3a39dc5 4461{
d62a17ae 4462 int idx_word = 1;
4463 int idx_remote_as = 4;
f4b8ec07
CS
4464 char base_xpath[XPATH_MAXLEN];
4465 const char *as_type_str = "as-specified";
4466
4467 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4468 argv[idx_word]->arg, "");
4469
4470 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4471
4472 if (argv[idx_remote_as]->arg[0] == 'i') {
4473 as_type_str = "internal";
4474 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4475 as_type_str = "external";
4476 } else {
4477 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4478 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4479 }
4480 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4481 NB_OP_MODIFY, as_type_str);
4482
4483 return nb_cli_apply_changes(vty, base_xpath);
b3a39dc5
DD
4484}
4485
f4b8ec07
CS
4486DEFUN_YANG(
4487 neighbor_interface_v6only_config_remote_as,
4488 neighbor_interface_v6only_config_remote_as_cmd,
4489 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4490 NEIGHBOR_STR
4491 "Interface name or neighbor tag\n"
4492 "Enable BGP with v6 link-local only\n"
4493 "Enable BGP on interface\n"
4494 "Specify a BGP neighbor\n" AS_STR
4495 "Internal BGP peer\n"
4496 "External BGP peer\n")
b3a39dc5 4497{
d62a17ae 4498 int idx_word = 1;
4499 int idx_remote_as = 5;
f4b8ec07
CS
4500 char base_xpath[XPATH_MAXLEN];
4501 const char *as_type_str = "as-specified";
4502
4503 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4504 argv[idx_word]->arg, "");
4505
4506 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4507
4508 nb_cli_enqueue_change(vty, "./v6only", NB_OP_MODIFY, "true");
4509
4510 if (argv[idx_remote_as]->arg[0] == 'i') {
4511 as_type_str = "internal";
4512 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4513 as_type_str = "external";
4514 } else {
4515 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4516 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4517 }
4518 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4519 NB_OP_MODIFY, as_type_str);
4520
4521 return nb_cli_apply_changes(vty, base_xpath);
b3a39dc5
DD
4522}
4523
f4b8ec07
CS
4524DEFUN_YANG(neighbor_peer_group, neighbor_peer_group_cmd,
4525 "neighbor WORD peer-group",
4526 NEIGHBOR_STR
4527 "Interface name or neighbor tag\n"
4528 "Configure peer-group\n")
718e3744 4529{
f4b8ec07 4530 char base_xpath[XPATH_MAXLEN];
d62a17ae 4531 int idx_word = 1;
718e3744 4532
f4b8ec07
CS
4533 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_PEER_GROUP_XPATH,
4534 argv[idx_word]->arg, "");
718e3744 4535
f4b8ec07 4536 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
718e3744 4537
f4b8ec07 4538 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4539}
4540
232c75cd
CS
4541DEFUN_YANG(no_neighbor,
4542 no_neighbor_cmd,
4543 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4544 NO_STR NEIGHBOR_STR
4545 NEIGHBOR_ADDR_STR2
4546 "Specify a BGP neighbor\n" AS_STR
4547 "Internal BGP peer\n"
4548 "External BGP peer\n")
718e3744 4549{
d62a17ae 4550 int idx_peer = 2;
f4b8ec07
CS
4551 char base_xpath[XPATH_MAXLEN];
4552 char num_xpath[XPATH_MAXLEN];
4553 char unnbr_xpath[XPATH_MAXLEN];
4554 char prgrp_xpath[XPATH_MAXLEN];
d62a17ae 4555 union sockunion su;
d62a17ae 4556
f4b8ec07
CS
4557 if (str2sockunion(argv[idx_peer]->arg, &su) == 0) {
4558 snprintf(num_xpath, sizeof(num_xpath),
4559 FRR_BGP_NEIGHBOR_NUM_XPATH, argv[idx_peer]->arg, "");
4560 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4561 VTY_CURR_XPATH, num_xpath + 1)) {
4562 strlcpy(base_xpath, num_xpath, sizeof(base_xpath));
d62a17ae 4563 }
f4b8ec07
CS
4564 } else {
4565 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
4566 FRR_BGP_NEIGHBOR_UNNUM_XPATH, argv[idx_peer]->arg, "");
4567
4568 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
4569 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg, "");
4570
4571 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4572 VTY_CURR_XPATH, unnbr_xpath + 1)) {
4573 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
4574 } else if (yang_dnode_exists(vty->candidate_config->dnode,
4575 "%s%s", VTY_CURR_XPATH,
4576 prgrp_xpath + 1)) {
4577 strlcpy(base_xpath, prgrp_xpath, sizeof(base_xpath));
4e2786df 4578 } else {
f4b8ec07
CS
4579 vty_out(vty,
4580 "%% Create the peer-group or interface first\n");
d62a17ae 4581 return CMD_WARNING_CONFIG_FAILED;
4582 }
1ff9a340 4583 }
718e3744 4584
f4b8ec07
CS
4585 nb_cli_enqueue_change(vty, base_xpath, NB_OP_DESTROY, NULL);
4586
4587 return nb_cli_apply_changes(vty, NULL);
718e3744 4588}
4589
f4b8ec07
CS
4590DEFUN_YANG(no_neighbor_interface_config,
4591 no_neighbor_interface_config_cmd,
4592 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4593 NO_STR NEIGHBOR_STR
4594 "Interface name\n"
4595 "Configure BGP on interface\n"
4596 "Enable BGP with v6 link-local only\n"
4597 "Member of the peer-group\n"
4598 "Peer-group name\n"
4599 "Specify a BGP neighbor\n" AS_STR
4600 "Internal BGP peer\n"
4601 "External BGP peer\n")
a80beece 4602{
d62a17ae 4603 int idx_word = 2;
f4b8ec07 4604 char base_xpath[XPATH_MAXLEN];
d62a17ae 4605
f4b8ec07
CS
4606 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4607 argv[idx_word]->arg, "");
4608
4609 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
4610
4611 return nb_cli_apply_changes(vty, base_xpath);
a80beece
DS
4612}
4613
f4b8ec07
CS
4614DEFUN_YANG(no_neighbor_peer_group,
4615 no_neighbor_peer_group_cmd,
4616 "no neighbor WORD peer-group",
4617 NO_STR NEIGHBOR_STR
4618 "Neighbor tag\n"
4619 "Configure peer-group\n")
718e3744 4620{
f4b8ec07 4621 char base_xpath[XPATH_MAXLEN];
d62a17ae 4622 int idx_word = 2;
718e3744 4623
f4b8ec07
CS
4624 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_PEER_GROUP_XPATH,
4625 argv[idx_word]->arg, "");
4626
4627 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
4628
4629 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4630}
4631
f4b8ec07
CS
4632DEFUN_YANG(no_neighbor_interface_peer_group_remote_as,
4633 no_neighbor_interface_peer_group_remote_as_cmd,
4634 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4635 NO_STR NEIGHBOR_STR
4636 "Interface name or neighbor tag\n"
4637 "Specify a BGP neighbor\n" AS_STR
4638 "Internal BGP peer\n"
4639 "External BGP peer\n")
718e3744 4640{
f4b8ec07
CS
4641 int idx_peer = 2;
4642 char base_xpath[XPATH_MAXLEN];
4643 char unnbr_xpath[XPATH_MAXLEN];
4644 char prgrp_xpath[XPATH_MAXLEN];
d62a17ae 4645
f4b8ec07
CS
4646 snprintf(unnbr_xpath, sizeof(unnbr_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4647 argv[idx_peer]->arg, "");
d62a17ae 4648
f4b8ec07
CS
4649 snprintf(prgrp_xpath, sizeof(prgrp_xpath), FRR_BGP_PEER_GROUP_XPATH,
4650 argv[idx_peer]->arg, "");
4651
4652 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4653 VTY_CURR_XPATH, unnbr_xpath + 1)) {
4654 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
4655 } else if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4656 VTY_CURR_XPATH, prgrp_xpath + 1)) {
4657 strlcpy(base_xpath, prgrp_xpath, sizeof(base_xpath));
4658 } else {
d62a17ae 4659 vty_out(vty, "%% Create the peer-group or interface first\n");
4660 return CMD_WARNING_CONFIG_FAILED;
4661 }
f4b8ec07
CS
4662
4663 strlcat(base_xpath, "/neighbor-remote-as/remote-as-type",
4664 sizeof(base_xpath));
4665
4666 nb_cli_enqueue_change(vty, base_xpath, NB_OP_DESTROY, NULL);
4667
4668 return nb_cli_apply_changes(vty, NULL);
718e3744 4669}
6b0655a2 4670
f4b8ec07
CS
4671DEFUN_YANG(neighbor_local_as,
4672 neighbor_local_as_cmd,
4673 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4674 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4675 "Specify a local-as number\n"
4676 "AS number used as local AS\n")
718e3744 4677{
d62a17ae 4678 int idx_peer = 1;
4679 int idx_number = 3;
f4b8ec07 4680 char base_xpath[XPATH_MAXLEN];
718e3744 4681
f4b8ec07
CS
4682 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4683 sizeof(base_xpath), NULL)
4684 < 0)
d62a17ae 4685 return CMD_WARNING_CONFIG_FAILED;
718e3744 4686
f4b8ec07
CS
4687 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4688 argv[idx_number]->arg);
4689
4690 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4691}
4692
f4b8ec07
CS
4693DEFUN_YANG(
4694 neighbor_local_as_no_prepend, neighbor_local_as_no_prepend_cmd,
4695 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
4696 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4697 "Specify a local-as number\n"
4698 "AS number used as local AS\n"
4699 "Do not prepend local-as to updates from ebgp peers\n")
718e3744 4700{
d62a17ae 4701 int idx_peer = 1;
4702 int idx_number = 3;
f4b8ec07 4703 char base_xpath[XPATH_MAXLEN];
718e3744 4704
f4b8ec07
CS
4705 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4706 sizeof(base_xpath), NULL)
4707 < 0)
d62a17ae 4708 return CMD_WARNING_CONFIG_FAILED;
718e3744 4709
f4b8ec07
CS
4710 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4711 argv[idx_number]->arg);
4712 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4713 "true");
4714
4715 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4716}
4717
f4b8ec07
CS
4718DEFUN_YANG(
4719 neighbor_local_as_no_prepend_replace_as,
4720 neighbor_local_as_no_prepend_replace_as_cmd,
4721 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4722 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4723 "Specify a local-as number\n"
4724 "AS number used as local AS\n"
4725 "Do not prepend local-as to updates from ebgp peers\n"
4726 "Do not prepend local-as to updates from ibgp peers\n")
9d3f9705 4727{
d62a17ae 4728 int idx_peer = 1;
4729 int idx_number = 3;
f4b8ec07 4730 char base_xpath[XPATH_MAXLEN];
9d3f9705 4731
f4b8ec07
CS
4732 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4733 sizeof(base_xpath), NULL)
4734 < 0)
d62a17ae 4735 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 4736
f4b8ec07
CS
4737 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4738 argv[idx_number]->arg);
4739 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4740 "true");
4741 nb_cli_enqueue_change(vty, "./local-as/no-replace-as", NB_OP_MODIFY,
4742 "true");
4743
4744 return nb_cli_apply_changes(vty, base_xpath);
9d3f9705
AC
4745}
4746
f4b8ec07
CS
4747DEFUN_YANG(no_neighbor_local_as,
4748 no_neighbor_local_as_cmd,
4749 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
4750 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4751 "Specify a local-as number\n"
4752 "AS number used as local AS\n"
4753 "Do not prepend local-as to updates from ebgp peers\n"
4754 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 4755{
d62a17ae 4756 int idx_peer = 2;
f4b8ec07 4757 char base_xpath[XPATH_MAXLEN];
718e3744 4758
f4b8ec07
CS
4759 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4760 sizeof(base_xpath), NULL)
4761 < 0)
d62a17ae 4762 return CMD_WARNING_CONFIG_FAILED;
718e3744 4763
f4b8ec07
CS
4764 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_DESTROY, NULL);
4765 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4766 "false");
4767 nb_cli_enqueue_change(vty, "./local-as/no-replace-as", NB_OP_MODIFY,
4768 "false");
4769
4770 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4771}
4772
718e3744 4773
3f9c7369
DS
4774DEFUN (neighbor_solo,
4775 neighbor_solo_cmd,
9ccf14f7 4776 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4777 NEIGHBOR_STR
4778 NEIGHBOR_ADDR_STR2
4779 "Solo peer - part of its own update group\n")
4780{
d62a17ae 4781 int idx_peer = 1;
4782 struct peer *peer;
4783 int ret;
3f9c7369 4784
d62a17ae 4785 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4786 if (!peer)
4787 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4788
d62a17ae 4789 ret = update_group_adjust_soloness(peer, 1);
4790 return bgp_vty_return(vty, ret);
3f9c7369
DS
4791}
4792
4793DEFUN (no_neighbor_solo,
4794 no_neighbor_solo_cmd,
9ccf14f7 4795 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4796 NO_STR
4797 NEIGHBOR_STR
4798 NEIGHBOR_ADDR_STR2
4799 "Solo peer - part of its own update group\n")
4800{
d62a17ae 4801 int idx_peer = 2;
4802 struct peer *peer;
4803 int ret;
3f9c7369 4804
d62a17ae 4805 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4806 if (!peer)
4807 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4808
d62a17ae 4809 ret = update_group_adjust_soloness(peer, 0);
4810 return bgp_vty_return(vty, ret);
3f9c7369
DS
4811}
4812
f4b8ec07
CS
4813DEFUN_YANG(neighbor_password,
4814 neighbor_password_cmd,
4815 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
4816 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4817 "Set a password\n"
4818 "The password\n")
0df7c91f 4819{
d62a17ae 4820 int idx_peer = 1;
4821 int idx_line = 3;
f4b8ec07 4822 char base_xpath[XPATH_MAXLEN];
0df7c91f 4823
f4b8ec07
CS
4824 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4825 sizeof(base_xpath), NULL)
4826 < 0)
d62a17ae 4827 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 4828
f4b8ec07
CS
4829 nb_cli_enqueue_change(vty, "./password", NB_OP_MODIFY,
4830 argv[idx_line]->arg);
4831
4832 return nb_cli_apply_changes(vty, base_xpath);
0df7c91f
PJ
4833}
4834
f4b8ec07
CS
4835DEFUN_YANG(no_neighbor_password,
4836 no_neighbor_password_cmd,
4837 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
4838 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4839 "Set a password\n"
4840 "The password\n")
0df7c91f 4841{
d62a17ae 4842 int idx_peer = 2;
f4b8ec07 4843 char base_xpath[XPATH_MAXLEN];
0df7c91f 4844
f4b8ec07
CS
4845 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4846 sizeof(base_xpath), NULL)
4847 < 0)
d62a17ae 4848 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 4849
f4b8ec07
CS
4850 nb_cli_enqueue_change(vty, "./password", NB_OP_DESTROY, NULL);
4851
4852 return nb_cli_apply_changes(vty, base_xpath);
0df7c91f 4853}
6b0655a2 4854
f4b8ec07
CS
4855DEFUN_YANG(neighbor_activate,
4856 neighbor_activate_cmd,
4857 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4858 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4859 "Enable the Address Family for this Neighbor\n")
718e3744 4860{
d62a17ae 4861 int idx_peer = 1;
f4b8ec07 4862 char base_xpath[XPATH_MAXLEN];
f4b8ec07
CS
4863 char af_xpath[XPATH_MAXLEN];
4864 afi_t afi = bgp_node_afi(vty);
4865 safi_t safi = bgp_node_safi(vty);
718e3744 4866
f4b8ec07
CS
4867 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
4868 yang_afi_safi_value2identity(afi, safi));
555c8ab7
CS
4869 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4870 sizeof(base_xpath), af_xpath)
f4b8ec07 4871 < 0)
d62a17ae 4872 return CMD_WARNING_CONFIG_FAILED;
718e3744 4873
555c8ab7 4874 nb_cli_enqueue_change(vty, "./enabled", NB_OP_MODIFY, "true");
f4b8ec07
CS
4875
4876 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4877}
4878
d62a17ae 4879ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
4880 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4881 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4882 "Enable the Address Family for this Neighbor\n")
596c17ba 4883
f4b8ec07
CS
4884DEFUN_YANG(no_neighbor_activate,
4885 no_neighbor_activate_cmd,
4886 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4887 NO_STR NEIGHBOR_STR
4888 NEIGHBOR_ADDR_STR2
4889 "Enable the Address Family for this Neighbor\n")
718e3744 4890{
d62a17ae 4891 int idx_peer = 2;
f4b8ec07
CS
4892 char base_xpath[XPATH_MAXLEN];
4893 char af_xpath[XPATH_MAXLEN];
4894 afi_t afi = bgp_node_afi(vty);
4895 safi_t safi = bgp_node_safi(vty);
718e3744 4896
f4b8ec07
CS
4897 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
4898 yang_afi_safi_value2identity(afi, safi));
4899
4900 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4901 sizeof(base_xpath), af_xpath)
4902 < 0)
d62a17ae 4903 return CMD_WARNING_CONFIG_FAILED;
718e3744 4904
f4b8ec07
CS
4905 nb_cli_enqueue_change(vty, "./enabled", NB_OP_MODIFY, "false");
4906
4907 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4908}
6b0655a2 4909
d62a17ae 4910ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
4911 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4912 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4913 "Enable the Address Family for this Neighbor\n")
596c17ba 4914
2a059a54
DS
4915DEFUN (neighbor_set_peer_group,
4916 neighbor_set_peer_group_cmd,
4917 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4918 NEIGHBOR_STR
4919 NEIGHBOR_ADDR_STR2
4920 "Member of the peer-group\n"
4921 "Peer-group name\n")
718e3744 4922{
2a059a54 4923 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4924 int idx_peer = 1;
4925 int idx_word = 3;
2a059a54
DS
4926 int ret;
4927 as_t as;
4928 union sockunion su;
4929 struct peer *peer;
4930 struct peer_group *group;
d62a17ae 4931
2a059a54
DS
4932 ret = str2sockunion(argv[idx_peer]->arg, &su);
4933 if (ret < 0) {
4934 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4935 if (!peer) {
4936 vty_out(vty, "%% Malformed address or name: %s\n",
4937 argv[idx_peer]->arg);
4938 return CMD_WARNING_CONFIG_FAILED;
4939 }
4940 } else {
4941 if (peer_address_self_check(bgp, &su)) {
4942 vty_out(vty,
4943 "%% Can not configure the local system as neighbor\n");
4944 return CMD_WARNING_CONFIG_FAILED;
4945 }
4946
4947 /* Disallow for dynamic neighbor. */
4948 peer = peer_lookup(bgp, &su);
4949 if (peer && peer_dynamic_neighbor(peer)) {
4950 vty_out(vty,
4951 "%% Operation not allowed on a dynamic neighbor\n");
4952 return CMD_WARNING_CONFIG_FAILED;
4953 }
4954 }
4955
4956 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4957 if (!group) {
4958 vty_out(vty, "%% Configure the peer-group first\n");
d62a17ae 4959 return CMD_WARNING_CONFIG_FAILED;
2a059a54 4960 }
d62a17ae 4961
2a059a54 4962 ret = peer_group_bind(bgp, &su, peer, group, &as);
d62a17ae 4963
2a059a54
DS
4964 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
4965 vty_out(vty,
4966 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
4967 as);
4968 return CMD_WARNING_CONFIG_FAILED;
4969 }
4970
4971 return bgp_vty_return(vty, ret);
d62a17ae 4972}
4973
4974ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
d7b9898c 4975 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 4976 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4977 "Member of the peer-group\n"
4978 "Peer-group name\n")
596c17ba 4979
f4b8ec07
CS
4980DEFUN_YANG (no_neighbor_set_peer_group,
4981 no_neighbor_set_peer_group_cmd,
2cbd181a 4982 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group [PGNAME]",
f4b8ec07
CS
4983 NO_STR
4984 NEIGHBOR_STR
4985 NEIGHBOR_ADDR_STR2
4986 "Member of the peer-group\n"
4987 "Peer-group name\n")
718e3744 4988{
d62a17ae 4989 int idx_peer = 2;
f4b8ec07 4990 char base_xpath[XPATH_MAXLEN];
d62a17ae 4991
f4b8ec07
CS
4992 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4993 sizeof(base_xpath), NULL)
4994 < 0)
d62a17ae 4995 return CMD_WARNING_CONFIG_FAILED;
b3a3290e 4996
f4b8ec07 4997 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_DESTROY, NULL);
718e3744 4998
f4b8ec07 4999 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5000}
6b0655a2 5001
d62a17ae 5002ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
2cbd181a 5003 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group [PGNAME]",
d62a17ae 5004 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5005 "Member of the peer-group\n"
5006 "Peer-group name\n")
596c17ba 5007
d62a17ae 5008static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
47cbc09b 5009 uint32_t flag, int set)
718e3744 5010{
d62a17ae 5011 int ret;
5012 struct peer *peer;
718e3744 5013
d62a17ae 5014 peer = peer_and_group_lookup_vty(vty, ip_str);
5015 if (!peer)
5016 return CMD_WARNING_CONFIG_FAILED;
718e3744 5017
7ebe625c
QY
5018 /*
5019 * If 'neighbor <interface>', then this is for directly connected peers,
5020 * we should not accept disable-connected-check.
5021 */
5022 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5023 vty_out(vty,
3efd0893 5024 "%s is directly connected peer, cannot accept disable-connected-check\n",
7ebe625c
QY
5025 ip_str);
5026 return CMD_WARNING_CONFIG_FAILED;
5027 }
5028
d62a17ae 5029 if (!set && flag == PEER_FLAG_SHUTDOWN)
5030 peer_tx_shutdown_message_unset(peer);
ae9b0e11 5031
d62a17ae 5032 if (set)
5033 ret = peer_flag_set(peer, flag);
5034 else
5035 ret = peer_flag_unset(peer, flag);
718e3744 5036
d62a17ae 5037 return bgp_vty_return(vty, ret);
718e3744 5038}
5039
47cbc09b 5040static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
718e3744 5041{
d62a17ae 5042 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 5043}
5044
d62a17ae 5045static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
47cbc09b 5046 uint32_t flag)
718e3744 5047{
d62a17ae 5048 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 5049}
5050
f4b8ec07
CS
5051int peer_flag_modify_nb(struct bgp *bgp, const char *ip_str, struct peer *peer,
5052 uint32_t flag, bool set, char *errmsg,
5053 size_t errmsg_len)
5054{
5055 int ret;
5056
5057 /*
5058 * If 'neighbor <interface>', then this is for directly connected peers,
5059 * we should not accept disable-connected-check.
5060 */
5061 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5062 snprintf(
5063 errmsg, errmsg_len,
5064 "%s is directly connected peer, cannot accept disable-connected-check\n",
5065 ip_str);
5066 return -1;
5067 }
5068
5069 if (!set && flag == PEER_FLAG_SHUTDOWN)
5070 peer_tx_shutdown_message_unset(peer);
5071
5072 if (set)
5073 ret = peer_flag_set(peer, flag);
5074 else
5075 ret = peer_flag_unset(peer, flag);
5076
5077 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
5078}
5079
718e3744 5080/* neighbor passive. */
f4b8ec07
CS
5081DEFUN_YANG(neighbor_passive,
5082 neighbor_passive_cmd,
5083 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5084 NEIGHBOR_STR
5085 NEIGHBOR_ADDR_STR2
5086 "Don't send open messages to this neighbor\n")
718e3744 5087{
d62a17ae 5088 int idx_peer = 1;
f4b8ec07
CS
5089 char base_xpath[XPATH_MAXLEN];
5090
5091 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5092 sizeof(base_xpath), NULL)
5093 < 0)
5094 return CMD_WARNING_CONFIG_FAILED;
5095
5096 nb_cli_enqueue_change(vty, "./passive-mode", NB_OP_MODIFY, "true");
5097
5098 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5099}
5100
f4b8ec07
CS
5101DEFUN_YANG(no_neighbor_passive,
5102 no_neighbor_passive_cmd,
5103 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5104 NO_STR NEIGHBOR_STR
5105 NEIGHBOR_ADDR_STR2
5106 "Don't send open messages to this neighbor\n")
718e3744 5107{
d62a17ae 5108 int idx_peer = 2;
f4b8ec07
CS
5109 char base_xpath[XPATH_MAXLEN];
5110
5111 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5112 sizeof(base_xpath), NULL)
5113 < 0)
5114 return CMD_WARNING_CONFIG_FAILED;
5115
5116 nb_cli_enqueue_change(vty, "./passive-mode", NB_OP_MODIFY, "false");
5117
5118 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5119}
6b0655a2 5120
718e3744 5121/* neighbor shutdown. */
f4b8ec07
CS
5122DEFUN_YANG(neighbor_shutdown_msg,
5123 neighbor_shutdown_msg_cmd,
5124 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5125 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5126 "Administratively shut down this neighbor\n"
5127 "Add a shutdown message (RFC 8203)\n"
5128 "Shutdown message\n")
718e3744 5129{
d62a17ae 5130 int idx_peer = 1;
f4b8ec07
CS
5131 char base_xpath[XPATH_MAXLEN];
5132
5133 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5134 sizeof(base_xpath), NULL)
5135 < 0)
5136 return CMD_WARNING_CONFIG_FAILED;
73d70fa6 5137
d62a17ae 5138 if (argc >= 5) {
d62a17ae 5139 char *message;
73d70fa6 5140
d62a17ae 5141 message = argv_concat(argv, argc, 4);
f4b8ec07
CS
5142 nb_cli_enqueue_change(vty, "./admin-shutdown/message",
5143 NB_OP_MODIFY, message);
d62a17ae 5144 }
73d70fa6 5145
f4b8ec07
CS
5146 nb_cli_enqueue_change(vty, "./admin-shutdown/enable", NB_OP_MODIFY,
5147 "true");
5148
5149 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5150}
5151
232c75cd 5152ALIAS_YANG(neighbor_shutdown_msg, neighbor_shutdown_cmd,
d62a17ae 5153 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5154 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5155 "Administratively shut down this neighbor\n")
73d70fa6 5156
f4b8ec07
CS
5157DEFUN_YANG(no_neighbor_shutdown_msg,
5158 no_neighbor_shutdown_msg_cmd,
5159 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5160 NO_STR NEIGHBOR_STR
5161 NEIGHBOR_ADDR_STR2
5162 "Administratively shut down this neighbor\n"
5163 "Remove a shutdown message (RFC 8203)\n"
5164 "Shutdown message\n")
718e3744 5165{
d62a17ae 5166 int idx_peer = 2;
f4b8ec07 5167 char base_xpath[XPATH_MAXLEN];
73d70fa6 5168
f4b8ec07
CS
5169 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5170 sizeof(base_xpath), NULL)
5171 < 0)
5172 return CMD_WARNING_CONFIG_FAILED;
5173
5174 nb_cli_enqueue_change(vty, "./admin-shutdown/enable", NB_OP_MODIFY,
5175 "false");
5176
5177 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5178}
6b0655a2 5179
232c75cd 5180ALIAS_YANG(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
d62a17ae 5181 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5182 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5183 "Administratively shut down this neighbor\n")
73d70fa6 5184
8336c896
DA
5185DEFUN(neighbor_shutdown_rtt,
5186 neighbor_shutdown_rtt_cmd,
5187 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5188 NEIGHBOR_STR
5189 NEIGHBOR_ADDR_STR2
5190 "Administratively shut down this neighbor\n"
5191 "Shutdown if round-trip-time is higher than expected\n"
5192 "Round-trip-time in milliseconds\n"
5193 "Specify the number of keepalives before shutdown\n"
5194 "The number of keepalives with higher RTT to shutdown\n")
5195{
5196 int idx_peer = 1;
5197 int idx_rtt = 4;
5198 int idx_count = 0;
5199 struct peer *peer;
5200
5201 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5202
5203 if (!peer)
5204 return CMD_WARNING_CONFIG_FAILED;
5205
5206 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5207
5208 if (argv_find(argv, argc, "count", &idx_count))
5209 peer->rtt_keepalive_conf =
5210 strtol(argv[idx_count + 1]->arg, NULL, 10);
5211
5212 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5213 PEER_FLAG_RTT_SHUTDOWN);
5214}
5215
5216DEFUN(no_neighbor_shutdown_rtt,
5217 no_neighbor_shutdown_rtt_cmd,
5218 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5219 NO_STR
5220 NEIGHBOR_STR
5221 NEIGHBOR_ADDR_STR2
5222 "Administratively shut down this neighbor\n"
5223 "Shutdown if round-trip-time is higher than expected\n"
5224 "Round-trip-time in milliseconds\n"
5225 "Specify the number of keepalives before shutdown\n"
5226 "The number of keepalives with higher RTT to shutdown\n")
5227{
5228 int idx_peer = 2;
5229 struct peer *peer;
5230
5231 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5232
5233 if (!peer)
5234 return CMD_WARNING_CONFIG_FAILED;
5235
5236 peer->rtt_expected = 0;
5237 peer->rtt_keepalive_conf = 1;
5238
5239 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5240 PEER_FLAG_RTT_SHUTDOWN);
5241}
5242
718e3744 5243/* neighbor capability dynamic. */
f4b8ec07
CS
5244DEFUN_YANG (neighbor_capability_dynamic,
5245 neighbor_capability_dynamic_cmd,
5246 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5247 NEIGHBOR_STR
5248 NEIGHBOR_ADDR_STR2
5249 "Advertise capability to the peer\n"
5250 "Advertise dynamic capability to this neighbor\n")
718e3744 5251{
d62a17ae 5252 int idx_peer = 1;
f4b8ec07
CS
5253 char base_xpath[XPATH_MAXLEN];
5254
5255 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5256 sizeof(base_xpath), NULL)
5257 < 0)
5258 return CMD_WARNING_CONFIG_FAILED;
5259
5260 nb_cli_enqueue_change(vty, "./capability-options/dynamic-capability",
5261 NB_OP_MODIFY, "true");
5262
5263 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5264}
5265
f4b8ec07
CS
5266DEFUN_YANG (no_neighbor_capability_dynamic,
5267 no_neighbor_capability_dynamic_cmd,
5268 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5269 NO_STR
5270 NEIGHBOR_STR
5271 NEIGHBOR_ADDR_STR2
5272 "Advertise capability to the peer\n"
5273 "Advertise dynamic capability to this neighbor\n")
718e3744 5274{
d62a17ae 5275 int idx_peer = 2;
f4b8ec07
CS
5276 char base_xpath[XPATH_MAXLEN];
5277
5278 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5279 sizeof(base_xpath), NULL)
5280 < 0)
5281 return CMD_WARNING_CONFIG_FAILED;
5282
5283 nb_cli_enqueue_change(vty, "./capability-options/dynamic-capability",
5284 NB_OP_MODIFY, "false");
5285
5286 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5287}
6b0655a2 5288
718e3744 5289/* neighbor dont-capability-negotiate */
5290DEFUN (neighbor_dont_capability_negotiate,
5291 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5292 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5293 NEIGHBOR_STR
5294 NEIGHBOR_ADDR_STR2
5295 "Do not perform capability negotiation\n")
5296{
d62a17ae 5297 int idx_peer = 1;
5298 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5299 PEER_FLAG_DONT_CAPABILITY);
718e3744 5300}
5301
5302DEFUN (no_neighbor_dont_capability_negotiate,
5303 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5304 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5305 NO_STR
5306 NEIGHBOR_STR
5307 NEIGHBOR_ADDR_STR2
5308 "Do not perform capability negotiation\n")
5309{
d62a17ae 5310 int idx_peer = 2;
5311 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5312 PEER_FLAG_DONT_CAPABILITY);
718e3744 5313}
6b0655a2 5314
8a92a8a0 5315/* neighbor capability extended next hop encoding */
f4b8ec07
CS
5316DEFUN_YANG (neighbor_capability_enhe,
5317 neighbor_capability_enhe_cmd,
5318 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5319 NEIGHBOR_STR
5320 NEIGHBOR_ADDR_STR2
5321 "Advertise capability to the peer\n"
5322 "Advertise extended next-hop capability to the peer\n")
8a92a8a0 5323{
d62a17ae 5324 int idx_peer = 1;
f4b8ec07
CS
5325 char base_xpath[XPATH_MAXLEN];
5326
5327 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5328 sizeof(base_xpath), NULL)
5329 < 0)
5330 return CMD_WARNING_CONFIG_FAILED;
5331
5332 nb_cli_enqueue_change(
5333 vty, "./capability-options/extended-nexthop-capability",
5334 NB_OP_MODIFY, "true");
5335
5336 return nb_cli_apply_changes(vty, base_xpath);
8a92a8a0
DS
5337}
5338
f4b8ec07
CS
5339DEFUN_YANG (no_neighbor_capability_enhe,
5340 no_neighbor_capability_enhe_cmd,
5341 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5342 NO_STR
5343 NEIGHBOR_STR
5344 NEIGHBOR_ADDR_STR2
5345 "Advertise capability to the peer\n"
5346 "Advertise extended next-hop capability to the peer\n")
8a92a8a0 5347{
d62a17ae 5348 int idx_peer = 2;
f4b8ec07
CS
5349 char base_xpath[XPATH_MAXLEN];
5350
5351 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5352 sizeof(base_xpath), NULL)
5353 < 0)
5354 return CMD_WARNING_CONFIG_FAILED;
5355
5356 nb_cli_enqueue_change(
5357 vty, "./capability-options/extended-nexthop-capability",
5358 NB_OP_MODIFY, "false");
5359
5360 return nb_cli_apply_changes(vty, base_xpath);
5361}
5362
5363int peer_af_flag_modify_nb(struct peer *peer, afi_t afi, safi_t safi,
5364 uint32_t flag, int set, char *errmsg,
5365 size_t errmsg_len)
5366{
5367 int ret;
5368
5369 if (set)
5370 ret = peer_af_flag_set(peer, afi, safi, flag);
5371 else
5372 ret = peer_af_flag_unset(peer, afi, safi, flag);
5373
5374 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
8a92a8a0
DS
5375}
5376
d62a17ae 5377static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5378 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 5379 int set)
718e3744 5380{
d62a17ae 5381 int ret;
5382 struct peer *peer;
718e3744 5383
d62a17ae 5384 peer = peer_and_group_lookup_vty(vty, peer_str);
5385 if (!peer)
5386 return CMD_WARNING_CONFIG_FAILED;
718e3744 5387
d62a17ae 5388 if (set)
5389 ret = peer_af_flag_set(peer, afi, safi, flag);
5390 else
5391 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 5392
d62a17ae 5393 return bgp_vty_return(vty, ret);
718e3744 5394}
5395
d62a17ae 5396static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5397 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5398{
d62a17ae 5399 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 5400}
5401
d62a17ae 5402static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5403 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5404{
d62a17ae 5405 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 5406}
6b0655a2 5407
718e3744 5408/* neighbor capability orf prefix-list. */
5409DEFUN (neighbor_capability_orf_prefix,
5410 neighbor_capability_orf_prefix_cmd,
9ccf14f7 5411 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5412 NEIGHBOR_STR
5413 NEIGHBOR_ADDR_STR2
5414 "Advertise capability to the peer\n"
5415 "Advertise ORF capability to the peer\n"
5416 "Advertise prefixlist ORF capability to this neighbor\n"
5417 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5418 "Capability to RECEIVE the ORF from this neighbor\n"
5419 "Capability to SEND the ORF to this neighbor\n")
5420{
d62a17ae 5421 int idx_send_recv = 5;
db45f64d
DS
5422 char *peer_str = argv[1]->arg;
5423 struct peer *peer;
5424 afi_t afi = bgp_node_afi(vty);
5425 safi_t safi = bgp_node_safi(vty);
d62a17ae 5426
db45f64d
DS
5427 peer = peer_and_group_lookup_vty(vty, peer_str);
5428 if (!peer)
d62a17ae 5429 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5430
db45f64d
DS
5431 if (strmatch(argv[idx_send_recv]->text, "send"))
5432 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5433 PEER_FLAG_ORF_PREFIX_SM);
5434
5435 if (strmatch(argv[idx_send_recv]->text, "receive"))
5436 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5437 PEER_FLAG_ORF_PREFIX_RM);
5438
5439 if (strmatch(argv[idx_send_recv]->text, "both"))
5440 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5441 PEER_FLAG_ORF_PREFIX_SM)
5442 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5443 PEER_FLAG_ORF_PREFIX_RM);
5444
5445 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5446}
5447
5448ALIAS_HIDDEN(
5449 neighbor_capability_orf_prefix,
5450 neighbor_capability_orf_prefix_hidden_cmd,
5451 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5452 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5453 "Advertise capability to the peer\n"
5454 "Advertise ORF capability to the peer\n"
5455 "Advertise prefixlist ORF capability to this neighbor\n"
5456 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5457 "Capability to RECEIVE the ORF from this neighbor\n"
5458 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5459
718e3744 5460DEFUN (no_neighbor_capability_orf_prefix,
5461 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 5462 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5463 NO_STR
5464 NEIGHBOR_STR
5465 NEIGHBOR_ADDR_STR2
5466 "Advertise capability to the peer\n"
5467 "Advertise ORF capability to the peer\n"
5468 "Advertise prefixlist ORF capability to this neighbor\n"
5469 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5470 "Capability to RECEIVE the ORF from this neighbor\n"
5471 "Capability to SEND the ORF to this neighbor\n")
5472{
d62a17ae 5473 int idx_send_recv = 6;
db45f64d
DS
5474 char *peer_str = argv[2]->arg;
5475 struct peer *peer;
5476 afi_t afi = bgp_node_afi(vty);
5477 safi_t safi = bgp_node_safi(vty);
d62a17ae 5478
db45f64d
DS
5479 peer = peer_and_group_lookup_vty(vty, peer_str);
5480 if (!peer)
d62a17ae 5481 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5482
db45f64d
DS
5483 if (strmatch(argv[idx_send_recv]->text, "send"))
5484 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5485 PEER_FLAG_ORF_PREFIX_SM);
5486
5487 if (strmatch(argv[idx_send_recv]->text, "receive"))
5488 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5489 PEER_FLAG_ORF_PREFIX_RM);
5490
5491 if (strmatch(argv[idx_send_recv]->text, "both"))
5492 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5493 PEER_FLAG_ORF_PREFIX_SM)
5494 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5495 PEER_FLAG_ORF_PREFIX_RM);
5496
5497 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5498}
5499
5500ALIAS_HIDDEN(
5501 no_neighbor_capability_orf_prefix,
5502 no_neighbor_capability_orf_prefix_hidden_cmd,
5503 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5504 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5505 "Advertise capability to the peer\n"
5506 "Advertise ORF capability to the peer\n"
5507 "Advertise prefixlist ORF capability to this neighbor\n"
5508 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5509 "Capability to RECEIVE the ORF from this neighbor\n"
5510 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5511
718e3744 5512/* neighbor next-hop-self. */
f4b8ec07
CS
5513DEFUN_YANG (neighbor_nexthop_self,
5514 neighbor_nexthop_self_cmd,
5515 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5516 NEIGHBOR_STR
5517 NEIGHBOR_ADDR_STR2
5518 "Disable the next hop calculation for this neighbor\n")
718e3744 5519{
d62a17ae 5520 int idx_peer = 1;
f4b8ec07
CS
5521 char base_xpath[XPATH_MAXLEN];
5522 char af_xpath[XPATH_MAXLEN];
5523 char attr_xpath[XPATH_MAXLEN];
5524 afi_t afi = bgp_node_afi(vty);
5525 safi_t safi = bgp_node_safi(vty);
5526
f4b8ec07
CS
5527 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5528 yang_afi_safi_value2identity(afi, safi));
5529
5530 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5531 sizeof(base_xpath), af_xpath)
5532 < 0)
5533 return CMD_WARNING_CONFIG_FAILED;
5534
5535 snprintf(attr_xpath, sizeof(attr_xpath),
5536 "./%s/nexthop-self/next-hop-self",
5537 bgp_afi_safi_get_container_str(afi, safi));
5538
5539 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5540
5541 return nb_cli_apply_changes(vty, base_xpath);
a538debe 5542}
9e7a53c1 5543
d62a17ae 5544ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5545 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5546 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5547 "Disable the next hop calculation for this neighbor\n")
596c17ba 5548
f4b8ec07
CS
5549/* neighbor next-hop-self. */
5550DEFUN_YANG(neighbor_nexthop_self_force,
5551 neighbor_nexthop_self_force_cmd,
5552 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5553 NEIGHBOR_STR
5554 NEIGHBOR_ADDR_STR2
5555 "Disable the next hop calculation for this neighbor\n"
5556 "Set the next hop to self for reflected routes\n")
5557{
5558 int idx_peer = 1;
5559 char base_xpath[XPATH_MAXLEN];
5560 char af_xpath[XPATH_MAXLEN];
5561 char attr_xpath[XPATH_MAXLEN];
5562 afi_t afi = bgp_node_afi(vty);
5563 safi_t safi = bgp_node_safi(vty);
5564
f4b8ec07
CS
5565 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5566 yang_afi_safi_value2identity(afi, safi));
5567
5568 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5569 sizeof(base_xpath), af_xpath)
5570 < 0)
5571 return CMD_WARNING_CONFIG_FAILED;
5572
5573 snprintf(attr_xpath, sizeof(attr_xpath),
5574 "./%s/nexthop-self/next-hop-self-force",
5575 bgp_afi_safi_get_container_str(afi, safi));
5576
5577 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5578
5579 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5580}
5581
d62a17ae 5582ALIAS_HIDDEN(neighbor_nexthop_self_force,
5583 neighbor_nexthop_self_force_hidden_cmd,
5584 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5585 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5586 "Disable the next hop calculation for this neighbor\n"
5587 "Set the next hop to self for reflected routes\n")
596c17ba 5588
1bc4e531
DA
5589ALIAS_HIDDEN(neighbor_nexthop_self_force,
5590 neighbor_nexthop_self_all_hidden_cmd,
5591 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5592 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5593 "Disable the next hop calculation for this neighbor\n"
5594 "Set the next hop to self for reflected routes\n")
5595
f4b8ec07
CS
5596DEFUN_YANG (no_neighbor_nexthop_self,
5597 no_neighbor_nexthop_self_cmd,
5598 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5599 NO_STR
5600 NEIGHBOR_STR
5601 NEIGHBOR_ADDR_STR2
5602 "Disable the next hop calculation for this neighbor\n")
718e3744 5603{
d62a17ae 5604 int idx_peer = 2;
f4b8ec07
CS
5605 char base_xpath[XPATH_MAXLEN];
5606 char af_xpath[XPATH_MAXLEN];
5607 char attr_xpath[XPATH_MAXLEN];
5608 afi_t afi = bgp_node_afi(vty);
5609 safi_t safi = bgp_node_safi(vty);
5610
5611 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5612 yang_afi_safi_value2identity(afi, safi));
5613
5614 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5615 sizeof(base_xpath), af_xpath)
5616 < 0)
5617 return CMD_WARNING_CONFIG_FAILED;
5618
5619 snprintf(attr_xpath, sizeof(attr_xpath),
5620 "./%s/nexthop-self/next-hop-self",
5621 bgp_afi_safi_get_container_str(afi, safi));
5622
5623 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5624
5625 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5626}
6b0655a2 5627
d62a17ae 5628ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5629 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5630 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5631 "Disable the next hop calculation for this neighbor\n")
596c17ba 5632
f4b8ec07
CS
5633DEFUN_YANG (no_neighbor_nexthop_self_force,
5634 no_neighbor_nexthop_self_force_cmd,
5635 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5636 NO_STR
5637 NEIGHBOR_STR
5638 NEIGHBOR_ADDR_STR2
5639 "Disable the next hop calculation for this neighbor\n"
5640 "Set the next hop to self for reflected routes\n")
88b8ed8d 5641{
d62a17ae 5642 int idx_peer = 2;
f4b8ec07
CS
5643 char base_xpath[XPATH_MAXLEN];
5644 char af_xpath[XPATH_MAXLEN];
5645 char attr_xpath[XPATH_MAXLEN];
5646 afi_t afi = bgp_node_afi(vty);
5647 safi_t safi = bgp_node_safi(vty);
5648
f4b8ec07
CS
5649 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5650 yang_afi_safi_value2identity(afi, safi));
5651
5652 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5653 sizeof(base_xpath), af_xpath)
5654 < 0)
5655 return CMD_WARNING_CONFIG_FAILED;
5656
5657 snprintf(attr_xpath, sizeof(attr_xpath),
5658 "./%s/nexthop-self/next-hop-self-force",
5659 bgp_afi_safi_get_container_str(afi, safi));
5660
5661 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5662
5663 return nb_cli_apply_changes(vty, base_xpath);
88b8ed8d 5664}
a538debe 5665
d62a17ae 5666ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5667 no_neighbor_nexthop_self_force_hidden_cmd,
5668 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5669 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5670 "Disable the next hop calculation for this neighbor\n"
5671 "Set the next hop to self for reflected routes\n")
596c17ba 5672
1bc4e531
DA
5673ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5674 no_neighbor_nexthop_self_all_hidden_cmd,
5675 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5676 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5677 "Disable the next hop calculation for this neighbor\n"
5678 "Set the next hop to self for reflected routes\n")
5679
c7122e14 5680/* neighbor as-override */
f4b8ec07
CS
5681DEFUN_YANG (neighbor_as_override,
5682 neighbor_as_override_cmd,
5683 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5684 NEIGHBOR_STR
5685 NEIGHBOR_ADDR_STR2
5686 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5687{
d62a17ae 5688 int idx_peer = 1;
f4b8ec07
CS
5689 char base_xpath[XPATH_MAXLEN];
5690 char af_xpath[XPATH_MAXLEN];
5691 char attr_xpath[XPATH_MAXLEN];
5692 afi_t afi = bgp_node_afi(vty);
5693 safi_t safi = bgp_node_safi(vty);
5694
5695 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5696 yang_afi_safi_value2identity(afi, safi));
5697
5698 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5699 sizeof(base_xpath), af_xpath)
5700 < 0)
5701 return CMD_WARNING_CONFIG_FAILED;
5702
5703 snprintf(attr_xpath, sizeof(attr_xpath),
5704 "./%s/as-path-options/replace-peer-as",
5705 bgp_afi_safi_get_container_str(afi, safi));
5706
5707 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5708
5709 return nb_cli_apply_changes(vty, base_xpath);
c7122e14
DS
5710}
5711
d62a17ae 5712ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5713 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5714 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5715 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5716
f4b8ec07
CS
5717DEFUN_YANG (no_neighbor_as_override,
5718 no_neighbor_as_override_cmd,
5719 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5720 NO_STR
5721 NEIGHBOR_STR
5722 NEIGHBOR_ADDR_STR2
5723 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5724{
d62a17ae 5725 int idx_peer = 2;
f4b8ec07
CS
5726 char base_xpath[XPATH_MAXLEN];
5727 char af_xpath[XPATH_MAXLEN];
5728 char attr_xpath[XPATH_MAXLEN];
5729 afi_t afi = bgp_node_afi(vty);
5730 safi_t safi = bgp_node_safi(vty);
5731
5732 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5733 yang_afi_safi_value2identity(afi, safi));
5734
5735 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5736 sizeof(base_xpath), af_xpath)
5737 < 0)
5738 return CMD_WARNING_CONFIG_FAILED;
5739
5740 snprintf(attr_xpath, sizeof(attr_xpath),
5741 "./%s/as-path-options/replace-peer-as",
5742 bgp_afi_safi_get_container_str(afi, safi));
5743
5744 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5745
5746 return nb_cli_apply_changes(vty, base_xpath);
c7122e14
DS
5747}
5748
d62a17ae 5749ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5750 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5751 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5752 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5753
718e3744 5754/* neighbor remove-private-AS. */
f4b8ec07
CS
5755DEFUN_YANG (neighbor_remove_private_as,
5756 neighbor_remove_private_as_cmd,
5757 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5758 NEIGHBOR_STR
5759 NEIGHBOR_ADDR_STR2
5760 "Remove private ASNs in outbound updates\n")
718e3744 5761{
d62a17ae 5762 int idx_peer = 1;
f4b8ec07
CS
5763 char base_xpath[XPATH_MAXLEN];
5764 char af_xpath[XPATH_MAXLEN];
5765 char attr_xpath[XPATH_MAXLEN];
5766 afi_t afi = bgp_node_afi(vty);
5767 safi_t safi = bgp_node_safi(vty);
5768
5769 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5770 yang_afi_safi_value2identity(afi, safi));
5771
5772 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5773 sizeof(base_xpath), af_xpath)
5774 < 0)
5775 return CMD_WARNING_CONFIG_FAILED;
5776
5777 snprintf(attr_xpath, sizeof(attr_xpath),
5778 "./%s/private-as/remove-private-as",
5779 bgp_afi_safi_get_container_str(afi, safi));
5780
5781 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5782
5783 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5784}
5785
d62a17ae 5786ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5787 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5788 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5789 "Remove private ASNs in outbound updates\n")
596c17ba 5790
f4b8ec07
CS
5791DEFUN_YANG (neighbor_remove_private_as_all,
5792 neighbor_remove_private_as_all_cmd,
5793 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5794 NEIGHBOR_STR
5795 NEIGHBOR_ADDR_STR2
5796 "Remove private ASNs in outbound updates\n"
5797 "Apply to all AS numbers\n")
5000f21c 5798{
d62a17ae 5799 int idx_peer = 1;
f4b8ec07
CS
5800 char base_xpath[XPATH_MAXLEN];
5801 char af_xpath[XPATH_MAXLEN];
5802 char attr_xpath[XPATH_MAXLEN];
5803 afi_t afi = bgp_node_afi(vty);
5804 safi_t safi = bgp_node_safi(vty);
5805
f4b8ec07
CS
5806 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5807 yang_afi_safi_value2identity(afi, safi));
5808
5809 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5810 sizeof(base_xpath), af_xpath)
5811 < 0)
5812 return CMD_WARNING_CONFIG_FAILED;
5813
5814 snprintf(attr_xpath, sizeof(attr_xpath),
5815 "./%s/private-as/remove-private-as-all",
5816 bgp_afi_safi_get_container_str(afi, safi));
5817
5818 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5819
5820 return nb_cli_apply_changes(vty, base_xpath);
5000f21c
DS
5821}
5822
d62a17ae 5823ALIAS_HIDDEN(neighbor_remove_private_as_all,
5824 neighbor_remove_private_as_all_hidden_cmd,
5825 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5826 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5827 "Remove private ASNs in outbound updates\n"
5828 "Apply to all AS numbers")
596c17ba 5829
f4b8ec07
CS
5830DEFUN_YANG (neighbor_remove_private_as_replace_as,
5831 neighbor_remove_private_as_replace_as_cmd,
5832 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5833 NEIGHBOR_STR
5834 NEIGHBOR_ADDR_STR2
5835 "Remove private ASNs in outbound updates\n"
5836 "Replace private ASNs with our ASN in outbound updates\n")
5000f21c 5837{
d62a17ae 5838 int idx_peer = 1;
f4b8ec07
CS
5839 char base_xpath[XPATH_MAXLEN];
5840 char af_xpath[XPATH_MAXLEN];
5841 char attr_xpath[XPATH_MAXLEN];
5842 afi_t afi = bgp_node_afi(vty);
5843 safi_t safi = bgp_node_safi(vty);
5844
f4b8ec07
CS
5845 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5846 yang_afi_safi_value2identity(afi, safi));
5847
5848 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5849 sizeof(base_xpath), af_xpath)
5850 < 0)
5851 return CMD_WARNING_CONFIG_FAILED;
5852
5853 snprintf(attr_xpath, sizeof(attr_xpath),
5854 "./%s/private-as/remove-private-as-replace",
5855 bgp_afi_safi_get_container_str(afi, safi));
5856
5857 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5858
5859 return nb_cli_apply_changes(vty, base_xpath);
5000f21c
DS
5860}
5861
d62a17ae 5862ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5863 neighbor_remove_private_as_replace_as_hidden_cmd,
5864 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5865 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5866 "Remove private ASNs in outbound updates\n"
5867 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5868
f4b8ec07
CS
5869DEFUN_YANG (neighbor_remove_private_as_all_replace_as,
5870 neighbor_remove_private_as_all_replace_as_cmd,
5871 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5872 NEIGHBOR_STR
5873 NEIGHBOR_ADDR_STR2
5874 "Remove private ASNs in outbound updates\n"
5875 "Apply to all AS numbers\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-all-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(
5903 neighbor_remove_private_as_all_replace_as,
5904 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5905 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5906 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5907 "Remove private ASNs in outbound updates\n"
5908 "Apply to all AS numbers\n"
5909 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5910
f4b8ec07
CS
5911DEFUN_YANG (no_neighbor_remove_private_as,
5912 no_neighbor_remove_private_as_cmd,
5913 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5914 NO_STR
5915 NEIGHBOR_STR
5916 NEIGHBOR_ADDR_STR2
5917 "Remove private ASNs in outbound updates\n")
718e3744 5918{
d62a17ae 5919 int idx_peer = 2;
f4b8ec07
CS
5920 char base_xpath[XPATH_MAXLEN];
5921 char af_xpath[XPATH_MAXLEN];
5922 char attr_xpath[XPATH_MAXLEN];
5923 afi_t afi = bgp_node_afi(vty);
5924 safi_t safi = bgp_node_safi(vty);
5925
5926 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5927 yang_afi_safi_value2identity(afi, safi));
5928
5929 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5930 sizeof(base_xpath), af_xpath)
5931 < 0)
5932 return CMD_WARNING_CONFIG_FAILED;
5933
5934 snprintf(attr_xpath, sizeof(attr_xpath),
5935 "./%s/private-as/remove-private-as",
5936 bgp_afi_safi_get_container_str(afi, safi));
5937
5938 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5939
5940 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5941}
6b0655a2 5942
d62a17ae 5943ALIAS_HIDDEN(no_neighbor_remove_private_as,
5944 no_neighbor_remove_private_as_hidden_cmd,
5945 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5946 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5947 "Remove private ASNs in outbound updates\n")
596c17ba 5948
f4b8ec07
CS
5949DEFUN_YANG (no_neighbor_remove_private_as_all,
5950 no_neighbor_remove_private_as_all_cmd,
5951 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5952 NO_STR
5953 NEIGHBOR_STR
5954 NEIGHBOR_ADDR_STR2
5955 "Remove private ASNs in outbound updates\n"
5956 "Apply to all AS numbers\n")
88b8ed8d 5957{
d62a17ae 5958 int idx_peer = 2;
f4b8ec07
CS
5959 char base_xpath[XPATH_MAXLEN];
5960 char af_xpath[XPATH_MAXLEN];
5961 char attr_xpath[XPATH_MAXLEN];
5962 afi_t afi = bgp_node_afi(vty);
5963 safi_t safi = bgp_node_safi(vty);
5964
f4b8ec07
CS
5965 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5966 yang_afi_safi_value2identity(afi, safi));
5967
5968 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5969 sizeof(base_xpath), af_xpath)
5970 < 0)
5971 return CMD_WARNING_CONFIG_FAILED;
5972
5973 snprintf(attr_xpath, sizeof(attr_xpath),
5974 "./%s/private-as/remove-private-as-all",
5975 bgp_afi_safi_get_container_str(afi, safi));
5976
5977 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5978
5979 return nb_cli_apply_changes(vty, base_xpath);
88b8ed8d 5980}
5000f21c 5981
d62a17ae 5982ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
5983 no_neighbor_remove_private_as_all_hidden_cmd,
5984 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5985 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5986 "Remove private ASNs in outbound updates\n"
5987 "Apply to all AS numbers\n")
596c17ba 5988
f4b8ec07
CS
5989DEFUN_YANG (no_neighbor_remove_private_as_replace_as,
5990 no_neighbor_remove_private_as_replace_as_cmd,
5991 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5992 NO_STR
5993 NEIGHBOR_STR
5994 NEIGHBOR_ADDR_STR2
5995 "Remove private ASNs in outbound updates\n"
5996 "Replace private ASNs with our ASN in outbound updates\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-replace",
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_replace_as,
6023 no_neighbor_remove_private_as_replace_as_hidden_cmd,
6024 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
6025 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6026 "Remove private ASNs in outbound updates\n"
6027 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 6028
f4b8ec07
CS
6029DEFUN_YANG (no_neighbor_remove_private_as_all_replace_as,
6030 no_neighbor_remove_private_as_all_replace_as_cmd,
6031 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6032 NO_STR
6033 NEIGHBOR_STR
6034 NEIGHBOR_ADDR_STR2
6035 "Remove private ASNs in outbound updates\n"
6036 "Apply to all AS numbers\n"
6037 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 6038{
d62a17ae 6039 int idx_peer = 2;
f4b8ec07
CS
6040 char base_xpath[XPATH_MAXLEN];
6041 char af_xpath[XPATH_MAXLEN];
6042 char attr_xpath[XPATH_MAXLEN];
6043 afi_t afi = bgp_node_afi(vty);
6044 safi_t safi = bgp_node_safi(vty);
6045
f4b8ec07
CS
6046 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6047 yang_afi_safi_value2identity(afi, safi));
6048
6049 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6050 sizeof(base_xpath), af_xpath)
6051 < 0)
6052 return CMD_WARNING_CONFIG_FAILED;
6053
6054 snprintf(attr_xpath, sizeof(attr_xpath),
6055 "./%s/private-as/remove-private-as-all-replace",
6056 bgp_afi_safi_get_container_str(afi, safi));
6057
6058 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6059
6060 return nb_cli_apply_changes(vty, base_xpath);
88b8ed8d 6061}
5000f21c 6062
d62a17ae 6063ALIAS_HIDDEN(
6064 no_neighbor_remove_private_as_all_replace_as,
6065 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
6066 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6067 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6068 "Remove private ASNs in outbound updates\n"
6069 "Apply to all AS numbers\n"
6070 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 6071
5000f21c 6072
718e3744 6073/* neighbor send-community. */
f4b8ec07
CS
6074DEFUN_YANG (neighbor_send_community,
6075 neighbor_send_community_cmd,
6076 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6077 NEIGHBOR_STR
6078 NEIGHBOR_ADDR_STR2
6079 "Send Community attribute to this neighbor\n")
718e3744 6080{
d62a17ae 6081 int idx_peer = 1;
27c05d4d 6082
d62a17ae 6083 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6084 bgp_node_safi(vty),
6085 PEER_FLAG_SEND_COMMUNITY);
718e3744 6086}
6087
d62a17ae 6088ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
6089 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6090 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6091 "Send Community attribute to this neighbor\n")
596c17ba 6092
f4b8ec07
CS
6093DEFUN_YANG (no_neighbor_send_community,
6094 no_neighbor_send_community_cmd,
6095 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6096 NO_STR
6097 NEIGHBOR_STR
6098 NEIGHBOR_ADDR_STR2
6099 "Send Community attribute to this neighbor\n")
718e3744 6100{
d62a17ae 6101 int idx_peer = 2;
27c05d4d 6102
d62a17ae 6103 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6104 bgp_node_afi(vty), bgp_node_safi(vty),
6105 PEER_FLAG_SEND_COMMUNITY);
718e3744 6106}
6b0655a2 6107
d62a17ae 6108ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
6109 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6110 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6111 "Send Community attribute to this neighbor\n")
596c17ba 6112
718e3744 6113/* neighbor send-community extended. */
f4b8ec07
CS
6114DEFUN_YANG (neighbor_send_community_type,
6115 neighbor_send_community_type_cmd,
6116 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6117 NEIGHBOR_STR
6118 NEIGHBOR_ADDR_STR2
6119 "Send Community attribute to this neighbor\n"
6120 "Send Standard and Extended Community attributes\n"
6121 "Send Standard, Large and Extended Community attributes\n"
6122 "Send Extended Community attributes\n"
6123 "Send Standard Community attributes\n"
6124 "Send Large Community attributes\n")
718e3744 6125{
27c05d4d 6126 const char *type = argv[argc - 1]->text;
db45f64d 6127 char *peer_str = argv[1]->arg;
f4b8ec07
CS
6128 char base_xpath[XPATH_MAXLEN];
6129 char af_xpath[XPATH_MAXLEN];
6130 char std_xpath[XPATH_MAXLEN];
6131 char ext_xpath[XPATH_MAXLEN];
6132 char lrg_xpath[XPATH_MAXLEN];
db45f64d
DS
6133 afi_t afi = bgp_node_afi(vty);
6134 safi_t safi = bgp_node_safi(vty);
d62a17ae 6135
f4b8ec07
CS
6136 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6137 yang_afi_safi_value2identity(afi, safi));
6138
6139 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6140 sizeof(base_xpath), af_xpath)
6141 < 0)
db45f64d 6142 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6143
f4b8ec07
CS
6144 if (strmatch(type, "standard")) {
6145 snprintf(std_xpath, sizeof(std_xpath),
6146 "./%s/send-community/send-community",
6147 bgp_afi_safi_get_container_str(afi, safi));
db45f64d 6148
f4b8ec07
CS
6149 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6150 }
db45f64d 6151
f4b8ec07
CS
6152 if (strmatch(type, "extended")) {
6153 snprintf(ext_xpath, sizeof(ext_xpath),
6154 "./%s/send-community/send-ext-community",
6155 bgp_afi_safi_get_container_str(afi, safi));
6156
6157 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
6158 }
6159
6160 if (strmatch(type, "large")) {
6161 snprintf(lrg_xpath, sizeof(lrg_xpath),
6162 "./%s/send-community/send-large-community",
6163 bgp_afi_safi_get_container_str(afi, safi));
6164
6165 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "true");
6166 }
db45f64d
DS
6167
6168 if (strmatch(type, "both")) {
f4b8ec07
CS
6169 snprintf(std_xpath, sizeof(std_xpath),
6170 "./%s/send-community/send-community",
6171 bgp_afi_safi_get_container_str(afi, safi));
6172
6173 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6174
6175 snprintf(ext_xpath, sizeof(ext_xpath),
6176 "./%s/send-community/send-ext-community",
6177 bgp_afi_safi_get_container_str(afi, safi));
6178
6179 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
db45f64d 6180 }
f4b8ec07
CS
6181
6182 if (strmatch(type, "all")) {
6183 snprintf(std_xpath, sizeof(std_xpath),
6184 "./%s/send-community/send-community",
6185 bgp_afi_safi_get_container_str(afi, safi));
6186
6187 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6188
6189 snprintf(ext_xpath, sizeof(ext_xpath),
6190 "./%s/send-community/send-ext-community",
6191 bgp_afi_safi_get_container_str(afi, safi));
6192
6193 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
6194
6195 snprintf(lrg_xpath, sizeof(lrg_xpath),
6196 "./%s/send-community/send-large-community",
6197 bgp_afi_safi_get_container_str(afi, safi));
6198
6199 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "true");
6200 }
6201
6202 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 6203}
6204
6205ALIAS_HIDDEN(
6206 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
6207 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6208 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6209 "Send Community attribute to this neighbor\n"
6210 "Send Standard and Extended Community attributes\n"
6211 "Send Standard, Large and Extended Community attributes\n"
6212 "Send Extended Community attributes\n"
6213 "Send Standard Community attributes\n"
6214 "Send Large Community attributes\n")
596c17ba 6215
f4b8ec07
CS
6216DEFUN_YANG (no_neighbor_send_community_type,
6217 no_neighbor_send_community_type_cmd,
6218 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6219 NO_STR
6220 NEIGHBOR_STR
6221 NEIGHBOR_ADDR_STR2
6222 "Send Community attribute to this neighbor\n"
6223 "Send Standard and Extended Community attributes\n"
6224 "Send Standard, Large and Extended Community attributes\n"
6225 "Send Extended Community attributes\n"
6226 "Send Standard Community attributes\n"
6227 "Send Large Community attributes\n")
718e3744 6228{
d62a17ae 6229 const char *type = argv[argc - 1]->text;
db45f64d 6230 char *peer_str = argv[2]->arg;
f4b8ec07
CS
6231 char base_xpath[XPATH_MAXLEN];
6232 char af_xpath[XPATH_MAXLEN];
6233 char std_xpath[XPATH_MAXLEN];
6234 char ext_xpath[XPATH_MAXLEN];
6235 char lrg_xpath[XPATH_MAXLEN];
db45f64d
DS
6236 afi_t afi = bgp_node_afi(vty);
6237 safi_t safi = bgp_node_safi(vty);
6238
f4b8ec07
CS
6239 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6240 yang_afi_safi_value2identity(afi, safi));
6241
6242 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6243 sizeof(base_xpath), af_xpath)
6244 < 0)
6245 return CMD_WARNING_CONFIG_FAILED;
6246
6247 if (strmatch(type, "standard")) {
6248 snprintf(std_xpath, sizeof(std_xpath),
6249 "./%s/send-community/send-community",
6250 bgp_afi_safi_get_container_str(afi, safi));
6251
6252 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6253 }
6254
6255 if (strmatch(type, "extended")) {
6256 snprintf(ext_xpath, sizeof(ext_xpath),
6257 "./%s/send-community/send-ext-community",
6258 bgp_afi_safi_get_container_str(afi, safi));
6259
6260 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
6261 }
6262
6263 if (strmatch(type, "large")) {
6264 snprintf(lrg_xpath, sizeof(lrg_xpath),
6265 "./%s/send-community/send-large-community",
6266 bgp_afi_safi_get_container_str(afi, safi));
6267
6268 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "false");
6269 }
6270
6271 if (strmatch(type, "both")) {
6272 snprintf(std_xpath, sizeof(std_xpath),
6273 "./%s/send-community/send-community",
6274 bgp_afi_safi_get_container_str(afi, safi));
6275
6276 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6277
6278 snprintf(ext_xpath, sizeof(ext_xpath),
6279 "./%s/send-community/send-ext-community",
6280 bgp_afi_safi_get_container_str(afi, safi));
6281
6282 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
6283 }
6284
6285 if (strmatch(type, "all")) {
6286 snprintf(std_xpath, sizeof(std_xpath),
6287 "./%s/send-community/send-community",
6288 bgp_afi_safi_get_container_str(afi, safi));
db45f64d 6289
f4b8ec07 6290 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
db45f64d 6291
f4b8ec07
CS
6292 snprintf(ext_xpath, sizeof(ext_xpath),
6293 "./%s/send-community/send-ext-community",
6294 bgp_afi_safi_get_container_str(afi, safi));
db45f64d 6295
f4b8ec07 6296 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
db45f64d 6297
f4b8ec07
CS
6298 snprintf(lrg_xpath, sizeof(lrg_xpath),
6299 "./%s/send-community/send-large-community",
6300 bgp_afi_safi_get_container_str(afi, safi));
d62a17ae 6301
f4b8ec07 6302 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "false");
27c05d4d
PM
6303 }
6304
f4b8ec07 6305 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 6306}
6307
6308ALIAS_HIDDEN(
6309 no_neighbor_send_community_type,
6310 no_neighbor_send_community_type_hidden_cmd,
6311 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6312 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6313 "Send Community attribute to this neighbor\n"
6314 "Send Standard and Extended Community attributes\n"
6315 "Send Standard, Large and Extended Community attributes\n"
6316 "Send Extended Community attributes\n"
6317 "Send Standard Community attributes\n"
6318 "Send Large Community attributes\n")
596c17ba 6319
718e3744 6320/* neighbor soft-reconfig. */
f4b8ec07
CS
6321DEFUN_YANG (neighbor_soft_reconfiguration,
6322 neighbor_soft_reconfiguration_cmd,
6323 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6324 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6325 "Per neighbor soft reconfiguration\n"
6326 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 6327{
d62a17ae 6328 int idx_peer = 1;
f4b8ec07
CS
6329 char base_xpath[XPATH_MAXLEN];
6330 char af_xpath[XPATH_MAXLEN];
6331 char soft_xpath[XPATH_MAXLEN];
6332 afi_t afi = bgp_node_afi(vty);
6333 safi_t safi = bgp_node_safi(vty);
6334
f4b8ec07
CS
6335 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6336 yang_afi_safi_value2identity(afi, safi));
6337
6338 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6339 sizeof(base_xpath), af_xpath)
6340 < 0)
6341 return CMD_WARNING_CONFIG_FAILED;
6342
6343 snprintf(soft_xpath, sizeof(soft_xpath), "./%s/soft-reconfiguration",
6344 bgp_afi_safi_get_container_str(afi, safi));
6345
6346 nb_cli_enqueue_change(vty, soft_xpath, NB_OP_MODIFY, "true");
6347
6348 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6349}
6350
d62a17ae 6351ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6352 neighbor_soft_reconfiguration_hidden_cmd,
6353 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6354 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6355 "Per neighbor soft reconfiguration\n"
6356 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 6357
f4b8ec07
CS
6358DEFUN_YANG (no_neighbor_soft_reconfiguration,
6359 no_neighbor_soft_reconfiguration_cmd,
6360 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6361 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6362 "Per neighbor soft reconfiguration\n"
6363 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 6364{
d62a17ae 6365 int idx_peer = 2;
f4b8ec07
CS
6366 char base_xpath[XPATH_MAXLEN];
6367 char af_xpath[XPATH_MAXLEN];
6368 char soft_xpath[XPATH_MAXLEN];
6369 afi_t afi = bgp_node_afi(vty);
6370 safi_t safi = bgp_node_safi(vty);
6371
6372 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6373 yang_afi_safi_value2identity(afi, safi));
6374
6375 snprintf(soft_xpath, sizeof(soft_xpath), "./%s/soft-reconfiguration",
6376 bgp_afi_safi_get_container_str(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 nb_cli_enqueue_change(vty, soft_xpath, NB_OP_MODIFY, "false");
6384
6385 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6386}
6b0655a2 6387
d62a17ae 6388ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6389 no_neighbor_soft_reconfiguration_hidden_cmd,
6390 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6391 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6392 "Per neighbor soft reconfiguration\n"
6393 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 6394
f4b8ec07
CS
6395DEFUN_YANG (neighbor_route_reflector_client,
6396 neighbor_route_reflector_client_cmd,
6397 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6398 NEIGHBOR_STR
6399 NEIGHBOR_ADDR_STR2
6400 "Configure a neighbor as Route Reflector client\n")
718e3744 6401{
d62a17ae 6402 int idx_peer = 1;
f4b8ec07
CS
6403 char base_xpath[XPATH_MAXLEN];
6404 char af_xpath[XPATH_MAXLEN];
6405 char attr_xpath[XPATH_MAXLEN];
6406 afi_t afi = bgp_node_afi(vty);
6407 safi_t safi = bgp_node_safi(vty);
718e3744 6408
f4b8ec07
CS
6409 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6410 yang_afi_safi_value2identity(afi, safi));
718e3744 6411
f4b8ec07
CS
6412 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6413 sizeof(base_xpath), af_xpath)
6414 < 0)
d62a17ae 6415 return CMD_WARNING_CONFIG_FAILED;
718e3744 6416
f4b8ec07
CS
6417 snprintf(attr_xpath, sizeof(attr_xpath),
6418 "./%s/route-reflector/route-reflector-client",
6419 bgp_afi_safi_get_container_str(afi, safi));
6420
6421 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
6422
6423 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6424}
6425
d62a17ae 6426ALIAS_HIDDEN(neighbor_route_reflector_client,
6427 neighbor_route_reflector_client_hidden_cmd,
6428 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6429 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6430 "Configure a neighbor as Route Reflector client\n")
596c17ba 6431
f4b8ec07
CS
6432DEFUN_YANG (no_neighbor_route_reflector_client,
6433 no_neighbor_route_reflector_client_cmd,
6434 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6435 NO_STR
6436 NEIGHBOR_STR
6437 NEIGHBOR_ADDR_STR2
6438 "Configure a neighbor as Route Reflector client\n")
718e3744 6439{
d62a17ae 6440 int idx_peer = 2;
f4b8ec07
CS
6441 char base_xpath[XPATH_MAXLEN];
6442 char af_xpath[XPATH_MAXLEN];
6443 char attr_xpath[XPATH_MAXLEN];
6444 afi_t afi = bgp_node_afi(vty);
6445 safi_t safi = bgp_node_safi(vty);
6446
6447 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6448 yang_afi_safi_value2identity(afi, safi));
6449
6450 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6451 sizeof(base_xpath), af_xpath)
6452 < 0)
6453 return CMD_WARNING_CONFIG_FAILED;
6454
6455 snprintf(attr_xpath, sizeof(attr_xpath),
6456 "./%s/route-reflector/route-reflector-client",
6457 bgp_afi_safi_get_container_str(afi, safi));
6458
6459 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6460
6461 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6462}
6b0655a2 6463
d62a17ae 6464ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6465 no_neighbor_route_reflector_client_hidden_cmd,
6466 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6467 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6468 "Configure a neighbor as Route Reflector client\n")
596c17ba 6469
718e3744 6470/* neighbor route-server-client. */
f4b8ec07
CS
6471DEFUN_YANG (neighbor_route_server_client,
6472 neighbor_route_server_client_cmd,
6473 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6474 NEIGHBOR_STR
6475 NEIGHBOR_ADDR_STR2
6476 "Configure a neighbor as Route Server client\n")
718e3744 6477{
d62a17ae 6478 int idx_peer = 1;
f4b8ec07
CS
6479 char base_xpath[XPATH_MAXLEN];
6480 char af_xpath[XPATH_MAXLEN];
6481 char attr_xpath[XPATH_MAXLEN];
6482 afi_t afi = bgp_node_afi(vty);
6483 safi_t safi = bgp_node_safi(vty);
2a3d5731 6484
f4b8ec07
CS
6485 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6486 yang_afi_safi_value2identity(afi, safi));
6487
6488 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6489 sizeof(base_xpath), af_xpath)
6490 < 0)
d62a17ae 6491 return CMD_WARNING_CONFIG_FAILED;
f4b8ec07
CS
6492
6493 snprintf(attr_xpath, sizeof(attr_xpath),
6494 "./%s/route-server/route-server-client",
6495 bgp_afi_safi_get_container_str(afi, safi));
6496
6497 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
6498
6499 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6500}
6501
d62a17ae 6502ALIAS_HIDDEN(neighbor_route_server_client,
6503 neighbor_route_server_client_hidden_cmd,
6504 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6505 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6506 "Configure a neighbor as Route Server client\n")
596c17ba 6507
f4b8ec07
CS
6508DEFUN_YANG (no_neighbor_route_server_client,
6509 no_neighbor_route_server_client_cmd,
6510 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6511 NO_STR
6512 NEIGHBOR_STR
6513 NEIGHBOR_ADDR_STR2
6514 "Configure a neighbor as Route Server client\n")
fee0f4c6 6515{
d62a17ae 6516 int idx_peer = 2;
f4b8ec07
CS
6517 char base_xpath[XPATH_MAXLEN];
6518 char af_xpath[XPATH_MAXLEN];
6519 char attr_xpath[XPATH_MAXLEN];
6520 afi_t afi = bgp_node_afi(vty);
6521 safi_t safi = bgp_node_safi(vty);
6522
6523 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6524 yang_afi_safi_value2identity(afi, safi));
6525
6526 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6527 sizeof(base_xpath), af_xpath)
6528 < 0)
6529 return CMD_WARNING_CONFIG_FAILED;
6530
6531 snprintf(attr_xpath, sizeof(attr_xpath),
6532 "./%s/route-server/route-server-client",
6533 bgp_afi_safi_get_container_str(afi, safi));
6534
6535 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6536
6537 return nb_cli_apply_changes(vty, base_xpath);
fee0f4c6 6538}
6b0655a2 6539
d62a17ae 6540ALIAS_HIDDEN(no_neighbor_route_server_client,
6541 no_neighbor_route_server_client_hidden_cmd,
6542 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6543 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6544 "Configure a neighbor as Route Server client\n")
596c17ba 6545
fee0f4c6 6546DEFUN (neighbor_nexthop_local_unchanged,
6547 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 6548 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 6549 NEIGHBOR_STR
6550 NEIGHBOR_ADDR_STR2
6551 "Configure treatment of outgoing link-local nexthop attribute\n"
6552 "Leave link-local nexthop unchanged for this peer\n")
6553{
d62a17ae 6554 int idx_peer = 1;
6555 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6556 bgp_node_safi(vty),
6557 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 6558}
6b0655a2 6559
fee0f4c6 6560DEFUN (no_neighbor_nexthop_local_unchanged,
6561 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 6562 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 6563 NO_STR
6564 NEIGHBOR_STR
6565 NEIGHBOR_ADDR_STR2
6566 "Configure treatment of outgoing link-local-nexthop attribute\n"
6567 "Leave link-local nexthop unchanged for this peer\n")
718e3744 6568{
d62a17ae 6569 int idx_peer = 2;
6570 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6571 bgp_node_afi(vty), bgp_node_safi(vty),
6572 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 6573}
6b0655a2 6574
f4b8ec07
CS
6575DEFUN_YANG (neighbor_attr_unchanged,
6576 neighbor_attr_unchanged_cmd,
6577 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6578 NEIGHBOR_STR
6579 NEIGHBOR_ADDR_STR2
6580 "BGP attribute is propagated unchanged to this neighbor\n"
6581 "As-path attribute\n"
6582 "Nexthop attribute\n"
6583 "Med attribute\n")
718e3744 6584{
d62a17ae 6585 int idx = 0;
8eeb0335 6586 char *peer_str = argv[1]->arg;
db45f64d
DS
6587 bool aspath = false;
6588 bool nexthop = false;
6589 bool med = false;
8eeb0335
DW
6590 afi_t afi = bgp_node_afi(vty);
6591 safi_t safi = bgp_node_safi(vty);
f4b8ec07
CS
6592 char base_xpath[XPATH_MAXLEN];
6593 char af_xpath[XPATH_MAXLEN];
6594 char as_xpath[XPATH_MAXLEN];
6595 char nxthop_xpath[XPATH_MAXLEN];
6596 char med_xpath[XPATH_MAXLEN];
8eeb0335 6597
f4b8ec07
CS
6598 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6599 yang_afi_safi_value2identity(afi, safi));
6600
6601 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6602 sizeof(base_xpath), af_xpath)
6603 < 0)
8eeb0335 6604 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6605
6606 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
6607 aspath = true;
6608
d62a17ae 6609 idx = 0;
6610 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6611 nexthop = true;
6612
d62a17ae 6613 idx = 0;
6614 if (argv_find(argv, argc, "med", &idx))
db45f64d 6615 med = true;
d62a17ae 6616
f4b8ec07
CS
6617 snprintf(as_xpath, sizeof(as_xpath),
6618 "./%s/attr-unchanged/as-path-unchanged",
6619 bgp_afi_safi_get_container_str(afi, safi));
6620 snprintf(nxthop_xpath, sizeof(nxthop_xpath),
6621 "./%s/attr-unchanged/next-hop-unchanged",
6622 bgp_afi_safi_get_container_str(afi, safi));
6623 snprintf(med_xpath, sizeof(med_xpath),
6624 "./%s/attr-unchanged/med-unchanged",
6625 bgp_afi_safi_get_container_str(afi, safi));
6626
8eeb0335 6627 /* no flags means all of them! */
db45f64d 6628 if (!aspath && !nexthop && !med) {
f4b8ec07
CS
6629 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "true");
6630 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "true");
6631 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "true");
8eeb0335 6632 } else {
f4b8ec07
CS
6633 if (!aspath)
6634 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY,
6635 "false");
6636 else
6637 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY,
6638 "true");
6639
6640 if (!nexthop)
6641 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY,
6642 "false");
6643 else
6644 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY,
6645 "true");
6646
6647 if (!med)
6648 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY,
6649 "false");
6650 else
6651 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY,
6652 "true");
d62a17ae 6653 }
6654
f4b8ec07 6655 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 6656}
6657
6658ALIAS_HIDDEN(
6659 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6660 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6661 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6662 "BGP attribute is propagated unchanged to this neighbor\n"
6663 "As-path attribute\n"
6664 "Nexthop attribute\n"
6665 "Med attribute\n")
596c17ba 6666
f4b8ec07
CS
6667DEFUN_YANG (no_neighbor_attr_unchanged,
6668 no_neighbor_attr_unchanged_cmd,
6669 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6670 NO_STR
6671 NEIGHBOR_STR
6672 NEIGHBOR_ADDR_STR2
6673 "BGP attribute is propagated unchanged to this neighbor\n"
6674 "As-path attribute\n"
6675 "Nexthop attribute\n"
6676 "Med attribute\n")
718e3744 6677{
d62a17ae 6678 int idx = 0;
db45f64d 6679 char *peer_str = argv[2]->arg;
db45f64d
DS
6680 bool aspath = false;
6681 bool nexthop = false;
6682 bool med = false;
6683 afi_t afi = bgp_node_afi(vty);
6684 safi_t safi = bgp_node_safi(vty);
f4b8ec07
CS
6685 char base_xpath[XPATH_MAXLEN];
6686 char af_xpath[XPATH_MAXLEN];
6687 char as_xpath[XPATH_MAXLEN];
6688 char nxthop_xpath[XPATH_MAXLEN];
6689 char med_xpath[XPATH_MAXLEN];
db45f64d 6690
f4b8ec07
CS
6691 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6692 yang_afi_safi_value2identity(afi, safi));
6693
6694 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6695 sizeof(base_xpath), af_xpath)
6696 < 0)
db45f64d 6697 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6698
6699 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
6700 aspath = true;
6701
d62a17ae 6702 idx = 0;
6703 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6704 nexthop = true;
6705
d62a17ae 6706 idx = 0;
6707 if (argv_find(argv, argc, "med", &idx))
db45f64d 6708 med = true;
d62a17ae 6709
f4b8ec07
CS
6710 snprintf(as_xpath, sizeof(as_xpath),
6711 "./%s/attr-unchanged/as-path-unchanged",
6712 bgp_afi_safi_get_container_str(afi, safi));
6713 snprintf(nxthop_xpath, sizeof(nxthop_xpath),
6714 "./%s/attr-unchanged/next-hop-unchanged",
6715 bgp_afi_safi_get_container_str(afi, safi));
6716 snprintf(med_xpath, sizeof(med_xpath),
6717 "./%s/attr-unchanged/med-unchanged",
6718 bgp_afi_safi_get_container_str(afi, safi));
6719
6720 /* no flags means all of them! */
6721 if (!aspath && !nexthop && !med) {
6722 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "false");
6723 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "false");
6724 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "false");
6725 }
db45f64d
DS
6726
6727 if (aspath)
f4b8ec07 6728 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "false");
db45f64d
DS
6729
6730 if (nexthop)
f4b8ec07 6731 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "false");
d62a17ae 6732
db45f64d 6733 if (med)
f4b8ec07 6734 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "false");
db45f64d 6735
f4b8ec07 6736 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 6737}
6738
6739ALIAS_HIDDEN(
6740 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6741 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6742 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6743 "BGP attribute is propagated unchanged to this neighbor\n"
6744 "As-path attribute\n"
6745 "Nexthop attribute\n"
6746 "Med attribute\n")
718e3744 6747
f4b8ec07
CS
6748/* neighbor ebgp-multihop. */
6749DEFUN_YANG (neighbor_ebgp_multihop,
6750 neighbor_ebgp_multihop_cmd,
6751 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6752 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6753 "Allow EBGP neighbors not on directly connected networks\n")
718e3744 6754{
f4b8ec07
CS
6755 int idx_peer = 1;
6756 char base_xpath[XPATH_MAXLEN];
718e3744 6757
f4b8ec07
CS
6758 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6759 sizeof(base_xpath), NULL)
6760 < 0)
d62a17ae 6761 return CMD_WARNING_CONFIG_FAILED;
718e3744 6762
f4b8ec07
CS
6763 nb_cli_enqueue_change(vty, "./ebgp-multihop/enabled", NB_OP_MODIFY,
6764 "true");
718e3744 6765
f4b8ec07 6766 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6767}
6768
f4b8ec07
CS
6769DEFUN_YANG (neighbor_ebgp_multihop_ttl,
6770 neighbor_ebgp_multihop_ttl_cmd,
6771 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6772 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6773 "Allow EBGP neighbors not on directly connected networks\n"
6774 "maximum hop count\n")
718e3744 6775{
f4b8ec07
CS
6776 int idx_peer = 1;
6777 int idx_number = 3;
6778 char base_xpath[XPATH_MAXLEN];
718e3744 6779
f4b8ec07
CS
6780 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6781 sizeof(base_xpath), NULL)
6782 < 0)
d62a17ae 6783 return CMD_WARNING_CONFIG_FAILED;
718e3744 6784
f4b8ec07
CS
6785 nb_cli_enqueue_change(vty, "./ebgp-multihop/multihop-ttl", NB_OP_MODIFY,
6786 argv[idx_number]->arg);
718e3744 6787
f4b8ec07 6788 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6789}
6790
f4b8ec07
CS
6791DEFUN_YANG (no_neighbor_ebgp_multihop,
6792 no_neighbor_ebgp_multihop_cmd,
6793 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6794 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6795 "Allow EBGP neighbors not on directly connected networks\n"
6796 "maximum hop count\n")
718e3744 6797{
d62a17ae 6798 int idx_peer = 2;
f4b8ec07
CS
6799 char base_xpath[XPATH_MAXLEN];
6800
6801 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6802 sizeof(base_xpath), NULL)
6803 < 0)
6804 return CMD_WARNING_CONFIG_FAILED;
6805
6806 if (argc > 4)
6807 nb_cli_enqueue_change(vty, "./ebgp-multihop/multihop-ttl",
6808 NB_OP_DESTROY, NULL);
6809 else
6810 nb_cli_enqueue_change(vty, "./ebgp-multihop/enabled",
6811 NB_OP_MODIFY, "false");
6812
6813 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6814}
6815
6b0655a2 6816
6ffd2079 6817/* disable-connected-check */
f4b8ec07
CS
6818DEFUN_YANG (neighbor_disable_connected_check,
6819 neighbor_disable_connected_check_cmd,
6820 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6821 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6822 "one-hop away EBGP peer using loopback address\n"
6823 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6824{
d62a17ae 6825 int idx_peer = 1;
f4b8ec07
CS
6826 char base_xpath[XPATH_MAXLEN];
6827
6828 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6829 sizeof(base_xpath), NULL)
6830 < 0)
6831 return CMD_WARNING_CONFIG_FAILED;
6832
6833 nb_cli_enqueue_change(vty, "./ebgp-multihop/disable-connected-check",
6834 NB_OP_MODIFY, "true");
6835
6836 return nb_cli_apply_changes(vty, base_xpath);
6ffd2079 6837}
6838
f4b8ec07
CS
6839DEFUN_YANG (no_neighbor_disable_connected_check,
6840 no_neighbor_disable_connected_check_cmd,
6841 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6842 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6843 "one-hop away EBGP peer using loopback address\n"
6844 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6845{
d62a17ae 6846 int idx_peer = 2;
f4b8ec07
CS
6847 char base_xpath[XPATH_MAXLEN];
6848
6849 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6850 sizeof(base_xpath), NULL)
6851 < 0)
6852 return CMD_WARNING_CONFIG_FAILED;
6853
6854 nb_cli_enqueue_change(vty, "./ebgp-multihop/disable-connected-check",
6855 NB_OP_MODIFY, "false");
6856
6857 return nb_cli_apply_changes(vty, base_xpath);
6ffd2079 6858}
6859
47cbc09b
PM
6860
6861/* enforce-first-as */
f4b8ec07
CS
6862DEFUN_YANG (neighbor_enforce_first_as,
6863 neighbor_enforce_first_as_cmd,
6864 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6865 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6866 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
6867{
6868 int idx_peer = 1;
f4b8ec07 6869 char base_xpath[XPATH_MAXLEN];
47cbc09b 6870
f4b8ec07
CS
6871 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6872 sizeof(base_xpath), NULL)
6873 < 0)
6874 return CMD_WARNING_CONFIG_FAILED;
6875
6876 nb_cli_enqueue_change(vty, "./enforce-first-as", NB_OP_MODIFY, "true");
6877
6878 return nb_cli_apply_changes(vty, base_xpath);
47cbc09b
PM
6879}
6880
f4b8ec07
CS
6881DEFUN_YANG (no_neighbor_enforce_first_as,
6882 no_neighbor_enforce_first_as_cmd,
6883 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6884 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6885 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
6886{
6887 int idx_peer = 2;
f4b8ec07 6888 char base_xpath[XPATH_MAXLEN];
47cbc09b 6889
f4b8ec07
CS
6890 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6891 sizeof(base_xpath), NULL)
6892 < 0)
6893 return CMD_WARNING_CONFIG_FAILED;
6894
6895 nb_cli_enqueue_change(vty, "./enforce-first-as", NB_OP_MODIFY, "false");
6896
6897 return nb_cli_apply_changes(vty, base_xpath);
47cbc09b
PM
6898}
6899
f4b8ec07
CS
6900static int peer_and_group_lookup_nb(struct vty *vty, const char *peer_str,
6901 char *base_xpath, int xpath_len,
6902 char *xpath)
6903{
6904 union sockunion su;
6905 char num_xpath[XPATH_MAXLEN];
6906 char unnbr_xpath[XPATH_MAXLEN];
6907 char prgrp_xpath[XPATH_MAXLEN];
6908
6909 if (str2sockunion(peer_str, &su) == 0) {
6910 snprintf(num_xpath, sizeof(num_xpath),
6911 "/neighbors/neighbor[remote-address='%s']", peer_str);
6912 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
6913 VTY_CURR_XPATH, num_xpath)) {
6914 snprintf(base_xpath, xpath_len,
6915 FRR_BGP_NEIGHBOR_NUM_XPATH, peer_str,
6916 xpath ? xpath : "");
6917 } else {
6918 vty_out(vty,
6919 "%% Specify remote-as or peer-group commands first\n");
6920 return -1;
6921 }
6922
6923 } else {
6924 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
6925 "/neighbors/unnumbered-neighbor[interface='%s']",
6926 peer_str);
6927
6928 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
6929 "/peer-groups/peer-group[peer-group-name='%s']",
6930 peer_str);
6931
6932 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
6933 VTY_CURR_XPATH, unnbr_xpath)) {
6934 snprintf(base_xpath, xpath_len,
6935 FRR_BGP_NEIGHBOR_UNNUM_XPATH, peer_str,
6936 xpath ? xpath : "");
6937 } else if (yang_dnode_exists(vty->candidate_config->dnode,
6938 "%s%s", VTY_CURR_XPATH,
6939 prgrp_xpath)) {
6940 snprintf(base_xpath, xpath_len,
6941 FRR_BGP_PEER_GROUP_XPATH, peer_str,
6942 xpath ? xpath : "");
6943 } else {
6944 vty_out(vty,
6945 "%% Create the peer-group or interface first\n");
6946 return -1;
6947 }
6948 }
6949
6950 return 0;
6951}
47cbc09b 6952
f4b8ec07
CS
6953DEFUN_YANG (neighbor_description,
6954 neighbor_description_cmd,
6955 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6956 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6957 "Neighbor specific description\n"
6958 "Up to 80 characters describing this neighbor\n")
718e3744 6959{
d62a17ae 6960 int idx_peer = 1;
6961 int idx_line = 3;
f4b8ec07
CS
6962 int ret;
6963 char base_xpath[XPATH_MAXLEN];
d62a17ae 6964 char *str;
718e3744 6965
f4b8ec07
CS
6966 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6967 sizeof(base_xpath), NULL)
6968 < 0)
d62a17ae 6969 return CMD_WARNING_CONFIG_FAILED;
718e3744 6970
d62a17ae 6971 str = argv_concat(argv, argc, idx_line);
718e3744 6972
f4b8ec07
CS
6973 nb_cli_enqueue_change(vty, "./description", NB_OP_MODIFY, str);
6974
6975 ret = nb_cli_apply_changes(vty, base_xpath);
718e3744 6976
d62a17ae 6977 XFREE(MTYPE_TMP, str);
718e3744 6978
f4b8ec07 6979 return ret;
718e3744 6980}
6981
f4b8ec07
CS
6982DEFUN_YANG (no_neighbor_description,
6983 no_neighbor_description_cmd,
6984 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6985 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6986 "Neighbor specific description\n")
718e3744 6987{
d62a17ae 6988 int idx_peer = 2;
f4b8ec07
CS
6989 char base_xpath[XPATH_MAXLEN];
6990
6991 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6992 sizeof(base_xpath), NULL)
6993 < 0)
d62a17ae 6994 return CMD_WARNING_CONFIG_FAILED;
718e3744 6995
f4b8ec07 6996 nb_cli_enqueue_change(vty, "./description", NB_OP_DESTROY, NULL);
718e3744 6997
f4b8ec07 6998 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6999}
7000
232c75cd 7001ALIAS_YANG(no_neighbor_description, no_neighbor_description_comment_cmd,
a14810f4
PM
7002 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
7003 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7004 "Neighbor specific description\n"
7005 "Up to 80 characters describing this neighbor\n")
6b0655a2 7006
d62a17ae 7007#define BGP_UPDATE_SOURCE_HELP_STR \
7008 "IPv4 address\n" \
7009 "IPv6 address\n" \
7010 "Interface name (requires zebra to be running)\n"
369688c0 7011
f4b8ec07
CS
7012DEFUN_YANG (neighbor_update_source,
7013 neighbor_update_source_cmd,
7014 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
7015 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7016 "Source of routing updates\n"
7017 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 7018{
d62a17ae 7019 int idx_peer = 1;
7020 int idx_peer_2 = 3;
f4b8ec07
CS
7021 union sockunion su;
7022 char base_xpath[XPATH_MAXLEN];
7023
7024 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7025 sizeof(base_xpath), NULL)
7026 < 0)
7027 return CMD_WARNING_CONFIG_FAILED;
7028
f4b8ec07
CS
7029 if (str2sockunion(argv[idx_peer_2]->arg, &su) == 0)
7030 nb_cli_enqueue_change(vty, "./update-source/ip", NB_OP_MODIFY,
d62a17ae 7031 argv[idx_peer_2]->arg);
f4b8ec07
CS
7032 else
7033 nb_cli_enqueue_change(vty, "./update-source/interface",
7034 NB_OP_MODIFY, argv[idx_peer_2]->arg);
7035
7036 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7037}
7038
f4b8ec07
CS
7039DEFUN_YANG (no_neighbor_update_source,
7040 no_neighbor_update_source_cmd,
7041 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
7042 NO_STR NEIGHBOR_STR
7043 NEIGHBOR_ADDR_STR2
7044 "Source of routing updates\n"
7045 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 7046{
d62a17ae 7047 int idx_peer = 2;
f4b8ec07 7048 char base_xpath[XPATH_MAXLEN];
f4b8ec07
CS
7049
7050 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7051 sizeof(base_xpath), NULL)
7052 < 0)
7053 return CMD_WARNING_CONFIG_FAILED;
7054
555c8ab7
CS
7055 nb_cli_enqueue_change(vty, "./update-source/ip", NB_OP_DESTROY, NULL);
7056 nb_cli_enqueue_change(vty, "./update-source/interface", NB_OP_DESTROY,
7057 NULL);
f4b8ec07
CS
7058
7059 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7060}
6b0655a2 7061
d62a17ae 7062static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
7063 afi_t afi, safi_t safi,
7064 const char *rmap, int set)
718e3744 7065{
d62a17ae 7066 int ret;
7067 struct peer *peer;
80912664 7068 struct route_map *route_map = NULL;
718e3744 7069
d62a17ae 7070 peer = peer_and_group_lookup_vty(vty, peer_str);
7071 if (!peer)
7072 return CMD_WARNING_CONFIG_FAILED;
718e3744 7073
1de27621 7074 if (set) {
80912664
DS
7075 if (rmap)
7076 route_map = route_map_lookup_warn_noexist(vty, rmap);
1de27621
DA
7077 ret = peer_default_originate_set(peer, afi, safi,
7078 rmap, route_map);
7079 } else
d62a17ae 7080 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 7081
d62a17ae 7082 return bgp_vty_return(vty, ret);
718e3744 7083}
7084
7085/* neighbor default-originate. */
7086DEFUN (neighbor_default_originate,
7087 neighbor_default_originate_cmd,
9ccf14f7 7088 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 7089 NEIGHBOR_STR
7090 NEIGHBOR_ADDR_STR2
7091 "Originate default route to this neighbor\n")
7092{
d62a17ae 7093 int idx_peer = 1;
7094 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7095 bgp_node_afi(vty),
7096 bgp_node_safi(vty), NULL, 1);
718e3744 7097}
7098
d62a17ae 7099ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
7100 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
7101 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7102 "Originate default route to this neighbor\n")
596c17ba 7103
718e3744 7104DEFUN (neighbor_default_originate_rmap,
7105 neighbor_default_originate_rmap_cmd,
9ccf14f7 7106 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 7107 NEIGHBOR_STR
7108 NEIGHBOR_ADDR_STR2
7109 "Originate default route to this neighbor\n"
7110 "Route-map to specify criteria to originate default\n"
7111 "route-map name\n")
7112{
d62a17ae 7113 int idx_peer = 1;
7114 int idx_word = 4;
7115 return peer_default_originate_set_vty(
7116 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7117 argv[idx_word]->arg, 1);
718e3744 7118}
7119
d62a17ae 7120ALIAS_HIDDEN(
7121 neighbor_default_originate_rmap,
7122 neighbor_default_originate_rmap_hidden_cmd,
7123 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
7124 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7125 "Originate default route to this neighbor\n"
7126 "Route-map to specify criteria to originate default\n"
7127 "route-map name\n")
596c17ba 7128
718e3744 7129DEFUN (no_neighbor_default_originate,
7130 no_neighbor_default_originate_cmd,
a636c635 7131 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 7132 NO_STR
7133 NEIGHBOR_STR
7134 NEIGHBOR_ADDR_STR2
a636c635
DW
7135 "Originate default route to this neighbor\n"
7136 "Route-map to specify criteria to originate default\n"
7137 "route-map name\n")
718e3744 7138{
d62a17ae 7139 int idx_peer = 2;
7140 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7141 bgp_node_afi(vty),
7142 bgp_node_safi(vty), NULL, 0);
718e3744 7143}
7144
d62a17ae 7145ALIAS_HIDDEN(
7146 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
7147 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
7148 NO_STR NEIGHBOR_STR 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")
596c17ba 7152
6b0655a2 7153
f418446b 7154/* Set specified peer's BGP port. */
f4b8ec07
CS
7155DEFUN_YANG (neighbor_port,
7156 neighbor_port_cmd,
7157 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
7158 NEIGHBOR_STR
7159 NEIGHBOR_ADDR_STR
7160 "Neighbor's BGP port\n"
7161 "TCP port number\n")
718e3744 7162{
d62a17ae 7163 int idx_ip = 1;
7164 int idx_number = 3;
f4b8ec07 7165 char base_xpath[XPATH_MAXLEN];
718e3744 7166
f4b8ec07
CS
7167 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7168 argv[idx_ip]->arg, "");
718e3744 7169
f4b8ec07
CS
7170 nb_cli_enqueue_change(vty, "./local-port", NB_OP_MODIFY,
7171 argv[idx_number]->arg);
7172
7173 return nb_cli_apply_changes(vty, base_xpath);
7174}
6b0655a2 7175
f4b8ec07
CS
7176DEFUN_YANG (no_neighbor_port,
7177 no_neighbor_port_cmd,
7178 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
7179 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR
7180 "Neighbor's BGP port\n"
7181 "TCP port number\n")
718e3744 7182{
f4b8ec07
CS
7183 int idx_ip = 2;
7184 char base_xpath[XPATH_MAXLEN];
718e3744 7185
f4b8ec07
CS
7186 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7187 argv[idx_ip]->arg, "");
718e3744 7188
f4b8ec07 7189 nb_cli_enqueue_change(vty, "./local-port", NB_OP_DESTROY, NULL);
718e3744 7190
f4b8ec07 7191 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7192}
7193
f4b8ec07
CS
7194DEFUN_YANG (neighbor_weight,
7195 neighbor_weight_cmd,
7196 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7197 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7198 "Set default weight for routes from this neighbor\n"
7199 "default weight\n")
718e3744 7200{
f4b8ec07
CS
7201 int idx_peer = 1;
7202 int idx_number = 3;
7203 char base_xpath[XPATH_MAXLEN];
7204 char af_xpath[XPATH_MAXLEN];
7205 char attr_xpath[XPATH_MAXLEN];
7206 afi_t afi = bgp_node_afi(vty);
7207 safi_t safi = bgp_node_safi(vty);
718e3744 7208
f4b8ec07
CS
7209 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7210 yang_afi_safi_value2identity(afi, safi));
7211
7212 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7213 sizeof(base_xpath), af_xpath)
7214 < 0)
d62a17ae 7215 return CMD_WARNING_CONFIG_FAILED;
718e3744 7216
f4b8ec07
CS
7217 snprintf(attr_xpath, sizeof(attr_xpath), "./%s/weight/weight-attribute",
7218 bgp_afi_safi_get_container_str(afi, safi));
718e3744 7219
f4b8ec07
CS
7220 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY,
7221 argv[idx_number]->arg);
7222
7223 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7224}
7225
d62a17ae 7226ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
7227 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7228 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7229 "Set default weight for routes from this neighbor\n"
7230 "default weight\n")
596c17ba 7231
f4b8ec07
CS
7232DEFUN_YANG (no_neighbor_weight,
7233 no_neighbor_weight_cmd,
7234 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7235 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7236 "Set default weight for routes from this neighbor\n"
7237 "default weight\n")
718e3744 7238{
d62a17ae 7239 int idx_peer = 2;
f4b8ec07
CS
7240 char base_xpath[XPATH_MAXLEN];
7241 char af_xpath[XPATH_MAXLEN];
7242 char attr_xpath[XPATH_MAXLEN];
7243 afi_t afi = bgp_node_afi(vty);
7244 safi_t safi = bgp_node_safi(vty);
7245
7246 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7247 yang_afi_safi_value2identity(afi, safi));
7248
7249 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7250 sizeof(base_xpath), af_xpath)
7251 < 0)
7252 return CMD_WARNING_CONFIG_FAILED;
7253
7254 snprintf(attr_xpath, sizeof(attr_xpath), "./%s/weight/weight-attribute",
7255 bgp_afi_safi_get_container_str(afi, safi));
7256
7257 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_DESTROY, NULL);
7258
7259 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7260}
7261
d62a17ae 7262ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
7263 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7264 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7265 "Set default weight for routes from this neighbor\n"
7266 "default weight\n")
596c17ba 7267
6b0655a2 7268
718e3744 7269/* Override capability negotiation. */
8611c7f3
CS
7270DEFUN_YANG (neighbor_override_capability,
7271 neighbor_override_capability_cmd,
7272 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7273 NEIGHBOR_STR
7274 NEIGHBOR_ADDR_STR2
7275 "Override capability negotiation result\n")
718e3744 7276{
d62a17ae 7277 int idx_peer = 1;
8611c7f3
CS
7278 char base_xpath[XPATH_MAXLEN];
7279
7280 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7281 sizeof(base_xpath), NULL)
7282 < 0)
7283 return CMD_WARNING_CONFIG_FAILED;
7284
7285 nb_cli_enqueue_change(
7286 vty, "./capability-options/override-capability",
7287 NB_OP_MODIFY, "true");
7288
7289 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7290}
7291
8611c7f3
CS
7292DEFUN_YANG (no_neighbor_override_capability,
7293 no_neighbor_override_capability_cmd,
7294 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7295 NO_STR
7296 NEIGHBOR_STR
7297 NEIGHBOR_ADDR_STR2
7298 "Override capability negotiation result\n")
718e3744 7299{
d62a17ae 7300 int idx_peer = 2;
8611c7f3
CS
7301 char base_xpath[XPATH_MAXLEN];
7302
7303 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7304 sizeof(base_xpath), NULL)
7305 < 0)
7306 return CMD_WARNING_CONFIG_FAILED;
7307
7308 nb_cli_enqueue_change(
7309 vty, "./capability-options/override-capability",
7310 NB_OP_MODIFY, "false");
7311
7312 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7313}
6b0655a2 7314
8611c7f3
CS
7315DEFUN_YANG (neighbor_strict_capability,
7316 neighbor_strict_capability_cmd,
7317 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7318 NEIGHBOR_STR
7319 NEIGHBOR_ADDR_STR2
7320 "Strict capability negotiation match\n")
718e3744 7321{
9fb964de 7322 int idx_peer = 1;
8611c7f3 7323 char base_xpath[XPATH_MAXLEN];
9fb964de 7324
8611c7f3
CS
7325 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7326 sizeof(base_xpath), NULL)
7327 < 0)
7328 return CMD_WARNING_CONFIG_FAILED;
7329
7330 nb_cli_enqueue_change(
7331 vty, "./capability-options/strict-capability",
7332 NB_OP_MODIFY, "true");
7333
7334 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7335}
7336
8611c7f3
CS
7337DEFUN_YANG (no_neighbor_strict_capability,
7338 no_neighbor_strict_capability_cmd,
7339 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7340 NO_STR
7341 NEIGHBOR_STR
7342 NEIGHBOR_ADDR_STR2
7343 "Strict capability negotiation match\n")
718e3744 7344{
9fb964de 7345 int idx_peer = 2;
8611c7f3 7346 char base_xpath[XPATH_MAXLEN];
9fb964de 7347
8611c7f3
CS
7348 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7349 sizeof(base_xpath), NULL)
7350 < 0)
7351 return CMD_WARNING_CONFIG_FAILED;
7352
7353 nb_cli_enqueue_change(
7354 vty, "./capability-options/strict-capability",
7355 NB_OP_MODIFY, "false");
7356
7357 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7358}
6b0655a2 7359
f4b8ec07
CS
7360DEFUN_YANG (neighbor_timers,
7361 neighbor_timers_cmd,
7362 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
7363 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7364 "BGP per neighbor timers\n"
7365 "Keepalive interval\n"
7366 "Holdtime\n")
718e3744 7367{
f4b8ec07
CS
7368 int idx_peer = 1;
7369 int idx_number = 3;
7370 int idx_number_2 = 4;
7371 char base_xpath[XPATH_MAXLEN];
718e3744 7372
f4b8ec07
CS
7373 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7374 sizeof(base_xpath), NULL)
7375 < 0)
d62a17ae 7376 return CMD_WARNING_CONFIG_FAILED;
718e3744 7377
f4b8ec07
CS
7378 nb_cli_enqueue_change(vty, "./timers/keepalive", NB_OP_MODIFY,
7379 argv[idx_number]->arg);
718e3744 7380
f4b8ec07
CS
7381 nb_cli_enqueue_change(vty, "./timers/hold-time", NB_OP_MODIFY,
7382 argv[idx_number_2]->arg);
718e3744 7383
f4b8ec07 7384 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7385}
6b0655a2 7386
f4b8ec07
CS
7387DEFUN_YANG (no_neighbor_timers,
7388 no_neighbor_timers_cmd,
7389 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
7390 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7391 "BGP per neighbor timers\n"
7392 "Keepalive interval\n"
7393 "Holdtime\n")
718e3744 7394{
f4b8ec07
CS
7395 int idx_peer = 2;
7396 char base_xpath[XPATH_MAXLEN];
718e3744 7397
f4b8ec07
CS
7398 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7399 sizeof(base_xpath), NULL)
7400 < 0)
d62a17ae 7401 return CMD_WARNING_CONFIG_FAILED;
718e3744 7402
f4b8ec07 7403 nb_cli_enqueue_change(vty, "./timers/hold-time", NB_OP_DESTROY, NULL);
718e3744 7404
f4b8ec07 7405 nb_cli_enqueue_change(vty, "./timers/keepalive", NB_OP_DESTROY, NULL);
718e3744 7406
f4b8ec07 7407 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7408}
6b0655a2 7409
f4b8ec07
CS
7410DEFUN_YANG (neighbor_timers_connect,
7411 neighbor_timers_connect_cmd,
7412 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7413 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7414 "BGP per neighbor timers\n"
7415 "BGP connect timer\n"
7416 "Connect timer\n")
718e3744 7417{
f4b8ec07
CS
7418 int idx_peer = 1;
7419 int idx_number = 4;
7420 char base_xpath[XPATH_MAXLEN];
718e3744 7421
f4b8ec07
CS
7422 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7423 sizeof(base_xpath), NULL)
7424 < 0)
d62a17ae 7425 return CMD_WARNING_CONFIG_FAILED;
718e3744 7426
f4b8ec07
CS
7427 nb_cli_enqueue_change(vty, "./timers/connect-time", NB_OP_MODIFY,
7428 argv[idx_number]->arg);
718e3744 7429
f4b8ec07 7430 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7431}
7432
f4b8ec07
CS
7433DEFUN_YANG (no_neighbor_timers_connect,
7434 no_neighbor_timers_connect_cmd,
7435 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7436 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7437 "BGP per neighbor timers\n"
7438 "BGP connect timer\n"
7439 "Connect timer\n")
718e3744 7440{
f4b8ec07
CS
7441 int idx_peer = 2;
7442 char base_xpath[XPATH_MAXLEN];
718e3744 7443
f4b8ec07
CS
7444 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7445 sizeof(base_xpath), NULL)
7446 < 0)
d62a17ae 7447 return CMD_WARNING_CONFIG_FAILED;
718e3744 7448
f4b8ec07
CS
7449 nb_cli_enqueue_change(vty, "./timers/connect-time", NB_OP_DESTROY,
7450 NULL);
718e3744 7451
f4b8ec07 7452 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7453}
7454
d43114f3
DS
7455DEFPY (neighbor_timers_delayopen,
7456 neighbor_timers_delayopen_cmd,
7457 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
7458 NEIGHBOR_STR
7459 NEIGHBOR_ADDR_STR2
7460 "BGP per neighbor timers\n"
7461 "RFC 4271 DelayOpenTimer\n"
7462 "DelayOpenTime timer interval\n")
7463{
7464 struct peer *peer;
7465
7466 peer = peer_and_group_lookup_vty(vty, neighbor);
7467 if (!peer)
7468 return CMD_WARNING_CONFIG_FAILED;
7469
7470 if (!interval) {
7471 if (peer_timers_delayopen_unset(peer))
7472 return CMD_WARNING_CONFIG_FAILED;
7473 } else {
7474 if (peer_timers_delayopen_set(peer, interval))
7475 return CMD_WARNING_CONFIG_FAILED;
7476 }
7477
7478 return CMD_SUCCESS;
7479}
7480
7481DEFPY (no_neighbor_timers_delayopen,
7482 no_neighbor_timers_delayopen_cmd,
7483 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7484 NO_STR
7485 NEIGHBOR_STR
7486 NEIGHBOR_ADDR_STR2
7487 "BGP per neighbor timers\n"
7488 "RFC 4271 DelayOpenTimer\n"
7489 "DelayOpenTime timer interval\n")
7490{
7491 struct peer *peer;
7492
7493 peer = peer_and_group_lookup_vty(vty, neighbor);
7494 if (!peer)
7495 return CMD_WARNING_CONFIG_FAILED;
7496
7497 if (peer_timers_delayopen_unset(peer))
7498 return CMD_WARNING_CONFIG_FAILED;
7499
7500 return CMD_SUCCESS;
7501}
7502
f4b8ec07
CS
7503DEFUN_YANG (neighbor_advertise_interval,
7504 neighbor_advertise_interval_cmd,
7505 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7506 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7507 "Minimum interval between sending BGP routing updates\n"
7508 "time in seconds\n")
718e3744 7509{
d62a17ae 7510 int idx_peer = 1;
f4b8ec07
CS
7511 int idx_number = 3;
7512 char base_xpath[XPATH_MAXLEN];
718e3744 7513
f4b8ec07
CS
7514 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7515 sizeof(base_xpath), NULL)
7516 < 0)
d62a17ae 7517 return CMD_WARNING_CONFIG_FAILED;
718e3744 7518
f4b8ec07
CS
7519 nb_cli_enqueue_change(vty, "./timers/advertise-interval", NB_OP_MODIFY,
7520 argv[idx_number]->arg);
718e3744 7521
f4b8ec07 7522 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7523}
7524
f4b8ec07
CS
7525DEFUN_YANG (no_neighbor_advertise_interval,
7526 no_neighbor_advertise_interval_cmd,
7527 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7528 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7529 "Minimum interval between sending BGP routing updates\n"
7530 "time in seconds\n")
718e3744 7531{
d62a17ae 7532 int idx_peer = 2;
f4b8ec07
CS
7533 char base_xpath[XPATH_MAXLEN];
7534
7535 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7536 sizeof(base_xpath), NULL)
7537 < 0)
7538 return CMD_WARNING_CONFIG_FAILED;
7539
7540 nb_cli_enqueue_change(vty, "./timers/advertise-interval", NB_OP_DESTROY,
7541 NULL);
7542
7543 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7544}
7545
6b0655a2 7546
518f0eb1
DS
7547/* Time to wait before processing route-map updates */
7548DEFUN (bgp_set_route_map_delay_timer,
7549 bgp_set_route_map_delay_timer_cmd,
6147e2c6 7550 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
7551 SET_STR
7552 "BGP route-map delay timer\n"
7553 "Time in secs to wait before processing route-map changes\n"
f414725f 7554 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 7555{
d62a17ae 7556 int idx_number = 3;
d7c0a89a 7557 uint32_t rmap_delay_timer;
d62a17ae 7558
7559 if (argv[idx_number]->arg) {
7560 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7561 bm->rmap_update_timer = rmap_delay_timer;
7562
7563 /* if the dynamic update handling is being disabled, and a timer
7564 * is
7565 * running, stop the timer and act as if the timer has already
7566 * fired.
7567 */
7568 if (!rmap_delay_timer && bm->t_rmap_update) {
7569 BGP_TIMER_OFF(bm->t_rmap_update);
7570 thread_execute(bm->master, bgp_route_map_update_timer,
7571 NULL, 0);
7572 }
7573 return CMD_SUCCESS;
7574 } else {
7575 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7576 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 7577 }
518f0eb1
DS
7578}
7579
7580DEFUN (no_bgp_set_route_map_delay_timer,
7581 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 7582 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 7583 NO_STR
3a2d747c 7584 BGP_STR
518f0eb1 7585 "Default BGP route-map delay timer\n"
8334fd5a
DW
7586 "Reset to default time to wait for processing route-map changes\n"
7587 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 7588{
518f0eb1 7589
d62a17ae 7590 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 7591
d62a17ae 7592 return CMD_SUCCESS;
518f0eb1
DS
7593}
7594
f4b8ec07
CS
7595DEFUN_YANG (neighbor_interface,
7596 neighbor_interface_cmd,
7597 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7598 NEIGHBOR_STR NEIGHBOR_ADDR_STR
7599 "Interface\n"
7600 "Interface name\n")
718e3744 7601{
f4b8ec07
CS
7602 int idx_ip = 1;
7603 int idx_word = 3;
7604 char base_xpath[XPATH_MAXLEN];
718e3744 7605
f4b8ec07
CS
7606 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7607 argv[idx_ip]->arg, "");
718e3744 7608
f4b8ec07
CS
7609 nb_cli_enqueue_change(vty, "./local-interface", NB_OP_MODIFY,
7610 argv[idx_word]->arg);
718e3744 7611
f4b8ec07 7612 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7613}
7614
f4b8ec07
CS
7615DEFUN_YANG (no_neighbor_interface,
7616 no_neighbor_interface_cmd,
7617 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
7618 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7619 "Interface\n"
7620 "Interface name\n")
718e3744 7621{
d62a17ae 7622 int idx_peer = 2;
f4b8ec07
CS
7623 char base_xpath[XPATH_MAXLEN];
7624
7625 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7626 argv[idx_peer]->arg, "");
7627
7628 nb_cli_enqueue_change(vty, "./local-interface", NB_OP_DESTROY, NULL);
7629
7630 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7631}
6b0655a2 7632
718e3744 7633DEFUN (neighbor_distribute_list,
7634 neighbor_distribute_list_cmd,
9ccf14f7 7635 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 7636 NEIGHBOR_STR
7637 NEIGHBOR_ADDR_STR2
7638 "Filter updates to/from this neighbor\n"
7639 "IP access-list number\n"
7640 "IP access-list number (expanded range)\n"
7641 "IP Access-list name\n"
7642 "Filter incoming updates\n"
7643 "Filter outgoing updates\n")
7644{
d62a17ae 7645 int idx_peer = 1;
7646 int idx_acl = 3;
7647 int direct, ret;
7648 struct peer *peer;
a8206004 7649
d62a17ae 7650 const char *pstr = argv[idx_peer]->arg;
7651 const char *acl = argv[idx_acl]->arg;
7652 const char *inout = argv[argc - 1]->text;
a8206004 7653
d62a17ae 7654 peer = peer_and_group_lookup_vty(vty, pstr);
7655 if (!peer)
7656 return CMD_WARNING_CONFIG_FAILED;
a8206004 7657
d62a17ae 7658 /* Check filter direction. */
7659 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7660 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7661 direct, acl);
a8206004 7662
d62a17ae 7663 return bgp_vty_return(vty, ret);
718e3744 7664}
7665
d62a17ae 7666ALIAS_HIDDEN(
7667 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
7668 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7669 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7670 "Filter updates to/from this neighbor\n"
7671 "IP access-list number\n"
7672 "IP access-list number (expanded range)\n"
7673 "IP Access-list name\n"
7674 "Filter incoming updates\n"
7675 "Filter outgoing updates\n")
596c17ba 7676
718e3744 7677DEFUN (no_neighbor_distribute_list,
7678 no_neighbor_distribute_list_cmd,
9ccf14f7 7679 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 7680 NO_STR
7681 NEIGHBOR_STR
7682 NEIGHBOR_ADDR_STR2
7683 "Filter updates to/from this neighbor\n"
7684 "IP access-list number\n"
7685 "IP access-list number (expanded range)\n"
7686 "IP Access-list name\n"
7687 "Filter incoming updates\n"
7688 "Filter outgoing updates\n")
7689{
d62a17ae 7690 int idx_peer = 2;
7691 int direct, ret;
7692 struct peer *peer;
a8206004 7693
d62a17ae 7694 const char *pstr = argv[idx_peer]->arg;
7695 const char *inout = argv[argc - 1]->text;
a8206004 7696
d62a17ae 7697 peer = peer_and_group_lookup_vty(vty, pstr);
7698 if (!peer)
7699 return CMD_WARNING_CONFIG_FAILED;
a8206004 7700
d62a17ae 7701 /* Check filter direction. */
7702 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7703 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7704 direct);
a8206004 7705
d62a17ae 7706 return bgp_vty_return(vty, ret);
718e3744 7707}
6b0655a2 7708
d62a17ae 7709ALIAS_HIDDEN(
7710 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
7711 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7712 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7713 "Filter updates to/from this neighbor\n"
7714 "IP access-list number\n"
7715 "IP access-list number (expanded range)\n"
7716 "IP Access-list name\n"
7717 "Filter incoming updates\n"
7718 "Filter outgoing updates\n")
596c17ba 7719
718e3744 7720/* Set prefix list to the peer. */
d9986d26
CS
7721DEFPY_YANG(
7722 neighbor_prefix_list, neighbor_prefix_list_cmd,
7723 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor_str prefix-list WORD$prefix_str <in|out>$direction",
7724 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7725 "Filter updates to/from this neighbor\n"
7726 "Name of a prefix list\n"
7727 "Filter incoming updates\n"
7728 "Filter outgoing updates\n")
718e3744 7729{
d9986d26
CS
7730 char base_xpath[XPATH_MAXLEN];
7731 char af_xpath[XPATH_MAXLEN];
c6685575 7732 char plist_xpath[XPATH_MAXLEN];
d9986d26
CS
7733 afi_t afi = bgp_node_afi(vty);
7734 safi_t safi = bgp_node_safi(vty);
718e3744 7735
d9986d26
CS
7736 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7737 yang_afi_safi_value2identity(afi, safi));
7738 if (peer_and_group_lookup_nb(vty, neighbor_str, base_xpath,
7739 sizeof(base_xpath), af_xpath)
7740 < 0)
d62a17ae 7741 return CMD_WARNING_CONFIG_FAILED;
e52702f2 7742
d9986d26
CS
7743 if (strmatch(direction, "in"))
7744 snprintf(plist_xpath, sizeof(plist_xpath),
7745 "./%s/filter-config/plist-import",
7746 bgp_afi_safi_get_container_str(afi, safi));
7747 else if (strmatch(direction, "out"))
7748 snprintf(plist_xpath, sizeof(plist_xpath),
7749 "./%s/filter-config/plist-export",
7750 bgp_afi_safi_get_container_str(afi, safi));
718e3744 7751
d9986d26
CS
7752 if (!no)
7753 nb_cli_enqueue_change(vty, plist_xpath, NB_OP_MODIFY,
7754 prefix_str);
7755 else
7756 nb_cli_enqueue_change(vty, plist_xpath, NB_OP_DESTROY, NULL);
718e3744 7757
d9986d26 7758 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7759}
7760
d62a17ae 7761ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7762 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7763 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7764 "Filter updates to/from this neighbor\n"
7765 "Name of a prefix list\n"
7766 "Filter incoming updates\n"
7767 "Filter outgoing updates\n")
596c17ba 7768
d62a17ae 7769static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7770 safi_t safi, const char *name_str,
7771 const char *direct_str)
718e3744 7772{
d62a17ae 7773 int ret;
7774 struct peer *peer;
7775 int direct = FILTER_IN;
718e3744 7776
d62a17ae 7777 peer = peer_and_group_lookup_vty(vty, ip_str);
7778 if (!peer)
7779 return CMD_WARNING_CONFIG_FAILED;
718e3744 7780
d62a17ae 7781 /* Check filter direction. */
7782 if (strncmp(direct_str, "i", 1) == 0)
7783 direct = FILTER_IN;
7784 else if (strncmp(direct_str, "o", 1) == 0)
7785 direct = FILTER_OUT;
718e3744 7786
d62a17ae 7787 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 7788
d62a17ae 7789 return bgp_vty_return(vty, ret);
718e3744 7790}
7791
d62a17ae 7792static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7793 safi_t safi, const char *direct_str)
718e3744 7794{
d62a17ae 7795 int ret;
7796 struct peer *peer;
7797 int direct = FILTER_IN;
718e3744 7798
d62a17ae 7799 peer = peer_and_group_lookup_vty(vty, ip_str);
7800 if (!peer)
7801 return CMD_WARNING_CONFIG_FAILED;
718e3744 7802
d62a17ae 7803 /* Check filter direction. */
7804 if (strncmp(direct_str, "i", 1) == 0)
7805 direct = FILTER_IN;
7806 else if (strncmp(direct_str, "o", 1) == 0)
7807 direct = FILTER_OUT;
718e3744 7808
d62a17ae 7809 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 7810
d62a17ae 7811 return bgp_vty_return(vty, ret);
718e3744 7812}
7813
7814DEFUN (neighbor_filter_list,
7815 neighbor_filter_list_cmd,
9ccf14f7 7816 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 7817 NEIGHBOR_STR
7818 NEIGHBOR_ADDR_STR2
7819 "Establish BGP filters\n"
7820 "AS path access-list name\n"
7821 "Filter incoming routes\n"
7822 "Filter outgoing routes\n")
7823{
d62a17ae 7824 int idx_peer = 1;
7825 int idx_word = 3;
7826 int idx_in_out = 4;
7827 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7828 bgp_node_safi(vty), argv[idx_word]->arg,
7829 argv[idx_in_out]->arg);
718e3744 7830}
7831
d62a17ae 7832ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
7833 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7834 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7835 "Establish BGP filters\n"
7836 "AS path access-list name\n"
7837 "Filter incoming routes\n"
7838 "Filter outgoing routes\n")
596c17ba 7839
718e3744 7840DEFUN (no_neighbor_filter_list,
7841 no_neighbor_filter_list_cmd,
9ccf14f7 7842 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 7843 NO_STR
7844 NEIGHBOR_STR
7845 NEIGHBOR_ADDR_STR2
7846 "Establish BGP filters\n"
7847 "AS path access-list name\n"
7848 "Filter incoming routes\n"
7849 "Filter outgoing routes\n")
7850{
d62a17ae 7851 int idx_peer = 2;
7852 int idx_in_out = 5;
7853 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7854 bgp_node_afi(vty), bgp_node_safi(vty),
7855 argv[idx_in_out]->arg);
718e3744 7856}
6b0655a2 7857
d62a17ae 7858ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
7859 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7860 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7861 "Establish BGP filters\n"
7862 "AS path access-list name\n"
7863 "Filter incoming routes\n"
7864 "Filter outgoing routes\n")
596c17ba 7865
7f7940e6
MK
7866/* Set advertise-map to the peer. */
7867static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7868 afi_t afi, safi_t safi,
cf2ad4d8
MK
7869 const char *advertise_str,
7870 const char *condition_str, bool condition,
7871 bool set)
7f7940e6
MK
7872{
7873 int ret = CMD_WARNING_CONFIG_FAILED;
7874 struct peer *peer;
7875 struct route_map *advertise_map;
7876 struct route_map *condition_map;
7877
7878 peer = peer_and_group_lookup_vty(vty, ip_str);
7879 if (!peer)
7880 return ret;
7881
7882 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7883 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7884
cf2ad4d8
MK
7885 if (set)
7886 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7887 advertise_map, condition_str,
7888 condition_map, condition);
7889 else
7890 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7891 advertise_map, condition_str,
7892 condition_map, condition);
7f7940e6
MK
7893
7894 return bgp_vty_return(vty, ret);
7895}
7896
cf2ad4d8 7897DEFPY (neighbor_advertise_map,
7f7940e6 7898 neighbor_advertise_map_cmd,
52b84062 7899 "[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 7900 NO_STR
7f7940e6
MK
7901 NEIGHBOR_STR
7902 NEIGHBOR_ADDR_STR2
7903 "Route-map to conditionally advertise routes\n"
7904 "Name of advertise map\n"
7905 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 7906 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 7907 "Name of the exist or non exist map\n")
7f7940e6 7908{
7f7940e6
MK
7909 bool condition = CONDITION_EXIST;
7910
52b84062 7911 if (!strcmp(exist, "non-exist-map"))
7f7940e6
MK
7912 condition = CONDITION_NON_EXIST;
7913
52b84062
MK
7914 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7915 bgp_node_safi(vty), advertise_str,
7916 condition_str, condition, !no);
7f7940e6
MK
7917}
7918
7919ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
52b84062 7920 "[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
7921 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7922 "Route-map to conditionally advertise routes\n"
7923 "Name of advertise map\n"
7924 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 7925 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 7926 "Name of the exist or non exist map\n")
7f7940e6 7927
718e3744 7928/* Set route-map to the peer. */
c6685575
CS
7929DEFPY_YANG(
7930 neighbor_route_map, neighbor_route_map_cmd,
7931 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor_str route-map WORD$rmap_str <in|out>$direction",
7932 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7933 "Apply route map to neighbor\n"
7934 "Name of route map\n"
7935 "Apply map to incoming routes\n"
7936 "Apply map to outbound routes\n")
718e3744 7937{
c6685575
CS
7938 char base_xpath[XPATH_MAXLEN];
7939 char af_xpath[XPATH_MAXLEN];
7940 char rmap_xpath[XPATH_MAXLEN];
7941 afi_t afi = bgp_node_afi(vty);
7942 safi_t safi = bgp_node_safi(vty);
718e3744 7943
c6685575
CS
7944 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7945 yang_afi_safi_value2identity(afi, safi));
7946 if (peer_and_group_lookup_nb(vty, neighbor_str, base_xpath,
7947 sizeof(base_xpath), af_xpath)
7948 < 0)
d62a17ae 7949 return CMD_WARNING_CONFIG_FAILED;
718e3744 7950
c6685575
CS
7951 if (strmatch(direction, "in"))
7952 snprintf(rmap_xpath, sizeof(rmap_xpath),
7953 "./%s/filter-config/rmap-import",
7954 bgp_afi_safi_get_container_str(afi, safi));
7955 else if (strmatch(direction, "out"))
7956 snprintf(rmap_xpath, sizeof(rmap_xpath),
7957 "./%s/filter-config/rmap-export",
7958 bgp_afi_safi_get_container_str(afi, safi));
718e3744 7959
c6685575
CS
7960 if (!no) {
7961 if (!yang_dnode_exists(
7962 vty->candidate_config->dnode,
7963 "/frr-route-map:lib/route-map[name='%s']",
7964 rmap_str)) {
7965 if (vty_shell_serv(vty))
7966 vty_out(vty,
7967 "The route-map '%s' does not exist.\n",
7968 rmap_str);
7969 }
7970 nb_cli_enqueue_change(vty, rmap_xpath, NB_OP_MODIFY, rmap_str);
7971 } else
7972 nb_cli_enqueue_change(vty, rmap_xpath, NB_OP_DESTROY, NULL);
718e3744 7973
c6685575 7974 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7975}
7976
718e3744 7977/* Set unsuppress-map to the peer. */
d62a17ae 7978static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
7979 afi_t afi, safi_t safi,
7980 const char *name_str)
718e3744 7981{
d62a17ae 7982 int ret;
7983 struct peer *peer;
1de27621 7984 struct route_map *route_map;
718e3744 7985
d62a17ae 7986 peer = peer_and_group_lookup_vty(vty, ip_str);
7987 if (!peer)
7988 return CMD_WARNING_CONFIG_FAILED;
718e3744 7989
1de27621
DA
7990 route_map = route_map_lookup_warn_noexist(vty, name_str);
7991 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
718e3744 7992
d62a17ae 7993 return bgp_vty_return(vty, ret);
718e3744 7994}
7995
7996/* Unset route-map from the peer. */
d62a17ae 7997static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
7998 afi_t afi, safi_t safi)
718e3744 7999{
d62a17ae 8000 int ret;
8001 struct peer *peer;
718e3744 8002
d62a17ae 8003 peer = peer_and_group_lookup_vty(vty, ip_str);
8004 if (!peer)
8005 return CMD_WARNING_CONFIG_FAILED;
718e3744 8006
d62a17ae 8007 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 8008
d62a17ae 8009 return bgp_vty_return(vty, ret);
718e3744 8010}
8011
8012DEFUN (neighbor_unsuppress_map,
8013 neighbor_unsuppress_map_cmd,
9ccf14f7 8014 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 8015 NEIGHBOR_STR
8016 NEIGHBOR_ADDR_STR2
8017 "Route-map to selectively unsuppress suppressed routes\n"
8018 "Name of route map\n")
8019{
d62a17ae 8020 int idx_peer = 1;
8021 int idx_word = 3;
8022 return peer_unsuppress_map_set_vty(
8023 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8024 argv[idx_word]->arg);
718e3744 8025}
8026
d62a17ae 8027ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
8028 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8029 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8030 "Route-map to selectively unsuppress suppressed routes\n"
8031 "Name of route map\n")
596c17ba 8032
718e3744 8033DEFUN (no_neighbor_unsuppress_map,
8034 no_neighbor_unsuppress_map_cmd,
9ccf14f7 8035 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 8036 NO_STR
8037 NEIGHBOR_STR
8038 NEIGHBOR_ADDR_STR2
8039 "Route-map to selectively unsuppress suppressed routes\n"
8040 "Name of route map\n")
8041{
d62a17ae 8042 int idx_peer = 2;
8043 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
8044 bgp_node_afi(vty),
8045 bgp_node_safi(vty));
718e3744 8046}
6b0655a2 8047
d62a17ae 8048ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
8049 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8050 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8051 "Route-map to selectively unsuppress suppressed routes\n"
8052 "Name of route map\n")
596c17ba 8053
fde246e8 8054/* Maximum number of prefix to be sent to the neighbor. */
232c75cd
CS
8055DEFUN_YANG(neighbor_maximum_prefix_out,
8056 neighbor_maximum_prefix_out_cmd,
8057 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
8058 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8059 "Maximum number of prefixes to be sent to this peer\n"
8060 "Maximum no. of prefix limit\n")
fde246e8 8061{
04261dec
CS
8062 char base_xpath[XPATH_MAXLEN];
8063 char af_xpath[XPATH_MAXLEN];
8064 char attr_xpath[XPATH_MAXLEN];
fde246e8
DA
8065 int idx_peer = 1;
8066 int idx_number = 3;
fde246e8
DA
8067 afi_t afi = bgp_node_afi(vty);
8068 safi_t safi = bgp_node_safi(vty);
8069
04261dec
CS
8070 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8071 yang_afi_safi_value2identity(afi, safi));
8072 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8073 sizeof(base_xpath), af_xpath)
8074 < 0)
fde246e8
DA
8075 return CMD_WARNING_CONFIG_FAILED;
8076
04261dec
CS
8077 snprintf(attr_xpath, sizeof(attr_xpath),
8078 "/%s/prefix-limit/direction-list[direction='out']",
8079 bgp_afi_safi_get_container_str(afi, safi));
8080 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
fde246e8 8081
04261dec 8082 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
fde246e8 8083
04261dec
CS
8084 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8085 argv[idx_number]->arg);
8086
8087 return nb_cli_apply_changes(vty, base_xpath);
fde246e8
DA
8088}
8089
232c75cd
CS
8090DEFUN_YANG(no_neighbor_maximum_prefix_out,
8091 no_neighbor_maximum_prefix_out_cmd,
8092 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out",
8093 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8094 "Maximum number of prefixes to be sent to this peer\n")
fde246e8 8095{
04261dec
CS
8096 char base_xpath[XPATH_MAXLEN];
8097 char af_xpath[XPATH_MAXLEN];
8098 char attr_xpath[XPATH_MAXLEN];
fde246e8 8099 int idx_peer = 2;
fde246e8
DA
8100 afi_t afi = bgp_node_afi(vty);
8101 safi_t safi = bgp_node_safi(vty);
8102
04261dec
CS
8103 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8104 yang_afi_safi_value2identity(afi, safi));
8105 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8106 sizeof(base_xpath), af_xpath)
8107 < 0)
fde246e8
DA
8108 return CMD_WARNING_CONFIG_FAILED;
8109
04261dec
CS
8110 snprintf(attr_xpath, sizeof(attr_xpath),
8111 "/%s/prefix-limit/direction-list[direction='out']",
8112 bgp_afi_safi_get_container_str(afi, safi));
8113 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8114
8115 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
fde246e8 8116
04261dec 8117 return nb_cli_apply_changes(vty, base_xpath);
fde246e8
DA
8118}
8119
9cbd06e0
DA
8120/* Maximum number of prefix configuration. Prefix count is different
8121 for each peer configuration. So this configuration can be set for
718e3744 8122 each peer configuration. */
232c75cd
CS
8123DEFUN_YANG(neighbor_maximum_prefix,
8124 neighbor_maximum_prefix_cmd,
8125 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8126 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8127 "Maximum number of prefix accept from this peer\n"
8128 "maximum no. of prefix limit\n"
8129 "Force checking all received routes not only accepted\n")
718e3744 8130{
d62a17ae 8131 int idx_peer = 1;
8132 int idx_number = 3;
9cbd06e0 8133 int idx_force = 0;
04261dec
CS
8134 char base_xpath[XPATH_MAXLEN];
8135 char af_xpath[XPATH_MAXLEN];
8136 char attr_xpath[XPATH_MAXLEN];
8137 afi_t afi = bgp_node_afi(vty);
8138 safi_t safi = bgp_node_safi(vty);
8139
8140 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8141 yang_afi_safi_value2identity(afi, safi));
8142 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8143 sizeof(base_xpath), af_xpath)
8144 < 0)
8145 return CMD_WARNING_CONFIG_FAILED;
8146
8147 snprintf(attr_xpath, sizeof(attr_xpath),
8148 "/%s/prefix-limit/direction-list[direction='in']",
8149 bgp_afi_safi_get_container_str(afi, safi));
8150 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8151
8152 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
9cbd06e0 8153
04261dec
CS
8154 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8155 argv[idx_number]->arg);
9cbd06e0 8156 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8157 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8158 "true");
9cbd06e0 8159
04261dec 8160 return nb_cli_apply_changes(vty, base_xpath);
718e3744 8161}
8162
d62a17ae 8163ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 8164 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
d62a17ae 8165 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8166 "Maximum number of prefix accept from this peer\n"
9cbd06e0
DA
8167 "maximum no. of prefix limit\n"
8168 "Force checking all received routes not only accepted\n")
596c17ba 8169
232c75cd
CS
8170DEFUN_YANG(neighbor_maximum_prefix_threshold,
8171 neighbor_maximum_prefix_threshold_cmd,
8172 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8173 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8174 "Maximum number of prefix accept from this peer\n"
8175 "maximum no. of prefix limit\n"
8176 "Threshold value (%) at which to generate a warning msg\n"
8177 "Force checking all received routes not only accepted\n")
e0701b79 8178{
d62a17ae 8179 int idx_peer = 1;
8180 int idx_number = 3;
8181 int idx_number_2 = 4;
9cbd06e0 8182 int idx_force = 0;
04261dec
CS
8183 char base_xpath[XPATH_MAXLEN];
8184 char af_xpath[XPATH_MAXLEN];
8185 char attr_xpath[XPATH_MAXLEN];
8186 afi_t afi = bgp_node_afi(vty);
8187 safi_t safi = bgp_node_safi(vty);
8188
8189 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8190 yang_afi_safi_value2identity(afi, safi));
8191 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8192 sizeof(base_xpath), af_xpath)
8193 < 0)
8194 return CMD_WARNING_CONFIG_FAILED;
8195
8196 snprintf(attr_xpath, sizeof(attr_xpath),
8197 "/%s/prefix-limit/direction-list[direction='in']",
8198 bgp_afi_safi_get_container_str(afi, safi));
8199 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8200
8201 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8202
8203 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8204 argv[idx_number]->arg);
8205
8206 nb_cli_enqueue_change(vty, "./options/shutdown-threshold-pct",
8207 NB_OP_MODIFY, argv[idx_number_2]->arg);
9cbd06e0
DA
8208
8209 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8210 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8211 "true");
9cbd06e0 8212
04261dec 8213 return nb_cli_apply_changes(vty, base_xpath);
0a486e5f 8214}
e0701b79 8215
d62a17ae 8216ALIAS_HIDDEN(
8217 neighbor_maximum_prefix_threshold,
8218 neighbor_maximum_prefix_threshold_hidden_cmd,
9cbd06e0 8219 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
d62a17ae 8220 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8221 "Maximum number of prefix accept from this peer\n"
8222 "maximum no. of prefix limit\n"
9cbd06e0
DA
8223 "Threshold value (%) at which to generate a warning msg\n"
8224 "Force checking all received routes not only accepted\n")
596c17ba 8225
232c75cd
CS
8226DEFUN_YANG(neighbor_maximum_prefix_warning,
8227 neighbor_maximum_prefix_warning_cmd,
8228 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [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 "Only give warning message when limit is exceeded\n"
8233 "Force checking all received routes not only accepted\n")
718e3744 8234{
d62a17ae 8235 int idx_peer = 1;
8236 int idx_number = 3;
9cbd06e0 8237 int idx_force = 0;
04261dec
CS
8238 char base_xpath[XPATH_MAXLEN];
8239 char af_xpath[XPATH_MAXLEN];
8240 char attr_xpath[XPATH_MAXLEN];
8241 afi_t afi = bgp_node_afi(vty);
8242 safi_t safi = bgp_node_safi(vty);
8243
8244 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8245 yang_afi_safi_value2identity(afi, safi));
8246 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8247 sizeof(base_xpath), af_xpath)
8248 < 0)
8249 return CMD_WARNING_CONFIG_FAILED;
9cbd06e0 8250
04261dec
CS
8251 snprintf(attr_xpath, sizeof(attr_xpath),
8252 "/%s/prefix-limit/direction-list[direction='in']",
8253 bgp_afi_safi_get_container_str(afi, safi));
8254 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8255
8256 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8257
8258 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8259 argv[idx_number]->arg);
8260
8261 nb_cli_enqueue_change(vty, "./options/warning-only", NB_OP_MODIFY,
8262 "true");
9cbd06e0 8263 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8264 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8265 "true");
9cbd06e0 8266
04261dec 8267 return nb_cli_apply_changes(vty, base_xpath);
718e3744 8268}
8269
d62a17ae 8270ALIAS_HIDDEN(
8271 neighbor_maximum_prefix_warning,
8272 neighbor_maximum_prefix_warning_hidden_cmd,
9cbd06e0 8273 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
d62a17ae 8274 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8275 "Maximum number of prefix accept from this peer\n"
8276 "maximum no. of prefix limit\n"
9cbd06e0
DA
8277 "Only give warning message when limit is exceeded\n"
8278 "Force checking all received routes not only accepted\n")
596c17ba 8279
232c75cd
CS
8280DEFUN_YANG(neighbor_maximum_prefix_threshold_warning,
8281 neighbor_maximum_prefix_threshold_warning_cmd,
8282 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8283 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8284 "Maximum number of prefix accept from this peer\n"
8285 "maximum no. of prefix limit\n"
8286 "Threshold value (%) at which to generate a warning msg\n"
8287 "Only give warning message when limit is exceeded\n"
8288 "Force checking all received routes not only accepted\n")
e0701b79 8289{
d62a17ae 8290 int idx_peer = 1;
8291 int idx_number = 3;
8292 int idx_number_2 = 4;
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);
9cbd06e0 8299
04261dec
CS
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;
8306
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 nb_cli_enqueue_change(vty, "./options/tw-shutdown-threshold-pct",
8317 NB_OP_MODIFY, argv[idx_number_2]->arg);
8318 nb_cli_enqueue_change(vty, "./options/tw-warning-only", NB_OP_MODIFY,
8319 "true");
9cbd06e0 8320 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8321 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8322 "true");
9cbd06e0 8323
04261dec 8324 return nb_cli_apply_changes(vty, base_xpath);
0a486e5f 8325}
8326
d62a17ae 8327ALIAS_HIDDEN(
8328 neighbor_maximum_prefix_threshold_warning,
8329 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
9cbd06e0 8330 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
d62a17ae 8331 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8332 "Maximum number of prefix accept from this peer\n"
8333 "maximum no. of prefix limit\n"
8334 "Threshold value (%) at which to generate a warning msg\n"
9cbd06e0
DA
8335 "Only give warning message when limit is exceeded\n"
8336 "Force checking all received routes not only accepted\n")
596c17ba 8337
232c75cd
CS
8338DEFUN_YANG(neighbor_maximum_prefix_restart,
8339 neighbor_maximum_prefix_restart_cmd,
8340 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8341 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8342 "Maximum number of prefix accept from this peer\n"
8343 "maximum no. of prefix limit\n"
8344 "Restart bgp connection after limit is exceeded\n"
8345 "Restart interval in minutes\n"
8346 "Force checking all received routes not only accepted\n")
0a486e5f 8347{
d62a17ae 8348 int idx_peer = 1;
8349 int idx_number = 3;
8350 int idx_number_2 = 5;
9cbd06e0 8351 int idx_force = 0;
04261dec
CS
8352 char base_xpath[XPATH_MAXLEN];
8353 char af_xpath[XPATH_MAXLEN];
8354 char attr_xpath[XPATH_MAXLEN];
8355 afi_t afi = bgp_node_afi(vty);
8356 safi_t safi = bgp_node_safi(vty);
9cbd06e0 8357
04261dec
CS
8358 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8359 yang_afi_safi_value2identity(afi, safi));
8360 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8361 sizeof(base_xpath), af_xpath)
8362 < 0)
8363 return CMD_WARNING_CONFIG_FAILED;
8364
8365 snprintf(attr_xpath, sizeof(attr_xpath),
8366 "/%s/prefix-limit/direction-list[direction='in']",
8367 bgp_afi_safi_get_container_str(afi, safi));
8368 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8369
8370 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8371
8372 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8373 argv[idx_number]->arg);
8374 nb_cli_enqueue_change(vty, "./options/restart-timer", NB_OP_MODIFY,
8375 argv[idx_number_2]->arg);
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_restart,
8385 neighbor_maximum_prefix_restart_hidden_cmd,
9cbd06e0 8386 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [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 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
8391 "Restart interval in minutes\n"
8392 "Force checking all received routes not only accepted\n")
596c17ba 8393
232c75cd
CS
8394DEFUN_YANG(neighbor_maximum_prefix_threshold_restart,
8395 neighbor_maximum_prefix_threshold_restart_cmd,
8396 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8397 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8398 "Maximum number of prefixes to accept from this peer\n"
8399 "maximum no. of prefix limit\n"
8400 "Threshold value (%) at which to generate a warning msg\n"
8401 "Restart bgp connection after limit is exceeded\n"
8402 "Restart interval in minutes\n"
8403 "Force checking all received routes not only accepted\n")
0a486e5f 8404{
d62a17ae 8405 int idx_peer = 1;
8406 int idx_number = 3;
8407 int idx_number_2 = 4;
8408 int idx_number_3 = 6;
9cbd06e0 8409 int idx_force = 0;
04261dec
CS
8410 char base_xpath[XPATH_MAXLEN];
8411 char af_xpath[XPATH_MAXLEN];
8412 char attr_xpath[XPATH_MAXLEN];
8413 afi_t afi = bgp_node_afi(vty);
8414 safi_t safi = bgp_node_safi(vty);
9cbd06e0 8415
04261dec
CS
8416 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8417 yang_afi_safi_value2identity(afi, safi));
8418 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8419 sizeof(base_xpath), af_xpath)
8420 < 0)
8421 return CMD_WARNING_CONFIG_FAILED;
8422
8423 snprintf(attr_xpath, sizeof(attr_xpath),
8424 "/%s/prefix-limit/direction-list[direction='in']",
8425 bgp_afi_safi_get_container_str(afi, safi));
8426 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8427
8428 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8429
8430 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8431 argv[idx_number]->arg);
8432 nb_cli_enqueue_change(vty, "./options/tr-shutdown-threshold-pct",
8433 NB_OP_MODIFY, argv[idx_number_2]->arg);
8434 nb_cli_enqueue_change(vty, "./options/tr-restart-timer", NB_OP_MODIFY,
8435 argv[idx_number_3]->arg);
9cbd06e0 8436 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8437 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8438 "true");
9cbd06e0 8439
04261dec 8440 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 8441}
8442
8443ALIAS_HIDDEN(
8444 neighbor_maximum_prefix_threshold_restart,
8445 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
9cbd06e0 8446 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
d62a17ae 8447 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8448 "Maximum number of prefixes to accept from this peer\n"
8449 "maximum no. of prefix limit\n"
8450 "Threshold value (%) at which to generate a warning msg\n"
8451 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
8452 "Restart interval in minutes\n"
8453 "Force checking all received routes not only accepted\n")
596c17ba 8454
232c75cd
CS
8455DEFUN_YANG(no_neighbor_maximum_prefix,
8456 no_neighbor_maximum_prefix_cmd,
8457 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8458 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8459 "Maximum number of prefixes to accept from this peer\n"
8460 "maximum no. of prefix limit\n"
8461 "Threshold value (%) at which to generate a warning msg\n"
8462 "Restart bgp connection after limit is exceeded\n"
8463 "Restart interval in minutes\n"
8464 "Only give warning message when limit is exceeded\n"
8465 "Force checking all received routes not only accepted\n")
718e3744 8466{
d62a17ae 8467 int idx_peer = 2;
04261dec
CS
8468 char base_xpath[XPATH_MAXLEN];
8469 char af_xpath[XPATH_MAXLEN];
8470 char attr_xpath[XPATH_MAXLEN];
8471 afi_t afi = bgp_node_afi(vty);
8472 safi_t safi = bgp_node_safi(vty);
8473
8474 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8475 yang_afi_safi_value2identity(afi, safi));
8476 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8477 sizeof(base_xpath), af_xpath)
8478 < 0)
8479 return CMD_WARNING_CONFIG_FAILED;
8480
8481 snprintf(attr_xpath, sizeof(attr_xpath),
8482 "/%s/prefix-limit/direction-list[direction='in']",
8483 bgp_afi_safi_get_container_str(afi, safi));
8484 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8485
8486 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
8487
8488 return nb_cli_apply_changes(vty, base_xpath);
718e3744 8489}
e52702f2 8490
d62a17ae 8491ALIAS_HIDDEN(
8492 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 8493 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
d62a17ae 8494 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8495 "Maximum number of prefixes to accept from this peer\n"
8496 "maximum no. of prefix limit\n"
8497 "Threshold value (%) at which to generate a warning msg\n"
8498 "Restart bgp connection after limit is exceeded\n"
8499 "Restart interval in minutes\n"
9cbd06e0
DA
8500 "Only give warning message when limit is exceeded\n"
8501 "Force checking all received routes not only accepted\n")
596c17ba 8502
718e3744 8503
718e3744 8504/* "neighbor allowas-in" */
8505DEFUN (neighbor_allowas_in,
8506 neighbor_allowas_in_cmd,
fd8503f5 8507 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 8508 NEIGHBOR_STR
8509 NEIGHBOR_ADDR_STR2
31500417 8510 "Accept as-path with my AS present in it\n"
f79f7a7b 8511 "Number of occurrences of AS number\n"
fd8503f5 8512 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 8513{
d62a17ae 8514 int idx_peer = 1;
8515 int idx_number_origin = 3;
8516 int ret;
8517 int origin = 0;
8518 struct peer *peer;
8519 int allow_num = 0;
8520
8521 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8522 if (!peer)
8523 return CMD_WARNING_CONFIG_FAILED;
8524
8525 if (argc <= idx_number_origin)
8526 allow_num = 3;
8527 else {
8528 if (argv[idx_number_origin]->type == WORD_TKN)
8529 origin = 1;
8530 else
8531 allow_num = atoi(argv[idx_number_origin]->arg);
8532 }
8533
8534 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8535 allow_num, origin);
8536
8537 return bgp_vty_return(vty, ret);
8538}
8539
8540ALIAS_HIDDEN(
8541 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8542 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8543 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8544 "Accept as-path with my AS present in it\n"
f79f7a7b 8545 "Number of occurrences of AS number\n"
d62a17ae 8546 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 8547
718e3744 8548DEFUN (no_neighbor_allowas_in,
8549 no_neighbor_allowas_in_cmd,
fd8503f5 8550 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 8551 NO_STR
8552 NEIGHBOR_STR
8553 NEIGHBOR_ADDR_STR2
8334fd5a 8554 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8555 "Number of occurrences of AS number\n"
fd8503f5 8556 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 8557{
d62a17ae 8558 int idx_peer = 2;
8559 int ret;
8560 struct peer *peer;
718e3744 8561
d62a17ae 8562 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8563 if (!peer)
8564 return CMD_WARNING_CONFIG_FAILED;
718e3744 8565
d62a17ae 8566 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8567 bgp_node_safi(vty));
718e3744 8568
d62a17ae 8569 return bgp_vty_return(vty, ret);
718e3744 8570}
6b0655a2 8571
d62a17ae 8572ALIAS_HIDDEN(
8573 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8574 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8575 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8576 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8577 "Number of occurrences of AS number\n"
d62a17ae 8578 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 8579
f4b8ec07
CS
8580DEFUN_YANG (neighbor_ttl_security,
8581 neighbor_ttl_security_cmd,
8582 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8583 NEIGHBOR_STR
8584 NEIGHBOR_ADDR_STR2
8585 "BGP ttl-security parameters\n"
8586 "Specify the maximum number of hops to the BGP peer\n"
8587 "Number of hops to BGP peer\n")
fa411a21 8588{
d62a17ae 8589 int idx_peer = 1;
8590 int idx_number = 4;
f4b8ec07 8591 char base_xpath[XPATH_MAXLEN];
d62a17ae 8592
f4b8ec07
CS
8593 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8594 sizeof(base_xpath), NULL)
8595 < 0)
d62a17ae 8596 return CMD_WARNING_CONFIG_FAILED;
8597
f4b8ec07
CS
8598 nb_cli_enqueue_change(vty, "./ttl-security", NB_OP_MODIFY,
8599 argv[idx_number]->arg);
7ebe625c 8600
f4b8ec07 8601 return nb_cli_apply_changes(vty, base_xpath);
fa411a21
NH
8602}
8603
232c75cd
CS
8604DEFUN_YANG(no_neighbor_ttl_security,
8605 no_neighbor_ttl_security_cmd,
8606 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8607 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8608 "BGP ttl-security parameters\n"
8609 "Specify the maximum number of hops to the BGP peer\n"
8610 "Number of hops to BGP peer\n")
fa411a21 8611{
d62a17ae 8612 int idx_peer = 2;
f4b8ec07 8613 char base_xpath[XPATH_MAXLEN];
fa411a21 8614
f4b8ec07
CS
8615 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8616 sizeof(base_xpath), NULL)
8617 < 0)
d62a17ae 8618 return CMD_WARNING_CONFIG_FAILED;
fa411a21 8619
f4b8ec07
CS
8620 nb_cli_enqueue_change(vty, "./ttl-security", NB_OP_DESTROY, NULL);
8621
8622 return nb_cli_apply_changes(vty, base_xpath);
fa411a21 8623}
6b0655a2 8624
adbac85e
DW
8625DEFUN (neighbor_addpath_tx_all_paths,
8626 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8627 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8628 NEIGHBOR_STR
8629 NEIGHBOR_ADDR_STR2
8630 "Use addpath to advertise all paths to a neighbor\n")
8631{
d62a17ae 8632 int idx_peer = 1;
8633 struct peer *peer;
adbac85e 8634
d62a17ae 8635 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8636 if (!peer)
8637 return CMD_WARNING_CONFIG_FAILED;
adbac85e 8638
dcc68b5e
MS
8639 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8640 BGP_ADDPATH_ALL);
8641 return CMD_SUCCESS;
adbac85e
DW
8642}
8643
d62a17ae 8644ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8645 neighbor_addpath_tx_all_paths_hidden_cmd,
8646 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8647 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8648 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8649
adbac85e
DW
8650DEFUN (no_neighbor_addpath_tx_all_paths,
8651 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8652 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8653 NO_STR
8654 NEIGHBOR_STR
8655 NEIGHBOR_ADDR_STR2
8656 "Use addpath to advertise all paths to a neighbor\n")
8657{
d62a17ae 8658 int idx_peer = 2;
dcc68b5e
MS
8659 struct peer *peer;
8660
8661 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8662 if (!peer)
8663 return CMD_WARNING_CONFIG_FAILED;
8664
8665 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8666 != BGP_ADDPATH_ALL) {
8667 vty_out(vty,
8668 "%% Peer not currently configured to transmit all paths.");
8669 return CMD_WARNING_CONFIG_FAILED;
8670 }
8671
8672 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8673 BGP_ADDPATH_NONE);
8674
8675 return CMD_SUCCESS;
adbac85e
DW
8676}
8677
d62a17ae 8678ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8679 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8680 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8681 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8682 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8683
06370dac
DW
8684DEFUN (neighbor_addpath_tx_bestpath_per_as,
8685 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8686 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8687 NEIGHBOR_STR
8688 NEIGHBOR_ADDR_STR2
8689 "Use addpath to advertise the bestpath per each neighboring AS\n")
8690{
d62a17ae 8691 int idx_peer = 1;
8692 struct peer *peer;
06370dac 8693
d62a17ae 8694 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8695 if (!peer)
8696 return CMD_WARNING_CONFIG_FAILED;
06370dac 8697
dcc68b5e
MS
8698 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8699 BGP_ADDPATH_BEST_PER_AS);
8700
8701 return CMD_SUCCESS;
06370dac
DW
8702}
8703
d62a17ae 8704ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8705 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8706 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8707 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8708 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8709
06370dac
DW
8710DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8711 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8712 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8713 NO_STR
8714 NEIGHBOR_STR
8715 NEIGHBOR_ADDR_STR2
8716 "Use addpath to advertise the bestpath per each neighboring AS\n")
8717{
d62a17ae 8718 int idx_peer = 2;
dcc68b5e
MS
8719 struct peer *peer;
8720
8721 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8722 if (!peer)
8723 return CMD_WARNING_CONFIG_FAILED;
8724
8725 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8726 != BGP_ADDPATH_BEST_PER_AS) {
8727 vty_out(vty,
8728 "%% Peer not currently configured to transmit all best path per as.");
8729 return CMD_WARNING_CONFIG_FAILED;
8730 }
8731
8732 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8733 BGP_ADDPATH_NONE);
8734
8735 return CMD_SUCCESS;
06370dac
DW
8736}
8737
d62a17ae 8738ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8739 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8740 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8741 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8742 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8743
2b31007c
RZ
8744DEFPY(
8745 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8746 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8747 NEIGHBOR_STR
8748 NEIGHBOR_ADDR_STR2
8749 "Detect AS loops before sending to neighbor\n")
8750{
8751 struct peer *peer;
8752
8753 peer = peer_and_group_lookup_vty(vty, neighbor);
8754 if (!peer)
8755 return CMD_WARNING_CONFIG_FAILED;
8756
8757 peer->as_path_loop_detection = true;
8758
8759 return CMD_SUCCESS;
8760}
8761
8762DEFPY(
8763 no_neighbor_aspath_loop_detection,
8764 no_neighbor_aspath_loop_detection_cmd,
8765 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8766 NO_STR
8767 NEIGHBOR_STR
8768 NEIGHBOR_ADDR_STR2
8769 "Detect AS loops before sending to neighbor\n")
8770{
8771 struct peer *peer;
8772
8773 peer = peer_and_group_lookup_vty(vty, neighbor);
8774 if (!peer)
8775 return CMD_WARNING_CONFIG_FAILED;
8776
8777 peer->as_path_loop_detection = false;
8778
8779 return CMD_SUCCESS;
8780}
8781
0221327c
DS
8782DEFPY(neighbor_damp,
8783 neighbor_damp_cmd,
8784 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor dampening [(1-45)$half [(1-20000)$reuse (1-20000)$suppress (1-255)$max]]",
8785 NEIGHBOR_STR
8786 NEIGHBOR_ADDR_STR2
8787 "Enable neighbor route-flap dampening\n"
8788 "Half-life time for the penalty\n"
8789 "Value to start reusing a route\n"
8790 "Value to start suppressing a route\n"
8791 "Maximum duration to suppress a stable route\n")
8792{
8793 struct peer *peer = peer_and_group_lookup_vty(vty, neighbor);
8794
8795 if (!peer)
8796 return CMD_WARNING_CONFIG_FAILED;
8797 if (!half)
8798 half = DEFAULT_HALF_LIFE;
8799 if (!reuse) {
8800 reuse = DEFAULT_REUSE;
8801 suppress = DEFAULT_SUPPRESS;
8802 max = half * 4;
8803 }
8804 if (suppress < reuse) {
8805 vty_out(vty,
8806 "Suppress value cannot be less than reuse value\n");
8807 return CMD_WARNING_CONFIG_FAILED;
8808 }
8809 bgp_peer_damp_enable(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8810 half * 60, reuse, suppress, max * 60);
8811 return CMD_SUCCESS;
8812}
8813
8814DEFPY(no_neighbor_damp,
8815 no_neighbor_damp_cmd,
8816 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor dampening [HALF [REUSE SUPPRESS MAX]]",
8817 NO_STR
8818 NEIGHBOR_STR
8819 NEIGHBOR_ADDR_STR2
8820 "Enable neighbor route-flap dampening\n"
8821 "Half-life time for the penalty\n"
8822 "Value to start reusing a route\n"
8823 "Value to start suppressing a route\n"
8824 "Maximum duration to suppress a stable route\n")
8825{
8826 struct peer *peer = peer_and_group_lookup_vty(vty, neighbor);
8827
8828 if (!peer)
8829 return CMD_WARNING_CONFIG_FAILED;
8830 bgp_peer_damp_disable(peer, bgp_node_afi(vty), bgp_node_safi(vty));
8831 return CMD_SUCCESS;
8832}
8833
8834DEFPY (show_ip_bgp_neighbor_damp_param,
8835 show_ip_bgp_neighbor_damp_param_cmd,
8836 "show [ip] bgp [<ipv4|ipv6> [unicast]] neighbors <A.B.C.D|X:X::X:X|WORD>$neighbor dampening parameters [json]$json",
8837 SHOW_STR
8838 IP_STR
8839 BGP_STR
8840 BGP_AFI_HELP_STR
8841 "Address Family modifier\n"
8842 NEIGHBOR_STR
8843 NEIGHBOR_ADDR_STR2
8844 "Neighbor route-flap dampening information\n"
8845 "Display detail of configured dampening parameters\n"
8846 JSON_STR)
8847{
8848 bool use_json = false;
8849 int idx = 0;
8850 afi_t afi = AFI_IP;
8851 safi_t safi = SAFI_UNICAST;
8852 struct peer *peer;
8853
8854 if (argv_find(argv, argc, "ip", &idx))
8855 afi = AFI_IP;
8856 if (argv_find(argv, argc, "ipv4", &idx))
8857 afi = AFI_IP;
8858 if (argv_find(argv, argc, "ipv6", &idx))
8859 afi = AFI_IP6;
8860 peer = peer_and_group_lookup_vty(vty, neighbor);
8861 if (!peer)
8862 return CMD_WARNING;
8863 if (json)
8864 use_json = true;
8865 bgp_show_peer_dampening_parameters(vty, peer, afi, safi, use_json);
8866 return CMD_SUCCESS;
8867}
8868
b9c7bc5a 8869static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
c6423c31 8870 struct ecommunity **list, bool is_rt6)
ddb5b488 8871{
b9c7bc5a
PZ
8872 struct ecommunity *ecom = NULL;
8873 struct ecommunity *ecomadd;
ddb5b488 8874
b9c7bc5a 8875 for (; argc; --argc, ++argv) {
9a659715
PG
8876 if (is_rt6)
8877 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8878 ECOMMUNITY_ROUTE_TARGET,
8879 0);
8880 else
8881 ecomadd = ecommunity_str2com(argv[0]->arg,
8882 ECOMMUNITY_ROUTE_TARGET,
8883 0);
b9c7bc5a
PZ
8884 if (!ecomadd) {
8885 vty_out(vty, "Malformed community-list value\n");
8886 if (ecom)
8887 ecommunity_free(&ecom);
8888 return CMD_WARNING_CONFIG_FAILED;
8889 }
ddb5b488 8890
b9c7bc5a
PZ
8891 if (ecom) {
8892 ecommunity_merge(ecom, ecomadd);
8893 ecommunity_free(&ecomadd);
8894 } else {
8895 ecom = ecomadd;
8896 }
8897 }
8898
8899 if (*list) {
8900 ecommunity_free(&*list);
ddb5b488 8901 }
b9c7bc5a
PZ
8902 *list = ecom;
8903
8904 return CMD_SUCCESS;
ddb5b488
PZ
8905}
8906
37a87b8f
CS
8907bool vpn_policy_check_import(struct bgp *bgp, afi_t afi, safi_t safi,
8908 bool v2vimport, char *errmsg, size_t errmsg_len)
8909{
8910 if (!v2vimport) {
8911 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8912 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8913 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8914 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8915 snprintf(
8916 errmsg, errmsg_len, "%s",
8917 "%% error: Please unconfigure import vrf commands before using vpn commands");
8918 return false;
8919 }
8920 } else {
8921 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8922 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8923 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8924 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8925 snprintf(
8926 errmsg, errmsg_len, "%s",
8927 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands");
8928 return false;
8929 }
8930 }
8931 return true;
8932}
8933
0ca70ba5
DS
8934/*
8935 * v2vimport is true if we are handling a `import vrf ...` command
8936 */
8937static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 8938{
0ca70ba5
DS
8939 afi_t afi;
8940
ddb5b488 8941 switch (vty->node) {
b9c7bc5a 8942 case BGP_IPV4_NODE:
0ca70ba5
DS
8943 afi = AFI_IP;
8944 break;
b9c7bc5a 8945 case BGP_IPV6_NODE:
0ca70ba5
DS
8946 afi = AFI_IP6;
8947 break;
ddb5b488
PZ
8948 default:
8949 vty_out(vty,
b9c7bc5a 8950 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 8951 return AFI_MAX;
ddb5b488 8952 }
69b07479 8953
0ca70ba5
DS
8954 if (!v2vimport) {
8955 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8956 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8957 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8958 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8959 vty_out(vty,
8960 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8961 return AFI_MAX;
8962 }
8963 } else {
8964 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8965 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8966 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8967 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8968 vty_out(vty,
8969 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
8970 return AFI_MAX;
8971 }
8972 }
8973 return afi;
ddb5b488
PZ
8974}
8975
37a87b8f
CS
8976DEFPY_YANG(
8977 af_rd_vpn_export,
8978 af_rd_vpn_export_cmd,
8979 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
8980 NO_STR
8981 "Specify route distinguisher\n"
8982 "Between current address-family and vpn\n"
8983 "For routes leaked from current address-family to vpn\n"
8984 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
ddb5b488 8985{
37a87b8f 8986 char base_xpath[XPATH_MAXLEN];
ddb5b488 8987 afi_t afi;
37a87b8f 8988 safi_t safi;
b9c7bc5a 8989 int idx = 0;
b9c7bc5a 8990
37a87b8f
CS
8991 afi = bgp_node_afi(vty);
8992 safi = bgp_node_safi(vty);
ddb5b488 8993
37a87b8f
CS
8994 snprintf(
8995 base_xpath, sizeof(base_xpath),
8996 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
8997 yang_afi_safi_value2identity(afi, safi),
8998 bgp_afi_safi_get_container_str(afi, safi));
ddb5b488 8999
37a87b8f
CS
9000 if (argv_find(argv, argc, "no", &idx))
9001 nb_cli_enqueue_change(vty, "./rd", NB_OP_DESTROY, NULL);
9002 else
9003 nb_cli_enqueue_change(vty, "./rd", NB_OP_MODIFY, rd_str);
ddb5b488 9004
37a87b8f
CS
9005 return nb_cli_apply_changes(vty, base_xpath);
9006}
ddb5b488 9007
37a87b8f
CS
9008void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rd(
9009 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9010{
9011 int indent = 2;
69b07479 9012
37a87b8f
CS
9013 vty_out(vty, "%*srd vpn export %s\n", indent, "",
9014 yang_dnode_get_string(dnode, NULL));
ddb5b488
PZ
9015}
9016
b9c7bc5a
PZ
9017ALIAS (af_rd_vpn_export,
9018 af_no_rd_vpn_export_cmd,
9019 "no rd vpn export",
ddb5b488 9020 NO_STR
b9c7bc5a
PZ
9021 "Specify route distinguisher\n"
9022 "Between current address-family and vpn\n"
9023 "For routes leaked from current address-family to vpn\n")
ddb5b488 9024
b9c7bc5a
PZ
9025DEFPY (af_label_vpn_export,
9026 af_label_vpn_export_cmd,
e70e9f8e 9027 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 9028 NO_STR
ddb5b488 9029 "label value for VRF\n"
b9c7bc5a
PZ
9030 "Between current address-family and vpn\n"
9031 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
9032 "Label Value <0-1048575>\n"
9033 "Automatically assign a label\n")
ddb5b488
PZ
9034{
9035 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 9036 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 9037 afi_t afi;
b9c7bc5a 9038 int idx = 0;
c6423c31 9039 bool yes = true;
b9c7bc5a
PZ
9040
9041 if (argv_find(argv, argc, "no", &idx))
c6423c31 9042 yes = false;
ddb5b488 9043
21a16cc2
PZ
9044 /* If "no ...", squash trailing parameter */
9045 if (!yes)
9046 label_auto = NULL;
9047
e70e9f8e
PZ
9048 if (yes) {
9049 if (!label_auto)
9050 label = label_val; /* parser should force unsigned */
9051 }
ddb5b488 9052
0ca70ba5 9053 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9054 if (afi == AFI_MAX)
9055 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 9056
e70e9f8e 9057
69b07479
DS
9058 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9059 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
9060 /* no change */
9061 return CMD_SUCCESS;
e70e9f8e 9062
69b07479
DS
9063 /*
9064 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9065 */
9066 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9067 bgp_get_default(), bgp);
9068
9069 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9070 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
9071
9072 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
9073
9074 /*
9075 * label has previously been automatically
9076 * assigned by labelpool: release it
9077 *
9078 * NB if tovpn_label == MPLS_LABEL_NONE it
9079 * means the automatic assignment is in flight
9080 * and therefore the labelpool callback must
9081 * detect that the auto label is not needed.
9082 */
9083
9084 bgp_lp_release(LP_TYPE_VRF,
9085 &bgp->vpn_policy[afi],
9086 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 9087 }
69b07479
DS
9088 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9089 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9090 }
ddb5b488 9091
69b07479
DS
9092 bgp->vpn_policy[afi].tovpn_label = label;
9093 if (label_auto) {
9094 SET_FLAG(bgp->vpn_policy[afi].flags,
9095 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9096 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
9097 vpn_leak_label_callback);
ddb5b488
PZ
9098 }
9099
69b07479
DS
9100 /* post-change: re-export vpn routes */
9101 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9102 bgp_get_default(), bgp);
9103
0d020cd6 9104 hook_call(bgp_snmp_update_last_changed, bgp);
ddb5b488
PZ
9105 return CMD_SUCCESS;
9106}
9107
b9c7bc5a
PZ
9108ALIAS (af_label_vpn_export,
9109 af_no_label_vpn_export_cmd,
9110 "no label vpn export",
9111 NO_STR
9112 "label value for VRF\n"
9113 "Between current address-family and vpn\n"
9114 "For routes leaked from current address-family to vpn\n")
ddb5b488 9115
37a87b8f 9116DEFPY_YANG (af_nexthop_vpn_export,
b9c7bc5a 9117 af_nexthop_vpn_export_cmd,
8c85ca28 9118 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
b9c7bc5a 9119 NO_STR
ddb5b488 9120 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
9121 "Between current address-family and vpn\n"
9122 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
9123 "IPv4 prefix\n"
9124 "IPv6 prefix\n")
9125{
37a87b8f 9126 char base_xpath[XPATH_MAXLEN];
ddb5b488 9127 afi_t afi;
37a87b8f
CS
9128 safi_t safi;
9129 int idx = 0;
ddb5b488
PZ
9130 struct prefix p;
9131
8c85ca28
QY
9132 if (!no) {
9133 if (!nexthop_su) {
9134 vty_out(vty, "%% Nexthop required\n");
9135 return CMD_WARNING_CONFIG_FAILED;
9136 }
8c85ca28 9137 if (!sockunion2hostprefix(nexthop_su, &p))
b9c7bc5a
PZ
9138 return CMD_WARNING_CONFIG_FAILED;
9139 }
ddb5b488 9140
37a87b8f
CS
9141 afi = bgp_node_afi(vty);
9142 safi = bgp_node_safi(vty);
ddb5b488 9143
37a87b8f
CS
9144 snprintf(
9145 base_xpath, sizeof(base_xpath),
9146 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9147 yang_afi_safi_value2identity(afi, safi),
9148 bgp_afi_safi_get_container_str(afi, safi));
ddb5b488 9149
37a87b8f
CS
9150 if (argv_find(argv, argc, "no", &idx))
9151 nb_cli_enqueue_change(vty, "./nexthop", NB_OP_DESTROY, NULL);
9152 else
9153 nb_cli_enqueue_change(vty, "./nexthop", NB_OP_MODIFY,
9154 nexthop_su_str);
ddb5b488 9155
37a87b8f
CS
9156 return nb_cli_apply_changes(vty, base_xpath);
9157}
69b07479 9158
37a87b8f
CS
9159void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_nexthop(
9160 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9161{
9162 int indent = 2;
9163
9164 vty_out(vty, "%*snexthop vpn export %s\n", indent, "",
9165 yang_dnode_get_string(dnode, NULL));
ddb5b488
PZ
9166}
9167
b9c7bc5a 9168static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 9169{
b9c7bc5a
PZ
9170 if (!strcmp(dstr, "import")) {
9171 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9172 } else if (!strcmp(dstr, "export")) {
9173 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9174 } else if (!strcmp(dstr, "both")) {
9175 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9176 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9177 } else {
9178 vty_out(vty, "%% direction parse error\n");
9179 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9180 }
ddb5b488
PZ
9181 return CMD_SUCCESS;
9182}
9183
b9c7bc5a
PZ
9184DEFPY (af_rt_vpn_imexport,
9185 af_rt_vpn_imexport_cmd,
9186 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9187 NO_STR
9188 "Specify route target list\n"
ddb5b488 9189 "Specify route target list\n"
b9c7bc5a
PZ
9190 "Between current address-family and vpn\n"
9191 "For routes leaked from vpn to current address-family: match any\n"
9192 "For routes leaked from current address-family to vpn: set\n"
9193 "both import: match any and export: set\n"
ddb5b488
PZ
9194 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9195{
9196 VTY_DECLVAR_CONTEXT(bgp, bgp);
9197 int ret;
9198 struct ecommunity *ecom = NULL;
9199 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
9200 vpn_policy_direction_t dir;
9201 afi_t afi;
9202 int idx = 0;
c6423c31 9203 bool yes = true;
ddb5b488 9204
b9c7bc5a 9205 if (argv_find(argv, argc, "no", &idx))
c6423c31 9206 yes = false;
b9c7bc5a 9207
0ca70ba5 9208 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9209 if (afi == AFI_MAX)
9210 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9211
b9c7bc5a 9212 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
9213 if (ret != CMD_SUCCESS)
9214 return ret;
9215
b9c7bc5a
PZ
9216 if (yes) {
9217 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9218 vty_out(vty, "%% Missing RTLIST\n");
9219 return CMD_WARNING_CONFIG_FAILED;
9220 }
c6423c31 9221 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
b9c7bc5a
PZ
9222 if (ret != CMD_SUCCESS) {
9223 return ret;
9224 }
ddb5b488
PZ
9225 }
9226
69b07479
DS
9227 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9228 if (!dodir[dir])
ddb5b488 9229 continue;
ddb5b488 9230
69b07479 9231 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 9232
69b07479
DS
9233 if (yes) {
9234 if (bgp->vpn_policy[afi].rtlist[dir])
9235 ecommunity_free(
9236 &bgp->vpn_policy[afi].rtlist[dir]);
9237 bgp->vpn_policy[afi].rtlist[dir] =
9238 ecommunity_dup(ecom);
9239 } else {
9240 if (bgp->vpn_policy[afi].rtlist[dir])
9241 ecommunity_free(
9242 &bgp->vpn_policy[afi].rtlist[dir]);
9243 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 9244 }
69b07479
DS
9245
9246 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 9247 }
69b07479 9248
d555f3e9
PZ
9249 if (ecom)
9250 ecommunity_free(&ecom);
ddb5b488
PZ
9251
9252 return CMD_SUCCESS;
9253}
9254
b9c7bc5a
PZ
9255ALIAS (af_rt_vpn_imexport,
9256 af_no_rt_vpn_imexport_cmd,
9257 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
9258 NO_STR
9259 "Specify route target list\n"
b9c7bc5a
PZ
9260 "Specify route target list\n"
9261 "Between current address-family and vpn\n"
9262 "For routes leaked from vpn to current address-family\n"
9263 "For routes leaked from current address-family to vpn\n"
9264 "both import and export\n")
9265
37a87b8f 9266DEFPY_YANG (af_route_map_vpn_imexport,
b9c7bc5a
PZ
9267 af_route_map_vpn_imexport_cmd,
9268/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9269 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9270 NO_STR
ddb5b488 9271 "Specify route map\n"
b9c7bc5a
PZ
9272 "Between current address-family and vpn\n"
9273 "For routes leaked from vpn to current address-family\n"
9274 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
9275 "name of route-map\n")
9276{
37a87b8f 9277 char base_xpath[XPATH_MAXLEN];
ddb5b488 9278 afi_t afi;
37a87b8f 9279 safi_t safi;
ddb5b488 9280 int idx = 0;
ddb5b488 9281
37a87b8f
CS
9282 afi = bgp_node_afi(vty);
9283 safi = bgp_node_safi(vty);
ddb5b488 9284
37a87b8f
CS
9285 snprintf(
9286 base_xpath, sizeof(base_xpath),
9287 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9288 yang_afi_safi_value2identity(afi, safi),
9289 bgp_afi_safi_get_container_str(afi, safi));
9290
9291 if (argv_find(argv, argc, "no", &idx)) {
9292 if (!strcmp(direction_str, "import"))
9293 nb_cli_enqueue_change(vty, "./rmap-import",
9294 NB_OP_DESTROY, NULL);
9295 else if (!strcmp(direction_str, "export"))
9296 nb_cli_enqueue_change(vty, "./rmap-export",
9297 NB_OP_DESTROY, NULL);
9298 } else {
9299 if (!strcmp(direction_str, "import"))
9300 nb_cli_enqueue_change(vty, "./rmap-import",
9301 NB_OP_MODIFY, rmap_str);
9302 if (!strcmp(direction_str, "export"))
9303 nb_cli_enqueue_change(vty, "./rmap-export",
9304 NB_OP_MODIFY, rmap_str);
9305 }
9306 return nb_cli_apply_changes(vty, base_xpath);
9307}
ddb5b488 9308
37a87b8f
CS
9309void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_import(
9310 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9311{
9312 int indent = 2;
ddb5b488 9313
37a87b8f
CS
9314 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
9315 yang_dnode_get_string(dnode, NULL));
9316}
69b07479 9317
37a87b8f
CS
9318void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_export(
9319 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9320{
9321 int indent = 2;
ddb5b488 9322
37a87b8f
CS
9323 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
9324 yang_dnode_get_string(dnode, NULL));
ddb5b488
PZ
9325}
9326
b9c7bc5a
PZ
9327ALIAS (af_route_map_vpn_imexport,
9328 af_no_route_map_vpn_imexport_cmd,
9329 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
9330 NO_STR
9331 "Specify route map\n"
b9c7bc5a
PZ
9332 "Between current address-family and vpn\n"
9333 "For routes leaked from vpn to current address-family\n"
9334 "For routes leaked from current address-family to vpn\n")
9335
bb4f6190 9336DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
ae6a6fb4 9337 "import vrf route-map RMAP$rmap_str",
bb4f6190
DS
9338 "Import routes from another VRF\n"
9339 "Vrf routes being filtered\n"
9340 "Specify route map\n"
9341 "name of route-map\n")
9342{
9343 VTY_DECLVAR_CONTEXT(bgp, bgp);
bb4f6190
DS
9344 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
9345 afi_t afi;
bb4f6190
DS
9346 struct bgp *bgp_default;
9347
0ca70ba5 9348 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
9349 if (afi == AFI_MAX)
9350 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
9351
9352 bgp_default = bgp_get_default();
9353 if (!bgp_default) {
9354 int32_t ret;
9355 as_t as = bgp->as;
9356
9357 /* Auto-create assuming the same AS */
5d5393b9
DL
9358 ret = bgp_get_vty(&bgp_default, &as, NULL,
9359 BGP_INSTANCE_TYPE_DEFAULT);
bb4f6190
DS
9360
9361 if (ret) {
9362 vty_out(vty,
9363 "VRF default is not configured as a bgp instance\n");
9364 return CMD_WARNING;
9365 }
9366 }
9367
69b07479 9368 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 9369
ae6a6fb4
DS
9370 if (bgp->vpn_policy[afi].rmap_name[dir])
9371 XFREE(MTYPE_ROUTE_MAP_NAME,
9372 bgp->vpn_policy[afi].rmap_name[dir]);
9373 bgp->vpn_policy[afi].rmap_name[dir] =
9374 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9375 bgp->vpn_policy[afi].rmap[dir] =
9376 route_map_lookup_warn_noexist(vty, rmap_str);
9377 if (!bgp->vpn_policy[afi].rmap[dir])
9378 return CMD_SUCCESS;
9379
9380 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9381 BGP_CONFIG_VRF_TO_VRF_IMPORT);
bb4f6190 9382
69b07479
DS
9383 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9384
bb4f6190
DS
9385 return CMD_SUCCESS;
9386}
9387
ae6a6fb4
DS
9388DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9389 "no import vrf route-map [RMAP$rmap_str]",
bb4f6190
DS
9390 NO_STR
9391 "Import routes from another VRF\n"
9392 "Vrf routes being filtered\n"
ae6a6fb4
DS
9393 "Specify route map\n"
9394 "name of route-map\n")
9395{
9396 VTY_DECLVAR_CONTEXT(bgp, bgp);
9397 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
9398 afi_t afi;
9399
9400 afi = vpn_policy_getafi(vty, bgp, true);
9401 if (afi == AFI_MAX)
9402 return CMD_WARNING_CONFIG_FAILED;
9403
9404 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9405
9406 if (bgp->vpn_policy[afi].rmap_name[dir])
9407 XFREE(MTYPE_ROUTE_MAP_NAME,
9408 bgp->vpn_policy[afi].rmap_name[dir]);
9409 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9410 bgp->vpn_policy[afi].rmap[dir] = NULL;
9411
9412 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9413 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9414 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9415
9416 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9417
9418 return CMD_SUCCESS;
9419}
bb4f6190 9420
37a87b8f
CS
9421DEFPY_YANG(bgp_imexport_vrf,
9422 bgp_imexport_vrf_cmd,
9423 "[no] import vrf VIEWVRFNAME$import_name",
9424 NO_STR
9425 "Import routes from another VRF\n"
9426 "VRF to import from\n"
9427 "The name of the VRF\n")
12a844a5 9428{
37a87b8f 9429 char base_xpath[XPATH_MAXLEN];
12a844a5
DS
9430 safi_t safi;
9431 afi_t afi;
37a87b8f 9432 int32_t idx = 0;
12a844a5 9433
867f0cca 9434 if (import_name == NULL) {
9435 vty_out(vty, "%% Missing import name\n");
9436 return CMD_WARNING;
9437 }
9438
ae6a6fb4
DS
9439 if (strcmp(import_name, "route-map") == 0) {
9440 vty_out(vty, "%% Must include route-map name\n");
9441 return CMD_WARNING;
9442 }
9443
37a87b8f 9444 afi = bgp_node_afi(vty);
12a844a5
DS
9445 safi = bgp_node_safi(vty);
9446
37a87b8f
CS
9447 snprintf(
9448 base_xpath, sizeof(base_xpath),
9449 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/import-vrf-list[vrf='%s']",
9450 yang_afi_safi_value2identity(afi, safi),
9451 bgp_afi_safi_get_container_str(afi, safi), import_name);
25679caa 9452
37a87b8f
CS
9453 if (argv_find(argv, argc, "no", &idx))
9454 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
9455 else
9456 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
12a844a5 9457
37a87b8f
CS
9458 return nb_cli_apply_changes(vty, base_xpath);
9459}
12a844a5 9460
37a87b8f
CS
9461void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vrfs(
9462 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9463{
9464 vty_out(vty, " import vrf %s\n",
9465 yang_dnode_get_string(dnode, "./vrf"));
12a844a5
DS
9466}
9467
b9c7bc5a 9468/* This command is valid only in a bgp vrf instance or the default instance */
37a87b8f 9469DEFPY_YANG (bgp_imexport_vpn,
b9c7bc5a
PZ
9470 bgp_imexport_vpn_cmd,
9471 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
9472 NO_STR
9473 "Import routes to this address-family\n"
9474 "Export routes from this address-family\n"
9475 "to/from default instance VPN RIB\n")
ddb5b488 9476{
37a87b8f 9477 char base_xpath[XPATH_MAXLEN];
b9c7bc5a 9478 safi_t safi;
37a87b8f
CS
9479 afi_t afi;
9480 int32_t idx = 0;
ddb5b488 9481
b9c7bc5a
PZ
9482 afi = bgp_node_afi(vty);
9483 safi = bgp_node_safi(vty);
ddb5b488 9484
b9c7bc5a 9485 if (!strcmp(direction_str, "import")) {
37a87b8f
CS
9486 snprintf(
9487 base_xpath, sizeof(base_xpath),
9488 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/import-vpn",
9489 yang_afi_safi_value2identity(afi, safi),
9490 bgp_afi_safi_get_container_str(afi, safi));
b9c7bc5a 9491 } else if (!strcmp(direction_str, "export")) {
37a87b8f
CS
9492 snprintf(
9493 base_xpath, sizeof(base_xpath),
9494 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/export-vpn",
9495 yang_afi_safi_value2identity(afi, safi),
9496 bgp_afi_safi_get_container_str(afi, safi));
b9c7bc5a
PZ
9497 } else {
9498 vty_out(vty, "%% unknown direction %s\n", direction_str);
9499 return CMD_WARNING_CONFIG_FAILED;
9500 }
9501
37a87b8f
CS
9502 if (argv_find(argv, argc, "no", &idx))
9503 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
9504 else
9505 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, "true");
ddb5b488 9506
37a87b8f
CS
9507 return nb_cli_apply_changes(vty, base_xpath);
9508}
ddb5b488 9509
37a87b8f
CS
9510void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vpn(
9511 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9512{
9513 if (yang_dnode_get_bool(dnode, NULL))
9514 vty_out(vty, " import vpn\n");
9515}
9516
9517void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_export_vpn(
9518 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9519{
9520 if (yang_dnode_get_bool(dnode, NULL))
9521 vty_out(vty, " export vpn\n");
ddb5b488
PZ
9522}
9523
301ad80a
PG
9524DEFPY (af_routetarget_import,
9525 af_routetarget_import_cmd,
9a659715 9526 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
301ad80a
PG
9527 NO_STR
9528 "Specify route target list\n"
9529 "Specify route target list\n"
9a659715
PG
9530 "Specify route target list\n"
9531 "Specify route target list\n"
301ad80a
PG
9532 "Flow-spec redirect type route target\n"
9533 "Import routes to this address-family\n"
9a659715 9534 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
301ad80a
PG
9535{
9536 VTY_DECLVAR_CONTEXT(bgp, bgp);
9537 int ret;
9538 struct ecommunity *ecom = NULL;
301ad80a 9539 afi_t afi;
9a659715 9540 int idx = 0, idx_unused = 0;
c6423c31
PG
9541 bool yes = true;
9542 bool rt6 = false;
301ad80a
PG
9543
9544 if (argv_find(argv, argc, "no", &idx))
c6423c31 9545 yes = false;
301ad80a 9546
9a659715
PG
9547 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9548 argv_find(argv, argc, "route-target6", &idx_unused))
c6423c31 9549 rt6 = true;
301ad80a 9550
0ca70ba5 9551 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9552 if (afi == AFI_MAX)
9553 return CMD_WARNING_CONFIG_FAILED;
9554
9a659715
PG
9555 if (rt6 && afi != AFI_IP6)
9556 return CMD_WARNING_CONFIG_FAILED;
9557
301ad80a
PG
9558 if (yes) {
9559 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9560 vty_out(vty, "%% Missing RTLIST\n");
9561 return CMD_WARNING_CONFIG_FAILED;
9562 }
9a659715 9563 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
301ad80a
PG
9564 if (ret != CMD_SUCCESS)
9565 return ret;
9566 }
69b07479
DS
9567
9568 if (yes) {
9569 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9570 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9571 .import_redirect_rtlist);
69b07479
DS
9572 bgp->vpn_policy[afi].import_redirect_rtlist =
9573 ecommunity_dup(ecom);
9574 } else {
9575 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9576 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9577 .import_redirect_rtlist);
69b07479 9578 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 9579 }
69b07479 9580
301ad80a
PG
9581 if (ecom)
9582 ecommunity_free(&ecom);
9583
9584 return CMD_SUCCESS;
9585}
9586
37a87b8f
CS
9587void cli_show_bgp_global_afi_safi_header(struct vty *vty,
9588 struct lyd_node *dnode,
9589 bool show_defaults)
9590{
9591 const char *af_name;
9592 afi_t afi;
9593 safi_t safi;
9594
9595 af_name = yang_dnode_get_string(dnode, "./afi-safi-name");
9596 yang_afi_safi_identity2value(af_name, &afi, &safi);
9597
9598 vty_out(vty, " !\n address-family ");
9599 if (afi == AFI_IP) {
9600 if (safi == SAFI_UNICAST)
9601 vty_out(vty, "ipv4 unicast");
9602 else if (safi == SAFI_LABELED_UNICAST)
9603 vty_out(vty, "ipv4 labeled-unicast");
9604 else if (safi == SAFI_MULTICAST)
9605 vty_out(vty, "ipv4 multicast");
9606 else if (safi == SAFI_MPLS_VPN)
9607 vty_out(vty, "ipv4 vpn");
9608 else if (safi == SAFI_ENCAP)
9609 vty_out(vty, "ipv4 encap");
9610 else if (safi == SAFI_FLOWSPEC)
9611 vty_out(vty, "ipv4 flowspec");
9612 } else if (afi == AFI_IP6) {
9613 if (safi == SAFI_UNICAST)
9614 vty_out(vty, "ipv6 unicast");
9615 else if (safi == SAFI_LABELED_UNICAST)
9616 vty_out(vty, "ipv6 labeled-unicast");
9617 else if (safi == SAFI_MULTICAST)
9618 vty_out(vty, "ipv6 multicast");
9619 else if (safi == SAFI_MPLS_VPN)
9620 vty_out(vty, "ipv6 vpn");
9621 else if (safi == SAFI_ENCAP)
9622 vty_out(vty, "ipv6 encap");
9623 else if (safi == SAFI_FLOWSPEC)
9624 vty_out(vty, "ipv6 flowspec");
9625 } else if (afi == AFI_L2VPN) {
9626 if (safi == SAFI_EVPN)
9627 vty_out(vty, "l2vpn evpn");
9628 }
9629 vty_out(vty, "\n");
9630}
9631
505e5056 9632DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 9633 address_family_ipv4_safi_cmd,
9634 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9635 "Enter Address Family command mode\n"
9636 "Address Family\n"
9637 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 9638{
f51bae9c 9639
37a87b8f
CS
9640 safi_t safi = SAFI_UNICAST;
9641 const struct lyd_node *vrf_dnode, *bgp_glb_dnode;
9642 const char *vrf_name = NULL;
9643
d62a17ae 9644 if (argc == 3) {
37a87b8f
CS
9645 safi = bgp_vty_safi_from_str(argv[2]->text);
9646
9647 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
9648 VTY_CURR_XPATH);
9649 vrf_dnode = yang_dnode_get_parent(bgp_glb_dnode,
9650 "control-plane-protocol");
9651 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
9652
9653 if (!strmatch(vrf_name, VRF_DEFAULT_NAME)
a4d82a8a 9654 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9655 && safi != SAFI_EVPN) {
31947174
MK
9656 vty_out(vty,
9657 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9658 return CMD_WARNING_CONFIG_FAILED;
9659 }
37a87b8f
CS
9660 }
9661 vty->node = bgp_node_type(AFI_IP, safi);
718e3744 9662
d62a17ae 9663 return CMD_SUCCESS;
718e3744 9664}
9665
505e5056 9666DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 9667 address_family_ipv6_safi_cmd,
9668 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9669 "Enter Address Family command mode\n"
9670 "Address Family\n"
9671 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 9672{
37a87b8f
CS
9673 safi_t safi = SAFI_UNICAST;
9674 const struct lyd_node *vrf_dnode, *bgp_glb_dnode;
9675 const char *vrf_name = NULL;
9676
d62a17ae 9677 if (argc == 3) {
37a87b8f
CS
9678 safi = bgp_vty_safi_from_str(argv[2]->text);
9679 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
9680 VTY_CURR_XPATH);
9681 vrf_dnode = yang_dnode_get_parent(bgp_glb_dnode,
9682 "control-plane-protocol");
9683 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
9684
9685 if (!strmatch(vrf_name, VRF_DEFAULT_NAME)
a4d82a8a 9686 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9687 && safi != SAFI_EVPN) {
31947174
MK
9688 vty_out(vty,
9689 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9690 return CMD_WARNING_CONFIG_FAILED;
9691 }
37a87b8f
CS
9692 }
9693 vty->node = bgp_node_type(AFI_IP6, safi);
25ffbdc1 9694
d62a17ae 9695 return CMD_SUCCESS;
25ffbdc1 9696}
718e3744 9697
d6902373 9698#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 9699DEFUN_NOSH (address_family_vpnv4,
718e3744 9700 address_family_vpnv4_cmd,
8334fd5a 9701 "address-family vpnv4 [unicast]",
718e3744 9702 "Enter Address Family command mode\n"
8c3deaae 9703 "Address Family\n"
3a2d747c 9704 "Address Family modifier\n")
718e3744 9705{
d62a17ae 9706 vty->node = BGP_VPNV4_NODE;
9707 return CMD_SUCCESS;
718e3744 9708}
9709
505e5056 9710DEFUN_NOSH (address_family_vpnv6,
8ecd3266 9711 address_family_vpnv6_cmd,
8334fd5a 9712 "address-family vpnv6 [unicast]",
8ecd3266 9713 "Enter Address Family command mode\n"
8c3deaae 9714 "Address Family\n"
3a2d747c 9715 "Address Family modifier\n")
8ecd3266 9716{
d62a17ae 9717 vty->node = BGP_VPNV6_NODE;
9718 return CMD_SUCCESS;
8ecd3266 9719}
64e4a6c5 9720#endif /* KEEP_OLD_VPN_COMMANDS */
d6902373 9721
505e5056 9722DEFUN_NOSH (address_family_evpn,
4e0b7b6d 9723 address_family_evpn_cmd,
7111c1a0 9724 "address-family l2vpn evpn",
4e0b7b6d 9725 "Enter Address Family command mode\n"
7111c1a0
QY
9726 "Address Family\n"
9727 "Address Family modifier\n")
4e0b7b6d 9728{
2131d5cf 9729 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 9730 vty->node = BGP_EVPN_NODE;
9731 return CMD_SUCCESS;
4e0b7b6d
PG
9732}
9733
505e5056 9734DEFUN_NOSH (exit_address_family,
718e3744 9735 exit_address_family_cmd,
9736 "exit-address-family",
9737 "Exit from Address Family configuration mode\n")
9738{
d62a17ae 9739 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9740 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9741 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9742 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
9743 || vty->node == BGP_EVPN_NODE
9744 || vty->node == BGP_FLOWSPECV4_NODE
9745 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 9746 vty->node = BGP_NODE;
9747 return CMD_SUCCESS;
718e3744 9748}
6b0655a2 9749
37a87b8f
CS
9750void cli_show_bgp_global_afi_safi_header_end(struct vty *vty,
9751 struct lyd_node *dnode
9752 __attribute__((__unused__)))
9753{
9754 vty_out(vty, " exit-address-family\n");
9755}
9756
8ad7271d 9757/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 9758static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9759 const char *ip_str, afi_t afi, safi_t safi,
9760 struct prefix_rd *prd)
9761{
9762 int ret;
9763 struct prefix match;
9bcb3eef
DS
9764 struct bgp_dest *dest;
9765 struct bgp_dest *rm;
d62a17ae 9766 struct bgp *bgp;
9767 struct bgp_table *table;
9768 struct bgp_table *rib;
9769
9770 /* BGP structure lookup. */
9771 if (view_name) {
9772 bgp = bgp_lookup_by_name(view_name);
9773 if (bgp == NULL) {
9774 vty_out(vty, "%% Can't find BGP instance %s\n",
9775 view_name);
9776 return CMD_WARNING;
9777 }
9778 } else {
9779 bgp = bgp_get_default();
9780 if (bgp == NULL) {
9781 vty_out(vty, "%% No BGP process is configured\n");
9782 return CMD_WARNING;
9783 }
9784 }
9785
9786 /* Check IP address argument. */
9787 ret = str2prefix(ip_str, &match);
9788 if (!ret) {
9789 vty_out(vty, "%% address is malformed\n");
9790 return CMD_WARNING;
9791 }
9792
9793 match.family = afi2family(afi);
9794 rib = bgp->rib[afi][safi];
9795
9796 if (safi == SAFI_MPLS_VPN) {
9bcb3eef
DS
9797 for (dest = bgp_table_top(rib); dest;
9798 dest = bgp_route_next(dest)) {
9799 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 9800
9bcb3eef 9801 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
d62a17ae 9802 continue;
9803
9bcb3eef 9804 table = bgp_dest_get_bgp_table_info(dest);
b54892e0
DS
9805 if (table == NULL)
9806 continue;
9807
9808 if ((rm = bgp_node_match(table, &match)) != NULL) {
9809 const struct prefix *rm_p =
9bcb3eef 9810 bgp_dest_get_prefix(rm);
b54892e0
DS
9811
9812 if (rm_p->prefixlen == match.prefixlen) {
9813 SET_FLAG(rm->flags,
9814 BGP_NODE_USER_CLEAR);
9815 bgp_process(bgp, rm, afi, safi);
d62a17ae 9816 }
9bcb3eef 9817 bgp_dest_unlock_node(rm);
d62a17ae 9818 }
9819 }
9820 } else {
9bcb3eef
DS
9821 if ((dest = bgp_node_match(rib, &match)) != NULL) {
9822 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 9823
9bcb3eef
DS
9824 if (dest_p->prefixlen == match.prefixlen) {
9825 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
9826 bgp_process(bgp, dest, afi, safi);
d62a17ae 9827 }
9bcb3eef 9828 bgp_dest_unlock_node(dest);
d62a17ae 9829 }
9830 }
9831
9832 return CMD_SUCCESS;
8ad7271d
DS
9833}
9834
b09b5ae0 9835/* one clear bgp command to rule them all */
718e3744 9836DEFUN (clear_ip_bgp_all,
9837 clear_ip_bgp_all_cmd,
453c92f6 9838 "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 9839 CLEAR_STR
9840 IP_STR
9841 BGP_STR
838758ac 9842 BGP_INSTANCE_HELP_STR
510afcd6 9843 BGP_AFI_HELP_STR
fd5e7b70 9844 "Address Family\n"
510afcd6 9845 BGP_SAFI_WITH_LABEL_HELP_STR
fd5e7b70 9846 "Address Family modifier\n"
b09b5ae0 9847 "Clear all peers\n"
453c92f6 9848 "BGP IPv4 neighbor to clear\n"
a80beece 9849 "BGP IPv6 neighbor to clear\n"
838758ac 9850 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
9851 "Clear peers with the AS number\n"
9852 "Clear all external peers\n"
718e3744 9853 "Clear all members of peer-group\n"
b09b5ae0 9854 "BGP peer-group name\n"
b09b5ae0
DW
9855 BGP_SOFT_STR
9856 BGP_SOFT_IN_STR
b09b5ae0
DW
9857 BGP_SOFT_OUT_STR
9858 BGP_SOFT_IN_STR
9859 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 9860 BGP_SOFT_OUT_STR)
718e3744 9861{
d62a17ae 9862 char *vrf = NULL;
9863
dc912615
DS
9864 afi_t afi = AFI_UNSPEC;
9865 safi_t safi = SAFI_UNSPEC;
d62a17ae 9866 enum clear_sort clr_sort = clear_peer;
9867 enum bgp_clear_type clr_type;
9868 char *clr_arg = NULL;
9869
9870 int idx = 0;
ff8a8a7a
CS
9871 char errmsg[BUFSIZ] = {'\0'};
9872 int ret;
d62a17ae 9873
9874 /* clear [ip] bgp */
9875 if (argv_find(argv, argc, "ip", &idx))
9876 afi = AFI_IP;
9877
9a8bdf1c
PG
9878 /* [<vrf> VIEWVRFNAME] */
9879 if (argv_find(argv, argc, "vrf", &idx)) {
9880 vrf = argv[idx + 1]->arg;
9881 idx += 2;
9882 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9883 vrf = NULL;
9884 } else if (argv_find(argv, argc, "view", &idx)) {
9885 /* [<view> VIEWVRFNAME] */
d62a17ae 9886 vrf = argv[idx + 1]->arg;
9887 idx += 2;
9888 }
d62a17ae 9889 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9890 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
9891 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9892
d7b9898c 9893 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
d62a17ae 9894 if (argv_find(argv, argc, "*", &idx)) {
9895 clr_sort = clear_all;
9896 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
9897 clr_sort = clear_peer;
9898 clr_arg = argv[idx]->arg;
9899 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
9900 clr_sort = clear_peer;
9901 clr_arg = argv[idx]->arg;
9902 } else if (argv_find(argv, argc, "peer-group", &idx)) {
9903 clr_sort = clear_group;
9904 idx++;
9905 clr_arg = argv[idx]->arg;
d7b9898c 9906 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
d62a17ae 9907 clr_sort = clear_peer;
9908 clr_arg = argv[idx]->arg;
8fa7d444
DS
9909 } else if (argv_find(argv, argc, "WORD", &idx)) {
9910 clr_sort = clear_peer;
9911 clr_arg = argv[idx]->arg;
d62a17ae 9912 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
9913 clr_sort = clear_as;
9914 clr_arg = argv[idx]->arg;
9915 } else if (argv_find(argv, argc, "external", &idx)) {
9916 clr_sort = clear_external;
9917 }
9918
9919 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
9920 if (argv_find(argv, argc, "soft", &idx)) {
9921 if (argv_find(argv, argc, "in", &idx)
9922 || argv_find(argv, argc, "out", &idx))
9923 clr_type = strmatch(argv[idx]->text, "in")
9924 ? BGP_CLEAR_SOFT_IN
9925 : BGP_CLEAR_SOFT_OUT;
9926 else
9927 clr_type = BGP_CLEAR_SOFT_BOTH;
9928 } else if (argv_find(argv, argc, "in", &idx)) {
9929 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
9930 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
9931 : BGP_CLEAR_SOFT_IN;
9932 } else if (argv_find(argv, argc, "out", &idx)) {
9933 clr_type = BGP_CLEAR_SOFT_OUT;
9934 } else
9935 clr_type = BGP_CLEAR_SOFT_NONE;
9936
ff8a8a7a
CS
9937 ret = bgp_clear_vty(vrf, afi, safi, clr_sort, clr_type, clr_arg, errmsg,
9938 sizeof(errmsg));
9939 if (ret != NB_OK)
9940 vty_out(vty, "Error description: %s\n", errmsg);
9941
9942 return ret;
838758ac 9943}
01080f7c 9944
8ad7271d
DS
9945DEFUN (clear_ip_bgp_prefix,
9946 clear_ip_bgp_prefix_cmd,
18c57037 9947 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
9948 CLEAR_STR
9949 IP_STR
9950 BGP_STR
838758ac 9951 BGP_INSTANCE_HELP_STR
8ad7271d 9952 "Clear bestpath and re-advertise\n"
0c7b1b01 9953 "IPv4 prefix\n")
8ad7271d 9954{
d62a17ae 9955 char *vrf = NULL;
9956 char *prefix = NULL;
8ad7271d 9957
d62a17ae 9958 int idx = 0;
01080f7c 9959
d62a17ae 9960 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
9961 if (argv_find(argv, argc, "vrf", &idx)) {
9962 vrf = argv[idx + 1]->arg;
9963 idx += 2;
9964 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9965 vrf = NULL;
9966 } else if (argv_find(argv, argc, "view", &idx)) {
9967 /* [<view> VIEWVRFNAME] */
9968 vrf = argv[idx + 1]->arg;
9969 idx += 2;
9970 }
0c7b1b01 9971
d62a17ae 9972 prefix = argv[argc - 1]->arg;
8ad7271d 9973
d62a17ae 9974 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 9975}
8ad7271d 9976
b09b5ae0
DW
9977DEFUN (clear_bgp_ipv6_safi_prefix,
9978 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 9979 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 9980 CLEAR_STR
3a2d747c 9981 IP_STR
718e3744 9982 BGP_STR
8c3deaae 9983 "Address Family\n"
46f296b4 9984 BGP_SAFI_HELP_STR
b09b5ae0 9985 "Clear bestpath and re-advertise\n"
0c7b1b01 9986 "IPv6 prefix\n")
718e3744 9987{
9b475e76
PG
9988 int idx_safi = 0;
9989 int idx_ipv6_prefix = 0;
9990 safi_t safi = SAFI_UNICAST;
9991 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9992 argv[idx_ipv6_prefix]->arg : NULL;
9993
9994 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 9995 return bgp_clear_prefix(
9b475e76
PG
9996 vty, NULL, prefix, AFI_IP6,
9997 safi, NULL);
838758ac 9998}
01080f7c 9999
b09b5ae0
DW
10000DEFUN (clear_bgp_instance_ipv6_safi_prefix,
10001 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 10002 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 10003 CLEAR_STR
3a2d747c 10004 IP_STR
718e3744 10005 BGP_STR
838758ac 10006 BGP_INSTANCE_HELP_STR
8c3deaae 10007 "Address Family\n"
46f296b4 10008 BGP_SAFI_HELP_STR
b09b5ae0 10009 "Clear bestpath and re-advertise\n"
0c7b1b01 10010 "IPv6 prefix\n")
718e3744 10011{
9b475e76 10012 int idx_safi = 0;
9a8bdf1c 10013 int idx_vrfview = 0;
9b475e76
PG
10014 int idx_ipv6_prefix = 0;
10015 safi_t safi = SAFI_UNICAST;
10016 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10017 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 10018 char *vrfview = NULL;
9b475e76 10019
9a8bdf1c
PG
10020 /* [<view|vrf> VIEWVRFNAME] */
10021 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
10022 vrfview = argv[idx_vrfview + 1]->arg;
10023 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
10024 vrfview = NULL;
10025 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
10026 /* [<view> VIEWVRFNAME] */
10027 vrfview = argv[idx_vrfview + 1]->arg;
10028 }
9b475e76
PG
10029 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10030
d62a17ae 10031 return bgp_clear_prefix(
9b475e76
PG
10032 vty, vrfview, prefix,
10033 AFI_IP6, safi, NULL);
718e3744 10034}
10035
b09b5ae0
DW
10036DEFUN (show_bgp_views,
10037 show_bgp_views_cmd,
d6e3c605 10038 "show [ip] bgp views",
b09b5ae0 10039 SHOW_STR
d6e3c605 10040 IP_STR
01080f7c 10041 BGP_STR
b09b5ae0 10042 "Show the defined BGP views\n")
01080f7c 10043{
d62a17ae 10044 struct list *inst = bm->bgp;
10045 struct listnode *node;
10046 struct bgp *bgp;
01080f7c 10047
d62a17ae 10048 vty_out(vty, "Defined BGP views:\n");
10049 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10050 /* Skip VRFs. */
10051 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
10052 continue;
10053 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
10054 bgp->as);
10055 }
e52702f2 10056
d62a17ae 10057 return CMD_SUCCESS;
e0081f70
ML
10058}
10059
8386ac43 10060DEFUN (show_bgp_vrfs,
10061 show_bgp_vrfs_cmd,
d6e3c605 10062 "show [ip] bgp vrfs [json]",
8386ac43 10063 SHOW_STR
d6e3c605 10064 IP_STR
8386ac43 10065 BGP_STR
10066 "Show BGP VRFs\n"
9973d184 10067 JSON_STR)
8386ac43 10068{
fe1dc5a3 10069 char buf[ETHER_ADDR_STRLEN];
d62a17ae 10070 struct list *inst = bm->bgp;
10071 struct listnode *node;
10072 struct bgp *bgp;
9f049418 10073 bool uj = use_json(argc, argv);
d62a17ae 10074 json_object *json = NULL;
10075 json_object *json_vrfs = NULL;
10076 int count = 0;
d62a17ae 10077
d62a17ae 10078 if (uj) {
10079 json = json_object_new_object();
10080 json_vrfs = json_object_new_object();
10081 }
10082
10083 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10084 const char *name, *type;
10085 struct peer *peer;
7fe96307 10086 struct listnode *node2, *nnode2;
d62a17ae 10087 int peers_cfg, peers_estb;
10088 json_object *json_vrf = NULL;
d62a17ae 10089
10090 /* Skip Views. */
10091 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
10092 continue;
10093
10094 count++;
efb4077a 10095 if (!uj && count == 1) {
fe1dc5a3 10096 vty_out(vty,
efb4077a 10097 "%4s %-5s %-16s %9s %10s %-37s\n",
3c0e7aa4 10098 "Type", "Id", "routerId", "#PeersCfg",
efb4077a
CS
10099 "#PeersEstb", "Name");
10100 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
10101 "L3-VNI", "RouterMAC", "Interface");
10102 }
d62a17ae 10103
10104 peers_cfg = peers_estb = 0;
10105 if (uj)
10106 json_vrf = json_object_new_object();
10107
10108
7fe96307 10109 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
d62a17ae 10110 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10111 continue;
10112 peers_cfg++;
10113 if (peer->status == Established)
10114 peers_estb++;
10115 }
10116
10117 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
5742e42b 10118 name = VRF_DEFAULT_NAME;
d62a17ae 10119 type = "DFLT";
10120 } else {
10121 name = bgp->name;
10122 type = "VRF";
10123 }
10124
a8bf7d9c 10125
d62a17ae 10126 if (uj) {
a4d82a8a
PZ
10127 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10128 ? -1
10129 : (int64_t)bgp->vrf_id;
23d0a753
DA
10130 char buf[BUFSIZ] = {0};
10131
d62a17ae 10132 json_object_string_add(json_vrf, "type", type);
10133 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
10134 json_object_string_add(json_vrf, "routerId",
23d0a753
DA
10135 inet_ntop(AF_INET,
10136 &bgp->router_id, buf,
10137 sizeof(buf)));
d62a17ae 10138 json_object_int_add(json_vrf, "numConfiguredPeers",
10139 peers_cfg);
10140 json_object_int_add(json_vrf, "numEstablishedPeers",
10141 peers_estb);
10142
fe1dc5a3 10143 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
10144 json_object_string_add(
10145 json_vrf, "rmac",
10146 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
efb4077a
CS
10147 json_object_string_add(json_vrf, "interface",
10148 ifindex2ifname(bgp->l3vni_svi_ifindex,
10149 bgp->vrf_id));
d62a17ae 10150 json_object_object_add(json_vrfs, name, json_vrf);
efb4077a 10151 } else {
23d0a753 10152 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
a4d82a8a
PZ
10153 type,
10154 bgp->vrf_id == VRF_UNKNOWN ? -1
10155 : (int)bgp->vrf_id,
23d0a753 10156 &bgp->router_id, peers_cfg, peers_estb, name);
efb4077a
CS
10157 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
10158 bgp->l3vni,
10159 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
10160 ifindex2ifname(bgp->l3vni_svi_ifindex,
10161 bgp->vrf_id));
10162 }
d62a17ae 10163 }
10164
10165 if (uj) {
10166 json_object_object_add(json, "vrfs", json_vrfs);
10167
10168 json_object_int_add(json, "totalVrfs", count);
10169
996c9314
LB
10170 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10171 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 10172 json_object_free(json);
10173 } else {
10174 if (count)
10175 vty_out(vty,
10176 "\nTotal number of VRFs (including default): %d\n",
10177 count);
10178 }
10179
10180 return CMD_SUCCESS;
8386ac43 10181}
10182
48ecf8f5
DS
10183DEFUN (show_bgp_mac_hash,
10184 show_bgp_mac_hash_cmd,
10185 "show bgp mac hash",
10186 SHOW_STR
10187 BGP_STR
10188 "Mac Address\n"
10189 "Mac Address database\n")
10190{
10191 bgp_mac_dump_table(vty);
10192
10193 return CMD_SUCCESS;
10194}
acf71666 10195
e3b78da8 10196static void show_tip_entry(struct hash_bucket *bucket, void *args)
acf71666 10197{
0291c246 10198 struct vty *vty = (struct vty *)args;
e3b78da8 10199 struct tip_addr *tip = (struct tip_addr *)bucket->data;
acf71666 10200
23d0a753 10201 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
acf71666
MK
10202}
10203
10204static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10205{
10206 vty_out(vty, "self nexthop database:\n");
af97a18b 10207 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
10208
10209 vty_out(vty, "Tunnel-ip database:\n");
10210 hash_iterate(bgp->tip_hash,
e3b78da8 10211 (void (*)(struct hash_bucket *, void *))show_tip_entry,
acf71666
MK
10212 vty);
10213}
10214
15c81ca4
DS
10215DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10216 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10217 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
10218 "martian next-hops\n"
10219 "martian next-hop database\n")
acf71666 10220{
0291c246 10221 struct bgp *bgp = NULL;
15c81ca4 10222 int idx = 0;
9a8bdf1c
PG
10223 char *name = NULL;
10224
10225 /* [<vrf> VIEWVRFNAME] */
10226 if (argv_find(argv, argc, "vrf", &idx)) {
10227 name = argv[idx + 1]->arg;
10228 if (name && strmatch(name, VRF_DEFAULT_NAME))
10229 name = NULL;
10230 } else if (argv_find(argv, argc, "view", &idx))
10231 /* [<view> VIEWVRFNAME] */
10232 name = argv[idx + 1]->arg;
10233 if (name)
10234 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
10235 else
10236 bgp = bgp_get_default();
acf71666 10237
acf71666
MK
10238 if (!bgp) {
10239 vty_out(vty, "%% No BGP process is configured\n");
10240 return CMD_WARNING;
10241 }
10242 bgp_show_martian_nexthops(vty, bgp);
10243
10244 return CMD_SUCCESS;
10245}
10246
f412b39a 10247DEFUN (show_bgp_memory,
4bf6a362 10248 show_bgp_memory_cmd,
7fa12b13 10249 "show [ip] bgp memory",
4bf6a362 10250 SHOW_STR
3a2d747c 10251 IP_STR
4bf6a362
PJ
10252 BGP_STR
10253 "Global BGP memory statistics\n")
10254{
d62a17ae 10255 char memstrbuf[MTYPE_MEMSTR_LEN];
10256 unsigned long count;
10257
10258 /* RIB related usage stats */
10259 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10260 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10261 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9bcb3eef 10262 count * sizeof(struct bgp_dest)));
d62a17ae 10263
10264 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10265 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10266 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 10267 count * sizeof(struct bgp_path_info)));
d62a17ae 10268 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10269 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10270 count,
4b7e6066
DS
10271 mtype_memstr(
10272 memstrbuf, sizeof(memstrbuf),
10273 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 10274
10275 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10276 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10277 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10278 count * sizeof(struct bgp_static)));
10279
10280 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10281 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10282 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10283 count * sizeof(struct bpacket)));
10284
10285 /* Adj-In/Out */
10286 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10287 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10288 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10289 count * sizeof(struct bgp_adj_in)));
10290 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10291 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10292 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10293 count * sizeof(struct bgp_adj_out)));
10294
10295 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10296 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10297 count,
10298 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10299 count * sizeof(struct bgp_nexthop_cache)));
10300
10301 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10302 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10303 count,
10304 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10305 count * sizeof(struct bgp_damp_info)));
10306
10307 /* Attributes */
10308 count = attr_count();
10309 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10310 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10311 count * sizeof(struct attr)));
10312
10313 if ((count = attr_unknown_count()))
10314 vty_out(vty, "%ld unknown attributes\n", count);
10315
10316 /* AS_PATH attributes */
10317 count = aspath_count();
10318 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10319 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10320 count * sizeof(struct aspath)));
10321
10322 count = mtype_stats_alloc(MTYPE_AS_SEG);
10323 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10324 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10325 count * sizeof(struct assegment)));
10326
10327 /* Other attributes */
10328 if ((count = community_count()))
10329 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
10330 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10331 count * sizeof(struct community)));
d62a17ae 10332 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
10333 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
10334 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10335 count * sizeof(struct ecommunity)));
d62a17ae 10336 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10337 vty_out(vty,
10338 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
10339 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10340 count * sizeof(struct lcommunity)));
d62a17ae 10341
10342 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10343 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10344 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10345 count * sizeof(struct cluster_list)));
10346
10347 /* Peer related usage */
10348 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10349 vty_out(vty, "%ld peers, using %s of memory\n", count,
10350 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10351 count * sizeof(struct peer)));
10352
10353 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10354 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10355 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10356 count * sizeof(struct peer_group)));
10357
10358 /* Other */
d62a17ae 10359 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10360 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
10361 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10362 count * sizeof(regex_t)));
d62a17ae 10363 return CMD_SUCCESS;
4bf6a362 10364}
fee0f4c6 10365
57a9c8a8
DS
10366static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10367{
10368 json_object *bestpath = json_object_new_object();
10369
892fedb6 10370 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
57a9c8a8
DS
10371 json_object_string_add(bestpath, "asPath", "ignore");
10372
892fedb6 10373 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
57a9c8a8
DS
10374 json_object_string_add(bestpath, "asPath", "confed");
10375
892fedb6
DA
10376 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10377 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
a4d82a8a 10378 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
10379 "as-set");
10380 else
a4d82a8a 10381 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
10382 "true");
10383 } else
a4d82a8a 10384 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8 10385
892fedb6 10386 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
57a9c8a8 10387 json_object_string_add(bestpath, "compareRouterId", "true");
892fedb6
DA
10388 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10389 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10390 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
a4d82a8a 10391 json_object_string_add(bestpath, "med", "confed");
892fedb6 10392 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
57a9c8a8
DS
10393 json_object_string_add(bestpath, "med",
10394 "missing-as-worst");
10395 else
10396 json_object_string_add(bestpath, "med", "true");
10397 }
10398
10399 json_object_object_add(json, "bestPath", bestpath);
10400}
10401
3577f1c5
DD
10402/* Print the error code/subcode for why the peer is down */
10403static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10404 json_object *json_peer, bool use_json)
10405{
10406 const char *code_str;
10407 const char *subcode_str;
10408
10409 if (use_json) {
10410 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10411 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10412 char errorcodesubcode_hexstr[5];
10413 char errorcodesubcode_str[256];
10414
10415 code_str = bgp_notify_code_str(peer->notify.code);
10416 subcode_str = bgp_notify_subcode_str(
10417 peer->notify.code,
10418 peer->notify.subcode);
10419
772270f3
QY
10420 snprintf(errorcodesubcode_hexstr,
10421 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10422 peer->notify.code, peer->notify.subcode);
3577f1c5
DD
10423 json_object_string_add(json_peer,
10424 "lastErrorCodeSubcode",
10425 errorcodesubcode_hexstr);
10426 snprintf(errorcodesubcode_str, 255, "%s%s",
10427 code_str, subcode_str);
10428 json_object_string_add(json_peer,
10429 "lastNotificationReason",
10430 errorcodesubcode_str);
10431 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10432 && peer->notify.code == BGP_NOTIFY_CEASE
10433 && (peer->notify.subcode
10434 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10435 || peer->notify.subcode
10436 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10437 && peer->notify.length) {
10438 char msgbuf[1024];
10439 const char *msg_str;
10440
10441 msg_str = bgp_notify_admin_message(
10442 msgbuf, sizeof(msgbuf),
10443 (uint8_t *)peer->notify.data,
10444 peer->notify.length);
10445 if (msg_str)
10446 json_object_string_add(
10447 json_peer,
10448 "lastShutdownDescription",
10449 msg_str);
10450 }
10451
c258527b 10452 }
3577f1c5
DD
10453 json_object_string_add(json_peer, "lastResetDueTo",
10454 peer_down_str[(int)peer->last_reset]);
05912a17
DD
10455 json_object_int_add(json_peer, "lastResetCode",
10456 peer->last_reset);
3577f1c5
DD
10457 } else {
10458 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10459 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10460 code_str = bgp_notify_code_str(peer->notify.code);
10461 subcode_str =
10462 bgp_notify_subcode_str(peer->notify.code,
10463 peer->notify.subcode);
10464 vty_out(vty, " Notification %s (%s%s)\n",
10465 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10466 ? "sent"
10467 : "received",
10468 code_str, subcode_str);
10469 } else {
e91c24c8 10470 vty_out(vty, " %s\n",
3577f1c5
DD
10471 peer_down_str[(int)peer->last_reset]);
10472 }
10473 }
10474}
10475
10476static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10477 safi_t safi)
10478{
10479 return ((peer->status != Established) ||
10480 !peer->afc_recv[afi][safi]);
10481}
10482
10483static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10484 struct peer *peer, json_object *json_peer,
10485 int max_neighbor_width, bool use_json)
10486{
10487 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10488 int len;
10489
10490 if (use_json) {
10491 if (peer_dynamic_neighbor(peer))
10492 json_object_boolean_true_add(json_peer,
10493 "dynamicPeer");
10494 if (peer->hostname)
10495 json_object_string_add(json_peer, "hostname",
10496 peer->hostname);
10497
10498 if (peer->domainname)
10499 json_object_string_add(json_peer, "domainname",
10500 peer->domainname);
10501 json_object_int_add(json_peer, "connectionsEstablished",
10502 peer->established);
10503 json_object_int_add(json_peer, "connectionsDropped",
10504 peer->dropped);
10505 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10506 use_json, json_peer);
10507 if (peer->status == Established)
10508 json_object_string_add(json_peer, "lastResetDueTo",
10509 "AFI/SAFI Not Negotiated");
10510 else
10511 bgp_show_peer_reset(NULL, peer, json_peer, true);
10512 } else {
10513 dn_flag[1] = '\0';
10514 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10515 if (peer->hostname
892fedb6 10516 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
3577f1c5
DD
10517 len = vty_out(vty, "%s%s(%s)", dn_flag,
10518 peer->hostname, peer->host);
10519 else
10520 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10521
10522 /* pad the neighbor column with spaces */
10523 if (len < max_neighbor_width)
10524 vty_out(vty, "%*s", max_neighbor_width - len,
10525 " ");
e91c24c8 10526 vty_out(vty, "%7d %7d %9s", peer->established,
3577f1c5
DD
10527 peer->dropped,
10528 peer_uptime(peer->uptime, timebuf,
10529 BGP_UPTIME_LEN, 0, NULL));
10530 if (peer->status == Established)
10531 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10532 else
10533 bgp_show_peer_reset(vty, peer, NULL,
10534 false);
10535 }
10536}
c258527b 10537
cb75bb31
DA
10538/* If the peer's description includes whitespaces
10539 * then return the first occurrence. Also strip description
10540 * to the given size if needed.
10541 */
10542static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10543{
10544 static char stripped[BUFSIZ];
10545 char *pnt;
10546 uint32_t len = size > strlen(desc) ? strlen(desc) : size;
10547
10548 pnt = strchr(desc, ' ');
10549 if (pnt)
10550 len = size > (uint32_t)(pnt - desc) ? (uint32_t)(pnt - desc)
10551 : size;
10552
10553 strlcpy(stripped, desc, len + 1);
10554
10555 return stripped;
10556}
3577f1c5 10557
718e3744 10558/* Show BGP peer's summary information. */
d62a17ae 10559static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
85eeb029 10560 uint8_t show_flags)
d62a17ae 10561{
10562 struct peer *peer;
10563 struct listnode *node, *nnode;
10564 unsigned int count = 0, dn_count = 0;
10565 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10566 char neighbor_buf[VTY_BUFSIZ];
10567 int neighbor_col_default_width = 16;
3577f1c5 10568 int len, failed_count = 0;
d62a17ae 10569 int max_neighbor_width = 0;
10570 int pfx_rcd_safi;
3c13337d 10571 json_object *json = NULL;
d62a17ae 10572 json_object *json_peer = NULL;
10573 json_object *json_peers = NULL;
50e05855 10574 struct peer_af *paf;
d3ada366 10575 struct bgp_filter *filter;
85eeb029
DA
10576 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10577 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10578 bool show_established =
10579 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10580 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
d62a17ae 10581
10582 /* labeled-unicast routes are installed in the unicast table so in order
10583 * to
10584 * display the correct PfxRcd value we must look at SAFI_UNICAST
10585 */
3577f1c5 10586
d62a17ae 10587 if (safi == SAFI_LABELED_UNICAST)
10588 pfx_rcd_safi = SAFI_UNICAST;
10589 else
10590 pfx_rcd_safi = safi;
10591
10592 if (use_json) {
3c13337d 10593 json = json_object_new_object();
d62a17ae 10594 json_peers = json_object_new_object();
3577f1c5
DD
10595 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10596 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10597 continue;
10598
10599 if (peer->afc[afi][safi]) {
10600 /* See if we have at least a single failed peer */
10601 if (bgp_has_peer_failed(peer, afi, safi))
10602 failed_count++;
10603 count++;
10604 }
10605 if (peer_dynamic_neighbor(peer))
10606 dn_count++;
10607 }
c258527b 10608
d62a17ae 10609 } else {
10610 /* Loop over all neighbors that will be displayed to determine
10611 * how many
10612 * characters are needed for the Neighbor column
10613 */
10614 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10615 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10616 continue;
10617
10618 if (peer->afc[afi][safi]) {
10619 memset(dn_flag, '\0', sizeof(dn_flag));
10620 if (peer_dynamic_neighbor(peer))
10621 dn_flag[0] = '*';
10622
10623 if (peer->hostname
892fedb6
DA
10624 && CHECK_FLAG(bgp->flags,
10625 BGP_FLAG_SHOW_HOSTNAME))
772270f3
QY
10626 snprintf(neighbor_buf,
10627 sizeof(neighbor_buf),
10628 "%s%s(%s) ", dn_flag,
10629 peer->hostname, peer->host);
d62a17ae 10630 else
772270f3
QY
10631 snprintf(neighbor_buf,
10632 sizeof(neighbor_buf), "%s%s ",
10633 dn_flag, peer->host);
d62a17ae 10634
10635 len = strlen(neighbor_buf);
10636
10637 if (len > max_neighbor_width)
10638 max_neighbor_width = len;
c258527b 10639
3577f1c5
DD
10640 /* See if we have at least a single failed peer */
10641 if (bgp_has_peer_failed(peer, afi, safi))
10642 failed_count++;
10643 count++;
d62a17ae 10644 }
10645 }
f933309e 10646
d62a17ae 10647 /* Originally we displayed the Neighbor column as 16
10648 * characters wide so make that the default
10649 */
10650 if (max_neighbor_width < neighbor_col_default_width)
10651 max_neighbor_width = neighbor_col_default_width;
10652 }
f933309e 10653
3577f1c5
DD
10654 if (show_failed && !failed_count) {
10655 if (use_json) {
10656 json_object_int_add(json, "failedPeersCount", 0);
10657 json_object_int_add(json, "dynamicPeers", dn_count);
c258527b 10658 json_object_int_add(json, "totalPeers", count);
3577f1c5
DD
10659
10660 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10661 json, JSON_C_TO_STRING_PRETTY));
10662 json_object_free(json);
10663 } else {
10664 vty_out(vty, "%% No failed BGP neighbors found\n");
10665 vty_out(vty, "\nTotal number of neighbors %d\n", count);
10666 }
10667 return CMD_SUCCESS;
10668 }
c258527b 10669
3577f1c5 10670 count = 0; /* Reset the value as its used again */
d62a17ae 10671 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10672 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10673 continue;
10674
ea47320b
DL
10675 if (!peer->afc[afi][safi])
10676 continue;
d62a17ae 10677
ea47320b
DL
10678 if (!count) {
10679 unsigned long ents;
10680 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 10681 int64_t vrf_id_ui;
d62a17ae 10682
a4d82a8a
PZ
10683 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10684 ? -1
10685 : (int64_t)bgp->vrf_id;
ea47320b
DL
10686
10687 /* Usage summary and header */
10688 if (use_json) {
23d0a753
DA
10689 char buf[BUFSIZ] = {0};
10690
ea47320b
DL
10691 json_object_string_add(
10692 json, "routerId",
23d0a753
DA
10693 inet_ntop(AF_INET, &bgp->router_id, buf,
10694 sizeof(buf)));
60466a63
QY
10695 json_object_int_add(json, "as", bgp->as);
10696 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
10697 json_object_string_add(
10698 json, "vrfName",
10699 (bgp->inst_type
10700 == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 10701 ? VRF_DEFAULT_NAME
ea47320b
DL
10702 : bgp->name);
10703 } else {
10704 vty_out(vty,
23d0a753
DA
10705 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10706 &bgp->router_id, bgp->as,
a4d82a8a
PZ
10707 bgp->vrf_id == VRF_UNKNOWN
10708 ? -1
10709 : (int)bgp->vrf_id);
ea47320b
DL
10710 vty_out(vty, "\n");
10711 }
d62a17ae 10712
ea47320b 10713 if (bgp_update_delay_configured(bgp)) {
d62a17ae 10714 if (use_json) {
ea47320b 10715 json_object_int_add(
60466a63 10716 json, "updateDelayLimit",
ea47320b 10717 bgp->v_update_delay);
d62a17ae 10718
ea47320b
DL
10719 if (bgp->v_update_delay
10720 != bgp->v_establish_wait)
d62a17ae 10721 json_object_int_add(
10722 json,
ea47320b
DL
10723 "updateDelayEstablishWait",
10724 bgp->v_establish_wait);
d62a17ae 10725
60466a63 10726 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
10727 json_object_string_add(
10728 json,
10729 "updateDelayFirstNeighbor",
10730 bgp->update_delay_begin_time);
10731 json_object_boolean_true_add(
10732 json,
10733 "updateDelayInProgress");
10734 } else {
10735 if (bgp->update_delay_over) {
d62a17ae 10736 json_object_string_add(
10737 json,
10738 "updateDelayFirstNeighbor",
10739 bgp->update_delay_begin_time);
ea47320b 10740 json_object_string_add(
d62a17ae 10741 json,
ea47320b
DL
10742 "updateDelayBestpathResumed",
10743 bgp->update_delay_end_time);
10744 json_object_string_add(
d62a17ae 10745 json,
ea47320b
DL
10746 "updateDelayZebraUpdateResume",
10747 bgp->update_delay_zebra_resume_time);
10748 json_object_string_add(
10749 json,
10750 "updateDelayPeerUpdateResume",
10751 bgp->update_delay_peers_resume_time);
d62a17ae 10752 }
ea47320b
DL
10753 }
10754 } else {
10755 vty_out(vty,
10756 "Read-only mode update-delay limit: %d seconds\n",
10757 bgp->v_update_delay);
10758 if (bgp->v_update_delay
10759 != bgp->v_establish_wait)
d62a17ae 10760 vty_out(vty,
ea47320b
DL
10761 " Establish wait: %d seconds\n",
10762 bgp->v_establish_wait);
d62a17ae 10763
60466a63 10764 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
10765 vty_out(vty,
10766 " First neighbor established: %s\n",
10767 bgp->update_delay_begin_time);
10768 vty_out(vty,
10769 " Delay in progress\n");
10770 } else {
10771 if (bgp->update_delay_over) {
d62a17ae 10772 vty_out(vty,
10773 " First neighbor established: %s\n",
10774 bgp->update_delay_begin_time);
10775 vty_out(vty,
ea47320b
DL
10776 " Best-paths resumed: %s\n",
10777 bgp->update_delay_end_time);
10778 vty_out(vty,
10779 " zebra update resumed: %s\n",
10780 bgp->update_delay_zebra_resume_time);
10781 vty_out(vty,
10782 " peers update resumed: %s\n",
10783 bgp->update_delay_peers_resume_time);
d62a17ae 10784 }
10785 }
10786 }
ea47320b 10787 }
d62a17ae 10788
ea47320b
DL
10789 if (use_json) {
10790 if (bgp_maxmed_onstartup_configured(bgp)
10791 && bgp->maxmed_active)
10792 json_object_boolean_true_add(
60466a63 10793 json, "maxMedOnStartup");
ea47320b
DL
10794 if (bgp->v_maxmed_admin)
10795 json_object_boolean_true_add(
60466a63 10796 json, "maxMedAdministrative");
d62a17ae 10797
ea47320b
DL
10798 json_object_int_add(
10799 json, "tableVersion",
60466a63 10800 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 10801
60466a63
QY
10802 ents = bgp_table_count(bgp->rib[afi][safi]);
10803 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
10804 json_object_int_add(
10805 json, "ribMemory",
9bcb3eef 10806 ents * sizeof(struct bgp_dest));
d62a17ae 10807
210ec2a0 10808 ents = bgp->af_peer_count[afi][safi];
60466a63
QY
10809 json_object_int_add(json, "peerCount", ents);
10810 json_object_int_add(json, "peerMemory",
10811 ents * sizeof(struct peer));
d62a17ae 10812
ea47320b
DL
10813 if ((ents = listcount(bgp->group))) {
10814 json_object_int_add(
60466a63 10815 json, "peerGroupCount", ents);
ea47320b
DL
10816 json_object_int_add(
10817 json, "peerGroupMemory",
996c9314
LB
10818 ents * sizeof(struct
10819 peer_group));
ea47320b 10820 }
d62a17ae 10821
ea47320b
DL
10822 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10823 BGP_CONFIG_DAMPENING))
10824 json_object_boolean_true_add(
60466a63 10825 json, "dampeningEnabled");
ea47320b
DL
10826 } else {
10827 if (bgp_maxmed_onstartup_configured(bgp)
10828 && bgp->maxmed_active)
d62a17ae 10829 vty_out(vty,
ea47320b
DL
10830 "Max-med on-startup active\n");
10831 if (bgp->v_maxmed_admin)
d62a17ae 10832 vty_out(vty,
ea47320b 10833 "Max-med administrative active\n");
d62a17ae 10834
60466a63
QY
10835 vty_out(vty, "BGP table version %" PRIu64 "\n",
10836 bgp_table_version(bgp->rib[afi][safi]));
d62a17ae 10837
60466a63 10838 ents = bgp_table_count(bgp->rib[afi][safi]);
ea47320b
DL
10839 vty_out(vty,
10840 "RIB entries %ld, using %s of memory\n",
10841 ents,
9bcb3eef
DS
10842 mtype_memstr(
10843 memstrbuf, sizeof(memstrbuf),
10844 ents
10845 * sizeof(struct
10846 bgp_dest)));
ea47320b
DL
10847
10848 /* Peer related usage */
210ec2a0 10849 ents = bgp->af_peer_count[afi][safi];
60466a63 10850 vty_out(vty, "Peers %ld, using %s of memory\n",
ea47320b
DL
10851 ents,
10852 mtype_memstr(
60466a63
QY
10853 memstrbuf, sizeof(memstrbuf),
10854 ents * sizeof(struct peer)));
ea47320b
DL
10855
10856 if ((ents = listcount(bgp->group)))
d62a17ae 10857 vty_out(vty,
ea47320b 10858 "Peer groups %ld, using %s of memory\n",
d62a17ae 10859 ents,
10860 mtype_memstr(
10861 memstrbuf,
10862 sizeof(memstrbuf),
996c9314
LB
10863 ents * sizeof(struct
10864 peer_group)));
d62a17ae 10865
ea47320b
DL
10866 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10867 BGP_CONFIG_DAMPENING))
60466a63 10868 vty_out(vty, "Dampening enabled.\n");
ea47320b 10869 vty_out(vty, "\n");
d62a17ae 10870
ea47320b
DL
10871 /* Subtract 8 here because 'Neighbor' is
10872 * 8 characters */
10873 vty_out(vty, "Neighbor");
60466a63
QY
10874 vty_out(vty, "%*s", max_neighbor_width - 8,
10875 " ");
3577f1c5 10876 if (show_failed)
85eeb029
DA
10877 vty_out(vty,
10878 BGP_SHOW_SUMMARY_HEADER_FAILED);
3577f1c5
DD
10879 else
10880 vty_out(vty,
85eeb029
DA
10881 show_wide
10882 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
10883 : BGP_SHOW_SUMMARY_HEADER_ALL);
d62a17ae 10884 }
ea47320b 10885 }
d62a17ae 10886
d55811cc 10887 paf = peer_af_find(peer, afi, safi);
d3ada366 10888 filter = &peer->filter[afi][safi];
db92d226 10889
ea47320b 10890 count++;
3577f1c5
DD
10891 /* Works for both failed & successful cases */
10892 if (peer_dynamic_neighbor(peer))
10893 dn_count++;
d62a17ae 10894
ea47320b 10895 if (use_json) {
3577f1c5
DD
10896 json_peer = NULL;
10897
10898 if (show_failed &&
10899 bgp_has_peer_failed(peer, afi, safi)) {
10900 json_peer = json_object_new_object();
10901 bgp_show_failed_summary(vty, bgp, peer,
10902 json_peer, 0, use_json);
10903 } else if (!show_failed) {
10b49f14
DA
10904 if (show_established
10905 && bgp_has_peer_failed(peer, afi, safi))
10906 continue;
10907
3577f1c5
DD
10908 json_peer = json_object_new_object();
10909 if (peer_dynamic_neighbor(peer)) {
10910 json_object_boolean_true_add(json_peer,
10911 "dynamicPeer");
10912 }
d62a17ae 10913
3577f1c5
DD
10914 if (peer->hostname)
10915 json_object_string_add(json_peer, "hostname",
10916 peer->hostname);
10917
10918 if (peer->domainname)
10919 json_object_string_add(json_peer, "domainname",
10920 peer->domainname);
10921
10922 json_object_int_add(json_peer, "remoteAs", peer->as);
c854765f
DA
10923 json_object_int_add(
10924 json_peer, "localAs",
10925 peer->change_local_as
10926 ? peer->change_local_as
10927 : peer->local_as);
3577f1c5
DD
10928 json_object_int_add(json_peer, "version", 4);
10929 json_object_int_add(json_peer, "msgRcvd",
10930 PEER_TOTAL_RX(peer));
10931 json_object_int_add(json_peer, "msgSent",
10932 PEER_TOTAL_TX(peer));
10933
43aa5965
QY
10934 atomic_size_t outq_count, inq_count;
10935 outq_count = atomic_load_explicit(
10936 &peer->obuf->count,
10937 memory_order_relaxed);
10938 inq_count = atomic_load_explicit(
10939 &peer->ibuf->count,
10940 memory_order_relaxed);
10941
3577f1c5
DD
10942 json_object_int_add(json_peer, "tableVersion",
10943 peer->version[afi][safi]);
10944 json_object_int_add(json_peer, "outq",
43aa5965
QY
10945 outq_count);
10946 json_object_int_add(json_peer, "inq",
10947 inq_count);
3577f1c5
DD
10948 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10949 use_json, json_peer);
10950
3577f1c5
DD
10951 json_object_int_add(json_peer, "pfxRcd",
10952 peer->pcount[afi][pfx_rcd_safi]);
10953
3577f1c5 10954 if (paf && PAF_SUBGRP(paf))
a616dd1f
DA
10955 json_object_int_add(
10956 json_peer, "pfxSnt",
10957 (PAF_SUBGRP(paf))->scount);
10958 else
10959 json_object_int_add(json_peer, "pfxSnt",
10960 0);
0e1f8ab5
DA
10961
10962 /* BGP FSM state */
cb9196e7 10963 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
736b68f3
DS
10964 || CHECK_FLAG(peer->bgp->flags,
10965 BGP_FLAG_SHUTDOWN))
0e1f8ab5
DA
10966 json_object_string_add(json_peer,
10967 "state",
3577f1c5
DD
10968 "Idle (Admin)");
10969 else if (peer->afc_recv[afi][safi])
10970 json_object_string_add(
0e1f8ab5
DA
10971 json_peer, "state",
10972 lookup_msg(bgp_status_msg,
10973 peer->status, NULL));
10974 else if (CHECK_FLAG(
10975 peer->sflags,
10976 PEER_STATUS_PREFIX_OVERFLOW))
10977 json_object_string_add(json_peer,
10978 "state",
3577f1c5
DD
10979 "Idle (PfxCt)");
10980 else
10981 json_object_string_add(
0e1f8ab5
DA
10982 json_peer, "state",
10983 lookup_msg(bgp_status_msg,
10984 peer->status, NULL));
10985
10986 /* BGP peer state */
10987 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
10988 || CHECK_FLAG(peer->bgp->flags,
10989 BGP_FLAG_SHUTDOWN))
10990 json_object_string_add(json_peer,
10991 "peerState",
10992 "Admin");
10993 else if (CHECK_FLAG(
10994 peer->sflags,
10995 PEER_STATUS_PREFIX_OVERFLOW))
10996 json_object_string_add(json_peer,
10997 "peerState",
10998 "PfxCt");
10999 else if (CHECK_FLAG(peer->flags,
11000 PEER_FLAG_PASSIVE))
11001 json_object_string_add(json_peer,
11002 "peerState",
11003 "Passive");
11004 else if (CHECK_FLAG(peer->sflags,
11005 PEER_STATUS_NSF_WAIT))
11006 json_object_string_add(json_peer,
11007 "peerState",
11008 "NSF passive");
11009 else if (CHECK_FLAG(
11010 peer->bgp->flags,
11011 BGP_FLAG_EBGP_REQUIRES_POLICY)
11012 && (!bgp_inbound_policy_exists(peer,
11013 filter)
11014 || !bgp_outbound_policy_exists(
11015 peer, filter)))
11016 json_object_string_add(json_peer,
11017 "peerState",
11018 "Policy");
11019 else
11020 json_object_string_add(
11021 json_peer, "peerState", "OK");
11022
200116db
DD
11023 json_object_int_add(json_peer, "connectionsEstablished",
11024 peer->established);
11025 json_object_int_add(json_peer, "connectionsDropped",
11026 peer->dropped);
aa72bd7e
PG
11027 if (peer->desc)
11028 json_object_string_add(
11029 json_peer, "desc", peer->desc);
b4e9dcba 11030 }
3577f1c5
DD
11031 /* Avoid creating empty peer dicts in JSON */
11032 if (json_peer == NULL)
11033 continue;
ea47320b
DL
11034
11035 if (peer->conf_if)
60466a63 11036 json_object_string_add(json_peer, "idType",
ea47320b
DL
11037 "interface");
11038 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
11039 json_object_string_add(json_peer, "idType",
11040 "ipv4");
ea47320b 11041 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
11042 json_object_string_add(json_peer, "idType",
11043 "ipv6");
ea47320b
DL
11044 json_object_object_add(json_peers, peer->host,
11045 json_peer);
11046 } else {
3577f1c5
DD
11047 if (show_failed &&
11048 bgp_has_peer_failed(peer, afi, safi)) {
11049 bgp_show_failed_summary(vty, bgp, peer, NULL,
11050 max_neighbor_width,
11051 use_json);
11052 } else if (!show_failed) {
10b49f14
DA
11053 if (show_established
11054 && bgp_has_peer_failed(peer, afi, safi))
11055 continue;
11056
3577f1c5
DD
11057 memset(dn_flag, '\0', sizeof(dn_flag));
11058 if (peer_dynamic_neighbor(peer)) {
11059 dn_flag[0] = '*';
11060 }
d62a17ae 11061
3577f1c5 11062 if (peer->hostname
892fedb6
DA
11063 && CHECK_FLAG(bgp->flags,
11064 BGP_FLAG_SHOW_HOSTNAME))
3577f1c5 11065 len = vty_out(vty, "%s%s(%s)", dn_flag,
892fedb6
DA
11066 peer->hostname,
11067 peer->host);
d62a17ae 11068 else
3577f1c5
DD
11069 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11070
11071 /* pad the neighbor column with spaces */
11072 if (len < max_neighbor_width)
11073 vty_out(vty, "%*s", max_neighbor_width - len,
11074 " ");
11075
43aa5965
QY
11076 atomic_size_t outq_count, inq_count;
11077 outq_count = atomic_load_explicit(
11078 &peer->obuf->count,
11079 memory_order_relaxed);
11080 inq_count = atomic_load_explicit(
11081 &peer->ibuf->count,
11082 memory_order_relaxed);
11083
85eeb029
DA
11084 if (show_wide)
11085 vty_out(vty,
11086 "4 %10u %10u %9u %9u %8" PRIu64
11087 " %4zu %4zu %8s",
11088 peer->as,
11089 peer->change_local_as
11090 ? peer->change_local_as
11091 : peer->local_as,
11092 PEER_TOTAL_RX(peer),
11093 PEER_TOTAL_TX(peer),
11094 peer->version[afi][safi],
11095 inq_count, outq_count,
11096 peer_uptime(peer->uptime,
11097 timebuf,
11098 BGP_UPTIME_LEN, 0,
11099 NULL));
11100 else
11101 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
11102 " %4zu %4zu %8s",
11103 peer->as, PEER_TOTAL_RX(peer),
11104 PEER_TOTAL_TX(peer),
11105 peer->version[afi][safi],
11106 inq_count, outq_count,
11107 peer_uptime(peer->uptime,
11108 timebuf,
11109 BGP_UPTIME_LEN, 0,
11110 NULL));
3577f1c5 11111
db92d226 11112 if (peer->status == Established) {
d3ada366
DA
11113 if (peer->afc_recv[afi][safi]) {
11114 if (CHECK_FLAG(
11115 bgp->flags,
11116 BGP_FLAG_EBGP_REQUIRES_POLICY)
11117 && !bgp_inbound_policy_exists(
11118 peer, filter))
11119 vty_out(vty, " %12s",
11120 "(Policy)");
11121 else
11122 vty_out(vty,
6cde4b45 11123 " %12u",
d3ada366
DA
11124 peer->pcount
11125 [afi]
11126 [pfx_rcd_safi]);
11127 } else {
749d0f27 11128 vty_out(vty, " NoNeg");
d3ada366 11129 }
db92d226 11130
d3ada366
DA
11131 if (paf && PAF_SUBGRP(paf)) {
11132 if (CHECK_FLAG(
11133 bgp->flags,
11134 BGP_FLAG_EBGP_REQUIRES_POLICY)
11135 && !bgp_outbound_policy_exists(
11136 peer, filter))
11137 vty_out(vty, " %8s",
11138 "(Policy)");
11139 else
11140 vty_out(vty,
6cde4b45 11141 " %8u",
d3ada366
DA
11142 (PAF_SUBGRP(
11143 paf))
11144 ->scount);
749d0f27
DA
11145 } else {
11146 vty_out(vty, " NoNeg");
d3ada366 11147 }
db92d226 11148 } else {
736b68f3
DS
11149 if (CHECK_FLAG(peer->flags,
11150 PEER_FLAG_SHUTDOWN)
11151 || CHECK_FLAG(peer->bgp->flags,
11152 BGP_FLAG_SHUTDOWN))
3577f1c5
DD
11153 vty_out(vty, " Idle (Admin)");
11154 else if (CHECK_FLAG(
11155 peer->sflags,
11156 PEER_STATUS_PREFIX_OVERFLOW))
11157 vty_out(vty, " Idle (PfxCt)");
11158 else
11159 vty_out(vty, " %12s",
11160 lookup_msg(bgp_status_msg,
11161 peer->status, NULL));
db92d226 11162
6cde4b45 11163 vty_out(vty, " %8u", 0);
3577f1c5 11164 }
aa72bd7e 11165 if (peer->desc)
cb75bb31
DA
11166 vty_out(vty, " %s",
11167 bgp_peer_description_stripped(
85eeb029
DA
11168 peer->desc,
11169 show_wide ? 64 : 20));
aa72bd7e
PG
11170 else
11171 vty_out(vty, " N/A");
3577f1c5 11172 vty_out(vty, "\n");
d62a17ae 11173 }
3577f1c5 11174
d62a17ae 11175 }
11176 }
f933309e 11177
d62a17ae 11178 if (use_json) {
11179 json_object_object_add(json, "peers", json_peers);
3577f1c5 11180 json_object_int_add(json, "failedPeers", failed_count);
d62a17ae 11181 json_object_int_add(json, "totalPeers", count);
11182 json_object_int_add(json, "dynamicPeers", dn_count);
11183
3577f1c5
DD
11184 if (!show_failed)
11185 bgp_show_bestpath_json(bgp, json);
57a9c8a8 11186
996c9314
LB
11187 vty_out(vty, "%s\n", json_object_to_json_string_ext(
11188 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 11189 json_object_free(json);
11190 } else {
11191 if (count)
11192 vty_out(vty, "\nTotal number of neighbors %d\n", count);
11193 else {
d6ceaca3 11194 vty_out(vty, "No %s neighbor is configured\n",
5cb5f4d0 11195 get_afi_safi_str(afi, safi, false));
d62a17ae 11196 }
b05a1c8b 11197
d6ceaca3 11198 if (dn_count) {
d62a17ae 11199 vty_out(vty, "* - dynamic neighbor\n");
11200 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11201 dn_count, bgp->dynamic_neighbors_limit);
11202 }
11203 }
1ff9a340 11204
d62a17ae 11205 return CMD_SUCCESS;
718e3744 11206}
11207
d62a17ae 11208static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
85eeb029 11209 int safi, uint8_t show_flags)
d62a17ae 11210{
11211 int is_first = 1;
11212 int afi_wildcard = (afi == AFI_MAX);
11213 int safi_wildcard = (safi == SAFI_MAX);
11214 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 11215 bool nbr_output = false;
85eeb029 11216 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 11217
11218 if (use_json && is_wildcard)
11219 vty_out(vty, "{\n");
11220 if (afi_wildcard)
11221 afi = 1; /* AFI_IP */
11222 while (afi < AFI_MAX) {
11223 if (safi_wildcard)
11224 safi = 1; /* SAFI_UNICAST */
11225 while (safi < SAFI_MAX) {
318cac96 11226 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 11227 nbr_output = true;
f86897b9 11228
d62a17ae 11229 if (is_wildcard) {
11230 /*
11231 * So limit output to those afi/safi
11232 * pairs that
11233 * actualy have something interesting in
11234 * them
11235 */
11236 if (use_json) {
d62a17ae 11237 if (!is_first)
11238 vty_out(vty, ",\n");
11239 else
11240 is_first = 0;
11241
11242 vty_out(vty, "\"%s\":",
5cb5f4d0
DD
11243 get_afi_safi_str(afi,
11244 safi,
11245 true));
d62a17ae 11246 } else {
11247 vty_out(vty, "\n%s Summary:\n",
5cb5f4d0
DD
11248 get_afi_safi_str(afi,
11249 safi,
11250 false));
d62a17ae 11251 }
11252 }
10b49f14 11253 bgp_show_summary(vty, bgp, afi, safi,
85eeb029 11254 show_flags);
d62a17ae 11255 }
11256 safi++;
d62a17ae 11257 if (!safi_wildcard)
11258 safi = SAFI_MAX;
11259 }
11260 afi++;
ee851c8c 11261 if (!afi_wildcard)
d62a17ae 11262 afi = AFI_MAX;
11263 }
11264
11265 if (use_json && is_wildcard)
11266 vty_out(vty, "}\n");
ca61fd25
DS
11267 else if (!nbr_output) {
11268 if (use_json)
11269 vty_out(vty, "{}\n");
11270 else
11271 vty_out(vty, "%% No BGP neighbors found\n");
11272 }
d62a17ae 11273}
11274
11275static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
85eeb029 11276 safi_t safi, uint8_t show_flags)
d62a17ae 11277{
11278 struct listnode *node, *nnode;
11279 struct bgp *bgp;
d62a17ae 11280 int is_first = 1;
9f049418 11281 bool nbr_output = false;
85eeb029 11282 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 11283
11284 if (use_json)
11285 vty_out(vty, "{\n");
11286
11287 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 11288 nbr_output = true;
d62a17ae 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\":",
11296 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11297 ? VRF_DEFAULT_NAME
d62a17ae 11298 : bgp->name);
11299 } else {
11300 vty_out(vty, "\nInstance %s:\n",
11301 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11302 ? VRF_DEFAULT_NAME
d62a17ae 11303 : bgp->name);
11304 }
85eeb029 11305 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_flags);
d62a17ae 11306 }
11307
11308 if (use_json)
11309 vty_out(vty, "}\n");
9f049418
DS
11310 else if (!nbr_output)
11311 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 11312}
11313
11314int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
85eeb029 11315 safi_t safi, uint8_t show_flags)
d62a17ae 11316{
11317 struct bgp *bgp;
85eeb029 11318 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 11319
11320 if (name) {
11321 if (strmatch(name, "all")) {
85eeb029
DA
11322 bgp_show_all_instances_summary_vty(vty, afi, safi,
11323 show_flags);
d62a17ae 11324 return CMD_SUCCESS;
11325 } else {
11326 bgp = bgp_lookup_by_name(name);
11327
11328 if (!bgp) {
11329 if (use_json)
11330 vty_out(vty, "{}\n");
11331 else
11332 vty_out(vty,
ca61fd25 11333 "%% BGP instance not found\n");
d62a17ae 11334 return CMD_WARNING;
11335 }
11336
f86897b9 11337 bgp_show_summary_afi_safi(vty, bgp, afi, safi,
85eeb029 11338 show_flags);
d62a17ae 11339 return CMD_SUCCESS;
11340 }
11341 }
11342
11343 bgp = bgp_get_default();
11344
11345 if (bgp)
85eeb029 11346 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_flags);
9f049418 11347 else {
ca61fd25
DS
11348 if (use_json)
11349 vty_out(vty, "{}\n");
11350 else
11351 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
11352 return CMD_WARNING;
11353 }
d62a17ae 11354
11355 return CMD_SUCCESS;
4fb25c53
DW
11356}
11357
716b2d8a 11358/* `show [ip] bgp summary' commands. */
96f3485c 11359DEFPY (show_ip_bgp_summary,
718e3744 11360 show_ip_bgp_summary_cmd,
85eeb029 11361 "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 11362 SHOW_STR
11363 IP_STR
11364 BGP_STR
8386ac43 11365 BGP_INSTANCE_HELP_STR
46f296b4 11366 BGP_AFI_HELP_STR
dd6bd0f1 11367 BGP_SAFI_WITH_LABEL_HELP_STR
96f3485c 11368 "Display the entries for all address families\n"
b05a1c8b 11369 "Summary of BGP neighbor status\n"
10b49f14 11370 "Show only sessions in Established state\n"
3577f1c5 11371 "Show only sessions not in Established state\n"
85eeb029 11372 "Increase table width for longer output\n"
9973d184 11373 JSON_STR)
718e3744 11374{
d62a17ae 11375 char *vrf = NULL;
11376 afi_t afi = AFI_MAX;
11377 safi_t safi = SAFI_MAX;
85eeb029 11378 uint8_t show_flags = 0;
d62a17ae 11379
11380 int idx = 0;
11381
11382 /* show [ip] bgp */
96f3485c 11383 if (!all && argv_find(argv, argc, "ip", &idx))
d62a17ae 11384 afi = AFI_IP;
9a8bdf1c
PG
11385 /* [<vrf> VIEWVRFNAME] */
11386 if (argv_find(argv, argc, "vrf", &idx)) {
11387 vrf = argv[idx + 1]->arg;
11388 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11389 vrf = NULL;
11390 } else if (argv_find(argv, argc, "view", &idx))
11391 /* [<view> VIEWVRFNAME] */
11392 vrf = argv[idx + 1]->arg;
d62a17ae 11393 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11394 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11395 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11396 }
11397
3577f1c5 11398 if (argv_find(argv, argc, "failed", &idx))
85eeb029
DA
11399 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11400
10b49f14 11401 if (argv_find(argv, argc, "established", &idx))
85eeb029
DA
11402 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11403
11404 if (argv_find(argv, argc, "wide", &idx))
11405 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11406
11407 if (argv_find(argv, argc, "json", &idx))
11408 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
3577f1c5 11409
85eeb029 11410 return bgp_show_summary_vty(vty, vrf, afi, safi, show_flags);
d62a17ae 11411}
11412
5cb5f4d0 11413const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
d62a17ae 11414{
5cb5f4d0
DD
11415 if (for_json)
11416 return get_afi_safi_json_str(afi, safi);
d62a17ae 11417 else
5cb5f4d0 11418 return get_afi_safi_vty_str(afi, safi);
27162734
LB
11419}
11420
d62a17ae 11421
11422static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11423 afi_t afi, safi_t safi,
d7c0a89a
QY
11424 uint16_t adv_smcap, uint16_t adv_rmcap,
11425 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 11426 bool use_json, json_object *json_pref)
d62a17ae 11427{
11428 /* Send-Mode */
11429 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11430 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11431 if (use_json) {
11432 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11433 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11434 json_object_string_add(json_pref, "sendMode",
11435 "advertisedAndReceived");
11436 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11437 json_object_string_add(json_pref, "sendMode",
11438 "advertised");
11439 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11440 json_object_string_add(json_pref, "sendMode",
11441 "received");
11442 } else {
11443 vty_out(vty, " Send-mode: ");
11444 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11445 vty_out(vty, "advertised");
11446 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11447 vty_out(vty, "%sreceived",
11448 CHECK_FLAG(p->af_cap[afi][safi],
11449 adv_smcap)
11450 ? ", "
11451 : "");
11452 vty_out(vty, "\n");
11453 }
11454 }
11455
11456 /* Receive-Mode */
11457 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11458 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11459 if (use_json) {
11460 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11461 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11462 json_object_string_add(json_pref, "recvMode",
11463 "advertisedAndReceived");
11464 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11465 json_object_string_add(json_pref, "recvMode",
11466 "advertised");
11467 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11468 json_object_string_add(json_pref, "recvMode",
11469 "received");
11470 } else {
11471 vty_out(vty, " Receive-mode: ");
11472 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11473 vty_out(vty, "advertised");
11474 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11475 vty_out(vty, "%sreceived",
11476 CHECK_FLAG(p->af_cap[afi][safi],
11477 adv_rmcap)
11478 ? ", "
11479 : "");
11480 vty_out(vty, "\n");
11481 }
11482 }
11483}
11484
13909c4f
DS
11485static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty,
11486 struct peer *p,
11487 bool use_json,
11488 json_object *json)
2986cac2 11489{
08c2d52a 11490 bool rbit_status = false;
2986cac2 11491
11492 if (!use_json)
a53ca37b 11493 vty_out(vty, "\n R bit: ");
2986cac2 11494
13909c4f
DS
11495 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11496 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
11497 && (p->status == Established)) {
2986cac2 11498
11499 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV))
08c2d52a 11500 rbit_status = true;
2986cac2 11501 else
08c2d52a 11502 rbit_status = false;
2986cac2 11503 }
11504
11505 if (rbit_status) {
11506 if (use_json)
13909c4f 11507 json_object_boolean_true_add(json, "rBit");
2986cac2 11508 else
11509 vty_out(vty, "True\n");
11510 } else {
11511 if (use_json)
13909c4f 11512 json_object_boolean_false_add(json, "rBit");
2986cac2 11513 else
11514 vty_out(vty, "False\n");
11515 }
11516}
11517
13909c4f
DS
11518static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11519 struct peer *peer,
11520 bool use_json,
11521 json_object *json)
2986cac2 11522{
2bb5d39b 11523 const char *mode = "NotApplicable";
2986cac2 11524
11525 if (!use_json)
a53ca37b 11526 vty_out(vty, "\n Remote GR Mode: ");
2986cac2 11527
13909c4f
DS
11528 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11529 && (peer->status == Established)) {
2986cac2 11530
13909c4f
DS
11531 if ((peer->nsf_af_count == 0)
11532 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11533
2986cac2 11534 mode = "Disable";
11535
13909c4f
DS
11536 } else if (peer->nsf_af_count == 0
11537 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11538
2986cac2 11539 mode = "Helper";
11540
13909c4f
DS
11541 } else if (peer->nsf_af_count != 0
11542 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11543
2986cac2 11544 mode = "Restart";
2986cac2 11545 }
11546 }
11547
11548 if (use_json) {
13909c4f 11549 json_object_string_add(json, "remoteGrMode", mode);
2986cac2 11550 } else
11551 vty_out(vty, mode, "\n");
11552}
11553
13909c4f
DS
11554static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11555 struct peer *p,
11556 bool use_json,
11557 json_object *json)
2986cac2 11558{
11559 const char *mode = "Invalid";
11560
11561 if (!use_json)
a53ca37b 11562 vty_out(vty, " Local GR Mode: ");
2986cac2 11563
11564 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11565 mode = "Helper";
11566 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11567 mode = "Restart";
11568 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11569 mode = "Disable";
2ba1fe69 11570 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
2986cac2 11571 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11572 mode = "Helper*";
11573 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11574 mode = "Restart*";
11575 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11576 mode = "Disable*";
11577 else
11578 mode = "Invalid*";
2ba1fe69 11579 }
2986cac2 11580
11581 if (use_json) {
13909c4f 11582 json_object_string_add(json, "localGrMode", mode);
2986cac2 11583 } else {
11584 vty_out(vty, mode, "\n");
11585 }
11586}
11587
13909c4f
DS
11588static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11589 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
2986cac2 11590{
2ba1fe69 11591 afi_t afi;
11592 safi_t safi;
2986cac2 11593 json_object *json_afi_safi = NULL;
11594 json_object *json_timer = NULL;
11595 json_object *json_endofrib_status = NULL;
9e3b51a7 11596 bool eor_flag = false;
2986cac2 11597
11598 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11599 for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) {
13909c4f
DS
11600 if (!peer->afc[afi][safi])
11601 continue;
2986cac2 11602
13909c4f
DS
11603 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11604 || !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11605 continue;
9e3b51a7 11606
13909c4f
DS
11607 if (use_json) {
11608 json_afi_safi = json_object_new_object();
11609 json_endofrib_status = json_object_new_object();
11610 json_timer = json_object_new_object();
11611 }
2986cac2 11612
13909c4f
DS
11613 if (peer->eor_stime[afi][safi]
11614 >= peer->pkt_stime[afi][safi])
11615 eor_flag = true;
11616 else
11617 eor_flag = false;
2986cac2 11618
13909c4f 11619 if (!use_json) {
a53ca37b 11620 vty_out(vty, " %s:\n",
13909c4f 11621 get_afi_safi_str(afi, safi, false));
2986cac2 11622
a53ca37b 11623 vty_out(vty, " F bit: ");
698ba8d0 11624 }
2986cac2 11625
13909c4f
DS
11626 if (peer->nsf[afi][safi]
11627 && CHECK_FLAG(peer->af_cap[afi][safi],
11628 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
2986cac2 11629
13909c4f
DS
11630 if (use_json) {
11631 json_object_boolean_true_add(
2986cac2 11632 json_afi_safi, "fBit");
13909c4f
DS
11633 } else
11634 vty_out(vty, "True\n");
11635 } else {
11636 if (use_json)
11637 json_object_boolean_false_add(
11638 json_afi_safi, "fBit");
11639 else
11640 vty_out(vty, "False\n");
11641 }
2986cac2 11642
13909c4f 11643 if (!use_json)
a53ca37b 11644 vty_out(vty, " End-of-RIB sent: ");
2986cac2 11645
13909c4f
DS
11646 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11647 PEER_STATUS_EOR_SEND)) {
11648 if (use_json) {
11649 json_object_boolean_true_add(
2986cac2 11650 json_endofrib_status,
13909c4f 11651 "endOfRibSend");
9e3b51a7 11652
13909c4f
DS
11653 PRINT_EOR_JSON(eor_flag);
11654 } else {
11655 vty_out(vty, "Yes\n");
11656 vty_out(vty,
a53ca37b 11657 " End-of-RIB sent after update: ");
2986cac2 11658
13909c4f
DS
11659 PRINT_EOR(eor_flag);
11660 }
11661 } else {
11662 if (use_json) {
11663 json_object_boolean_false_add(
2986cac2 11664 json_endofrib_status,
13909c4f
DS
11665 "endOfRibSend");
11666 json_object_boolean_false_add(
9e3b51a7 11667 json_endofrib_status,
13909c4f
DS
11668 "endOfRibSentAfterUpdate");
11669 } else {
11670 vty_out(vty, "No\n");
11671 vty_out(vty,
a53ca37b 11672 " End-of-RIB sent after update: ");
13909c4f 11673 vty_out(vty, "No\n");
2986cac2 11674 }
13909c4f 11675 }
2986cac2 11676
a53ca37b
DA
11677 if (!use_json)
11678 vty_out(vty, " End-of-RIB received: ");
11679
11680 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11681 PEER_STATUS_EOR_RECEIVED)) {
11682 if (use_json)
11683 json_object_boolean_true_add(
11684 json_endofrib_status,
11685 "endOfRibRecv");
11686 else
11687 vty_out(vty, "Yes\n");
11688 } else {
11689 if (use_json)
11690 json_object_boolean_false_add(
11691 json_endofrib_status,
11692 "endOfRibRecv");
11693 else
11694 vty_out(vty, "No\n");
11695 }
11696
13909c4f
DS
11697 if (use_json) {
11698 json_object_int_add(json_timer,
11699 "stalePathTimer",
11700 peer->bgp->stalepath_time);
2986cac2 11701
13909c4f
DS
11702 if (peer->t_gr_stale != NULL) {
11703 json_object_int_add(
2986cac2 11704 json_timer,
11705 "stalePathTimerRemaining",
11706 thread_timer_remain_second(
13909c4f
DS
11707 peer->t_gr_stale));
11708 }
3a75afa4 11709
13909c4f
DS
11710 /* Display Configured Selection
11711 * Deferral only when when
11712 * Gr mode is enabled.
11713 */
11714 if (CHECK_FLAG(peer->flags,
11715 PEER_FLAG_GRACEFUL_RESTART)) {
11716 json_object_int_add(
3a75afa4 11717 json_timer,
2986cac2 11718 "selectionDeferralTimer",
11719 peer->bgp->stalepath_time);
13909c4f 11720 }
2986cac2 11721
13909c4f
DS
11722 if (peer->bgp->gr_info[afi][safi]
11723 .t_select_deferral
11724 != NULL) {
2986cac2 11725
13909c4f 11726 json_object_int_add(
2986cac2 11727 json_timer,
11728 "selectionDeferralTimerRemaining",
11729 thread_timer_remain_second(
13909c4f
DS
11730 peer->bgp
11731 ->gr_info[afi]
11732 [safi]
11733 .t_select_deferral));
11734 }
11735 } else {
a53ca37b 11736 vty_out(vty, " Timers:\n");
13909c4f 11737 vty_out(vty,
a53ca37b
DA
11738 " Configured Stale Path Time(sec): %u\n",
11739 peer->bgp->stalepath_time);
2986cac2 11740
a53ca37b 11741 if (peer->t_gr_stale != NULL)
2986cac2 11742 vty_out(vty,
a53ca37b 11743 " Stale Path Remaining(sec): %ld\n",
2986cac2 11744 thread_timer_remain_second(
13909c4f 11745 peer->t_gr_stale));
13909c4f
DS
11746 /* Display Configured Selection
11747 * Deferral only when when
11748 * Gr mode is enabled.
11749 */
11750 if (CHECK_FLAG(peer->flags,
a53ca37b 11751 PEER_FLAG_GRACEFUL_RESTART))
13909c4f 11752 vty_out(vty,
a53ca37b 11753 " Configured Selection Deferral Time(sec): %u\n",
3a75afa4 11754 peer->bgp->select_defer_time);
2986cac2 11755
13909c4f
DS
11756 if (peer->bgp->gr_info[afi][safi]
11757 .t_select_deferral
a53ca37b 11758 != NULL)
13909c4f 11759 vty_out(vty,
a53ca37b 11760 " Selection Deferral Time Remaining(sec): %ld\n",
2986cac2 11761 thread_timer_remain_second(
13909c4f
DS
11762 peer->bgp
11763 ->gr_info[afi]
11764 [safi]
11765 .t_select_deferral));
2986cac2 11766 }
13909c4f
DS
11767 if (use_json) {
11768 json_object_object_add(json_afi_safi,
11769 "endOfRibStatus",
11770 json_endofrib_status);
11771 json_object_object_add(json_afi_safi, "timers",
11772 json_timer);
11773 json_object_object_add(
11774 json, get_afi_safi_str(afi, safi, true),
11775 json_afi_safi);
11776 }
2986cac2 11777 }
11778 }
11779}
11780
36235319
QY
11781static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
11782 struct peer *p,
11783 bool use_json,
11784 json_object *json)
2986cac2 11785{
11786 if (use_json) {
11787 json_object *json_timer = NULL;
11788
11789 json_timer = json_object_new_object();
11790
13909c4f
DS
11791 json_object_int_add(json_timer, "configuredRestartTimer",
11792 p->bgp->restart_time);
2986cac2 11793
13909c4f
DS
11794 json_object_int_add(json_timer, "receivedRestartTimer",
11795 p->v_gr_restart);
2986cac2 11796
13909c4f
DS
11797 if (p->t_gr_restart != NULL)
11798 json_object_int_add(
11799 json_timer, "restartTimerRemaining",
11800 thread_timer_remain_second(p->t_gr_restart));
2986cac2 11801
11802 json_object_object_add(json, "timers", json_timer);
11803 } else {
11804
a53ca37b
DA
11805 vty_out(vty, " Timers:\n");
11806 vty_out(vty, " Configured Restart Time(sec): %u\n",
13909c4f 11807 p->bgp->restart_time);
2986cac2 11808
a53ca37b 11809 vty_out(vty, " Received Restart Time(sec): %u\n",
13909c4f
DS
11810 p->v_gr_restart);
11811 if (p->t_gr_restart != NULL)
a53ca37b 11812 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
13909c4f 11813 thread_timer_remain_second(p->t_gr_restart));
36235319 11814 if (p->t_gr_restart != NULL) {
a53ca37b 11815 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
36235319
QY
11816 thread_timer_remain_second(p->t_gr_restart));
11817 }
2986cac2 11818 }
11819}
11820
11821static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
36235319 11822 bool use_json, json_object *json)
2986cac2 11823{
11824 char buf[SU_ADDRSTRLEN] = {0};
11825 char dn_flag[2] = {0};
2b7165e7
QY
11826 /* '*' + v6 address of neighbor */
11827 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
2986cac2 11828
2986cac2 11829 if (!p->conf_if && peer_dynamic_neighbor(p))
11830 dn_flag[0] = '*';
11831
11832 if (p->conf_if) {
11833 if (use_json)
13909c4f
DS
11834 json_object_string_add(
11835 json, "neighborAddr",
2986cac2 11836 BGP_PEER_SU_UNSPEC(p)
13909c4f
DS
11837 ? "none"
11838 : sockunion2str(&p->su, buf,
11839 SU_ADDRSTRLEN));
2986cac2 11840 else
13909c4f 11841 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
2986cac2 11842 BGP_PEER_SU_UNSPEC(p)
11843 ? "none"
11844 : sockunion2str(&p->su, buf,
11845 SU_ADDRSTRLEN));
11846 } else {
772270f3
QY
11847 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
11848 p->host);
2986cac2 11849
11850 if (use_json)
36235319
QY
11851 json_object_string_add(json, "neighborAddr",
11852 neighborAddr);
2986cac2 11853 else
36235319 11854 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
2986cac2 11855 }
11856
11857 /* more gr info in new format */
11858 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
11859}
11860
d62a17ae 11861static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 11862 safi_t safi, bool use_json,
d62a17ae 11863 json_object *json_neigh)
11864{
0291c246
MK
11865 struct bgp_filter *filter;
11866 struct peer_af *paf;
11867 char orf_pfx_name[BUFSIZ];
11868 int orf_pfx_count;
11869 json_object *json_af = NULL;
11870 json_object *json_prefA = NULL;
11871 json_object *json_prefB = NULL;
11872 json_object *json_addr = NULL;
fa36596c 11873 json_object *json_advmap = NULL;
d62a17ae 11874
11875 if (use_json) {
11876 json_addr = json_object_new_object();
11877 json_af = json_object_new_object();
11878 filter = &p->filter[afi][safi];
11879
11880 if (peer_group_active(p))
11881 json_object_string_add(json_addr, "peerGroupMember",
11882 p->group->name);
11883
11884 paf = peer_af_find(p, afi, safi);
11885 if (paf && PAF_SUBGRP(paf)) {
11886 json_object_int_add(json_addr, "updateGroupId",
11887 PAF_UPDGRP(paf)->id);
11888 json_object_int_add(json_addr, "subGroupId",
11889 PAF_SUBGRP(paf)->id);
11890 json_object_int_add(json_addr, "packetQueueLength",
11891 bpacket_queue_virtual_length(paf));
11892 }
11893
11894 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11895 || CHECK_FLAG(p->af_cap[afi][safi],
11896 PEER_CAP_ORF_PREFIX_SM_RCV)
11897 || CHECK_FLAG(p->af_cap[afi][safi],
11898 PEER_CAP_ORF_PREFIX_RM_ADV)
11899 || CHECK_FLAG(p->af_cap[afi][safi],
11900 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11901 json_object_int_add(json_af, "orfType",
11902 ORF_TYPE_PREFIX);
11903 json_prefA = json_object_new_object();
11904 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
11905 PEER_CAP_ORF_PREFIX_SM_ADV,
11906 PEER_CAP_ORF_PREFIX_RM_ADV,
11907 PEER_CAP_ORF_PREFIX_SM_RCV,
11908 PEER_CAP_ORF_PREFIX_RM_RCV,
11909 use_json, json_prefA);
11910 json_object_object_add(json_af, "orfPrefixList",
11911 json_prefA);
11912 }
11913
11914 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11915 || CHECK_FLAG(p->af_cap[afi][safi],
11916 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11917 || CHECK_FLAG(p->af_cap[afi][safi],
11918 PEER_CAP_ORF_PREFIX_RM_ADV)
11919 || CHECK_FLAG(p->af_cap[afi][safi],
11920 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
11921 json_object_int_add(json_af, "orfOldType",
11922 ORF_TYPE_PREFIX_OLD);
11923 json_prefB = json_object_new_object();
11924 bgp_show_peer_afi_orf_cap(
11925 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11926 PEER_CAP_ORF_PREFIX_RM_ADV,
11927 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
11928 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
11929 json_prefB);
11930 json_object_object_add(json_af, "orfOldPrefixList",
11931 json_prefB);
11932 }
11933
11934 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11935 || CHECK_FLAG(p->af_cap[afi][safi],
11936 PEER_CAP_ORF_PREFIX_SM_RCV)
11937 || CHECK_FLAG(p->af_cap[afi][safi],
11938 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11939 || CHECK_FLAG(p->af_cap[afi][safi],
11940 PEER_CAP_ORF_PREFIX_RM_ADV)
11941 || CHECK_FLAG(p->af_cap[afi][safi],
11942 PEER_CAP_ORF_PREFIX_RM_RCV)
11943 || CHECK_FLAG(p->af_cap[afi][safi],
11944 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
11945 json_object_object_add(json_addr, "afDependentCap",
11946 json_af);
11947 else
11948 json_object_free(json_af);
11949
772270f3
QY
11950 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
11951 p->host, afi, safi);
d62a17ae 11952 orf_pfx_count = prefix_bgp_show_prefix_list(
11953 NULL, afi, orf_pfx_name, use_json);
11954
11955 if (CHECK_FLAG(p->af_sflags[afi][safi],
11956 PEER_STATUS_ORF_PREFIX_SEND)
11957 || orf_pfx_count) {
11958 if (CHECK_FLAG(p->af_sflags[afi][safi],
11959 PEER_STATUS_ORF_PREFIX_SEND))
11960 json_object_boolean_true_add(json_neigh,
11961 "orfSent");
11962 if (orf_pfx_count)
11963 json_object_int_add(json_addr, "orfRecvCounter",
11964 orf_pfx_count);
11965 }
11966 if (CHECK_FLAG(p->af_sflags[afi][safi],
11967 PEER_STATUS_ORF_WAIT_REFRESH))
11968 json_object_string_add(
11969 json_addr, "orfFirstUpdate",
11970 "deferredUntilORFOrRouteRefreshRecvd");
11971
11972 if (CHECK_FLAG(p->af_flags[afi][safi],
11973 PEER_FLAG_REFLECTOR_CLIENT))
11974 json_object_boolean_true_add(json_addr,
11975 "routeReflectorClient");
11976 if (CHECK_FLAG(p->af_flags[afi][safi],
11977 PEER_FLAG_RSERVER_CLIENT))
11978 json_object_boolean_true_add(json_addr,
11979 "routeServerClient");
11980 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
11981 json_object_boolean_true_add(json_addr,
11982 "inboundSoftConfigPermit");
11983
11984 if (CHECK_FLAG(p->af_flags[afi][safi],
11985 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
11986 json_object_boolean_true_add(
11987 json_addr,
11988 "privateAsNumsAllReplacedInUpdatesToNbr");
11989 else if (CHECK_FLAG(p->af_flags[afi][safi],
11990 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
11991 json_object_boolean_true_add(
11992 json_addr,
11993 "privateAsNumsReplacedInUpdatesToNbr");
11994 else if (CHECK_FLAG(p->af_flags[afi][safi],
11995 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
11996 json_object_boolean_true_add(
11997 json_addr,
11998 "privateAsNumsAllRemovedInUpdatesToNbr");
11999 else if (CHECK_FLAG(p->af_flags[afi][safi],
12000 PEER_FLAG_REMOVE_PRIVATE_AS))
12001 json_object_boolean_true_add(
12002 json_addr,
12003 "privateAsNumsRemovedInUpdatesToNbr");
12004
dcc68b5e
MS
12005 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12006 json_object_boolean_true_add(
12007 json_addr,
12008 bgp_addpath_names(p->addpath_type[afi][safi])
12009 ->type_json_name);
d62a17ae 12010
12011 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12012 json_object_string_add(json_addr,
12013 "overrideASNsInOutboundUpdates",
12014 "ifAspathEqualRemoteAs");
12015
12016 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12017 || CHECK_FLAG(p->af_flags[afi][safi],
12018 PEER_FLAG_FORCE_NEXTHOP_SELF))
12019 json_object_boolean_true_add(json_addr,
12020 "routerAlwaysNextHop");
12021 if (CHECK_FLAG(p->af_flags[afi][safi],
12022 PEER_FLAG_AS_PATH_UNCHANGED))
12023 json_object_boolean_true_add(
12024 json_addr, "unchangedAsPathPropogatedToNbr");
12025 if (CHECK_FLAG(p->af_flags[afi][safi],
12026 PEER_FLAG_NEXTHOP_UNCHANGED))
12027 json_object_boolean_true_add(
12028 json_addr, "unchangedNextHopPropogatedToNbr");
12029 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12030 json_object_boolean_true_add(
12031 json_addr, "unchangedMedPropogatedToNbr");
12032 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12033 || CHECK_FLAG(p->af_flags[afi][safi],
12034 PEER_FLAG_SEND_EXT_COMMUNITY)) {
12035 if (CHECK_FLAG(p->af_flags[afi][safi],
12036 PEER_FLAG_SEND_COMMUNITY)
12037 && CHECK_FLAG(p->af_flags[afi][safi],
12038 PEER_FLAG_SEND_EXT_COMMUNITY))
12039 json_object_string_add(json_addr,
12040 "commAttriSentToNbr",
12041 "extendedAndStandard");
12042 else if (CHECK_FLAG(p->af_flags[afi][safi],
12043 PEER_FLAG_SEND_EXT_COMMUNITY))
12044 json_object_string_add(json_addr,
12045 "commAttriSentToNbr",
12046 "extended");
12047 else
12048 json_object_string_add(json_addr,
12049 "commAttriSentToNbr",
12050 "standard");
12051 }
12052 if (CHECK_FLAG(p->af_flags[afi][safi],
12053 PEER_FLAG_DEFAULT_ORIGINATE)) {
12054 if (p->default_rmap[afi][safi].name)
12055 json_object_string_add(
12056 json_addr, "defaultRouteMap",
12057 p->default_rmap[afi][safi].name);
12058
12059 if (paf && PAF_SUBGRP(paf)
12060 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12061 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12062 json_object_boolean_true_add(json_addr,
12063 "defaultSent");
12064 else
12065 json_object_boolean_true_add(json_addr,
12066 "defaultNotSent");
12067 }
12068
dff8f48d 12069 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 12070 if (is_evpn_enabled())
60466a63
QY
12071 json_object_boolean_true_add(
12072 json_addr, "advertiseAllVnis");
dff8f48d
MK
12073 }
12074
d62a17ae 12075 if (filter->plist[FILTER_IN].name
12076 || filter->dlist[FILTER_IN].name
12077 || filter->aslist[FILTER_IN].name
12078 || filter->map[RMAP_IN].name)
12079 json_object_boolean_true_add(json_addr,
12080 "inboundPathPolicyConfig");
12081 if (filter->plist[FILTER_OUT].name
12082 || filter->dlist[FILTER_OUT].name
12083 || filter->aslist[FILTER_OUT].name
12084 || filter->map[RMAP_OUT].name || filter->usmap.name)
12085 json_object_boolean_true_add(
12086 json_addr, "outboundPathPolicyConfig");
12087
12088 /* prefix-list */
12089 if (filter->plist[FILTER_IN].name)
12090 json_object_string_add(json_addr,
12091 "incomingUpdatePrefixFilterList",
12092 filter->plist[FILTER_IN].name);
12093 if (filter->plist[FILTER_OUT].name)
12094 json_object_string_add(json_addr,
12095 "outgoingUpdatePrefixFilterList",
12096 filter->plist[FILTER_OUT].name);
12097
12098 /* distribute-list */
12099 if (filter->dlist[FILTER_IN].name)
12100 json_object_string_add(
12101 json_addr, "incomingUpdateNetworkFilterList",
12102 filter->dlist[FILTER_IN].name);
12103 if (filter->dlist[FILTER_OUT].name)
12104 json_object_string_add(
12105 json_addr, "outgoingUpdateNetworkFilterList",
12106 filter->dlist[FILTER_OUT].name);
12107
12108 /* filter-list. */
12109 if (filter->aslist[FILTER_IN].name)
12110 json_object_string_add(json_addr,
12111 "incomingUpdateAsPathFilterList",
12112 filter->aslist[FILTER_IN].name);
12113 if (filter->aslist[FILTER_OUT].name)
12114 json_object_string_add(json_addr,
12115 "outgoingUpdateAsPathFilterList",
12116 filter->aslist[FILTER_OUT].name);
12117
12118 /* route-map. */
12119 if (filter->map[RMAP_IN].name)
12120 json_object_string_add(
12121 json_addr, "routeMapForIncomingAdvertisements",
12122 filter->map[RMAP_IN].name);
12123 if (filter->map[RMAP_OUT].name)
12124 json_object_string_add(
12125 json_addr, "routeMapForOutgoingAdvertisements",
12126 filter->map[RMAP_OUT].name);
12127
9dac9fc8 12128 /* ebgp-requires-policy (inbound) */
1d3fdccf 12129 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12130 && !bgp_inbound_policy_exists(p, filter))
12131 json_object_string_add(
12132 json_addr, "inboundEbgpRequiresPolicy",
12133 "Inbound updates discarded due to missing policy");
12134
12135 /* ebgp-requires-policy (outbound) */
1d3fdccf 12136 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12137 && (!bgp_outbound_policy_exists(p, filter)))
12138 json_object_string_add(
12139 json_addr, "outboundEbgpRequiresPolicy",
12140 "Outbound updates discarded due to missing policy");
12141
d62a17ae 12142 /* unsuppress-map */
12143 if (filter->usmap.name)
12144 json_object_string_add(json_addr,
12145 "selectiveUnsuppressRouteMap",
12146 filter->usmap.name);
12147
fa36596c
MK
12148 /* advertise-map */
12149 if (filter->advmap.aname) {
12150 json_advmap = json_object_new_object();
12151 json_object_string_add(json_advmap, "condition",
12152 filter->advmap.condition
12153 ? "EXIST"
12154 : "NON_EXIST");
12155 json_object_string_add(json_advmap, "conditionMap",
12156 filter->advmap.cname);
12157 json_object_string_add(json_advmap, "advertiseMap",
12158 filter->advmap.aname);
12159 json_object_string_add(json_advmap, "advertiseStatus",
12160 filter->advmap.update_type
12161 == ADVERTISE
12162 ? "Advertise"
12163 : "Withdraw");
12164 json_object_object_add(json_addr, "advertiseMap",
12165 json_advmap);
12166 }
12167
d62a17ae 12168 /* Receive prefix count */
12169 json_object_int_add(json_addr, "acceptedPrefixCounter",
12170 p->pcount[afi][safi]);
50e05855
AD
12171 if (paf && PAF_SUBGRP(paf))
12172 json_object_int_add(json_addr, "sentPrefixCounter",
12173 (PAF_SUBGRP(paf))->scount);
d62a17ae 12174
fde246e8
DA
12175 /* Maximum prefix */
12176 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12177 json_object_int_add(json_addr, "prefixOutAllowedMax",
12178 p->pmax_out[afi][safi]);
12179
d62a17ae 12180 /* Maximum prefix */
12181 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12182 json_object_int_add(json_addr, "prefixAllowedMax",
12183 p->pmax[afi][safi]);
12184 if (CHECK_FLAG(p->af_flags[afi][safi],
12185 PEER_FLAG_MAX_PREFIX_WARNING))
12186 json_object_boolean_true_add(
12187 json_addr, "prefixAllowedMaxWarning");
12188 json_object_int_add(json_addr,
12189 "prefixAllowedWarningThresh",
12190 p->pmax_threshold[afi][safi]);
12191 if (p->pmax_restart[afi][safi])
12192 json_object_int_add(
12193 json_addr,
12194 "prefixAllowedRestartIntervalMsecs",
12195 p->pmax_restart[afi][safi] * 60000);
12196 }
2986cac2 12197 json_object_object_add(json_neigh,
36235319 12198 get_afi_safi_str(afi, safi, true),
d62a17ae 12199 json_addr);
12200
12201 } else {
12202 filter = &p->filter[afi][safi];
12203
12204 vty_out(vty, " For address family: %s\n",
5cb5f4d0 12205 get_afi_safi_str(afi, safi, false));
d62a17ae 12206
12207 if (peer_group_active(p))
12208 vty_out(vty, " %s peer-group member\n",
12209 p->group->name);
12210
12211 paf = peer_af_find(p, afi, safi);
12212 if (paf && PAF_SUBGRP(paf)) {
6cde4b45 12213 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
d62a17ae 12214 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12215 vty_out(vty, " Packet Queue length %d\n",
12216 bpacket_queue_virtual_length(paf));
12217 } else {
12218 vty_out(vty, " Not part of any update group\n");
12219 }
12220 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12221 || CHECK_FLAG(p->af_cap[afi][safi],
12222 PEER_CAP_ORF_PREFIX_SM_RCV)
12223 || CHECK_FLAG(p->af_cap[afi][safi],
12224 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12225 || CHECK_FLAG(p->af_cap[afi][safi],
12226 PEER_CAP_ORF_PREFIX_RM_ADV)
12227 || CHECK_FLAG(p->af_cap[afi][safi],
12228 PEER_CAP_ORF_PREFIX_RM_RCV)
12229 || CHECK_FLAG(p->af_cap[afi][safi],
12230 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12231 vty_out(vty, " AF-dependant capabilities:\n");
12232
12233 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12234 || CHECK_FLAG(p->af_cap[afi][safi],
12235 PEER_CAP_ORF_PREFIX_SM_RCV)
12236 || CHECK_FLAG(p->af_cap[afi][safi],
12237 PEER_CAP_ORF_PREFIX_RM_ADV)
12238 || CHECK_FLAG(p->af_cap[afi][safi],
12239 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12240 vty_out(vty,
12241 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12242 ORF_TYPE_PREFIX);
12243 bgp_show_peer_afi_orf_cap(
12244 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12245 PEER_CAP_ORF_PREFIX_RM_ADV,
12246 PEER_CAP_ORF_PREFIX_SM_RCV,
12247 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12248 }
12249 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12250 || CHECK_FLAG(p->af_cap[afi][safi],
12251 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12252 || CHECK_FLAG(p->af_cap[afi][safi],
12253 PEER_CAP_ORF_PREFIX_RM_ADV)
12254 || CHECK_FLAG(p->af_cap[afi][safi],
12255 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12256 vty_out(vty,
12257 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12258 ORF_TYPE_PREFIX_OLD);
12259 bgp_show_peer_afi_orf_cap(
12260 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12261 PEER_CAP_ORF_PREFIX_RM_ADV,
12262 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12263 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12264 }
12265
772270f3
QY
12266 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12267 p->host, afi, safi);
d62a17ae 12268 orf_pfx_count = prefix_bgp_show_prefix_list(
12269 NULL, afi, orf_pfx_name, use_json);
12270
12271 if (CHECK_FLAG(p->af_sflags[afi][safi],
12272 PEER_STATUS_ORF_PREFIX_SEND)
12273 || orf_pfx_count) {
12274 vty_out(vty, " Outbound Route Filter (ORF):");
12275 if (CHECK_FLAG(p->af_sflags[afi][safi],
12276 PEER_STATUS_ORF_PREFIX_SEND))
12277 vty_out(vty, " sent;");
12278 if (orf_pfx_count)
12279 vty_out(vty, " received (%d entries)",
12280 orf_pfx_count);
12281 vty_out(vty, "\n");
12282 }
12283 if (CHECK_FLAG(p->af_sflags[afi][safi],
12284 PEER_STATUS_ORF_WAIT_REFRESH))
12285 vty_out(vty,
12286 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12287
12288 if (CHECK_FLAG(p->af_flags[afi][safi],
12289 PEER_FLAG_REFLECTOR_CLIENT))
12290 vty_out(vty, " Route-Reflector Client\n");
12291 if (CHECK_FLAG(p->af_flags[afi][safi],
12292 PEER_FLAG_RSERVER_CLIENT))
12293 vty_out(vty, " Route-Server Client\n");
12294 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12295 vty_out(vty,
12296 " Inbound soft reconfiguration allowed\n");
12297
12298 if (CHECK_FLAG(p->af_flags[afi][safi],
12299 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12300 vty_out(vty,
12301 " Private AS numbers (all) replaced in updates to this neighbor\n");
12302 else if (CHECK_FLAG(p->af_flags[afi][safi],
12303 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12304 vty_out(vty,
12305 " Private AS numbers replaced in updates to this neighbor\n");
12306 else if (CHECK_FLAG(p->af_flags[afi][safi],
12307 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12308 vty_out(vty,
12309 " Private AS numbers (all) removed in updates to this neighbor\n");
12310 else if (CHECK_FLAG(p->af_flags[afi][safi],
12311 PEER_FLAG_REMOVE_PRIVATE_AS))
12312 vty_out(vty,
12313 " Private AS numbers removed in updates to this neighbor\n");
12314
dcc68b5e
MS
12315 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12316 vty_out(vty, " %s\n",
12317 bgp_addpath_names(p->addpath_type[afi][safi])
12318 ->human_description);
d62a17ae 12319
12320 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12321 vty_out(vty,
12322 " Override ASNs in outbound updates if aspath equals remote-as\n");
12323
12324 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12325 || CHECK_FLAG(p->af_flags[afi][safi],
12326 PEER_FLAG_FORCE_NEXTHOP_SELF))
12327 vty_out(vty, " NEXT_HOP is always this router\n");
12328 if (CHECK_FLAG(p->af_flags[afi][safi],
12329 PEER_FLAG_AS_PATH_UNCHANGED))
12330 vty_out(vty,
12331 " AS_PATH is propagated unchanged to this neighbor\n");
12332 if (CHECK_FLAG(p->af_flags[afi][safi],
12333 PEER_FLAG_NEXTHOP_UNCHANGED))
12334 vty_out(vty,
12335 " NEXT_HOP is propagated unchanged to this neighbor\n");
12336 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12337 vty_out(vty,
12338 " MED is propagated unchanged to this neighbor\n");
12339 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12340 || CHECK_FLAG(p->af_flags[afi][safi],
12341 PEER_FLAG_SEND_EXT_COMMUNITY)
12342 || CHECK_FLAG(p->af_flags[afi][safi],
12343 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12344 vty_out(vty,
12345 " Community attribute sent to this neighbor");
12346 if (CHECK_FLAG(p->af_flags[afi][safi],
12347 PEER_FLAG_SEND_COMMUNITY)
12348 && CHECK_FLAG(p->af_flags[afi][safi],
12349 PEER_FLAG_SEND_EXT_COMMUNITY)
12350 && CHECK_FLAG(p->af_flags[afi][safi],
12351 PEER_FLAG_SEND_LARGE_COMMUNITY))
12352 vty_out(vty, "(all)\n");
12353 else if (CHECK_FLAG(p->af_flags[afi][safi],
12354 PEER_FLAG_SEND_LARGE_COMMUNITY))
12355 vty_out(vty, "(large)\n");
12356 else if (CHECK_FLAG(p->af_flags[afi][safi],
12357 PEER_FLAG_SEND_EXT_COMMUNITY))
12358 vty_out(vty, "(extended)\n");
12359 else
12360 vty_out(vty, "(standard)\n");
12361 }
12362 if (CHECK_FLAG(p->af_flags[afi][safi],
12363 PEER_FLAG_DEFAULT_ORIGINATE)) {
12364 vty_out(vty, " Default information originate,");
12365
12366 if (p->default_rmap[afi][safi].name)
12367 vty_out(vty, " default route-map %s%s,",
12368 p->default_rmap[afi][safi].map ? "*"
12369 : "",
12370 p->default_rmap[afi][safi].name);
12371 if (paf && PAF_SUBGRP(paf)
12372 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12373 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12374 vty_out(vty, " default sent\n");
12375 else
12376 vty_out(vty, " default not sent\n");
12377 }
12378
dff8f48d
MK
12379 /* advertise-vni-all */
12380 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 12381 if (is_evpn_enabled())
dff8f48d
MK
12382 vty_out(vty, " advertise-all-vni\n");
12383 }
12384
d62a17ae 12385 if (filter->plist[FILTER_IN].name
12386 || filter->dlist[FILTER_IN].name
12387 || filter->aslist[FILTER_IN].name
12388 || filter->map[RMAP_IN].name)
12389 vty_out(vty, " Inbound path policy configured\n");
12390 if (filter->plist[FILTER_OUT].name
12391 || filter->dlist[FILTER_OUT].name
12392 || filter->aslist[FILTER_OUT].name
12393 || filter->map[RMAP_OUT].name || filter->usmap.name)
12394 vty_out(vty, " Outbound path policy configured\n");
12395
12396 /* prefix-list */
12397 if (filter->plist[FILTER_IN].name)
12398 vty_out(vty,
12399 " Incoming update prefix filter list is %s%s\n",
12400 filter->plist[FILTER_IN].plist ? "*" : "",
12401 filter->plist[FILTER_IN].name);
12402 if (filter->plist[FILTER_OUT].name)
12403 vty_out(vty,
12404 " Outgoing update prefix filter list is %s%s\n",
12405 filter->plist[FILTER_OUT].plist ? "*" : "",
12406 filter->plist[FILTER_OUT].name);
12407
12408 /* distribute-list */
12409 if (filter->dlist[FILTER_IN].name)
12410 vty_out(vty,
12411 " Incoming update network filter list is %s%s\n",
12412 filter->dlist[FILTER_IN].alist ? "*" : "",
12413 filter->dlist[FILTER_IN].name);
12414 if (filter->dlist[FILTER_OUT].name)
12415 vty_out(vty,
12416 " Outgoing update network filter list is %s%s\n",
12417 filter->dlist[FILTER_OUT].alist ? "*" : "",
12418 filter->dlist[FILTER_OUT].name);
12419
12420 /* filter-list. */
12421 if (filter->aslist[FILTER_IN].name)
12422 vty_out(vty,
12423 " Incoming update AS path filter list is %s%s\n",
12424 filter->aslist[FILTER_IN].aslist ? "*" : "",
12425 filter->aslist[FILTER_IN].name);
12426 if (filter->aslist[FILTER_OUT].name)
12427 vty_out(vty,
12428 " Outgoing update AS path filter list is %s%s\n",
12429 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12430 filter->aslist[FILTER_OUT].name);
12431
12432 /* route-map. */
12433 if (filter->map[RMAP_IN].name)
12434 vty_out(vty,
12435 " Route map for incoming advertisements is %s%s\n",
12436 filter->map[RMAP_IN].map ? "*" : "",
12437 filter->map[RMAP_IN].name);
12438 if (filter->map[RMAP_OUT].name)
12439 vty_out(vty,
12440 " Route map for outgoing advertisements is %s%s\n",
12441 filter->map[RMAP_OUT].map ? "*" : "",
12442 filter->map[RMAP_OUT].name);
12443
9dac9fc8 12444 /* ebgp-requires-policy (inbound) */
1d3fdccf 12445 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12446 && !bgp_inbound_policy_exists(p, filter))
12447 vty_out(vty,
12448 " Inbound updates discarded due to missing policy\n");
12449
12450 /* ebgp-requires-policy (outbound) */
1d3fdccf 12451 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12452 && !bgp_outbound_policy_exists(p, filter))
12453 vty_out(vty,
12454 " Outbound updates discarded due to missing policy\n");
12455
d62a17ae 12456 /* unsuppress-map */
12457 if (filter->usmap.name)
12458 vty_out(vty,
12459 " Route map for selective unsuppress is %s%s\n",
12460 filter->usmap.map ? "*" : "",
12461 filter->usmap.name);
12462
7f7940e6
MK
12463 /* advertise-map */
12464 if (filter->advmap.aname && filter->advmap.cname)
12465 vty_out(vty,
12466 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12467 filter->advmap.condition ? "EXIST"
12468 : "NON_EXIST",
12469 filter->advmap.cmap ? "*" : "",
12470 filter->advmap.cname,
12471 filter->advmap.amap ? "*" : "",
12472 filter->advmap.aname,
fa36596c 12473 filter->advmap.update_type == ADVERTISE
c385f82a
MK
12474 ? "Advertise"
12475 : "Withdraw");
7f7940e6 12476
d62a17ae 12477 /* Receive prefix count */
6cde4b45 12478 vty_out(vty, " %u accepted prefixes\n",
a0a87037 12479 p->pcount[afi][safi]);
d62a17ae 12480
fde246e8
DA
12481 /* maximum-prefix-out */
12482 if (CHECK_FLAG(p->af_flags[afi][safi],
12483 PEER_FLAG_MAX_PREFIX_OUT))
12484 vty_out(vty,
6cde4b45 12485 " Maximum allowed prefixes sent %u\n",
fde246e8
DA
12486 p->pmax_out[afi][safi]);
12487
d62a17ae 12488 /* Maximum prefix */
12489 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
a0a87037 12490 vty_out(vty,
6cde4b45 12491 " Maximum prefixes allowed %u%s\n",
d62a17ae 12492 p->pmax[afi][safi],
12493 CHECK_FLAG(p->af_flags[afi][safi],
12494 PEER_FLAG_MAX_PREFIX_WARNING)
12495 ? " (warning-only)"
12496 : "");
12497 vty_out(vty, " Threshold for warning message %d%%",
12498 p->pmax_threshold[afi][safi]);
12499 if (p->pmax_restart[afi][safi])
12500 vty_out(vty, ", restart interval %d min",
12501 p->pmax_restart[afi][safi]);
12502 vty_out(vty, "\n");
12503 }
12504
12505 vty_out(vty, "\n");
12506 }
12507}
12508
9f049418 12509static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 12510 json_object *json)
718e3744 12511{
d62a17ae 12512 struct bgp *bgp;
12513 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
12514 char timebuf[BGP_UPTIME_LEN];
12515 char dn_flag[2];
d62a17ae 12516 afi_t afi;
12517 safi_t safi;
d7c0a89a
QY
12518 uint16_t i;
12519 uint8_t *msg;
d62a17ae 12520 json_object *json_neigh = NULL;
12521 time_t epoch_tbuf;
718e3744 12522
d62a17ae 12523 bgp = p->bgp;
12524
12525 if (use_json)
12526 json_neigh = json_object_new_object();
12527
12528 memset(dn_flag, '\0', sizeof(dn_flag));
12529 if (!p->conf_if && peer_dynamic_neighbor(p))
12530 dn_flag[0] = '*';
12531
12532 if (!use_json) {
12533 if (p->conf_if) /* Configured interface name. */
12534 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
12535 BGP_PEER_SU_UNSPEC(p)
12536 ? "None"
12537 : sockunion2str(&p->su, buf,
12538 SU_ADDRSTRLEN));
12539 else /* Configured IP address. */
12540 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12541 p->host);
12542 }
12543
12544 if (use_json) {
12545 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12546 json_object_string_add(json_neigh, "bgpNeighborAddr",
12547 "none");
12548 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12549 json_object_string_add(
12550 json_neigh, "bgpNeighborAddr",
12551 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
12552
12553 json_object_int_add(json_neigh, "remoteAs", p->as);
12554
12555 if (p->change_local_as)
12556 json_object_int_add(json_neigh, "localAs",
12557 p->change_local_as);
12558 else
12559 json_object_int_add(json_neigh, "localAs", p->local_as);
12560
12561 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12562 json_object_boolean_true_add(json_neigh,
12563 "localAsNoPrepend");
12564
12565 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12566 json_object_boolean_true_add(json_neigh,
12567 "localAsReplaceAs");
12568 } else {
12569 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12570 || (p->as_type == AS_INTERNAL))
12571 vty_out(vty, "remote AS %u, ", p->as);
12572 else
12573 vty_out(vty, "remote AS Unspecified, ");
12574 vty_out(vty, "local AS %u%s%s, ",
12575 p->change_local_as ? p->change_local_as : p->local_as,
12576 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12577 ? " no-prepend"
12578 : "",
12579 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12580 ? " replace-as"
12581 : "");
12582 }
faa16034
DS
12583 /* peer type internal or confed-internal */
12584 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
d62a17ae 12585 if (use_json) {
12586 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12587 json_object_boolean_true_add(
12588 json_neigh, "nbrConfedInternalLink");
12589 else
12590 json_object_boolean_true_add(json_neigh,
12591 "nbrInternalLink");
12592 } else {
12593 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12594 vty_out(vty, "confed-internal link\n");
12595 else
12596 vty_out(vty, "internal link\n");
12597 }
faa16034
DS
12598 /* peer type external or confed-external */
12599 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
d62a17ae 12600 if (use_json) {
12601 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12602 json_object_boolean_true_add(
12603 json_neigh, "nbrConfedExternalLink");
12604 else
12605 json_object_boolean_true_add(json_neigh,
12606 "nbrExternalLink");
12607 } else {
12608 if (bgp_confederation_peers_check(bgp, p->as))
12609 vty_out(vty, "confed-external link\n");
12610 else
12611 vty_out(vty, "external link\n");
12612 }
faa16034
DS
12613 } else {
12614 if (use_json)
12615 json_object_boolean_true_add(json_neigh,
12616 "nbrUnspecifiedLink");
12617 else
12618 vty_out(vty, "unspecified link\n");
d62a17ae 12619 }
12620
12621 /* Description. */
12622 if (p->desc) {
12623 if (use_json)
12624 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12625 else
12626 vty_out(vty, " Description: %s\n", p->desc);
12627 }
12628
12629 if (p->hostname) {
12630 if (use_json) {
12631 if (p->hostname)
12632 json_object_string_add(json_neigh, "hostname",
12633 p->hostname);
12634
12635 if (p->domainname)
12636 json_object_string_add(json_neigh, "domainname",
12637 p->domainname);
12638 } else {
12639 if (p->domainname && (p->domainname[0] != '\0'))
12640 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
12641 p->domainname);
12642 else
12643 vty_out(vty, "Hostname: %s\n", p->hostname);
12644 }
12645 }
12646
12647 /* Peer-group */
12648 if (p->group) {
12649 if (use_json) {
12650 json_object_string_add(json_neigh, "peerGroup",
12651 p->group->name);
12652
12653 if (dn_flag[0]) {
12654 struct prefix prefix, *range = NULL;
12655
0154d8ce
DS
12656 if (sockunion2hostprefix(&(p->su), &prefix))
12657 range = peer_group_lookup_dynamic_neighbor_range(
12658 p->group, &prefix);
d62a17ae 12659
12660 if (range) {
12661 prefix2str(range, buf1, sizeof(buf1));
12662 json_object_string_add(
12663 json_neigh,
12664 "peerSubnetRangeGroup", buf1);
12665 }
12666 }
12667 } else {
12668 vty_out(vty,
12669 " Member of peer-group %s for session parameters\n",
12670 p->group->name);
12671
12672 if (dn_flag[0]) {
12673 struct prefix prefix, *range = NULL;
12674
0154d8ce
DS
12675 if (sockunion2hostprefix(&(p->su), &prefix))
12676 range = peer_group_lookup_dynamic_neighbor_range(
12677 p->group, &prefix);
d62a17ae 12678
12679 if (range) {
d62a17ae 12680 vty_out(vty,
1b78780b
DL
12681 " Belongs to the subnet range group: %pFX\n",
12682 range);
d62a17ae 12683 }
12684 }
12685 }
12686 }
12687
12688 if (use_json) {
12689 /* Administrative shutdown. */
cb9196e7
DS
12690 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12691 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 12692 json_object_boolean_true_add(json_neigh,
12693 "adminShutDown");
12694
12695 /* BGP Version. */
12696 json_object_int_add(json_neigh, "bgpVersion", 4);
12697 json_object_string_add(
12698 json_neigh, "remoteRouterId",
12699 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
d0086e8e
AD
12700 json_object_string_add(
12701 json_neigh, "localRouterId",
12702 inet_ntop(AF_INET, &bgp->router_id, buf1,
12703 sizeof(buf1)));
d62a17ae 12704
12705 /* Confederation */
12706 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12707 && bgp_confederation_peers_check(bgp, p->as))
12708 json_object_boolean_true_add(json_neigh,
12709 "nbrCommonAdmin");
12710
12711 /* Status. */
12712 json_object_string_add(
12713 json_neigh, "bgpState",
12714 lookup_msg(bgp_status_msg, p->status, NULL));
12715
12716 if (p->status == Established) {
12717 time_t uptime;
d62a17ae 12718
12719 uptime = bgp_clock();
12720 uptime -= p->uptime;
d62a17ae 12721 epoch_tbuf = time(NULL) - uptime;
12722
d3c7efed
DS
12723 json_object_int_add(json_neigh, "bgpTimerUpMsec",
12724 uptime * 1000);
d62a17ae 12725 json_object_string_add(json_neigh, "bgpTimerUpString",
12726 peer_uptime(p->uptime, timebuf,
12727 BGP_UPTIME_LEN, 0,
12728 NULL));
12729 json_object_int_add(json_neigh,
12730 "bgpTimerUpEstablishedEpoch",
12731 epoch_tbuf);
12732 }
12733
12734 else if (p->status == Active) {
12735 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12736 json_object_string_add(json_neigh, "bgpStateIs",
12737 "passive");
12738 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12739 json_object_string_add(json_neigh, "bgpStateIs",
12740 "passiveNSF");
12741 }
12742
12743 /* read timer */
12744 time_t uptime;
a2700b50 12745 struct tm tm;
d62a17ae 12746
12747 uptime = bgp_clock();
12748 uptime -= p->readtime;
a2700b50
MS
12749 gmtime_r(&uptime, &tm);
12750
d62a17ae 12751 json_object_int_add(json_neigh, "bgpTimerLastRead",
a2700b50
MS
12752 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12753 + (tm.tm_hour * 3600000));
d62a17ae 12754
12755 uptime = bgp_clock();
12756 uptime -= p->last_write;
a2700b50
MS
12757 gmtime_r(&uptime, &tm);
12758
d62a17ae 12759 json_object_int_add(json_neigh, "bgpTimerLastWrite",
a2700b50
MS
12760 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12761 + (tm.tm_hour * 3600000));
d62a17ae 12762
12763 uptime = bgp_clock();
12764 uptime -= p->update_time;
a2700b50
MS
12765 gmtime_r(&uptime, &tm);
12766
d62a17ae 12767 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
a2700b50
MS
12768 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12769 + (tm.tm_hour * 3600000));
d62a17ae 12770
12771 /* Configured timer values. */
12772 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
12773 p->v_holdtime * 1000);
12774 json_object_int_add(json_neigh,
12775 "bgpTimerKeepAliveIntervalMsecs",
12776 p->v_keepalive * 1000);
d43114f3
DS
12777 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
12778 json_object_int_add(json_neigh,
12779 "bgpTimerDelayOpenTimeMsecs",
12780 p->v_delayopen * 1000);
12781 }
12782
b90a8e13 12783 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 12784 json_object_int_add(json_neigh,
12785 "bgpTimerConfiguredHoldTimeMsecs",
12786 p->holdtime * 1000);
12787 json_object_int_add(
12788 json_neigh,
12789 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12790 p->keepalive * 1000);
5d5393b9
DL
12791 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12792 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
12793 json_object_int_add(json_neigh,
12794 "bgpTimerConfiguredHoldTimeMsecs",
12795 bgp->default_holdtime);
12796 json_object_int_add(
12797 json_neigh,
12798 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12799 bgp->default_keepalive);
d62a17ae 12800 }
12801 } else {
12802 /* Administrative shutdown. */
cb9196e7
DS
12803 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12804 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 12805 vty_out(vty, " Administratively shut down\n");
12806
12807 /* BGP Version. */
12808 vty_out(vty, " BGP version 4");
0e38aeb4 12809 vty_out(vty, ", remote router ID %s",
d62a17ae 12810 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
0e38aeb4
AD
12811 vty_out(vty, ", local router ID %s\n",
12812 inet_ntop(AF_INET, &bgp->router_id, buf1,
12813 sizeof(buf1)));
d62a17ae 12814
12815 /* Confederation */
12816 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12817 && bgp_confederation_peers_check(bgp, p->as))
12818 vty_out(vty,
12819 " Neighbor under common administration\n");
12820
12821 /* Status. */
12822 vty_out(vty, " BGP state = %s",
12823 lookup_msg(bgp_status_msg, p->status, NULL));
12824
12825 if (p->status == Established)
12826 vty_out(vty, ", up for %8s",
12827 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
12828 0, NULL));
12829
12830 else if (p->status == Active) {
12831 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12832 vty_out(vty, " (passive)");
12833 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12834 vty_out(vty, " (NSF passive)");
12835 }
12836 vty_out(vty, "\n");
12837
12838 /* read timer */
12839 vty_out(vty, " Last read %s",
12840 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
12841 NULL));
12842 vty_out(vty, ", Last write %s\n",
12843 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
12844 NULL));
12845
12846 /* Configured timer values. */
12847 vty_out(vty,
12848 " Hold time is %d, keepalive interval is %d seconds\n",
12849 p->v_holdtime, p->v_keepalive);
b90a8e13 12850 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 12851 vty_out(vty, " Configured hold time is %d",
12852 p->holdtime);
12853 vty_out(vty, ", keepalive interval is %d seconds\n",
12854 p->keepalive);
5d5393b9
DL
12855 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12856 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
12857 vty_out(vty, " Configured hold time is %d",
12858 bgp->default_holdtime);
12859 vty_out(vty, ", keepalive interval is %d seconds\n",
12860 bgp->default_keepalive);
d62a17ae 12861 }
d43114f3
DS
12862 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
12863 vty_out(vty,
12864 " Configured DelayOpenTime is %d seconds\n",
12865 p->delayopen);
d62a17ae 12866 }
12867 /* Capability. */
12868 if (p->status == Established) {
12869 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
12870 || p->afc_recv[AFI_IP][SAFI_UNICAST]
12871 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
12872 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
12873 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
12874 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
12875 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
12876 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
12877 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
12878 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
12879 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
12880 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
7c40bf39 12881 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
12882 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
d62a17ae 12883 || p->afc_adv[AFI_IP][SAFI_ENCAP]
12884 || p->afc_recv[AFI_IP][SAFI_ENCAP]
7c40bf39 12885 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
12886 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
d62a17ae 12887 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
12888 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
12889 if (use_json) {
12890 json_object *json_cap = NULL;
12891
12892 json_cap = json_object_new_object();
12893
12894 /* AS4 */
12895 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
12896 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
12897 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
12898 && CHECK_FLAG(p->cap,
12899 PEER_CAP_AS4_RCV))
12900 json_object_string_add(
12901 json_cap, "4byteAs",
12902 "advertisedAndReceived");
12903 else if (CHECK_FLAG(p->cap,
12904 PEER_CAP_AS4_ADV))
12905 json_object_string_add(
12906 json_cap, "4byteAs",
12907 "advertised");
12908 else if (CHECK_FLAG(p->cap,
12909 PEER_CAP_AS4_RCV))
12910 json_object_string_add(
12911 json_cap, "4byteAs",
12912 "received");
12913 }
12914
ef56aee4
DA
12915 /* Extended Message Support */
12916 if (CHECK_FLAG(p->cap,
12917 PEER_CAP_EXTENDED_MESSAGE_ADV)
12918 && CHECK_FLAG(
12919 p->cap,
12920 PEER_CAP_EXTENDED_MESSAGE_RCV))
12921 json_object_string_add(
12922 json_cap, "extendedMessage",
12923 "advertisedAndReceived");
12924 else if (CHECK_FLAG(
12925 p->cap,
12926 PEER_CAP_EXTENDED_MESSAGE_ADV))
12927 json_object_string_add(
12928 json_cap, "extendedMessage",
12929 "advertised");
12930 else if (CHECK_FLAG(
12931 p->cap,
12932 PEER_CAP_EXTENDED_MESSAGE_RCV))
12933 json_object_string_add(
12934 json_cap, "extendedMessage",
12935 "received");
12936
d62a17ae 12937 /* AddPath */
12938 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
12939 || CHECK_FLAG(p->cap,
12940 PEER_CAP_ADDPATH_ADV)) {
12941 json_object *json_add = NULL;
12942 const char *print_store;
12943
12944 json_add = json_object_new_object();
12945
05c7a1cc
QY
12946 FOREACH_AFI_SAFI (afi, safi) {
12947 json_object *json_sub = NULL;
12948 json_sub =
12949 json_object_new_object();
5cb5f4d0
DD
12950 print_store = get_afi_safi_str(
12951 afi, safi, true);
d62a17ae 12952
05c7a1cc
QY
12953 if (CHECK_FLAG(
12954 p->af_cap[afi]
12955 [safi],
12956 PEER_CAP_ADDPATH_AF_TX_ADV)
12957 || CHECK_FLAG(
12958 p->af_cap[afi]
12959 [safi],
12960 PEER_CAP_ADDPATH_AF_TX_RCV)) {
d62a17ae 12961 if (CHECK_FLAG(
12962 p->af_cap
12963 [afi]
12964 [safi],
12965 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 12966 && CHECK_FLAG(
d62a17ae 12967 p->af_cap
12968 [afi]
12969 [safi],
05c7a1cc
QY
12970 PEER_CAP_ADDPATH_AF_TX_RCV))
12971 json_object_boolean_true_add(
12972 json_sub,
12973 "txAdvertisedAndReceived");
12974 else if (
12975 CHECK_FLAG(
12976 p->af_cap
12977 [afi]
12978 [safi],
12979 PEER_CAP_ADDPATH_AF_TX_ADV))
12980 json_object_boolean_true_add(
12981 json_sub,
12982 "txAdvertised");
12983 else if (
12984 CHECK_FLAG(
12985 p->af_cap
12986 [afi]
12987 [safi],
12988 PEER_CAP_ADDPATH_AF_TX_RCV))
12989 json_object_boolean_true_add(
12990 json_sub,
12991 "txReceived");
12992 }
d62a17ae 12993
05c7a1cc
QY
12994 if (CHECK_FLAG(
12995 p->af_cap[afi]
12996 [safi],
12997 PEER_CAP_ADDPATH_AF_RX_ADV)
12998 || CHECK_FLAG(
12999 p->af_cap[afi]
13000 [safi],
13001 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 13002 if (CHECK_FLAG(
13003 p->af_cap
13004 [afi]
13005 [safi],
13006 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 13007 && CHECK_FLAG(
d62a17ae 13008 p->af_cap
13009 [afi]
13010 [safi],
13011 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
13012 json_object_boolean_true_add(
13013 json_sub,
13014 "rxAdvertisedAndReceived");
13015 else if (
13016 CHECK_FLAG(
13017 p->af_cap
13018 [afi]
13019 [safi],
13020 PEER_CAP_ADDPATH_AF_RX_ADV))
13021 json_object_boolean_true_add(
13022 json_sub,
13023 "rxAdvertised");
13024 else if (
13025 CHECK_FLAG(
13026 p->af_cap
13027 [afi]
13028 [safi],
13029 PEER_CAP_ADDPATH_AF_RX_RCV))
13030 json_object_boolean_true_add(
13031 json_sub,
13032 "rxReceived");
d62a17ae 13033 }
13034
05c7a1cc
QY
13035 if (CHECK_FLAG(
13036 p->af_cap[afi]
13037 [safi],
13038 PEER_CAP_ADDPATH_AF_TX_ADV)
13039 || CHECK_FLAG(
13040 p->af_cap[afi]
13041 [safi],
13042 PEER_CAP_ADDPATH_AF_TX_RCV)
13043 || CHECK_FLAG(
13044 p->af_cap[afi]
13045 [safi],
13046 PEER_CAP_ADDPATH_AF_RX_ADV)
13047 || CHECK_FLAG(
13048 p->af_cap[afi]
13049 [safi],
13050 PEER_CAP_ADDPATH_AF_RX_RCV))
13051 json_object_object_add(
13052 json_add,
13053 print_store,
13054 json_sub);
13055 else
13056 json_object_free(
13057 json_sub);
13058 }
13059
d62a17ae 13060 json_object_object_add(
13061 json_cap, "addPath", json_add);
13062 }
13063
13064 /* Dynamic */
13065 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
13066 || CHECK_FLAG(p->cap,
13067 PEER_CAP_DYNAMIC_ADV)) {
13068 if (CHECK_FLAG(p->cap,
13069 PEER_CAP_DYNAMIC_ADV)
13070 && CHECK_FLAG(p->cap,
13071 PEER_CAP_DYNAMIC_RCV))
13072 json_object_string_add(
13073 json_cap, "dynamic",
13074 "advertisedAndReceived");
13075 else if (CHECK_FLAG(
13076 p->cap,
13077 PEER_CAP_DYNAMIC_ADV))
13078 json_object_string_add(
13079 json_cap, "dynamic",
13080 "advertised");
13081 else if (CHECK_FLAG(
13082 p->cap,
13083 PEER_CAP_DYNAMIC_RCV))
13084 json_object_string_add(
13085 json_cap, "dynamic",
13086 "received");
13087 }
13088
13089 /* Extended nexthop */
13090 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
13091 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13092 json_object *json_nxt = NULL;
13093 const char *print_store;
13094
13095
13096 if (CHECK_FLAG(p->cap,
13097 PEER_CAP_ENHE_ADV)
13098 && CHECK_FLAG(p->cap,
13099 PEER_CAP_ENHE_RCV))
13100 json_object_string_add(
13101 json_cap,
13102 "extendedNexthop",
13103 "advertisedAndReceived");
13104 else if (CHECK_FLAG(p->cap,
13105 PEER_CAP_ENHE_ADV))
13106 json_object_string_add(
13107 json_cap,
13108 "extendedNexthop",
13109 "advertised");
13110 else if (CHECK_FLAG(p->cap,
13111 PEER_CAP_ENHE_RCV))
13112 json_object_string_add(
13113 json_cap,
13114 "extendedNexthop",
13115 "received");
13116
13117 if (CHECK_FLAG(p->cap,
13118 PEER_CAP_ENHE_RCV)) {
13119 json_nxt =
13120 json_object_new_object();
13121
13122 for (safi = SAFI_UNICAST;
13123 safi < SAFI_MAX; safi++) {
13124 if (CHECK_FLAG(
13125 p->af_cap
13126 [AFI_IP]
13127 [safi],
13128 PEER_CAP_ENHE_AF_RCV)) {
5cb5f4d0 13129 print_store = get_afi_safi_str(
d62a17ae 13130 AFI_IP,
5cb5f4d0 13131 safi, true);
d62a17ae 13132 json_object_string_add(
13133 json_nxt,
13134 print_store,
54f29523 13135 "recieved"); /* misspelled for compatibility */
d62a17ae 13136 }
13137 }
13138 json_object_object_add(
13139 json_cap,
13140 "extendedNexthopFamililesByPeer",
13141 json_nxt);
13142 }
13143 }
13144
13145 /* Route Refresh */
13146 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
13147 || CHECK_FLAG(p->cap,
13148 PEER_CAP_REFRESH_NEW_RCV)
13149 || CHECK_FLAG(p->cap,
13150 PEER_CAP_REFRESH_OLD_RCV)) {
13151 if (CHECK_FLAG(p->cap,
13152 PEER_CAP_REFRESH_ADV)
13153 && (CHECK_FLAG(
13154 p->cap,
13155 PEER_CAP_REFRESH_NEW_RCV)
13156 || CHECK_FLAG(
13157 p->cap,
13158 PEER_CAP_REFRESH_OLD_RCV))) {
13159 if (CHECK_FLAG(
13160 p->cap,
13161 PEER_CAP_REFRESH_OLD_RCV)
13162 && CHECK_FLAG(
13163 p->cap,
13164 PEER_CAP_REFRESH_NEW_RCV))
13165 json_object_string_add(
13166 json_cap,
13167 "routeRefresh",
13168 "advertisedAndReceivedOldNew");
13169 else {
13170 if (CHECK_FLAG(
13171 p->cap,
13172 PEER_CAP_REFRESH_OLD_RCV))
13173 json_object_string_add(
13174 json_cap,
13175 "routeRefresh",
13176 "advertisedAndReceivedOld");
13177 else
13178 json_object_string_add(
13179 json_cap,
13180 "routeRefresh",
13181 "advertisedAndReceivedNew");
13182 }
13183 } else if (
13184 CHECK_FLAG(
13185 p->cap,
13186 PEER_CAP_REFRESH_ADV))
13187 json_object_string_add(
13188 json_cap,
13189 "routeRefresh",
13190 "advertised");
13191 else if (
13192 CHECK_FLAG(
13193 p->cap,
13194 PEER_CAP_REFRESH_NEW_RCV)
13195 || CHECK_FLAG(
13196 p->cap,
13197 PEER_CAP_REFRESH_OLD_RCV))
13198 json_object_string_add(
13199 json_cap,
13200 "routeRefresh",
13201 "received");
13202 }
13203
9af52ccf
DA
13204 /* Enhanced Route Refresh */
13205 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV)
13206 || CHECK_FLAG(p->cap,
13207 PEER_CAP_ENHANCED_RR_RCV)) {
13208 if (CHECK_FLAG(p->cap,
13209 PEER_CAP_ENHANCED_RR_ADV)
13210 && CHECK_FLAG(
13211 p->cap,
13212 PEER_CAP_ENHANCED_RR_RCV))
13213 json_object_string_add(
13214 json_cap,
13215 "enhancedRouteRefresh",
13216 "advertisedAndReceived");
13217 else if (
13218 CHECK_FLAG(
13219 p->cap,
13220 PEER_CAP_ENHANCED_RR_ADV))
13221 json_object_string_add(
13222 json_cap,
13223 "enhancedRouteRefresh",
13224 "advertised");
13225 else if (
13226 CHECK_FLAG(
13227 p->cap,
13228 PEER_CAP_ENHANCED_RR_RCV))
13229 json_object_string_add(
13230 json_cap,
13231 "enhancedRouteRefresh",
13232 "received");
13233 }
13234
d62a17ae 13235 /* Multiprotocol Extensions */
13236 json_object *json_multi = NULL;
13237 json_multi = json_object_new_object();
13238
05c7a1cc
QY
13239 FOREACH_AFI_SAFI (afi, safi) {
13240 if (p->afc_adv[afi][safi]
13241 || p->afc_recv[afi][safi]) {
13242 json_object *json_exten = NULL;
13243 json_exten =
13244 json_object_new_object();
13245
d62a17ae 13246 if (p->afc_adv[afi][safi]
05c7a1cc
QY
13247 && p->afc_recv[afi][safi])
13248 json_object_boolean_true_add(
13249 json_exten,
13250 "advertisedAndReceived");
13251 else if (p->afc_adv[afi][safi])
13252 json_object_boolean_true_add(
13253 json_exten,
13254 "advertised");
13255 else if (p->afc_recv[afi][safi])
13256 json_object_boolean_true_add(
13257 json_exten,
13258 "received");
d62a17ae 13259
05c7a1cc
QY
13260 json_object_object_add(
13261 json_multi,
5cb5f4d0
DD
13262 get_afi_safi_str(afi,
13263 safi,
13264 true),
05c7a1cc 13265 json_exten);
d62a17ae 13266 }
13267 }
13268 json_object_object_add(
13269 json_cap, "multiprotocolExtensions",
13270 json_multi);
13271
d77114b7 13272 /* Hostname capabilities */
60466a63 13273 json_object *json_hname = NULL;
d77114b7
MK
13274
13275 json_hname = json_object_new_object();
13276
13277 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13278 json_object_string_add(
60466a63
QY
13279 json_hname, "advHostName",
13280 bgp->peer_self->hostname
13281 ? bgp->peer_self
13282 ->hostname
d77114b7
MK
13283 : "n/a");
13284 json_object_string_add(
60466a63
QY
13285 json_hname, "advDomainName",
13286 bgp->peer_self->domainname
13287 ? bgp->peer_self
13288 ->domainname
d77114b7
MK
13289 : "n/a");
13290 }
13291
13292
13293 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13294 json_object_string_add(
60466a63
QY
13295 json_hname, "rcvHostName",
13296 p->hostname ? p->hostname
13297 : "n/a");
d77114b7 13298 json_object_string_add(
60466a63
QY
13299 json_hname, "rcvDomainName",
13300 p->domainname ? p->domainname
13301 : "n/a");
d77114b7
MK
13302 }
13303
60466a63 13304 json_object_object_add(json_cap, "hostName",
d77114b7
MK
13305 json_hname);
13306
d62a17ae 13307 /* Gracefull Restart */
13308 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
13309 || CHECK_FLAG(p->cap,
13310 PEER_CAP_RESTART_ADV)) {
13311 if (CHECK_FLAG(p->cap,
13312 PEER_CAP_RESTART_ADV)
13313 && CHECK_FLAG(p->cap,
13314 PEER_CAP_RESTART_RCV))
13315 json_object_string_add(
13316 json_cap,
13317 "gracefulRestart",
13318 "advertisedAndReceived");
13319 else if (CHECK_FLAG(
13320 p->cap,
13321 PEER_CAP_RESTART_ADV))
13322 json_object_string_add(
13323 json_cap,
13324 "gracefulRestartCapability",
13325 "advertised");
13326 else if (CHECK_FLAG(
13327 p->cap,
13328 PEER_CAP_RESTART_RCV))
13329 json_object_string_add(
13330 json_cap,
13331 "gracefulRestartCapability",
13332 "received");
13333
13334 if (CHECK_FLAG(p->cap,
13335 PEER_CAP_RESTART_RCV)) {
13336 int restart_af_count = 0;
13337 json_object *json_restart =
13338 NULL;
13339 json_restart =
13340 json_object_new_object();
13341
13342 json_object_int_add(
13343 json_cap,
13344 "gracefulRestartRemoteTimerMsecs",
13345 p->v_gr_restart * 1000);
13346
05c7a1cc
QY
13347 FOREACH_AFI_SAFI (afi, safi) {
13348 if (CHECK_FLAG(
13349 p->af_cap
13350 [afi]
13351 [safi],
13352 PEER_CAP_RESTART_AF_RCV)) {
13353 json_object *
13354 json_sub =
13355 NULL;
13356 json_sub =
13357 json_object_new_object();
13358
d62a17ae 13359 if (CHECK_FLAG(
13360 p->af_cap
13361 [afi]
13362 [safi],
05c7a1cc
QY
13363 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13364 json_object_boolean_true_add(
13365 json_sub,
13366 "preserved");
13367 restart_af_count++;
13368 json_object_object_add(
13369 json_restart,
5cb5f4d0 13370 get_afi_safi_str(
05c7a1cc 13371 afi,
5cb5f4d0
DD
13372 safi,
13373 true),
05c7a1cc 13374 json_sub);
d62a17ae 13375 }
13376 }
13377 if (!restart_af_count) {
13378 json_object_string_add(
13379 json_cap,
13380 "addressFamiliesByPeer",
13381 "none");
13382 json_object_free(
13383 json_restart);
13384 } else
13385 json_object_object_add(
13386 json_cap,
13387 "addressFamiliesByPeer",
13388 json_restart);
13389 }
13390 }
13391 json_object_object_add(json_neigh,
13392 "neighborCapabilities",
13393 json_cap);
13394 } else {
13395 vty_out(vty, " Neighbor capabilities:\n");
13396
13397 /* AS4 */
13398 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
13399 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13400 vty_out(vty, " 4 Byte AS:");
13401 if (CHECK_FLAG(p->cap,
13402 PEER_CAP_AS4_ADV))
13403 vty_out(vty, " advertised");
13404 if (CHECK_FLAG(p->cap,
13405 PEER_CAP_AS4_RCV))
13406 vty_out(vty, " %sreceived",
13407 CHECK_FLAG(
13408 p->cap,
13409 PEER_CAP_AS4_ADV)
13410 ? "and "
13411 : "");
13412 vty_out(vty, "\n");
13413 }
13414
ef56aee4
DA
13415 /* Extended Message Support */
13416 if (CHECK_FLAG(p->cap,
13417 PEER_CAP_EXTENDED_MESSAGE_RCV)
13418 || CHECK_FLAG(
13419 p->cap,
13420 PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13421 vty_out(vty, " Extended Message:");
13422 if (CHECK_FLAG(
13423 p->cap,
13424 PEER_CAP_EXTENDED_MESSAGE_ADV))
13425 vty_out(vty, " advertised");
13426 if (CHECK_FLAG(
13427 p->cap,
13428 PEER_CAP_EXTENDED_MESSAGE_RCV))
13429 vty_out(vty, " %sreceived",
13430 CHECK_FLAG(
13431 p->cap,
13432 PEER_CAP_EXTENDED_MESSAGE_ADV)
13433 ? "and "
13434 : "");
13435 vty_out(vty, "\n");
13436 }
13437
d62a17ae 13438 /* AddPath */
13439 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
13440 || CHECK_FLAG(p->cap,
13441 PEER_CAP_ADDPATH_ADV)) {
13442 vty_out(vty, " AddPath:\n");
13443
05c7a1cc
QY
13444 FOREACH_AFI_SAFI (afi, safi) {
13445 if (CHECK_FLAG(
13446 p->af_cap[afi]
13447 [safi],
13448 PEER_CAP_ADDPATH_AF_TX_ADV)
13449 || CHECK_FLAG(
13450 p->af_cap[afi]
13451 [safi],
13452 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13453 vty_out(vty,
13454 " %s: TX ",
5cb5f4d0 13455 get_afi_safi_str(
05c7a1cc 13456 afi,
5cb5f4d0
DD
13457 safi,
13458 false));
05c7a1cc 13459
d62a17ae 13460 if (CHECK_FLAG(
13461 p->af_cap
13462 [afi]
13463 [safi],
05c7a1cc 13464 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 13465 vty_out(vty,
05c7a1cc 13466 "advertised %s",
5cb5f4d0 13467 get_afi_safi_str(
d62a17ae 13468 afi,
5cb5f4d0
DD
13469 safi,
13470 false));
d62a17ae 13471
05c7a1cc
QY
13472 if (CHECK_FLAG(
13473 p->af_cap
13474 [afi]
13475 [safi],
13476 PEER_CAP_ADDPATH_AF_TX_RCV))
13477 vty_out(vty,
13478 "%sreceived",
13479 CHECK_FLAG(
13480 p->af_cap
13481 [afi]
13482 [safi],
13483 PEER_CAP_ADDPATH_AF_TX_ADV)
13484 ? " and "
13485 : "");
d62a17ae 13486
05c7a1cc
QY
13487 vty_out(vty, "\n");
13488 }
d62a17ae 13489
05c7a1cc
QY
13490 if (CHECK_FLAG(
13491 p->af_cap[afi]
13492 [safi],
13493 PEER_CAP_ADDPATH_AF_RX_ADV)
13494 || CHECK_FLAG(
13495 p->af_cap[afi]
13496 [safi],
13497 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13498 vty_out(vty,
13499 " %s: RX ",
5cb5f4d0 13500 get_afi_safi_str(
05c7a1cc 13501 afi,
5cb5f4d0
DD
13502 safi,
13503 false));
d62a17ae 13504
13505 if (CHECK_FLAG(
13506 p->af_cap
13507 [afi]
13508 [safi],
05c7a1cc 13509 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 13510 vty_out(vty,
05c7a1cc 13511 "advertised %s",
5cb5f4d0 13512 get_afi_safi_str(
d62a17ae 13513 afi,
5cb5f4d0
DD
13514 safi,
13515 false));
d62a17ae 13516
05c7a1cc
QY
13517 if (CHECK_FLAG(
13518 p->af_cap
13519 [afi]
13520 [safi],
13521 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 13522 vty_out(vty,
05c7a1cc
QY
13523 "%sreceived",
13524 CHECK_FLAG(
13525 p->af_cap
13526 [afi]
13527 [safi],
13528 PEER_CAP_ADDPATH_AF_RX_ADV)
13529 ? " and "
13530 : "");
13531
13532 vty_out(vty, "\n");
d62a17ae 13533 }
05c7a1cc 13534 }
d62a17ae 13535 }
13536
13537 /* Dynamic */
13538 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
13539 || CHECK_FLAG(p->cap,
13540 PEER_CAP_DYNAMIC_ADV)) {
13541 vty_out(vty, " Dynamic:");
13542 if (CHECK_FLAG(p->cap,
13543 PEER_CAP_DYNAMIC_ADV))
13544 vty_out(vty, " advertised");
13545 if (CHECK_FLAG(p->cap,
13546 PEER_CAP_DYNAMIC_RCV))
13547 vty_out(vty, " %sreceived",
13548 CHECK_FLAG(
13549 p->cap,
13550 PEER_CAP_DYNAMIC_ADV)
13551 ? "and "
13552 : "");
13553 vty_out(vty, "\n");
13554 }
13555
13556 /* Extended nexthop */
13557 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
13558 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13559 vty_out(vty, " Extended nexthop:");
13560 if (CHECK_FLAG(p->cap,
13561 PEER_CAP_ENHE_ADV))
13562 vty_out(vty, " advertised");
13563 if (CHECK_FLAG(p->cap,
13564 PEER_CAP_ENHE_RCV))
13565 vty_out(vty, " %sreceived",
13566 CHECK_FLAG(
13567 p->cap,
13568 PEER_CAP_ENHE_ADV)
13569 ? "and "
13570 : "");
13571 vty_out(vty, "\n");
13572
13573 if (CHECK_FLAG(p->cap,
13574 PEER_CAP_ENHE_RCV)) {
13575 vty_out(vty,
13576 " Address families by peer:\n ");
13577 for (safi = SAFI_UNICAST;
13578 safi < SAFI_MAX; safi++)
13579 if (CHECK_FLAG(
13580 p->af_cap
13581 [AFI_IP]
13582 [safi],
13583 PEER_CAP_ENHE_AF_RCV))
13584 vty_out(vty,
13585 " %s\n",
5cb5f4d0 13586 get_afi_safi_str(
d62a17ae 13587 AFI_IP,
5cb5f4d0
DD
13588 safi,
13589 false));
d62a17ae 13590 }
13591 }
13592
13593 /* Route Refresh */
13594 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
13595 || CHECK_FLAG(p->cap,
13596 PEER_CAP_REFRESH_NEW_RCV)
13597 || CHECK_FLAG(p->cap,
13598 PEER_CAP_REFRESH_OLD_RCV)) {
13599 vty_out(vty, " Route refresh:");
13600 if (CHECK_FLAG(p->cap,
13601 PEER_CAP_REFRESH_ADV))
13602 vty_out(vty, " advertised");
13603 if (CHECK_FLAG(p->cap,
13604 PEER_CAP_REFRESH_NEW_RCV)
13605 || CHECK_FLAG(
13606 p->cap,
13607 PEER_CAP_REFRESH_OLD_RCV))
13608 vty_out(vty, " %sreceived(%s)",
13609 CHECK_FLAG(
13610 p->cap,
13611 PEER_CAP_REFRESH_ADV)
13612 ? "and "
13613 : "",
13614 (CHECK_FLAG(
13615 p->cap,
13616 PEER_CAP_REFRESH_OLD_RCV)
13617 && CHECK_FLAG(
13618 p->cap,
13619 PEER_CAP_REFRESH_NEW_RCV))
13620 ? "old & new"
13621 : CHECK_FLAG(
13622 p->cap,
13623 PEER_CAP_REFRESH_OLD_RCV)
13624 ? "old"
13625 : "new");
13626
13627 vty_out(vty, "\n");
13628 }
13629
9af52ccf
DA
13630 /* Enhanced Route Refresh */
13631 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV)
13632 || CHECK_FLAG(p->cap,
13633 PEER_CAP_ENHANCED_RR_RCV)) {
13634 vty_out(vty,
13635 " Enhanced Route Refresh:");
13636 if (CHECK_FLAG(
13637 p->cap,
13638 PEER_CAP_ENHANCED_RR_ADV))
13639 vty_out(vty, " advertised");
13640 if (CHECK_FLAG(
13641 p->cap,
13642 PEER_CAP_ENHANCED_RR_RCV))
13643 vty_out(vty, " %sreceived",
13644 CHECK_FLAG(
13645 p->cap,
13646 PEER_CAP_REFRESH_ADV)
13647 ? "and "
13648 : "");
13649 vty_out(vty, "\n");
13650 }
13651
d62a17ae 13652 /* Multiprotocol Extensions */
05c7a1cc
QY
13653 FOREACH_AFI_SAFI (afi, safi)
13654 if (p->afc_adv[afi][safi]
13655 || p->afc_recv[afi][safi]) {
13656 vty_out(vty,
13657 " Address Family %s:",
5cb5f4d0
DD
13658 get_afi_safi_str(
13659 afi,
13660 safi,
13661 false));
05c7a1cc 13662 if (p->afc_adv[afi][safi])
d62a17ae 13663 vty_out(vty,
05c7a1cc
QY
13664 " advertised");
13665 if (p->afc_recv[afi][safi])
13666 vty_out(vty,
13667 " %sreceived",
13668 p->afc_adv[afi]
13669 [safi]
13670 ? "and "
13671 : "");
13672 vty_out(vty, "\n");
13673 }
d62a17ae 13674
13675 /* Hostname capability */
60466a63 13676 vty_out(vty, " Hostname Capability:");
d77114b7
MK
13677
13678 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
13679 vty_out(vty,
13680 " advertised (name: %s,domain name: %s)",
60466a63
QY
13681 bgp->peer_self->hostname
13682 ? bgp->peer_self
13683 ->hostname
d77114b7 13684 : "n/a",
60466a63
QY
13685 bgp->peer_self->domainname
13686 ? bgp->peer_self
13687 ->domainname
d77114b7
MK
13688 : "n/a");
13689 } else {
13690 vty_out(vty, " not advertised");
d62a17ae 13691 }
13692
d77114b7 13693 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
13694 vty_out(vty,
13695 " received (name: %s,domain name: %s)",
60466a63
QY
13696 p->hostname ? p->hostname
13697 : "n/a",
13698 p->domainname ? p->domainname
13699 : "n/a");
d77114b7
MK
13700 } else {
13701 vty_out(vty, " not received");
13702 }
13703
13704 vty_out(vty, "\n");
13705
61bfbd51 13706 /* Graceful Restart */
d62a17ae 13707 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
13708 || CHECK_FLAG(p->cap,
13709 PEER_CAP_RESTART_ADV)) {
13710 vty_out(vty,
61bfbd51 13711 " Graceful Restart Capability:");
d62a17ae 13712 if (CHECK_FLAG(p->cap,
13713 PEER_CAP_RESTART_ADV))
13714 vty_out(vty, " advertised");
13715 if (CHECK_FLAG(p->cap,
13716 PEER_CAP_RESTART_RCV))
13717 vty_out(vty, " %sreceived",
13718 CHECK_FLAG(
13719 p->cap,
13720 PEER_CAP_RESTART_ADV)
13721 ? "and "
13722 : "");
13723 vty_out(vty, "\n");
13724
13725 if (CHECK_FLAG(p->cap,
13726 PEER_CAP_RESTART_RCV)) {
13727 int restart_af_count = 0;
13728
13729 vty_out(vty,
13730 " Remote Restart timer is %d seconds\n",
13731 p->v_gr_restart);
13732 vty_out(vty,
13733 " Address families by peer:\n ");
13734
05c7a1cc
QY
13735 FOREACH_AFI_SAFI (afi, safi)
13736 if (CHECK_FLAG(
13737 p->af_cap
13738 [afi]
13739 [safi],
13740 PEER_CAP_RESTART_AF_RCV)) {
13741 vty_out(vty,
13742 "%s%s(%s)",
13743 restart_af_count
13744 ? ", "
13745 : "",
5cb5f4d0 13746 get_afi_safi_str(
05c7a1cc 13747 afi,
5cb5f4d0
DD
13748 safi,
13749 false),
05c7a1cc
QY
13750 CHECK_FLAG(
13751 p->af_cap
13752 [afi]
13753 [safi],
13754 PEER_CAP_RESTART_AF_PRESERVE_RCV)
13755 ? "preserved"
13756 : "not preserved");
13757 restart_af_count++;
13758 }
d62a17ae 13759 if (!restart_af_count)
13760 vty_out(vty, "none");
13761 vty_out(vty, "\n");
13762 }
2986cac2 13763 } /* Gracefull Restart */
d62a17ae 13764 }
13765 }
13766 }
13767
13768 /* graceful restart information */
d62a17ae 13769 json_object *json_grace = NULL;
13770 json_object *json_grace_send = NULL;
13771 json_object *json_grace_recv = NULL;
13772 int eor_send_af_count = 0;
13773 int eor_receive_af_count = 0;
13774
13775 if (use_json) {
13776 json_grace = json_object_new_object();
13777 json_grace_send = json_object_new_object();
13778 json_grace_recv = json_object_new_object();
13779
36235319
QY
13780 if ((p->status == Established)
13781 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
05c7a1cc
QY
13782 FOREACH_AFI_SAFI (afi, safi) {
13783 if (CHECK_FLAG(p->af_sflags[afi][safi],
36235319 13784 PEER_STATUS_EOR_SEND)) {
05c7a1cc
QY
13785 json_object_boolean_true_add(
13786 json_grace_send,
5cb5f4d0
DD
13787 get_afi_safi_str(afi,
13788 safi,
13789 true));
05c7a1cc 13790 eor_send_af_count++;
d62a17ae 13791 }
13792 }
05c7a1cc
QY
13793 FOREACH_AFI_SAFI (afi, safi) {
13794 if (CHECK_FLAG(
36235319
QY
13795 p->af_sflags[afi][safi],
13796 PEER_STATUS_EOR_RECEIVED)) {
05c7a1cc
QY
13797 json_object_boolean_true_add(
13798 json_grace_recv,
5cb5f4d0
DD
13799 get_afi_safi_str(afi,
13800 safi,
13801 true));
05c7a1cc 13802 eor_receive_af_count++;
d62a17ae 13803 }
13804 }
13805 }
36235319
QY
13806 json_object_object_add(json_grace, "endOfRibSend",
13807 json_grace_send);
13808 json_object_object_add(json_grace, "endOfRibRecv",
13809 json_grace_recv);
d62a17ae 13810
d62a17ae 13811
13812 if (p->t_gr_restart)
13813 json_object_int_add(json_grace,
13814 "gracefulRestartTimerMsecs",
13815 thread_timer_remain_second(
13816 p->t_gr_restart)
13817 * 1000);
13818
13819 if (p->t_gr_stale)
13820 json_object_int_add(
13821 json_grace,
13822 "gracefulStalepathTimerMsecs",
13823 thread_timer_remain_second(
13824 p->t_gr_stale)
13825 * 1000);
2986cac2 13826 /* more gr info in new format */
13827 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json,
36235319 13828 json_grace);
d62a17ae 13829 json_object_object_add(
13830 json_neigh, "gracefulRestartInfo", json_grace);
13831 } else {
2089dd80 13832 vty_out(vty, " Graceful restart information:\n");
36235319
QY
13833 if ((p->status == Established)
13834 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 13835
d62a17ae 13836 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
13837 FOREACH_AFI_SAFI (afi, safi) {
13838 if (CHECK_FLAG(p->af_sflags[afi][safi],
13839 PEER_STATUS_EOR_SEND)) {
13840 vty_out(vty, "%s%s",
13841 eor_send_af_count ? ", "
13842 : "",
36235319
QY
13843 get_afi_safi_str(
13844 afi, safi,
13845 false));
05c7a1cc 13846 eor_send_af_count++;
d62a17ae 13847 }
13848 }
13849 vty_out(vty, "\n");
13850 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
13851 FOREACH_AFI_SAFI (afi, safi) {
13852 if (CHECK_FLAG(
13853 p->af_sflags[afi][safi],
13854 PEER_STATUS_EOR_RECEIVED)) {
13855 vty_out(vty, "%s%s",
13856 eor_receive_af_count
13857 ? ", "
13858 : "",
5cb5f4d0
DD
13859 get_afi_safi_str(afi,
13860 safi,
13861 false));
05c7a1cc 13862 eor_receive_af_count++;
d62a17ae 13863 }
13864 }
13865 vty_out(vty, "\n");
13866 }
13867
13868 if (p->t_gr_restart)
13869 vty_out(vty,
13870 " The remaining time of restart timer is %ld\n",
13871 thread_timer_remain_second(
13872 p->t_gr_restart));
13873
13874 if (p->t_gr_stale)
13875 vty_out(vty,
13876 " The remaining time of stalepath timer is %ld\n",
13877 thread_timer_remain_second(
13878 p->t_gr_stale));
2986cac2 13879
13880 /* more gr info in new format */
13881 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
d62a17ae 13882 }
2986cac2 13883
d62a17ae 13884 if (use_json) {
13885 json_object *json_stat = NULL;
13886 json_stat = json_object_new_object();
13887 /* Packet counts. */
43aa5965
QY
13888
13889 atomic_size_t outq_count, inq_count;
13890 outq_count = atomic_load_explicit(&p->obuf->count,
13891 memory_order_relaxed);
13892 inq_count = atomic_load_explicit(&p->ibuf->count,
13893 memory_order_relaxed);
13894
13895 json_object_int_add(json_stat, "depthInq",
13896 (unsigned long)inq_count);
d62a17ae 13897 json_object_int_add(json_stat, "depthOutq",
43aa5965 13898 (unsigned long)outq_count);
0112e9e0
QY
13899 json_object_int_add(json_stat, "opensSent",
13900 atomic_load_explicit(&p->open_out,
13901 memory_order_relaxed));
13902 json_object_int_add(json_stat, "opensRecv",
13903 atomic_load_explicit(&p->open_in,
13904 memory_order_relaxed));
d62a17ae 13905 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
13906 atomic_load_explicit(&p->notify_out,
13907 memory_order_relaxed));
d62a17ae 13908 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
13909 atomic_load_explicit(&p->notify_in,
13910 memory_order_relaxed));
13911 json_object_int_add(json_stat, "updatesSent",
13912 atomic_load_explicit(&p->update_out,
13913 memory_order_relaxed));
13914 json_object_int_add(json_stat, "updatesRecv",
13915 atomic_load_explicit(&p->update_in,
13916 memory_order_relaxed));
d62a17ae 13917 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
13918 atomic_load_explicit(&p->keepalive_out,
13919 memory_order_relaxed));
d62a17ae 13920 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
13921 atomic_load_explicit(&p->keepalive_in,
13922 memory_order_relaxed));
d62a17ae 13923 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
13924 atomic_load_explicit(&p->refresh_out,
13925 memory_order_relaxed));
d62a17ae 13926 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
13927 atomic_load_explicit(&p->refresh_in,
13928 memory_order_relaxed));
d62a17ae 13929 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
13930 atomic_load_explicit(&p->dynamic_cap_out,
13931 memory_order_relaxed));
d62a17ae 13932 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
13933 atomic_load_explicit(&p->dynamic_cap_in,
13934 memory_order_relaxed));
13935 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
13936 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 13937 json_object_object_add(json_neigh, "messageStats", json_stat);
13938 } else {
43aa5965
QY
13939 atomic_size_t outq_count, inq_count;
13940 outq_count = atomic_load_explicit(&p->obuf->count,
13941 memory_order_relaxed);
13942 inq_count = atomic_load_explicit(&p->ibuf->count,
13943 memory_order_relaxed);
13944
d62a17ae 13945 /* Packet counts. */
13946 vty_out(vty, " Message statistics:\n");
43aa5965
QY
13947 vty_out(vty, " Inq depth is %zu\n", inq_count);
13948 vty_out(vty, " Outq depth is %zu\n", outq_count);
d62a17ae 13949 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
13950 vty_out(vty, " Opens: %10d %10d\n",
13951 atomic_load_explicit(&p->open_out,
13952 memory_order_relaxed),
13953 atomic_load_explicit(&p->open_in,
13954 memory_order_relaxed));
13955 vty_out(vty, " Notifications: %10d %10d\n",
13956 atomic_load_explicit(&p->notify_out,
13957 memory_order_relaxed),
13958 atomic_load_explicit(&p->notify_in,
13959 memory_order_relaxed));
13960 vty_out(vty, " Updates: %10d %10d\n",
13961 atomic_load_explicit(&p->update_out,
13962 memory_order_relaxed),
13963 atomic_load_explicit(&p->update_in,
13964 memory_order_relaxed));
13965 vty_out(vty, " Keepalives: %10d %10d\n",
13966 atomic_load_explicit(&p->keepalive_out,
13967 memory_order_relaxed),
13968 atomic_load_explicit(&p->keepalive_in,
13969 memory_order_relaxed));
13970 vty_out(vty, " Route Refresh: %10d %10d\n",
13971 atomic_load_explicit(&p->refresh_out,
13972 memory_order_relaxed),
13973 atomic_load_explicit(&p->refresh_in,
13974 memory_order_relaxed));
d62a17ae 13975 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
13976 atomic_load_explicit(&p->dynamic_cap_out,
13977 memory_order_relaxed),
13978 atomic_load_explicit(&p->dynamic_cap_in,
13979 memory_order_relaxed));
13980 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
13981 PEER_TOTAL_RX(p));
d62a17ae 13982 }
13983
13984 if (use_json) {
13985 /* advertisement-interval */
13986 json_object_int_add(json_neigh,
13987 "minBtwnAdvertisementRunsTimerMsecs",
13988 p->v_routeadv * 1000);
13989
13990 /* Update-source. */
13991 if (p->update_if || p->update_source) {
13992 if (p->update_if)
13993 json_object_string_add(json_neigh,
13994 "updateSource",
13995 p->update_if);
13996 else if (p->update_source)
13997 json_object_string_add(
13998 json_neigh, "updateSource",
13999 sockunion2str(p->update_source, buf1,
14000 SU_ADDRSTRLEN));
14001 }
14002 } else {
14003 /* advertisement-interval */
14004 vty_out(vty,
14005 " Minimum time between advertisement runs is %d seconds\n",
14006 p->v_routeadv);
14007
14008 /* Update-source. */
14009 if (p->update_if || p->update_source) {
14010 vty_out(vty, " Update source is ");
14011 if (p->update_if)
14012 vty_out(vty, "%s", p->update_if);
14013 else if (p->update_source)
14014 vty_out(vty, "%s",
14015 sockunion2str(p->update_source, buf1,
14016 SU_ADDRSTRLEN));
14017 vty_out(vty, "\n");
14018 }
14019
14020 vty_out(vty, "\n");
14021 }
14022
14023 /* Address Family Information */
14024 json_object *json_hold = NULL;
14025
14026 if (use_json)
14027 json_hold = json_object_new_object();
14028
05c7a1cc
QY
14029 FOREACH_AFI_SAFI (afi, safi)
14030 if (p->afc[afi][safi])
14031 bgp_show_peer_afi(vty, p, afi, safi, use_json,
14032 json_hold);
d62a17ae 14033
14034 if (use_json) {
14035 json_object_object_add(json_neigh, "addressFamilyInfo",
14036 json_hold);
14037 json_object_int_add(json_neigh, "connectionsEstablished",
14038 p->established);
14039 json_object_int_add(json_neigh, "connectionsDropped",
14040 p->dropped);
14041 } else
14042 vty_out(vty, " Connections established %d; dropped %d\n",
14043 p->established, p->dropped);
14044
14045 if (!p->last_reset) {
14046 if (use_json)
14047 json_object_string_add(json_neigh, "lastReset",
14048 "never");
14049 else
14050 vty_out(vty, " Last reset never\n");
14051 } else {
14052 if (use_json) {
14053 time_t uptime;
a2700b50 14054 struct tm tm;
d62a17ae 14055
14056 uptime = bgp_clock();
14057 uptime -= p->resettime;
a2700b50
MS
14058 gmtime_r(&uptime, &tm);
14059
d62a17ae 14060 json_object_int_add(json_neigh, "lastResetTimerMsecs",
a2700b50
MS
14061 (tm.tm_sec * 1000)
14062 + (tm.tm_min * 60000)
14063 + (tm.tm_hour * 3600000));
3577f1c5 14064 bgp_show_peer_reset(NULL, p, json_neigh, true);
d62a17ae 14065 } else {
14066 vty_out(vty, " Last reset %s, ",
14067 peer_uptime(p->resettime, timebuf,
14068 BGP_UPTIME_LEN, 0, NULL));
14069
3577f1c5 14070 bgp_show_peer_reset(vty, p, NULL, false);
d62a17ae 14071 if (p->last_reset_cause_size) {
14072 msg = p->last_reset_cause;
14073 vty_out(vty,
14074 " Message received that caused BGP to send a NOTIFICATION:\n ");
14075 for (i = 1; i <= p->last_reset_cause_size;
14076 i++) {
14077 vty_out(vty, "%02X", *msg++);
14078
14079 if (i != p->last_reset_cause_size) {
14080 if (i % 16 == 0) {
14081 vty_out(vty, "\n ");
14082 } else if (i % 4 == 0) {
14083 vty_out(vty, " ");
14084 }
14085 }
14086 }
14087 vty_out(vty, "\n");
14088 }
14089 }
14090 }
14091
14092 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
14093 if (use_json)
14094 json_object_boolean_true_add(json_neigh,
14095 "prefixesConfigExceedMax");
14096 else
14097 vty_out(vty,
14098 " Peer had exceeded the max. no. of prefixes configured.\n");
14099
14100 if (p->t_pmax_restart) {
14101 if (use_json) {
14102 json_object_boolean_true_add(
14103 json_neigh, "reducePrefixNumFrom");
14104 json_object_int_add(json_neigh,
14105 "restartInTimerMsec",
14106 thread_timer_remain_second(
14107 p->t_pmax_restart)
14108 * 1000);
14109 } else
14110 vty_out(vty,
14111 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
14112 p->host, thread_timer_remain_second(
14113 p->t_pmax_restart));
d62a17ae 14114 } else {
14115 if (use_json)
14116 json_object_boolean_true_add(
14117 json_neigh,
14118 "reducePrefixNumAndClearIpBgp");
14119 else
14120 vty_out(vty,
14121 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
14122 p->host);
14123 }
14124 }
14125
14126 /* EBGP Multihop and GTSM */
14127 if (p->sort != BGP_PEER_IBGP) {
14128 if (use_json) {
e2521429 14129 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14130 json_object_int_add(json_neigh,
14131 "externalBgpNbrMaxHopsAway",
14132 p->gtsm_hops);
c8d6f0d6 14133 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 14134 json_object_int_add(json_neigh,
14135 "externalBgpNbrMaxHopsAway",
14136 p->ttl);
14137 } else {
e2521429 14138 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14139 vty_out(vty,
14140 " External BGP neighbor may be up to %d hops away.\n",
14141 p->gtsm_hops);
c8d6f0d6 14142 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 14143 vty_out(vty,
14144 " External BGP neighbor may be up to %d hops away.\n",
14145 p->ttl);
14146 }
14147 } else {
e2521429 14148 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED) {
d62a17ae 14149 if (use_json)
14150 json_object_int_add(json_neigh,
14151 "internalBgpNbrMaxHopsAway",
14152 p->gtsm_hops);
14153 else
14154 vty_out(vty,
14155 " Internal BGP neighbor may be up to %d hops away.\n",
14156 p->gtsm_hops);
14157 }
14158 }
14159
14160 /* Local address. */
14161 if (p->su_local) {
14162 if (use_json) {
14163 json_object_string_add(json_neigh, "hostLocal",
14164 sockunion2str(p->su_local, buf1,
14165 SU_ADDRSTRLEN));
14166 json_object_int_add(json_neigh, "portLocal",
14167 ntohs(p->su_local->sin.sin_port));
14168 } else
14169 vty_out(vty, "Local host: %s, Local port: %d\n",
14170 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
14171 ntohs(p->su_local->sin.sin_port));
14172 }
14173
14174 /* Remote address. */
14175 if (p->su_remote) {
14176 if (use_json) {
14177 json_object_string_add(json_neigh, "hostForeign",
14178 sockunion2str(p->su_remote, buf1,
14179 SU_ADDRSTRLEN));
14180 json_object_int_add(json_neigh, "portForeign",
14181 ntohs(p->su_remote->sin.sin_port));
14182 } else
14183 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
14184 sockunion2str(p->su_remote, buf1,
14185 SU_ADDRSTRLEN),
14186 ntohs(p->su_remote->sin.sin_port));
14187 }
14188
14189 /* Nexthop display. */
14190 if (p->su_local) {
14191 if (use_json) {
14192 json_object_string_add(json_neigh, "nexthop",
14193 inet_ntop(AF_INET,
14194 &p->nexthop.v4, buf1,
14195 sizeof(buf1)));
14196 json_object_string_add(json_neigh, "nexthopGlobal",
14197 inet_ntop(AF_INET6,
14198 &p->nexthop.v6_global,
14199 buf1, sizeof(buf1)));
14200 json_object_string_add(json_neigh, "nexthopLocal",
14201 inet_ntop(AF_INET6,
14202 &p->nexthop.v6_local,
14203 buf1, sizeof(buf1)));
14204 if (p->shared_network)
14205 json_object_string_add(json_neigh,
14206 "bgpConnection",
14207 "sharedNetwork");
14208 else
14209 json_object_string_add(json_neigh,
14210 "bgpConnection",
14211 "nonSharedNetwork");
14212 } else {
14213 vty_out(vty, "Nexthop: %s\n",
14214 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
14215 sizeof(buf1)));
14216 vty_out(vty, "Nexthop global: %s\n",
14217 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
14218 sizeof(buf1)));
14219 vty_out(vty, "Nexthop local: %s\n",
14220 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
14221 sizeof(buf1)));
14222 vty_out(vty, "BGP connection: %s\n",
14223 p->shared_network ? "shared network"
14224 : "non shared network");
14225 }
14226 }
14227
14228 /* Timer information. */
14229 if (use_json) {
14230 json_object_int_add(json_neigh, "connectRetryTimer",
14231 p->v_connect);
14232 if (p->status == Established && p->rtt)
14233 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14234 p->rtt);
14235 if (p->t_start)
14236 json_object_int_add(
14237 json_neigh, "nextStartTimerDueInMsecs",
14238 thread_timer_remain_second(p->t_start) * 1000);
14239 if (p->t_connect)
14240 json_object_int_add(
14241 json_neigh, "nextConnectTimerDueInMsecs",
14242 thread_timer_remain_second(p->t_connect)
14243 * 1000);
14244 if (p->t_routeadv) {
14245 json_object_int_add(json_neigh, "mraiInterval",
14246 p->v_routeadv);
14247 json_object_int_add(
14248 json_neigh, "mraiTimerExpireInMsecs",
14249 thread_timer_remain_second(p->t_routeadv)
14250 * 1000);
14251 }
14252 if (p->password)
14253 json_object_int_add(json_neigh, "authenticationEnabled",
14254 1);
14255
14256 if (p->t_read)
14257 json_object_string_add(json_neigh, "readThread", "on");
14258 else
14259 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
14260
14261 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 14262 json_object_string_add(json_neigh, "writeThread", "on");
14263 else
14264 json_object_string_add(json_neigh, "writeThread",
14265 "off");
14266 } else {
14267 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14268 p->v_connect);
14269 if (p->status == Established && p->rtt)
14270 vty_out(vty, "Estimated round trip time: %d ms\n",
14271 p->rtt);
14272 if (p->t_start)
14273 vty_out(vty, "Next start timer due in %ld seconds\n",
14274 thread_timer_remain_second(p->t_start));
14275 if (p->t_connect)
14276 vty_out(vty, "Next connect timer due in %ld seconds\n",
14277 thread_timer_remain_second(p->t_connect));
14278 if (p->t_routeadv)
14279 vty_out(vty,
14280 "MRAI (interval %u) timer expires in %ld seconds\n",
14281 p->v_routeadv,
14282 thread_timer_remain_second(p->t_routeadv));
14283 if (p->password)
14284 vty_out(vty, "Peer Authentication Enabled\n");
14285
cac9e917 14286 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
49507a6f
QY
14287 p->t_read ? "on" : "off",
14288 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14289 ? "on"
cac9e917 14290 : "off", p->fd);
d62a17ae 14291 }
14292
14293 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14294 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14295 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14296
14297 if (!use_json)
14298 vty_out(vty, "\n");
14299
14300 /* BFD information. */
14301 bgp_bfd_show_info(vty, p, use_json, json_neigh);
14302
14303 if (use_json) {
14304 if (p->conf_if) /* Configured interface name. */
14305 json_object_object_add(json, p->conf_if, json_neigh);
14306 else /* Configured IP address. */
14307 json_object_object_add(json, p->host, json_neigh);
14308 }
14309}
14310
36235319
QY
14311static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14312 enum show_type type,
14313 union sockunion *su,
14314 const char *conf_if, afi_t afi,
74a630b6 14315 bool use_json)
2986cac2 14316{
14317 struct listnode *node, *nnode;
14318 struct peer *peer;
14319 int find = 0;
14320 safi_t safi = SAFI_UNICAST;
74a630b6 14321 json_object *json = NULL;
2986cac2 14322 json_object *json_neighbor = NULL;
14323
74a630b6
NT
14324 if (use_json) {
14325 json = json_object_new_object();
14326 json_neighbor = json_object_new_object();
14327 }
14328
2986cac2 14329 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14330
14331 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14332 continue;
14333
14334 if ((peer->afc[afi][safi]) == 0)
14335 continue;
14336
2ba1fe69 14337 if (type == show_all) {
2986cac2 14338 bgp_show_peer_gr_status(vty, peer, use_json,
13909c4f 14339 json_neighbor);
2986cac2 14340
74a630b6 14341 if (use_json) {
13909c4f
DS
14342 json_object_object_add(json, peer->host,
14343 json_neighbor);
74a630b6
NT
14344 json_neighbor = NULL;
14345 }
2986cac2 14346
2ba1fe69 14347 } else if (type == show_peer) {
2986cac2 14348 if (conf_if) {
14349 if ((peer->conf_if
13909c4f
DS
14350 && !strcmp(peer->conf_if, conf_if))
14351 || (peer->hostname
2986cac2 14352 && !strcmp(peer->hostname, conf_if))) {
14353 find = 1;
13909c4f
DS
14354 bgp_show_peer_gr_status(vty, peer,
14355 use_json,
14356 json_neighbor);
2986cac2 14357 }
14358 } else {
14359 if (sockunion_same(&peer->su, su)) {
14360 find = 1;
13909c4f
DS
14361 bgp_show_peer_gr_status(vty, peer,
14362 use_json,
14363 json_neighbor);
2986cac2 14364 }
14365 }
13909c4f
DS
14366 if (use_json && find)
14367 json_object_object_add(json, peer->host,
14368 json_neighbor);
2986cac2 14369 }
14370
74a630b6
NT
14371 if (find) {
14372 json_neighbor = NULL;
2986cac2 14373 break;
74a630b6 14374 }
2986cac2 14375 }
14376
14377 if (type == show_peer && !find) {
14378 if (use_json)
13909c4f 14379 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
2986cac2 14380 else
14381 vty_out(vty, "%% No such neighbor\n");
14382 }
14383 if (use_json) {
13909c4f
DS
14384 vty_out(vty, "%s\n",
14385 json_object_to_json_string_ext(
14386 json, JSON_C_TO_STRING_PRETTY));
74a630b6
NT
14387
14388 if (json_neighbor)
14389 json_object_free(json_neighbor);
14390 json_object_free(json);
2986cac2 14391 } else {
14392 vty_out(vty, "\n");
14393 }
14394
14395 return CMD_SUCCESS;
14396}
14397
d62a17ae 14398static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14399 enum show_type type, union sockunion *su,
9f049418 14400 const char *conf_if, bool use_json,
d62a17ae 14401 json_object *json)
14402{
14403 struct listnode *node, *nnode;
14404 struct peer *peer;
14405 int find = 0;
9f049418 14406 bool nbr_output = false;
d1927ebe
AS
14407 afi_t afi = AFI_MAX;
14408 safi_t safi = SAFI_MAX;
14409
14410 if (type == show_ipv4_peer || type == show_ipv4_all) {
14411 afi = AFI_IP;
14412 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14413 afi = AFI_IP6;
14414 }
d62a17ae 14415
14416 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14417 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14418 continue;
14419
14420 switch (type) {
14421 case show_all:
14422 bgp_show_peer(vty, peer, use_json, json);
9f049418 14423 nbr_output = true;
d62a17ae 14424 break;
14425 case show_peer:
14426 if (conf_if) {
14427 if ((peer->conf_if
14428 && !strcmp(peer->conf_if, conf_if))
14429 || (peer->hostname
14430 && !strcmp(peer->hostname, conf_if))) {
14431 find = 1;
14432 bgp_show_peer(vty, peer, use_json,
14433 json);
14434 }
14435 } else {
14436 if (sockunion_same(&peer->su, su)) {
14437 find = 1;
14438 bgp_show_peer(vty, peer, use_json,
14439 json);
14440 }
14441 }
14442 break;
d1927ebe
AS
14443 case show_ipv4_peer:
14444 case show_ipv6_peer:
14445 FOREACH_SAFI (safi) {
14446 if (peer->afc[afi][safi]) {
14447 if (conf_if) {
14448 if ((peer->conf_if
14449 && !strcmp(peer->conf_if, conf_if))
14450 || (peer->hostname
14451 && !strcmp(peer->hostname, conf_if))) {
14452 find = 1;
14453 bgp_show_peer(vty, peer, use_json,
14454 json);
14455 break;
14456 }
14457 } else {
14458 if (sockunion_same(&peer->su, su)) {
14459 find = 1;
14460 bgp_show_peer(vty, peer, use_json,
14461 json);
14462 break;
14463 }
14464 }
14465 }
14466 }
14467 break;
14468 case show_ipv4_all:
14469 case show_ipv6_all:
14470 FOREACH_SAFI (safi) {
14471 if (peer->afc[afi][safi]) {
14472 bgp_show_peer(vty, peer, use_json, json);
14473 nbr_output = true;
14474 break;
14475 }
14476 }
14477 break;
d62a17ae 14478 }
14479 }
14480
d1927ebe
AS
14481 if ((type == show_peer || type == show_ipv4_peer ||
14482 type == show_ipv6_peer) && !find) {
d62a17ae 14483 if (use_json)
14484 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14485 else
88b7d255 14486 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 14487 }
14488
d1927ebe
AS
14489 if (type != show_peer && type != show_ipv4_peer &&
14490 type != show_ipv6_peer && !nbr_output && !use_json)
94d4c685 14491 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 14492
d62a17ae 14493 if (use_json) {
996c9314
LB
14494 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14495 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 14496 } else {
14497 vty_out(vty, "\n");
14498 }
14499
14500 return CMD_SUCCESS;
14501}
14502
36235319
QY
14503static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14504 enum show_type type,
14505 const char *ip_str,
14506 afi_t afi, bool use_json)
2986cac2 14507{
14508
14509 int ret;
14510 struct bgp *bgp;
14511 union sockunion su;
2986cac2 14512
14513 bgp = bgp_get_default();
14514
13909c4f
DS
14515 if (!bgp)
14516 return;
2986cac2 14517
13909c4f
DS
14518 if (!use_json)
14519 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
14520 NULL);
2986cac2 14521
13909c4f
DS
14522 if (ip_str) {
14523 ret = str2sockunion(ip_str, &su);
14524 if (ret < 0)
13909c4f 14525 bgp_show_neighbor_graceful_restart(
74a630b6
NT
14526 vty, bgp, type, NULL, ip_str, afi, use_json);
14527 else
14528 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14529 NULL, afi, use_json);
13909c4f
DS
14530 } else
14531 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
74a630b6 14532 afi, use_json);
2986cac2 14533}
14534
d62a17ae 14535static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
14536 enum show_type type,
14537 const char *ip_str,
9f049418 14538 bool use_json)
d62a17ae 14539{
0291c246
MK
14540 struct listnode *node, *nnode;
14541 struct bgp *bgp;
71aedaa3 14542 union sockunion su;
0291c246 14543 json_object *json = NULL;
71aedaa3 14544 int ret, is_first = 1;
9f049418 14545 bool nbr_output = false;
d62a17ae 14546
14547 if (use_json)
14548 vty_out(vty, "{\n");
14549
14550 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 14551 nbr_output = true;
d62a17ae 14552 if (use_json) {
14553 if (!(json = json_object_new_object())) {
af4c2728 14554 flog_err(
e50f7cfd 14555 EC_BGP_JSON_MEM_ERROR,
d62a17ae 14556 "Unable to allocate memory for JSON object");
14557 vty_out(vty,
14558 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14559 return;
14560 }
14561
14562 json_object_int_add(json, "vrfId",
14563 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
14564 ? -1
14565 : (int64_t)bgp->vrf_id);
d62a17ae 14566 json_object_string_add(
14567 json, "vrfName",
14568 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14569 ? VRF_DEFAULT_NAME
d62a17ae 14570 : bgp->name);
14571
14572 if (!is_first)
14573 vty_out(vty, ",\n");
14574 else
14575 is_first = 0;
14576
14577 vty_out(vty, "\"%s\":",
14578 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14579 ? VRF_DEFAULT_NAME
d62a17ae 14580 : bgp->name);
14581 } else {
14582 vty_out(vty, "\nInstance %s:\n",
14583 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14584 ? VRF_DEFAULT_NAME
d62a17ae 14585 : bgp->name);
14586 }
71aedaa3 14587
d1927ebe
AS
14588 if (type == show_peer || type == show_ipv4_peer ||
14589 type == show_ipv6_peer) {
71aedaa3
DS
14590 ret = str2sockunion(ip_str, &su);
14591 if (ret < 0)
14592 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14593 use_json, json);
14594 else
14595 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14596 use_json, json);
14597 } else {
d1927ebe 14598 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
71aedaa3
DS
14599 use_json, json);
14600 }
b77004d6 14601 json_object_free(json);
121067e9 14602 json = NULL;
d62a17ae 14603 }
14604
3e78a6ce 14605 if (use_json)
d62a17ae 14606 vty_out(vty, "}\n");
9f049418
DS
14607 else if (!nbr_output)
14608 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 14609}
14610
14611static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14612 enum show_type type, const char *ip_str,
9f049418 14613 bool use_json)
d62a17ae 14614{
14615 int ret;
14616 struct bgp *bgp;
14617 union sockunion su;
14618 json_object *json = NULL;
14619
14620 if (name) {
14621 if (strmatch(name, "all")) {
71aedaa3
DS
14622 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14623 use_json);
d62a17ae 14624 return CMD_SUCCESS;
14625 } else {
14626 bgp = bgp_lookup_by_name(name);
14627 if (!bgp) {
14628 if (use_json) {
14629 json = json_object_new_object();
d62a17ae 14630 vty_out(vty, "%s\n",
14631 json_object_to_json_string_ext(
14632 json,
14633 JSON_C_TO_STRING_PRETTY));
14634 json_object_free(json);
14635 } else
14636 vty_out(vty,
9f049418 14637 "%% BGP instance not found\n");
d62a17ae 14638
14639 return CMD_WARNING;
14640 }
14641 }
14642 } else {
14643 bgp = bgp_get_default();
14644 }
14645
14646 if (bgp) {
14647 json = json_object_new_object();
14648 if (ip_str) {
14649 ret = str2sockunion(ip_str, &su);
14650 if (ret < 0)
14651 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14652 use_json, json);
14653 else
14654 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14655 use_json, json);
14656 } else {
14657 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
14658 json);
14659 }
14660 json_object_free(json);
ca61fd25
DS
14661 } else {
14662 if (use_json)
14663 vty_out(vty, "{}\n");
14664 else
14665 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 14666 }
14667
14668 return CMD_SUCCESS;
4fb25c53
DW
14669}
14670
2986cac2 14671
14672
14673/* "show [ip] bgp neighbors graceful-restart" commands. */
14674DEFUN (show_ip_bgp_neighbors_gracrful_restart,
14675 show_ip_bgp_neighbors_graceful_restart_cmd,
14676 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
14677 SHOW_STR
14678 BGP_STR
14679 IP_STR
14680 IPV6_STR
14681 NEIGHBOR_STR
14682 "Neighbor to display information about\n"
14683 "Neighbor to display information about\n"
14684 "Neighbor on BGP configured interface\n"
14685 GR_SHOW
14686 JSON_STR)
14687{
14688 char *sh_arg = NULL;
14689 enum show_type sh_type;
14690 int idx = 0;
14691 afi_t afi = AFI_MAX;
2986cac2 14692 bool uj = use_json(argc, argv);
14693
36235319 14694 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
2986cac2 14695 afi = AFI_MAX;
14696
14697 idx++;
14698
14699 if (argv_find(argv, argc, "A.B.C.D", &idx)
14700 || argv_find(argv, argc, "X:X::X:X", &idx)
14701 || argv_find(argv, argc, "WORD", &idx)) {
14702 sh_type = show_peer;
14703 sh_arg = argv[idx]->arg;
14704 } else
14705 sh_type = show_all;
14706
14707 if (!argv_find(argv, argc, "graceful-restart", &idx))
14708 return CMD_SUCCESS;
14709
14710
36235319
QY
14711 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
14712 afi, uj);
2986cac2 14713}
14714
716b2d8a 14715/* "show [ip] bgp neighbors" commands. */
718e3744 14716DEFUN (show_ip_bgp_neighbors,
14717 show_ip_bgp_neighbors_cmd,
24345e82 14718 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 14719 SHOW_STR
14720 IP_STR
14721 BGP_STR
f2a8972b 14722 BGP_INSTANCE_HELP_STR
8c3deaae
QY
14723 "Address Family\n"
14724 "Address Family\n"
718e3744 14725 "Detailed information on TCP and BGP neighbor connections\n"
14726 "Neighbor to display information about\n"
a80beece 14727 "Neighbor to display information about\n"
91d37724 14728 "Neighbor on BGP configured interface\n"
9973d184 14729 JSON_STR)
718e3744 14730{
d62a17ae 14731 char *vrf = NULL;
14732 char *sh_arg = NULL;
14733 enum show_type sh_type;
d1927ebe 14734 afi_t afi = AFI_MAX;
718e3744 14735
9f049418 14736 bool uj = use_json(argc, argv);
718e3744 14737
d62a17ae 14738 int idx = 0;
718e3744 14739
9a8bdf1c
PG
14740 /* [<vrf> VIEWVRFNAME] */
14741 if (argv_find(argv, argc, "vrf", &idx)) {
14742 vrf = argv[idx + 1]->arg;
14743 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14744 vrf = NULL;
14745 } else if (argv_find(argv, argc, "view", &idx))
14746 /* [<view> VIEWVRFNAME] */
d62a17ae 14747 vrf = argv[idx + 1]->arg;
718e3744 14748
d62a17ae 14749 idx++;
d1927ebe
AS
14750
14751 if (argv_find(argv, argc, "ipv4", &idx)) {
14752 sh_type = show_ipv4_all;
14753 afi = AFI_IP;
14754 } else if (argv_find(argv, argc, "ipv6", &idx)) {
14755 sh_type = show_ipv6_all;
14756 afi = AFI_IP6;
14757 } else {
14758 sh_type = show_all;
14759 }
14760
d62a17ae 14761 if (argv_find(argv, argc, "A.B.C.D", &idx)
14762 || argv_find(argv, argc, "X:X::X:X", &idx)
14763 || argv_find(argv, argc, "WORD", &idx)) {
14764 sh_type = show_peer;
14765 sh_arg = argv[idx]->arg;
d1927ebe
AS
14766 }
14767
14768 if (sh_type == show_peer && afi == AFI_IP) {
14769 sh_type = show_ipv4_peer;
14770 } else if (sh_type == show_peer && afi == AFI_IP6) {
14771 sh_type = show_ipv6_peer;
14772 }
856ca177 14773
d62a17ae 14774 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 14775}
14776
716b2d8a 14777/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 14778 paths' and `show ip mbgp paths'. Those functions results are the
14779 same.*/
f412b39a 14780DEFUN (show_ip_bgp_paths,
718e3744 14781 show_ip_bgp_paths_cmd,
46f296b4 14782 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 14783 SHOW_STR
14784 IP_STR
14785 BGP_STR
46f296b4 14786 BGP_SAFI_HELP_STR
718e3744 14787 "Path information\n")
14788{
d62a17ae 14789 vty_out(vty, "Address Refcnt Path\n");
14790 aspath_print_all_vty(vty);
14791 return CMD_SUCCESS;
718e3744 14792}
14793
718e3744 14794#include "hash.h"
14795
e3b78da8 14796static void community_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 14797 struct vty *vty)
718e3744 14798{
d62a17ae 14799 struct community *com;
718e3744 14800
e3b78da8 14801 com = (struct community *)bucket->data;
3f65c5b1 14802 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 14803 community_str(com, false));
718e3744 14804}
14805
14806/* Show BGP's community internal data. */
f412b39a 14807DEFUN (show_ip_bgp_community_info,
718e3744 14808 show_ip_bgp_community_info_cmd,
bec37ba5 14809 "show [ip] bgp community-info",
718e3744 14810 SHOW_STR
14811 IP_STR
14812 BGP_STR
14813 "List all bgp community information\n")
14814{
d62a17ae 14815 vty_out(vty, "Address Refcnt Community\n");
718e3744 14816
d62a17ae 14817 hash_iterate(community_hash(),
e3b78da8 14818 (void (*)(struct hash_bucket *,
d62a17ae 14819 void *))community_show_all_iterator,
14820 vty);
718e3744 14821
d62a17ae 14822 return CMD_SUCCESS;
718e3744 14823}
14824
e3b78da8 14825static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 14826 struct vty *vty)
57d187bc 14827{
d62a17ae 14828 struct lcommunity *lcom;
57d187bc 14829
e3b78da8 14830 lcom = (struct lcommunity *)bucket->data;
3f65c5b1 14831 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 14832 lcommunity_str(lcom, false));
57d187bc
JS
14833}
14834
14835/* Show BGP's community internal data. */
14836DEFUN (show_ip_bgp_lcommunity_info,
14837 show_ip_bgp_lcommunity_info_cmd,
14838 "show ip bgp large-community-info",
14839 SHOW_STR
14840 IP_STR
14841 BGP_STR
14842 "List all bgp large-community information\n")
14843{
d62a17ae 14844 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 14845
d62a17ae 14846 hash_iterate(lcommunity_hash(),
e3b78da8 14847 (void (*)(struct hash_bucket *,
d62a17ae 14848 void *))lcommunity_show_all_iterator,
14849 vty);
57d187bc 14850
d62a17ae 14851 return CMD_SUCCESS;
57d187bc 14852}
2986cac2 14853/* Graceful Restart */
14854
14855static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
36235319
QY
14856 struct bgp *bgp,
14857 bool use_json,
14858 json_object *json)
2986cac2 14859{
57d187bc
JS
14860
14861
2986cac2 14862 vty_out(vty, "\n%s", SHOW_GR_HEADER);
14863
7318ae88 14864 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
2986cac2 14865
14866 switch (bgp_global_gr_mode) {
14867
14868 case GLOBAL_HELPER:
13909c4f 14869 vty_out(vty, "Global BGP GR Mode : Helper\n");
2986cac2 14870 break;
14871
14872 case GLOBAL_GR:
13909c4f 14873 vty_out(vty, "Global BGP GR Mode : Restart\n");
2986cac2 14874 break;
14875
14876 case GLOBAL_DISABLE:
13909c4f 14877 vty_out(vty, "Global BGP GR Mode : Disable\n");
2986cac2 14878 break;
14879
14880 case GLOBAL_INVALID:
2986cac2 14881 vty_out(vty,
2ba1fe69 14882 "Global BGP GR Mode Invalid\n");
2986cac2 14883 break;
14884 }
14885 vty_out(vty, "\n");
14886}
14887
36235319
QY
14888static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
14889 enum show_type type,
14890 const char *ip_str,
14891 afi_t afi, bool use_json)
2986cac2 14892{
14893 if ((afi == AFI_MAX) && (ip_str == NULL)) {
14894 afi = AFI_IP;
14895
14896 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
14897
36235319
QY
14898 bgp_show_neighbor_graceful_restart_vty(
14899 vty, type, ip_str, afi, use_json);
2986cac2 14900 afi++;
14901 }
14902 } else if (afi != AFI_MAX) {
36235319
QY
14903 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
14904 use_json);
2986cac2 14905 } else {
14906 return CMD_ERR_INCOMPLETE;
14907 }
14908
14909 return CMD_SUCCESS;
14910}
14911/* Graceful Restart */
14912
f412b39a 14913DEFUN (show_ip_bgp_attr_info,
718e3744 14914 show_ip_bgp_attr_info_cmd,
bec37ba5 14915 "show [ip] bgp attribute-info",
718e3744 14916 SHOW_STR
14917 IP_STR
14918 BGP_STR
14919 "List all bgp attribute information\n")
14920{
d62a17ae 14921 attr_show_all(vty);
14922 return CMD_SUCCESS;
718e3744 14923}
6b0655a2 14924
03915806
CS
14925static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
14926 afi_t afi, safi_t safi,
14927 bool use_json, json_object *json)
53089bec 14928{
14929 struct bgp *bgp;
14930 struct listnode *node;
14931 char *vname;
14932 char buf1[INET6_ADDRSTRLEN];
14933 char *ecom_str;
14934 vpn_policy_direction_t dir;
14935
03915806 14936 if (json) {
b46dfd20
DS
14937 json_object *json_import_vrfs = NULL;
14938 json_object *json_export_vrfs = NULL;
14939
b46dfd20
DS
14940 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14941
53089bec 14942 if (!bgp) {
b46dfd20
DS
14943 vty_out(vty, "%s\n",
14944 json_object_to_json_string_ext(
14945 json,
14946 JSON_C_TO_STRING_PRETTY));
14947 json_object_free(json);
14948
53089bec 14949 return CMD_WARNING;
14950 }
b46dfd20 14951
94d4c685
DS
14952 /* Provide context for the block */
14953 json_object_string_add(json, "vrf", name ? name : "default");
14954 json_object_string_add(json, "afiSafi",
5cb5f4d0 14955 get_afi_safi_str(afi, safi, true));
94d4c685 14956
b46dfd20
DS
14957 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14958 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
14959 json_object_string_add(json, "importFromVrfs", "none");
14960 json_object_string_add(json, "importRts", "none");
14961 } else {
6ce24e52
DS
14962 json_import_vrfs = json_object_new_array();
14963
b46dfd20
DS
14964 for (ALL_LIST_ELEMENTS_RO(
14965 bgp->vpn_policy[afi].import_vrf,
14966 node, vname))
14967 json_object_array_add(json_import_vrfs,
14968 json_object_new_string(vname));
14969
b20875ea
CS
14970 json_object_object_add(json, "importFromVrfs",
14971 json_import_vrfs);
b46dfd20 14972 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
14973 if (bgp->vpn_policy[afi].rtlist[dir]) {
14974 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14975 bgp->vpn_policy[afi].rtlist[dir],
14976 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
14977 json_object_string_add(json, "importRts",
14978 ecom_str);
14979 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14980 } else
14981 json_object_string_add(json, "importRts",
14982 "none");
b46dfd20
DS
14983 }
14984
14985 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14986 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
14987 json_object_string_add(json, "exportToVrfs", "none");
14988 json_object_string_add(json, "routeDistinguisher",
14989 "none");
14990 json_object_string_add(json, "exportRts", "none");
14991 } else {
6ce24e52
DS
14992 json_export_vrfs = json_object_new_array();
14993
b46dfd20
DS
14994 for (ALL_LIST_ELEMENTS_RO(
14995 bgp->vpn_policy[afi].export_vrf,
14996 node, vname))
14997 json_object_array_add(json_export_vrfs,
14998 json_object_new_string(vname));
14999 json_object_object_add(json, "exportToVrfs",
15000 json_export_vrfs);
15001 json_object_string_add(json, "routeDistinguisher",
15002 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
15003 buf1, RD_ADDRSTRLEN));
15004
15005 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
15006 if (bgp->vpn_policy[afi].rtlist[dir]) {
15007 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15008 bgp->vpn_policy[afi].rtlist[dir],
15009 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
15010 json_object_string_add(json, "exportRts",
15011 ecom_str);
15012 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15013 } else
15014 json_object_string_add(json, "exportRts",
15015 "none");
b46dfd20
DS
15016 }
15017
03915806
CS
15018 if (use_json) {
15019 vty_out(vty, "%s\n",
15020 json_object_to_json_string_ext(json,
b46dfd20 15021 JSON_C_TO_STRING_PRETTY));
03915806
CS
15022 json_object_free(json);
15023 }
53089bec 15024 } else {
b46dfd20
DS
15025 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15026
53089bec 15027 if (!bgp) {
b46dfd20 15028 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 15029 return CMD_WARNING;
15030 }
53089bec 15031
b46dfd20
DS
15032 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15033 BGP_CONFIG_VRF_TO_VRF_IMPORT))
15034 vty_out(vty,
15035 "This VRF is not importing %s routes from any other VRF\n",
5cb5f4d0 15036 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15037 else {
15038 vty_out(vty,
15039 "This VRF is importing %s routes from the following VRFs:\n",
5cb5f4d0 15040 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15041
15042 for (ALL_LIST_ELEMENTS_RO(
15043 bgp->vpn_policy[afi].import_vrf,
15044 node, vname))
15045 vty_out(vty, " %s\n", vname);
15046
15047 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
15048 ecom_str = NULL;
15049 if (bgp->vpn_policy[afi].rtlist[dir]) {
15050 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15051 bgp->vpn_policy[afi].rtlist[dir],
15052 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea 15053 vty_out(vty, "Import RT(s): %s\n", ecom_str);
b46dfd20 15054
b20875ea
CS
15055 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15056 } else
15057 vty_out(vty, "Import RT(s):\n");
53089bec 15058 }
53089bec 15059
b46dfd20
DS
15060 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15061 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15062 vty_out(vty,
15063 "This VRF is not exporting %s routes to any other VRF\n",
5cb5f4d0 15064 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15065 else {
15066 vty_out(vty,
04c9077f 15067 "This VRF is exporting %s routes to the following VRFs:\n",
5cb5f4d0 15068 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15069
15070 for (ALL_LIST_ELEMENTS_RO(
15071 bgp->vpn_policy[afi].export_vrf,
15072 node, vname))
15073 vty_out(vty, " %s\n", vname);
15074
15075 vty_out(vty, "RD: %s\n",
15076 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
15077 buf1, RD_ADDRSTRLEN));
15078
15079 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
15080 if (bgp->vpn_policy[afi].rtlist[dir]) {
15081 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15082 bgp->vpn_policy[afi].rtlist[dir],
15083 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
15084 vty_out(vty, "Export RT: %s\n", ecom_str);
15085 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15086 } else
15087 vty_out(vty, "Import RT(s):\n");
53089bec 15088 }
53089bec 15089 }
15090
15091 return CMD_SUCCESS;
15092}
15093
03915806
CS
15094static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
15095 safi_t safi, bool use_json)
15096{
15097 struct listnode *node, *nnode;
15098 struct bgp *bgp;
15099 char *vrf_name = NULL;
15100 json_object *json = NULL;
15101 json_object *json_vrf = NULL;
15102 json_object *json_vrfs = NULL;
15103
15104 if (use_json) {
15105 json = json_object_new_object();
15106 json_vrfs = json_object_new_object();
15107 }
15108
15109 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15110
15111 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
15112 vrf_name = bgp->name;
15113
15114 if (use_json) {
15115 json_vrf = json_object_new_object();
15116 } else {
15117 vty_out(vty, "\nInstance %s:\n",
15118 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15119 ? VRF_DEFAULT_NAME : bgp->name);
15120 }
15121 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
15122 if (use_json) {
15123 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15124 json_object_object_add(json_vrfs,
15125 VRF_DEFAULT_NAME, json_vrf);
15126 else
15127 json_object_object_add(json_vrfs, vrf_name,
15128 json_vrf);
15129 }
15130 }
15131
15132 if (use_json) {
15133 json_object_object_add(json, "vrfs", json_vrfs);
15134 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
15135 JSON_C_TO_STRING_PRETTY));
15136 json_object_free(json);
15137 }
15138
15139 return CMD_SUCCESS;
15140}
15141
53089bec 15142/* "show [ip] bgp route-leak" command. */
15143DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
15144 show_ip_bgp_route_leak_cmd,
15145 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
15146 SHOW_STR
15147 IP_STR
15148 BGP_STR
15149 BGP_INSTANCE_HELP_STR
15150 BGP_AFI_HELP_STR
15151 BGP_SAFI_HELP_STR
15152 "Route leaking information\n"
15153 JSON_STR)
53089bec 15154{
15155 char *vrf = NULL;
15156 afi_t afi = AFI_MAX;
15157 safi_t safi = SAFI_MAX;
15158
9f049418 15159 bool uj = use_json(argc, argv);
53089bec 15160 int idx = 0;
03915806 15161 json_object *json = NULL;
53089bec 15162
15163 /* show [ip] bgp */
15164 if (argv_find(argv, argc, "ip", &idx)) {
15165 afi = AFI_IP;
15166 safi = SAFI_UNICAST;
15167 }
15168 /* [vrf VIEWVRFNAME] */
15169 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
15170 vty_out(vty,
15171 "%% This command is not applicable to BGP views\n");
53089bec 15172 return CMD_WARNING;
15173 }
15174
9a8bdf1c
PG
15175 if (argv_find(argv, argc, "vrf", &idx)) {
15176 vrf = argv[idx + 1]->arg;
15177 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15178 vrf = NULL;
15179 }
53089bec 15180 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15181 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15182 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15183 }
15184
15185 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
15186 vty_out(vty,
15187 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 15188 return CMD_WARNING;
15189 }
15190
03915806
CS
15191 if (vrf && strmatch(vrf, "all"))
15192 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15193
15194 if (uj)
15195 json = json_object_new_object();
15196
15197 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
53089bec 15198}
15199
d62a17ae 15200static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
15201 safi_t safi)
f186de26 15202{
d62a17ae 15203 struct listnode *node, *nnode;
15204 struct bgp *bgp;
f186de26 15205
d62a17ae 15206 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15207 vty_out(vty, "\nInstance %s:\n",
15208 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 15209 ? VRF_DEFAULT_NAME
d62a17ae 15210 : bgp->name);
15211 update_group_show(bgp, afi, safi, vty, 0);
15212 }
f186de26 15213}
15214
d62a17ae 15215static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
15216 int safi, uint64_t subgrp_id)
4fb25c53 15217{
d62a17ae 15218 struct bgp *bgp;
4fb25c53 15219
d62a17ae 15220 if (name) {
15221 if (strmatch(name, "all")) {
15222 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
15223 return CMD_SUCCESS;
15224 } else {
15225 bgp = bgp_lookup_by_name(name);
15226 }
15227 } else {
15228 bgp = bgp_get_default();
15229 }
4fb25c53 15230
d62a17ae 15231 if (bgp)
15232 update_group_show(bgp, afi, safi, vty, subgrp_id);
15233 return CMD_SUCCESS;
4fb25c53
DW
15234}
15235
8fe8a7f6
DS
15236DEFUN (show_ip_bgp_updgrps,
15237 show_ip_bgp_updgrps_cmd,
c1a44e43 15238 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 15239 SHOW_STR
15240 IP_STR
15241 BGP_STR
15242 BGP_INSTANCE_HELP_STR
c9e571b4 15243 BGP_AFI_HELP_STR
9bedbb1e 15244 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
15245 "Detailed info about dynamic update groups\n"
15246 "Specific subgroup to display detailed info for\n")
8386ac43 15247{
d62a17ae 15248 char *vrf = NULL;
15249 afi_t afi = AFI_IP6;
15250 safi_t safi = SAFI_UNICAST;
15251 uint64_t subgrp_id = 0;
15252
15253 int idx = 0;
15254
15255 /* show [ip] bgp */
15256 if (argv_find(argv, argc, "ip", &idx))
15257 afi = AFI_IP;
9a8bdf1c
PG
15258 /* [<vrf> VIEWVRFNAME] */
15259 if (argv_find(argv, argc, "vrf", &idx)) {
15260 vrf = argv[idx + 1]->arg;
15261 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15262 vrf = NULL;
15263 } else if (argv_find(argv, argc, "view", &idx))
15264 /* [<view> VIEWVRFNAME] */
15265 vrf = argv[idx + 1]->arg;
d62a17ae 15266 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15267 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15268 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15269 }
5bf15956 15270
d62a17ae 15271 /* get subgroup id, if provided */
15272 idx = argc - 1;
15273 if (argv[idx]->type == VARIABLE_TKN)
15274 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 15275
d62a17ae 15276 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
15277}
15278
f186de26 15279DEFUN (show_bgp_instance_all_ipv6_updgrps,
15280 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 15281 "show [ip] bgp <view|vrf> all update-groups",
f186de26 15282 SHOW_STR
716b2d8a 15283 IP_STR
f186de26 15284 BGP_STR
15285 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 15286 "Detailed info about dynamic update groups\n")
f186de26 15287{
d62a17ae 15288 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
15289 return CMD_SUCCESS;
f186de26 15290}
15291
43d3f4fc
DS
15292DEFUN (show_bgp_l2vpn_evpn_updgrps,
15293 show_bgp_l2vpn_evpn_updgrps_cmd,
15294 "show [ip] bgp l2vpn evpn update-groups",
15295 SHOW_STR
15296 IP_STR
15297 BGP_STR
15298 "l2vpn address family\n"
15299 "evpn sub-address family\n"
15300 "Detailed info about dynamic update groups\n")
15301{
15302 char *vrf = NULL;
15303 uint64_t subgrp_id = 0;
15304
15305 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
15306 return CMD_SUCCESS;
15307}
15308
5bf15956
DW
15309DEFUN (show_bgp_updgrps_stats,
15310 show_bgp_updgrps_stats_cmd,
716b2d8a 15311 "show [ip] bgp update-groups statistics",
3f9c7369 15312 SHOW_STR
716b2d8a 15313 IP_STR
3f9c7369 15314 BGP_STR
0c7b1b01 15315 "Detailed info about dynamic update groups\n"
3f9c7369
DS
15316 "Statistics\n")
15317{
d62a17ae 15318 struct bgp *bgp;
3f9c7369 15319
d62a17ae 15320 bgp = bgp_get_default();
15321 if (bgp)
15322 update_group_show_stats(bgp, vty);
3f9c7369 15323
d62a17ae 15324 return CMD_SUCCESS;
3f9c7369
DS
15325}
15326
8386ac43 15327DEFUN (show_bgp_instance_updgrps_stats,
15328 show_bgp_instance_updgrps_stats_cmd,
18c57037 15329 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 15330 SHOW_STR
716b2d8a 15331 IP_STR
8386ac43 15332 BGP_STR
15333 BGP_INSTANCE_HELP_STR
0c7b1b01 15334 "Detailed info about dynamic update groups\n"
8386ac43 15335 "Statistics\n")
15336{
d62a17ae 15337 int idx_word = 3;
15338 struct bgp *bgp;
8386ac43 15339
d62a17ae 15340 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15341 if (bgp)
15342 update_group_show_stats(bgp, vty);
8386ac43 15343
d62a17ae 15344 return CMD_SUCCESS;
8386ac43 15345}
15346
d62a17ae 15347static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15348 afi_t afi, safi_t safi,
15349 const char *what, uint64_t subgrp_id)
3f9c7369 15350{
d62a17ae 15351 struct bgp *bgp;
8386ac43 15352
d62a17ae 15353 if (name)
15354 bgp = bgp_lookup_by_name(name);
15355 else
15356 bgp = bgp_get_default();
8386ac43 15357
d62a17ae 15358 if (bgp) {
15359 if (!strcmp(what, "advertise-queue"))
15360 update_group_show_adj_queue(bgp, afi, safi, vty,
15361 subgrp_id);
15362 else if (!strcmp(what, "advertised-routes"))
15363 update_group_show_advertised(bgp, afi, safi, vty,
15364 subgrp_id);
15365 else if (!strcmp(what, "packet-queue"))
15366 update_group_show_packet_queue(bgp, afi, safi, vty,
15367 subgrp_id);
15368 }
3f9c7369
DS
15369}
15370
dc64bdec
QY
15371DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15372 show_ip_bgp_instance_updgrps_adj_s_cmd,
15373 "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",
15374 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15375 BGP_SAFI_HELP_STR
15376 "Detailed info about dynamic update groups\n"
15377 "Specific subgroup to display info for\n"
15378 "Advertisement queue\n"
15379 "Announced routes\n"
15380 "Packet queue\n")
3f9c7369 15381{
dc64bdec
QY
15382 uint64_t subgrp_id = 0;
15383 afi_t afiz;
15384 safi_t safiz;
15385 if (sgid)
15386 subgrp_id = strtoull(sgid, NULL, 10);
15387
15388 if (!ip && !afi)
15389 afiz = AFI_IP6;
15390 if (!ip && afi)
15391 afiz = bgp_vty_afi_from_str(afi);
15392 if (ip && !afi)
15393 afiz = AFI_IP;
15394 if (ip && afi) {
15395 afiz = bgp_vty_afi_from_str(afi);
15396 if (afiz != AFI_IP)
15397 vty_out(vty,
15398 "%% Cannot specify both 'ip' and 'ipv6'\n");
15399 return CMD_WARNING;
15400 }
d62a17ae 15401
dc64bdec 15402 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 15403
dc64bdec 15404 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 15405 return CMD_SUCCESS;
15406}
15407
6f4eacf3
DA
15408static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
15409 json_object *json)
d62a17ae 15410{
15411 struct listnode *node, *nnode;
15412 struct prefix *range;
15413 struct peer *conf;
15414 struct peer *peer;
d62a17ae 15415 afi_t afi;
15416 safi_t safi;
15417 const char *peer_status;
d62a17ae 15418 int lr_count;
15419 int dynamic;
6f4eacf3
DA
15420 bool af_cfgd;
15421 json_object *json_peer_group = NULL;
15422 json_object *json_peer_group_afc = NULL;
15423 json_object *json_peer_group_members = NULL;
15424 json_object *json_peer_group_dynamic = NULL;
15425 json_object *json_peer_group_dynamic_af = NULL;
15426 json_object *json_peer_group_ranges = NULL;
d62a17ae 15427
15428 conf = group->conf;
15429
6f4eacf3
DA
15430 if (json) {
15431 json_peer_group = json_object_new_object();
15432 json_peer_group_afc = json_object_new_array();
15433 }
15434
d62a17ae 15435 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
6f4eacf3
DA
15436 if (json)
15437 json_object_int_add(json_peer_group, "remoteAs",
15438 conf->as);
15439 else
15440 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15441 group->name, conf->as);
d62a17ae 15442 } else if (conf->as_type == AS_INTERNAL) {
6f4eacf3
DA
15443 if (json)
15444 json_object_int_add(json_peer_group, "remoteAs",
15445 group->bgp->as);
15446 else
15447 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15448 group->name, group->bgp->as);
d62a17ae 15449 } else {
6f4eacf3
DA
15450 if (!json)
15451 vty_out(vty, "\nBGP peer-group %s\n", group->name);
d62a17ae 15452 }
f14e6fdb 15453
6f4eacf3
DA
15454 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
15455 if (json)
15456 json_object_string_add(json_peer_group, "type",
15457 "internal");
15458 else
15459 vty_out(vty, " Peer-group type is internal\n");
15460 } else {
15461 if (json)
15462 json_object_string_add(json_peer_group, "type",
15463 "external");
15464 else
15465 vty_out(vty, " Peer-group type is external\n");
15466 }
d62a17ae 15467
15468 /* Display AFs configured. */
6f4eacf3
DA
15469 if (!json)
15470 vty_out(vty, " Configured address-families:");
15471
05c7a1cc
QY
15472 FOREACH_AFI_SAFI (afi, safi) {
15473 if (conf->afc[afi][safi]) {
6f4eacf3
DA
15474 af_cfgd = true;
15475 if (json)
15476 json_object_array_add(
15477 json_peer_group_afc,
15478 json_object_new_string(get_afi_safi_str(
15479 afi, safi, false)));
15480 else
15481 vty_out(vty, " %s;",
15482 get_afi_safi_str(afi, safi, false));
d62a17ae 15483 }
05c7a1cc 15484 }
6f4eacf3
DA
15485
15486 if (json) {
15487 json_object_object_add(json_peer_group,
15488 "addressFamiliesConfigured",
15489 json_peer_group_afc);
15490 } else {
15491 if (!af_cfgd)
15492 vty_out(vty, " none\n");
15493 else
15494 vty_out(vty, "\n");
15495 }
d62a17ae 15496
15497 /* Display listen ranges (for dynamic neighbors), if any */
15498 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
d62a17ae 15499 lr_count = listcount(group->listen_range[afi]);
15500 if (lr_count) {
6f4eacf3
DA
15501 if (json) {
15502 if (!json_peer_group_dynamic)
15503 json_peer_group_dynamic =
15504 json_object_new_object();
15505
15506 json_peer_group_dynamic_af =
15507 json_object_new_object();
15508 json_peer_group_ranges =
15509 json_object_new_array();
15510 json_object_int_add(json_peer_group_dynamic_af,
15511 "count", lr_count);
15512 } else {
15513 vty_out(vty, " %d %s listen range(s)\n",
15514 lr_count, afi2str(afi));
15515 }
d62a17ae 15516
15517 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
6f4eacf3
DA
15518 nnode, range)) {
15519 if (json) {
15520 char buf[BUFSIZ];
15521
15522 snprintfrr(buf, sizeof(buf), "%pFX",
15523 range);
15524
15525 json_object_array_add(
15526 json_peer_group_ranges,
15527 json_object_new_string(buf));
15528 } else {
15529 vty_out(vty, " %pFX\n", range);
15530 }
15531 }
15532
15533 if (json) {
15534 json_object_object_add(
15535 json_peer_group_dynamic_af, "ranges",
15536 json_peer_group_ranges);
15537
15538 json_object_object_add(
15539 json_peer_group_dynamic, afi2str(afi),
15540 json_peer_group_dynamic_af);
15541 }
d62a17ae 15542 }
15543 }
f14e6fdb 15544
6f4eacf3
DA
15545 if (json_peer_group_dynamic)
15546 json_object_object_add(json_peer_group, "dynamicRanges",
15547 json_peer_group_dynamic);
15548
d62a17ae 15549 /* Display group members and their status */
15550 if (listcount(group->peer)) {
6f4eacf3
DA
15551 if (json)
15552 json_peer_group_members = json_object_new_object();
15553 else
15554 vty_out(vty, " Peer-group members:\n");
d62a17ae 15555 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
cb9196e7
DS
15556 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15557 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 15558 peer_status = "Idle (Admin)";
15559 else if (CHECK_FLAG(peer->sflags,
15560 PEER_STATUS_PREFIX_OVERFLOW))
15561 peer_status = "Idle (PfxCt)";
15562 else
15563 peer_status = lookup_msg(bgp_status_msg,
15564 peer->status, NULL);
15565
15566 dynamic = peer_dynamic_neighbor(peer);
6f4eacf3
DA
15567
15568 if (json) {
15569 json_object *json_peer_group_member =
15570 json_object_new_object();
15571
15572 json_object_string_add(json_peer_group_member,
15573 "status", peer_status);
15574
15575 if (dynamic)
15576 json_object_boolean_true_add(
15577 json_peer_group_member,
15578 "dynamic");
15579
15580 json_object_object_add(json_peer_group_members,
15581 peer->host,
15582 json_peer_group_member);
15583 } else {
15584 vty_out(vty, " %s %s %s \n", peer->host,
15585 dynamic ? "(dynamic)" : "",
15586 peer_status);
15587 }
d62a17ae 15588 }
6f4eacf3
DA
15589 if (json)
15590 json_object_object_add(json_peer_group, "members",
15591 json_peer_group_members);
d62a17ae 15592 }
f14e6fdb 15593
6f4eacf3
DA
15594 if (json)
15595 json_object_object_add(json, group->name, json_peer_group);
15596
d62a17ae 15597 return CMD_SUCCESS;
15598}
15599
ff9959b0 15600static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
6f4eacf3 15601 const char *group_name, bool uj)
d62a17ae 15602{
ff9959b0 15603 struct bgp *bgp;
d62a17ae 15604 struct listnode *node, *nnode;
15605 struct peer_group *group;
ff9959b0 15606 bool found = false;
6f4eacf3
DA
15607 json_object *json = NULL;
15608
15609 if (uj)
15610 json = json_object_new_object();
ff9959b0
QY
15611
15612 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15613
15614 if (!bgp) {
6f4eacf3
DA
15615 if (uj) {
15616 vty_out(vty, "%s\n",
15617 json_object_to_json_string_ext(
15618 json, JSON_C_TO_STRING_PRETTY));
15619 json_object_free(json);
15620 } else {
15621 vty_out(vty, "%% BGP instance not found\n");
15622 }
15623
ff9959b0
QY
15624 return CMD_WARNING;
15625 }
d62a17ae 15626
15627 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
15628 if (group_name) {
15629 if (strmatch(group->name, group_name)) {
6f4eacf3 15630 bgp_show_one_peer_group(vty, group, json);
ff9959b0
QY
15631 found = true;
15632 break;
d62a17ae 15633 }
ff9959b0 15634 } else {
6f4eacf3 15635 bgp_show_one_peer_group(vty, group, json);
d62a17ae 15636 }
f14e6fdb 15637 }
f14e6fdb 15638
6f4eacf3 15639 if (group_name && !found && !uj)
d62a17ae 15640 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 15641
6f4eacf3
DA
15642 if (uj) {
15643 vty_out(vty, "%s\n",
15644 json_object_to_json_string_ext(
15645 json, JSON_C_TO_STRING_PRETTY));
15646 json_object_free(json);
15647 }
15648
d62a17ae 15649 return CMD_SUCCESS;
f14e6fdb
DS
15650}
15651
6f4eacf3
DA
15652DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
15653 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
15654 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
15655 "Detailed information on BGP peer groups\n"
15656 "Peer group name\n" JSON_STR)
f14e6fdb 15657{
d62a17ae 15658 char *vrf, *pg;
d62a17ae 15659 int idx = 0;
6f4eacf3 15660 bool uj = use_json(argc, argv);
f14e6fdb 15661
a4d82a8a
PZ
15662 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
15663 : NULL;
d62a17ae 15664 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 15665
6f4eacf3 15666 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
f14e6fdb 15667}
3f9c7369 15668
d6e3c605 15669
718e3744 15670/* Redistribute VTY commands. */
15671
37a87b8f
CS
15672DEFUN_YANG (bgp_redistribute_ipv4,
15673 bgp_redistribute_ipv4_cmd,
15674 "redistribute " FRR_IP_REDIST_STR_BGPD,
15675 "Redistribute information from another routing protocol\n"
15676 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 15677{
d62a17ae 15678 int idx_protocol = 1;
37a87b8f 15679 char base_xpath[XPATH_MAXLEN];
718e3744 15680
37a87b8f
CS
15681 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15682 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15683 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15684 argv[idx_protocol]->text, "0");
15685
15686 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
7f323236 15687
37a87b8f 15688 return nb_cli_apply_changes(vty, base_xpath);
718e3744 15689}
15690
d62a17ae 15691ALIAS_HIDDEN(
15692 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
15693 "redistribute " FRR_IP_REDIST_STR_BGPD,
15694 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 15695
37a87b8f
CS
15696DEFUN_YANG (bgp_redistribute_ipv4_rmap,
15697 bgp_redistribute_ipv4_rmap_cmd,
15698 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15699 "Redistribute information from another routing protocol\n"
15700 FRR_IP_REDIST_HELP_STR_BGPD
15701 "Route map reference\n"
15702 "Pointer to route-map entries\n")
718e3744 15703{
d62a17ae 15704 int idx_protocol = 1;
15705 int idx_word = 3;
37a87b8f
CS
15706 char base_xpath[XPATH_MAXLEN];
15707
15708 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15709 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15710 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15711 argv[idx_protocol]->text, "0");
718e3744 15712
37a87b8f
CS
15713 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15714 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15715 argv[idx_word]->arg);
15716
15717 return nb_cli_apply_changes(vty, base_xpath);
718e3744 15718}
15719
d62a17ae 15720ALIAS_HIDDEN(
15721 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
15722 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15723 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15724 "Route map reference\n"
15725 "Pointer to route-map entries\n")
596c17ba 15726
37a87b8f
CS
15727DEFUN_YANG (bgp_redistribute_ipv4_metric,
15728 bgp_redistribute_ipv4_metric_cmd,
15729 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15730 "Redistribute information from another routing protocol\n"
15731 FRR_IP_REDIST_HELP_STR_BGPD
15732 "Metric for redistributed routes\n"
15733 "Default metric\n")
718e3744 15734{
d62a17ae 15735 int idx_protocol = 1;
15736 int idx_number = 3;
37a87b8f
CS
15737 char base_xpath[XPATH_MAXLEN];
15738
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, "0");
d62a17ae 15743
37a87b8f
CS
15744 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15745 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15746 argv[idx_number]->arg);
15747
15748 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15749}
15750
15751ALIAS_HIDDEN(
15752 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
15753 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15754 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15755 "Metric for redistributed routes\n"
15756 "Default metric\n")
596c17ba 15757
37a87b8f
CS
15758DEFUN_YANG(
15759 bgp_redistribute_ipv4_rmap_metric,
15760 bgp_redistribute_ipv4_rmap_metric_cmd,
15761 "redistribute " FRR_IP_REDIST_STR_BGPD
15762 " route-map WORD metric (0-4294967295)",
15763 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15764 "Route map reference\n"
15765 "Pointer to route-map entries\n"
15766 "Metric for redistributed routes\n"
15767 "Default metric\n")
718e3744 15768{
d62a17ae 15769 int idx_protocol = 1;
15770 int idx_word = 3;
15771 int idx_number = 5;
37a87b8f
CS
15772 char base_xpath[XPATH_MAXLEN];
15773
15774 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15775 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15776 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15777 argv[idx_protocol]->text, "0");
15778
15779 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15780 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15781 argv[idx_word]->arg);
15782 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15783 argv[idx_number]->arg);
d62a17ae 15784
37a87b8f 15785 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15786}
15787
15788ALIAS_HIDDEN(
15789 bgp_redistribute_ipv4_rmap_metric,
15790 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
15791 "redistribute " FRR_IP_REDIST_STR_BGPD
15792 " route-map WORD metric (0-4294967295)",
15793 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15794 "Route map reference\n"
15795 "Pointer to route-map entries\n"
15796 "Metric for redistributed routes\n"
15797 "Default metric\n")
596c17ba 15798
37a87b8f
CS
15799DEFUN_YANG(
15800 bgp_redistribute_ipv4_metric_rmap,
15801 bgp_redistribute_ipv4_metric_rmap_cmd,
15802 "redistribute " FRR_IP_REDIST_STR_BGPD
15803 " metric (0-4294967295) route-map WORD",
15804 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15805 "Metric for redistributed routes\n"
15806 "Default metric\n"
15807 "Route map reference\n"
15808 "Pointer to route-map entries\n")
718e3744 15809{
d62a17ae 15810 int idx_protocol = 1;
d62a17ae 15811 int idx_word = 5;
37a87b8f
CS
15812 int idx_number = 3;
15813 char base_xpath[XPATH_MAXLEN];
15814
15815 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15816 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15817 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15818 argv[idx_protocol]->text, "0");
15819
15820 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15821 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15822 argv[idx_number]->arg);
15823 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15824 argv[idx_word]->arg);
d62a17ae 15825
37a87b8f 15826 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15827}
15828
15829ALIAS_HIDDEN(
15830 bgp_redistribute_ipv4_metric_rmap,
15831 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
15832 "redistribute " FRR_IP_REDIST_STR_BGPD
15833 " metric (0-4294967295) route-map WORD",
15834 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15835 "Metric for redistributed routes\n"
15836 "Default metric\n"
15837 "Route map reference\n"
15838 "Pointer to route-map entries\n")
596c17ba 15839
37a87b8f
CS
15840DEFUN_YANG (bgp_redistribute_ipv4_ospf,
15841 bgp_redistribute_ipv4_ospf_cmd,
15842 "redistribute <ospf|table> (1-65535)",
15843 "Redistribute information from another routing protocol\n"
15844 "Open Shortest Path First (OSPFv2)\n"
15845 "Non-main Kernel Routing Table\n"
15846 "Instance ID/Table ID\n")
7c8ff89e 15847{
37a87b8f 15848 int idx_protocol = 1;
d62a17ae 15849 int idx_number = 2;
37a87b8f 15850 char base_xpath[XPATH_MAXLEN];
7c8ff89e 15851
37a87b8f
CS
15852 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15853 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15854 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15855 argv[idx_protocol]->text, argv[idx_number]->arg);
7a4bb9c5 15856
37a87b8f 15857 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
7a4bb9c5 15858
37a87b8f 15859 return nb_cli_apply_changes(vty, base_xpath);
7c8ff89e
DS
15860}
15861
d62a17ae 15862ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
15863 "redistribute <ospf|table> (1-65535)",
15864 "Redistribute information from another routing protocol\n"
15865 "Open Shortest Path First (OSPFv2)\n"
15866 "Non-main Kernel Routing Table\n"
15867 "Instance ID/Table ID\n")
596c17ba 15868
37a87b8f
CS
15869DEFUN_YANG (bgp_redistribute_ipv4_ospf_rmap,
15870 bgp_redistribute_ipv4_ospf_rmap_cmd,
15871 "redistribute <ospf|table> (1-65535) route-map WORD",
15872 "Redistribute information from another routing protocol\n"
15873 "Open Shortest Path First (OSPFv2)\n"
15874 "Non-main Kernel Routing Table\n"
15875 "Instance ID/Table ID\n"
15876 "Route map reference\n"
15877 "Pointer to route-map entries\n")
7c8ff89e 15878{
37a87b8f 15879 int idx_protocol = 1;
d62a17ae 15880 int idx_number = 2;
15881 int idx_word = 4;
37a87b8f
CS
15882 char base_xpath[XPATH_MAXLEN];
15883
15884 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15885 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15886 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15887 argv[idx_protocol]->text, argv[idx_number]->arg);
15888
15889 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15890
15891 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15892 argv[idx_word]->arg);
d62a17ae 15893
37a87b8f 15894 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15895}
15896
15897ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
15898 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
15899 "redistribute <ospf|table> (1-65535) route-map WORD",
15900 "Redistribute information from another routing protocol\n"
15901 "Open Shortest Path First (OSPFv2)\n"
15902 "Non-main Kernel Routing Table\n"
15903 "Instance ID/Table ID\n"
15904 "Route map reference\n"
15905 "Pointer to route-map entries\n")
596c17ba 15906
37a87b8f
CS
15907DEFUN_YANG(bgp_redistribute_ipv4_ospf_metric,
15908 bgp_redistribute_ipv4_ospf_metric_cmd,
15909 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15910 "Redistribute information from another routing protocol\n"
15911 "Open Shortest Path First (OSPFv2)\n"
15912 "Non-main Kernel Routing Table\n"
15913 "Instance ID/Table ID\n"
15914 "Metric for redistributed routes\n"
15915 "Default metric\n")
7c8ff89e 15916{
37a87b8f 15917 int idx_protocol = 1;
d62a17ae 15918 int idx_number = 2;
15919 int idx_number_2 = 4;
37a87b8f
CS
15920 char base_xpath[XPATH_MAXLEN];
15921
15922 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15923 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15924 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15925 argv[idx_protocol]->text, argv[idx_number]->arg);
15926
15927 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 15928
37a87b8f
CS
15929 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15930 argv[idx_number_2]->arg);
d62a17ae 15931
37a87b8f 15932 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15933}
15934
15935ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
15936 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
15937 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15938 "Redistribute information from another routing protocol\n"
15939 "Open Shortest Path First (OSPFv2)\n"
15940 "Non-main Kernel Routing Table\n"
15941 "Instance ID/Table ID\n"
15942 "Metric for redistributed routes\n"
15943 "Default metric\n")
596c17ba 15944
37a87b8f
CS
15945DEFUN_YANG(
15946 bgp_redistribute_ipv4_ospf_rmap_metric,
15947 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
15948 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15949 "Redistribute information from another routing protocol\n"
15950 "Open Shortest Path First (OSPFv2)\n"
15951 "Non-main Kernel Routing Table\n"
15952 "Instance ID/Table ID\n"
15953 "Route map reference\n"
15954 "Pointer to route-map entries\n"
15955 "Metric for redistributed routes\n"
15956 "Default metric\n")
7c8ff89e 15957{
37a87b8f 15958 int idx_protocol = 1;
d62a17ae 15959 int idx_number = 2;
15960 int idx_word = 4;
15961 int idx_number_2 = 6;
37a87b8f
CS
15962 char base_xpath[XPATH_MAXLEN];
15963
15964 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15965 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15966 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15967 argv[idx_protocol]->text, argv[idx_number]->arg);
15968
15969 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 15970
37a87b8f
CS
15971 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15972 argv[idx_word]->arg);
15973 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15974 argv[idx_number_2]->arg);
d62a17ae 15975
37a87b8f 15976 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15977}
15978
15979ALIAS_HIDDEN(
15980 bgp_redistribute_ipv4_ospf_rmap_metric,
15981 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
15982 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15983 "Redistribute information from another routing protocol\n"
15984 "Open Shortest Path First (OSPFv2)\n"
15985 "Non-main Kernel Routing Table\n"
15986 "Instance ID/Table ID\n"
15987 "Route map reference\n"
15988 "Pointer to route-map entries\n"
15989 "Metric for redistributed routes\n"
15990 "Default metric\n")
596c17ba 15991
37a87b8f
CS
15992DEFUN_YANG(
15993 bgp_redistribute_ipv4_ospf_metric_rmap,
15994 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
15995 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15996 "Redistribute information from another routing protocol\n"
15997 "Open Shortest Path First (OSPFv2)\n"
15998 "Non-main Kernel Routing Table\n"
15999 "Instance ID/Table ID\n"
16000 "Metric for redistributed routes\n"
16001 "Default metric\n"
16002 "Route map reference\n"
16003 "Pointer to route-map entries\n")
7c8ff89e 16004{
37a87b8f 16005 int idx_protocol = 1;
d62a17ae 16006 int idx_number = 2;
16007 int idx_number_2 = 4;
16008 int idx_word = 6;
37a87b8f
CS
16009 char base_xpath[XPATH_MAXLEN];
16010
16011 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16012 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16013 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16014 argv[idx_protocol]->text, argv[idx_number]->arg);
16015
16016 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 16017
37a87b8f
CS
16018 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16019 argv[idx_number_2]->arg);
16020 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16021 argv[idx_word]->arg);
d62a17ae 16022
37a87b8f 16023 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 16024}
16025
16026ALIAS_HIDDEN(
16027 bgp_redistribute_ipv4_ospf_metric_rmap,
16028 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
16029 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
16030 "Redistribute information from another routing protocol\n"
16031 "Open Shortest Path First (OSPFv2)\n"
16032 "Non-main Kernel Routing Table\n"
16033 "Instance ID/Table ID\n"
16034 "Metric for redistributed routes\n"
16035 "Default metric\n"
16036 "Route map reference\n"
16037 "Pointer to route-map entries\n")
596c17ba 16038
37a87b8f
CS
16039DEFUN_YANG (no_bgp_redistribute_ipv4_ospf,
16040 no_bgp_redistribute_ipv4_ospf_cmd,
16041 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
16042 NO_STR
16043 "Redistribute information from another routing protocol\n"
16044 "Open Shortest Path First (OSPFv2)\n"
16045 "Non-main Kernel Routing Table\n"
16046 "Instance ID/Table ID\n"
16047 "Metric for redistributed routes\n"
16048 "Default metric\n"
16049 "Route map reference\n"
16050 "Pointer to route-map entries\n")
7c8ff89e 16051{
37a87b8f 16052 int idx_protocol = 2;
d62a17ae 16053 int idx_number = 3;
37a87b8f 16054 char base_xpath[XPATH_MAXLEN];
d62a17ae 16055
37a87b8f
CS
16056 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16057 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16058 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16059 argv[idx_protocol]->text, argv[idx_number]->arg);
16060
16061 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
d62a17ae 16062
37a87b8f 16063 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 16064}
16065
16066ALIAS_HIDDEN(
16067 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
e27957c0 16068 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 16069 NO_STR
16070 "Redistribute information from another routing protocol\n"
16071 "Open Shortest Path First (OSPFv2)\n"
16072 "Non-main Kernel Routing Table\n"
16073 "Instance ID/Table ID\n"
16074 "Metric for redistributed routes\n"
16075 "Default metric\n"
16076 "Route map reference\n"
16077 "Pointer to route-map entries\n")
596c17ba 16078
37a87b8f
CS
16079DEFUN_YANG (no_bgp_redistribute_ipv4,
16080 no_bgp_redistribute_ipv4_cmd,
16081 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
16082 NO_STR
16083 "Redistribute information from another routing protocol\n"
16084 FRR_IP_REDIST_HELP_STR_BGPD
16085 "Metric for redistributed routes\n"
16086 "Default metric\n"
16087 "Route map reference\n"
16088 "Pointer to route-map entries\n")
718e3744 16089{
d62a17ae 16090 int idx_protocol = 2;
37a87b8f 16091 char base_xpath[XPATH_MAXLEN];
d62a17ae 16092
37a87b8f
CS
16093 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16094 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16095 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16096 argv[idx_protocol]->text, "0");
16097
16098 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
16099
16100 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 16101}
16102
16103ALIAS_HIDDEN(
16104 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
16105 "no redistribute " FRR_IP_REDIST_STR_BGPD
e27957c0 16106 " [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 16107 NO_STR
16108 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16109 "Metric for redistributed routes\n"
16110 "Default metric\n"
16111 "Route map reference\n"
16112 "Pointer to route-map entries\n")
596c17ba 16113
37a87b8f
CS
16114DEFUN_YANG (bgp_redistribute_ipv6,
16115 bgp_redistribute_ipv6_cmd,
16116 "redistribute " FRR_IP6_REDIST_STR_BGPD,
16117 "Redistribute information from another routing protocol\n"
16118 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 16119{
d62a17ae 16120 int idx_protocol = 1;
37a87b8f 16121 char base_xpath[XPATH_MAXLEN];
718e3744 16122
37a87b8f
CS
16123 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16124 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16125 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16126 argv[idx_protocol]->text, "0");
16127
16128 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
718e3744 16129
37a87b8f 16130 return nb_cli_apply_changes(vty, base_xpath);
718e3744 16131}
16132
37a87b8f
CS
16133DEFUN_YANG (bgp_redistribute_ipv6_rmap,
16134 bgp_redistribute_ipv6_rmap_cmd,
16135 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
16136 "Redistribute information from another routing protocol\n"
16137 FRR_IP6_REDIST_HELP_STR_BGPD
16138 "Route map reference\n"
16139 "Pointer to route-map entries\n")
718e3744 16140{
d62a17ae 16141 int idx_protocol = 1;
16142 int idx_word = 3;
37a87b8f
CS
16143 char base_xpath[XPATH_MAXLEN];
16144
16145 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16146 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16147 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16148 argv[idx_protocol]->text, "0");
718e3744 16149
37a87b8f
CS
16150 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16151 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16152 argv[idx_word]->arg);
16153
16154 return nb_cli_apply_changes(vty, base_xpath);
718e3744 16155}
16156
37a87b8f 16157DEFUN_YANG (bgp_redistribute_ipv6_metric,
718e3744 16158 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 16159 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 16160 "Redistribute information from another routing protocol\n"
ab0181ee 16161 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 16162 "Metric for redistributed routes\n"
16163 "Default metric\n")
16164{
d62a17ae 16165 int idx_protocol = 1;
16166 int idx_number = 3;
37a87b8f
CS
16167 char base_xpath[XPATH_MAXLEN];
16168
16169 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16170 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16171 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16172 argv[idx_protocol]->text, "0");
718e3744 16173
37a87b8f
CS
16174 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16175 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16176 argv[idx_number]->arg);
16177
16178 return nb_cli_apply_changes(vty, base_xpath);
718e3744 16179}
16180
37a87b8f
CS
16181DEFUN_YANG(
16182 bgp_redistribute_ipv6_rmap_metric,
16183 bgp_redistribute_ipv6_rmap_metric_cmd,
16184 "redistribute " FRR_IP6_REDIST_STR_BGPD
16185 " route-map WORD metric (0-4294967295)",
16186 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
16187 "Route map reference\n"
16188 "Pointer to route-map entries\n"
16189 "Metric for redistributed routes\n"
16190 "Default metric\n")
718e3744 16191{
d62a17ae 16192 int idx_protocol = 1;
16193 int idx_word = 3;
16194 int idx_number = 5;
37a87b8f
CS
16195 char base_xpath[XPATH_MAXLEN];
16196
16197 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16198 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16199 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16200 argv[idx_protocol]->text, "0");
718e3744 16201
37a87b8f
CS
16202 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16203 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16204 argv[idx_word]->arg);
16205 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16206 argv[idx_number]->arg);
16207
16208 return nb_cli_apply_changes(vty, base_xpath);
718e3744 16209}
16210
37a87b8f
CS
16211DEFUN_YANG(
16212 bgp_redistribute_ipv6_metric_rmap,
16213 bgp_redistribute_ipv6_metric_rmap_cmd,
16214 "redistribute " FRR_IP6_REDIST_STR_BGPD
16215 " metric (0-4294967295) route-map WORD",
16216 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
16217 "Metric for redistributed routes\n"
16218 "Default metric\n"
16219 "Route map reference\n"
16220 "Pointer to route-map entries\n")
718e3744 16221{
d62a17ae 16222 int idx_protocol = 1;
d62a17ae 16223 int idx_word = 5;
37a87b8f
CS
16224 int idx_number = 3;
16225 char base_xpath[XPATH_MAXLEN];
16226
16227 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16228 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16229 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16230 argv[idx_protocol]->text, "0");
718e3744 16231
37a87b8f
CS
16232 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16233 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16234 argv[idx_number]->arg);
16235 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16236 argv[idx_word]->arg);
16237
16238 return nb_cli_apply_changes(vty, base_xpath);
718e3744 16239}
16240
37a87b8f
CS
16241DEFUN_YANG(
16242 no_bgp_redistribute_ipv6,
16243 no_bgp_redistribute_ipv6_cmd,
16244 "no redistribute " FRR_IP6_REDIST_STR_BGPD
16245 " [{metric (0-4294967295)|route-map WORD}]",
16246 NO_STR
16247 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
16248 "Metric for redistributed routes\n"
16249 "Default metric\n"
16250 "Route map reference\n"
16251 "Pointer to route-map entries\n")
718e3744 16252{
d62a17ae 16253 int idx_protocol = 2;
37a87b8f 16254 char base_xpath[XPATH_MAXLEN];
718e3744 16255
37a87b8f
CS
16256 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16257 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16258 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16259 argv[idx_protocol]->text, "0");
16260
16261 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
16262
16263 return nb_cli_apply_changes(vty, base_xpath);
16264}
718e3744 16265
37a87b8f
CS
16266void cli_show_bgp_global_afi_safi_ip_unicast_redistribution_list(
16267 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
16268{
16269 uint32_t instance = 0;
16270
16271 vty_out(vty, " redistribute %s",
16272 yang_dnode_get_string(dnode, "./route-type"));
16273 if ((instance = yang_dnode_get_uint16(dnode, "./route-instance")))
16274 vty_out(vty, " %d", instance);
16275 if (yang_dnode_exists(dnode, "./metric"))
16276 vty_out(vty, " metric %u",
16277 yang_dnode_get_uint32(dnode, "./metric"));
16278 if (yang_dnode_exists(dnode, "./rmap-policy-import"))
16279 vty_out(vty, " route-map %s",
16280 yang_dnode_get_string(dnode, "./rmap-policy-import"));
16281 vty_out(vty, "\n");
d62a17ae 16282}
16283
dd65f45e
DL
16284static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16285 afi_t afi, safi_t safi)
d62a17ae 16286{
16287 int i;
16288
16289 /* Unicast redistribution only. */
16290 if (safi != SAFI_UNICAST)
2b791107 16291 return;
d62a17ae 16292
16293 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16294 /* Redistribute BGP does not make sense. */
16295 if (i != ZEBRA_ROUTE_BGP) {
16296 struct list *red_list;
16297 struct listnode *node;
16298 struct bgp_redist *red;
16299
16300 red_list = bgp->redist[afi][i];
16301 if (!red_list)
16302 continue;
16303
16304 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 16305 /* "redistribute" configuration. */
16306 vty_out(vty, " redistribute %s",
16307 zebra_route_string(i));
16308 if (red->instance)
16309 vty_out(vty, " %d", red->instance);
16310 if (red->redist_metric_flag)
16311 vty_out(vty, " metric %u",
16312 red->redist_metric);
16313 if (red->rmap.name)
16314 vty_out(vty, " route-map %s",
16315 red->rmap.name);
16316 vty_out(vty, "\n");
16317 }
16318 }
16319 }
718e3744 16320}
6b0655a2 16321
dd65f45e
DL
16322/* peer-group helpers for config-write */
16323
16324static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
16325{
16326 if (!peer_group_active(peer)) {
16327 if (CHECK_FLAG(peer->flags_invert, flag))
16328 return !CHECK_FLAG(peer->flags, flag);
16329 else
16330 return !!CHECK_FLAG(peer->flags, flag);
16331 }
16332
16333 return !!CHECK_FLAG(peer->flags_override, flag);
16334}
16335
16336static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16337 uint32_t flag)
16338{
16339 if (!peer_group_active(peer)) {
16340 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16341 return !peer_af_flag_check(peer, afi, safi, flag);
16342 else
16343 return !!peer_af_flag_check(peer, afi, safi, flag);
16344 }
16345
16346 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16347}
16348
16349static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16350 uint8_t type, int direct)
16351{
16352 struct bgp_filter *filter;
16353
16354 if (peer_group_active(peer))
16355 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16356 type);
16357
16358 filter = &peer->filter[afi][safi];
16359 switch (type) {
16360 case PEER_FT_DISTRIBUTE_LIST:
16361 return !!(filter->dlist[direct].name);
16362 case PEER_FT_FILTER_LIST:
16363 return !!(filter->aslist[direct].name);
16364 case PEER_FT_PREFIX_LIST:
16365 return !!(filter->plist[direct].name);
16366 case PEER_FT_ROUTE_MAP:
16367 return !!(filter->map[direct].name);
16368 case PEER_FT_UNSUPPRESS_MAP:
16369 return !!(filter->usmap.name);
7f7940e6
MK
16370 case PEER_FT_ADVERTISE_MAP:
16371 return !!(filter->advmap.aname
16372 && ((filter->advmap.condition == direct)
16373 && filter->advmap.cname));
dd65f45e
DL
16374 default:
16375 return false;
16376 }
16377}
16378
16379/* Return true if the addpath type is set for peer and different from
16380 * peer-group.
16381 */
3dc339cd
DA
16382static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16383 safi_t safi)
dd65f45e
DL
16384{
16385 enum bgp_addpath_strat type, g_type;
16386
16387 type = peer->addpath_type[afi][safi];
16388
16389 if (type != BGP_ADDPATH_NONE) {
16390 if (peer_group_active(peer)) {
16391 g_type = peer->group->conf->addpath_type[afi][safi];
16392
16393 if (type != g_type)
3dc339cd 16394 return true;
dd65f45e 16395 else
3dc339cd 16396 return false;
dd65f45e
DL
16397 }
16398
3dc339cd 16399 return true;
dd65f45e
DL
16400 }
16401
3dc339cd 16402 return false;
dd65f45e
DL
16403}
16404
b9c7bc5a 16405/* This is part of the address-family block (unicast only) */
dd65f45e 16406static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
16407 afi_t afi)
16408{
b9c7bc5a 16409 int indent = 2;
ddb5b488 16410
8a066a70 16411 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
ae6a6fb4
DS
16412 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16413 BGP_CONFIG_VRF_TO_VRF_IMPORT))
8a066a70
PG
16414 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16415 bgp->vpn_policy[afi]
bb4f6190 16416 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
16417 else
16418 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16419 bgp->vpn_policy[afi]
16420 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16421 }
12a844a5
DS
16422 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16423 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16424 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16425 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16426 return;
16427
e70e9f8e
PZ
16428 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16429 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16430
16431 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16432
16433 } else {
16434 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16435 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16436 bgp->vpn_policy[afi].tovpn_label);
16437 }
ddb5b488
PZ
16438 }
16439 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16440 BGP_VPN_POLICY_TOVPN_RD_SET)) {
16441 char buf[RD_ADDRSTRLEN];
b9c7bc5a 16442 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
16443 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
16444 sizeof(buf)));
16445 }
16446 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16447 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
16448
16449 char buf[PREFIX_STRLEN];
16450 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
16451 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
16452 sizeof(buf))) {
16453
b9c7bc5a
PZ
16454 vty_out(vty, "%*snexthop vpn export %s\n",
16455 indent, "", buf);
ddb5b488
PZ
16456 }
16457 }
16458 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
16459 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
16460 && ecommunity_cmp(
16461 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16462 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16463
16464 char *b = ecommunity_ecom2str(
16465 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16466 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16467 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
16468 XFREE(MTYPE_ECOMMUNITY_STR, b);
16469 } else {
16470 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16471 char *b = ecommunity_ecom2str(
16472 bgp->vpn_policy[afi]
16473 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16474 ECOMMUNITY_FORMAT_ROUTE_MAP,
16475 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16476 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
16477 XFREE(MTYPE_ECOMMUNITY_STR, b);
16478 }
16479 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16480 char *b = ecommunity_ecom2str(
16481 bgp->vpn_policy[afi]
16482 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16483 ECOMMUNITY_FORMAT_ROUTE_MAP,
16484 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16485 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
16486 XFREE(MTYPE_ECOMMUNITY_STR, b);
16487 }
16488 }
bb4f6190
DS
16489
16490 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 16491 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
16492 bgp->vpn_policy[afi]
16493 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 16494
301ad80a
PG
16495 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16496 char *b = ecommunity_ecom2str(
16497 bgp->vpn_policy[afi]
16498 .import_redirect_rtlist,
16499 ECOMMUNITY_FORMAT_ROUTE_MAP,
16500 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 16501
9a659715
PG
16502 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16503 != ECOMMUNITY_SIZE)
c6423c31 16504 vty_out(vty, "%*srt6 redirect import %s\n",
9a659715
PG
16505 indent, "", b);
16506 else
16507 vty_out(vty, "%*srt redirect import %s\n",
16508 indent, "", b);
301ad80a
PG
16509 XFREE(MTYPE_ECOMMUNITY_STR, b);
16510 }
ddb5b488
PZ
16511}
16512
dd65f45e
DL
16513static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
16514 afi_t afi, safi_t safi)
16515{
16516 struct bgp_filter *filter;
16517 char *addr;
16518
16519 addr = peer->host;
16520 filter = &peer->filter[afi][safi];
16521
16522 /* distribute-list. */
16523 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16524 FILTER_IN))
16525 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
16526 filter->dlist[FILTER_IN].name);
16527
16528 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16529 FILTER_OUT))
16530 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
16531 filter->dlist[FILTER_OUT].name);
16532
16533 /* prefix-list. */
16534 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16535 FILTER_IN))
16536 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
16537 filter->plist[FILTER_IN].name);
16538
16539 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16540 FILTER_OUT))
16541 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
16542 filter->plist[FILTER_OUT].name);
16543
16544 /* route-map. */
16545 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
16546 vty_out(vty, " neighbor %s route-map %s in\n", addr,
16547 filter->map[RMAP_IN].name);
16548
16549 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
16550 RMAP_OUT))
16551 vty_out(vty, " neighbor %s route-map %s out\n", addr,
16552 filter->map[RMAP_OUT].name);
16553
16554 /* unsuppress-map */
16555 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
16556 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
16557 filter->usmap.name);
16558
7f7940e6
MK
16559 /* advertise-map : always applied in OUT direction*/
16560 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16561 CONDITION_NON_EXIST))
16562 vty_out(vty,
16563 " neighbor %s advertise-map %s non-exist-map %s\n",
16564 addr, filter->advmap.aname, filter->advmap.cname);
16565
16566 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16567 CONDITION_EXIST))
16568 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
16569 addr, filter->advmap.aname, filter->advmap.cname);
16570
dd65f45e
DL
16571 /* filter-list. */
16572 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16573 FILTER_IN))
16574 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
16575 filter->aslist[FILTER_IN].name);
16576
16577 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16578 FILTER_OUT))
16579 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
16580 filter->aslist[FILTER_OUT].name);
16581}
16582
16583/* BGP peer configuration display function. */
16584static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
16585 struct peer *peer)
16586{
16587 struct peer *g_peer = NULL;
16588 char buf[SU_ADDRSTRLEN];
16589 char *addr;
16590 int if_pg_printed = false;
16591 int if_ras_printed = false;
16592
16593 /* Skip dynamic neighbors. */
16594 if (peer_dynamic_neighbor(peer))
16595 return;
16596
16597 if (peer->conf_if)
16598 addr = peer->conf_if;
16599 else
16600 addr = peer->host;
16601
16602 /************************************
16603 ****** Global to the neighbor ******
16604 ************************************/
16605 if (peer->conf_if) {
16606 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
16607 vty_out(vty, " neighbor %s interface v6only", addr);
16608 else
16609 vty_out(vty, " neighbor %s interface", addr);
16610
16611 if (peer_group_active(peer)) {
16612 vty_out(vty, " peer-group %s", peer->group->name);
16613 if_pg_printed = true;
16614 } else if (peer->as_type == AS_SPECIFIED) {
16615 vty_out(vty, " remote-as %u", peer->as);
16616 if_ras_printed = true;
16617 } else if (peer->as_type == AS_INTERNAL) {
16618 vty_out(vty, " remote-as internal");
16619 if_ras_printed = true;
16620 } else if (peer->as_type == AS_EXTERNAL) {
16621 vty_out(vty, " remote-as external");
16622 if_ras_printed = true;
16623 }
16624
16625 vty_out(vty, "\n");
16626 }
16627
16628 /* remote-as and peer-group */
16629 /* peer is a member of a peer-group */
16630 if (peer_group_active(peer)) {
16631 g_peer = peer->group->conf;
16632
16633 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
16634 if (peer->as_type == AS_SPECIFIED) {
16635 vty_out(vty, " neighbor %s remote-as %u\n",
16636 addr, peer->as);
16637 } else if (peer->as_type == AS_INTERNAL) {
16638 vty_out(vty,
16639 " neighbor %s remote-as internal\n",
16640 addr);
16641 } else if (peer->as_type == AS_EXTERNAL) {
16642 vty_out(vty,
16643 " neighbor %s remote-as external\n",
16644 addr);
16645 }
16646 }
16647
16648 /* For swpX peers we displayed the peer-group
16649 * via 'neighbor swpX interface peer-group PGNAME' */
16650 if (!if_pg_printed)
16651 vty_out(vty, " neighbor %s peer-group %s\n", addr,
16652 peer->group->name);
16653 }
16654
16655 /* peer is NOT a member of a peer-group */
16656 else {
16657 /* peer is a peer-group, declare the peer-group */
16658 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
16659 vty_out(vty, " neighbor %s peer-group\n", addr);
16660 }
16661
16662 if (!if_ras_printed) {
16663 if (peer->as_type == AS_SPECIFIED) {
16664 vty_out(vty, " neighbor %s remote-as %u\n",
16665 addr, peer->as);
16666 } else if (peer->as_type == AS_INTERNAL) {
16667 vty_out(vty,
16668 " neighbor %s remote-as internal\n",
16669 addr);
16670 } else if (peer->as_type == AS_EXTERNAL) {
16671 vty_out(vty,
16672 " neighbor %s remote-as external\n",
16673 addr);
16674 }
16675 }
16676 }
16677
16678 /* local-as */
16679 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
16680 vty_out(vty, " neighbor %s local-as %u", addr,
16681 peer->change_local_as);
16682 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
16683 vty_out(vty, " no-prepend");
16684 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
16685 vty_out(vty, " replace-as");
16686 vty_out(vty, "\n");
16687 }
16688
16689 /* description */
16690 if (peer->desc) {
16691 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
16692 }
16693
16694 /* shutdown */
16695 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
16696 if (peer->tx_shutdown_message)
16697 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
16698 peer->tx_shutdown_message);
16699 else
16700 vty_out(vty, " neighbor %s shutdown\n", addr);
16701 }
16702
8336c896
DA
16703 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
16704 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
16705 peer->rtt_expected, peer->rtt_keepalive_conf);
16706
dd65f45e
DL
16707 /* bfd */
16708 if (peer->bfd_info) {
16709 if (!peer_group_active(peer) || !g_peer->bfd_info) {
16710 bgp_bfd_peer_config_write(vty, peer, addr);
16711 }
16712 }
16713
16714 /* password */
16715 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
16716 vty_out(vty, " neighbor %s password %s\n", addr,
16717 peer->password);
16718
16719 /* neighbor solo */
16720 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
16721 if (!peer_group_active(peer)) {
16722 vty_out(vty, " neighbor %s solo\n", addr);
16723 }
16724 }
16725
16726 /* BGP port */
16727 if (peer->port != BGP_PORT_DEFAULT) {
16728 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
16729 }
16730
16731 /* Local interface name */
16732 if (peer->ifname) {
16733 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
16734 }
16735
16736 /* passive */
16737 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
16738 vty_out(vty, " neighbor %s passive\n", addr);
16739
16740 /* ebgp-multihop */
16741 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
e2521429
DA
16742 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
16743 && peer->ttl == MAXTTL)) {
dd65f45e
DL
16744 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
16745 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
16746 peer->ttl);
16747 }
16748 }
16749
16750 /* ttl-security hops */
e2521429 16751 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
dd65f45e
DL
16752 if (!peer_group_active(peer)
16753 || g_peer->gtsm_hops != peer->gtsm_hops) {
16754 vty_out(vty, " neighbor %s ttl-security hops %d\n",
16755 addr, peer->gtsm_hops);
16756 }
16757 }
16758
16759 /* disable-connected-check */
16760 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
16761 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
16762
16763 /* enforce-first-as */
16764 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
16765 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
16766
16767 /* update-source */
16768 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
16769 if (peer->update_source)
16770 vty_out(vty, " neighbor %s update-source %s\n", addr,
16771 sockunion2str(peer->update_source, buf,
16772 SU_ADDRSTRLEN));
16773 else if (peer->update_if)
16774 vty_out(vty, " neighbor %s update-source %s\n", addr,
16775 peer->update_if);
16776 }
16777
16778 /* advertisement-interval */
16779 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
16780 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
16781 peer->routeadv);
16782
16783 /* timers */
16784 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
16785 vty_out(vty, " neighbor %s timers %u %u\n", addr,
16786 peer->keepalive, peer->holdtime);
16787
16788 /* timers connect */
16789 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
16790 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16791 peer->connect);
5d5393b9
DL
16792 /* need special-case handling for changed default values due to
16793 * config profile / version (because there is no "timers bgp connect"
16794 * command, we need to save this per-peer :/)
16795 */
16796 else if (!peer_group_active(peer) && !peer->connect &&
16797 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
16798 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16799 peer->bgp->default_connect_retry);
dd65f45e 16800
d43114f3
DS
16801 /* timers delayopen */
16802 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
16803 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16804 peer->delayopen);
16805 /* Save config even though flag is not set if default values have been
16806 * changed
16807 */
16808 else if (!peer_group_active(peer) && !peer->delayopen
16809 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
16810 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16811 peer->bgp->default_delayopen);
16812
dd65f45e
DL
16813 /* capability dynamic */
16814 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
16815 vty_out(vty, " neighbor %s capability dynamic\n", addr);
16816
16817 /* capability extended-nexthop */
16818 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
16819 if (!peer->conf_if) {
16820 if (CHECK_FLAG(peer->flags_invert,
16821 PEER_FLAG_CAPABILITY_ENHE))
16822 vty_out(vty,
16823 " no neighbor %s capability extended-nexthop\n",
16824 addr);
16825 else
16826 vty_out(vty,
16827 " neighbor %s capability extended-nexthop\n",
16828 addr);
16829 }
16830 }
16831
16832 /* dont-capability-negotiation */
16833 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
16834 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
16835
16836 /* override-capability */
16837 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
16838 vty_out(vty, " neighbor %s override-capability\n", addr);
16839
16840 /* strict-capability-match */
16841 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
16842 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
16843
16844 /* Sender side AS path loop detection. */
16845 if (peer->as_path_loop_detection)
16846 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
16847 addr);
cfd47646 16848
16849 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 16850 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
cfd47646 16851
16852 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 16853 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
cfd47646 16854 vty_out(vty,
16855 " neighbor %s graceful-restart-helper\n", addr);
13909c4f
DS
16856 } else if (CHECK_FLAG(
16857 peer->peer_gr_new_status_flag,
16858 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
cfd47646 16859 vty_out(vty,
16860 " neighbor %s graceful-restart\n", addr);
13909c4f
DS
16861 } else if (
16862 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
16863 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
16864 && !(CHECK_FLAG(
16865 peer->peer_gr_new_status_flag,
16866 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
16867 vty_out(vty, " neighbor %s graceful-restart-disable\n",
16868 addr);
cfd47646 16869 }
16870 }
dd65f45e
DL
16871}
16872
16873/* BGP peer configuration display function. */
16874static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
16875 struct peer *peer, afi_t afi, safi_t safi)
16876{
16877 struct peer *g_peer = NULL;
16878 char *addr;
16879 bool flag_scomm, flag_secomm, flag_slcomm;
16880
16881 /* Skip dynamic neighbors. */
16882 if (peer_dynamic_neighbor(peer))
16883 return;
16884
16885 if (peer->conf_if)
16886 addr = peer->conf_if;
16887 else
16888 addr = peer->host;
16889
16890 /************************************
16891 ****** Per AF to the neighbor ******
16892 ************************************/
16893 if (peer_group_active(peer)) {
16894 g_peer = peer->group->conf;
16895
16896 /* If the peer-group is active but peer is not, print a 'no
16897 * activate' */
16898 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
16899 vty_out(vty, " no neighbor %s activate\n", addr);
16900 }
16901
16902 /* If the peer-group is not active but peer is, print an
16903 'activate' */
16904 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
16905 vty_out(vty, " neighbor %s activate\n", addr);
16906 }
16907 } else {
16908 if (peer->afc[afi][safi]) {
16909 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
892fedb6
DA
16910 if (CHECK_FLAG(bgp->flags,
16911 BGP_FLAG_NO_DEFAULT_IPV4)) {
dd65f45e
DL
16912 vty_out(vty, " neighbor %s activate\n",
16913 addr);
16914 }
16915 } else
16916 vty_out(vty, " neighbor %s activate\n", addr);
16917 } else {
16918 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
892fedb6
DA
16919 if (!CHECK_FLAG(bgp->flags,
16920 BGP_FLAG_NO_DEFAULT_IPV4)) {
dd65f45e
DL
16921 vty_out(vty,
16922 " no neighbor %s activate\n",
16923 addr);
16924 }
16925 }
16926 }
16927 }
16928
16929 /* addpath TX knobs */
16930 if (peergroup_af_addpath_check(peer, afi, safi)) {
16931 switch (peer->addpath_type[afi][safi]) {
16932 case BGP_ADDPATH_ALL:
16933 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
16934 addr);
16935 break;
16936 case BGP_ADDPATH_BEST_PER_AS:
16937 vty_out(vty,
16938 " neighbor %s addpath-tx-bestpath-per-AS\n",
16939 addr);
16940 break;
16941 case BGP_ADDPATH_MAX:
16942 case BGP_ADDPATH_NONE:
16943 break;
16944 }
16945 }
16946
16947 /* ORF capability. */
16948 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
16949 || peergroup_af_flag_check(peer, afi, safi,
16950 PEER_FLAG_ORF_PREFIX_RM)) {
16951 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
16952
16953 if (peergroup_af_flag_check(peer, afi, safi,
16954 PEER_FLAG_ORF_PREFIX_SM)
16955 && peergroup_af_flag_check(peer, afi, safi,
16956 PEER_FLAG_ORF_PREFIX_RM))
16957 vty_out(vty, " both");
16958 else if (peergroup_af_flag_check(peer, afi, safi,
16959 PEER_FLAG_ORF_PREFIX_SM))
16960 vty_out(vty, " send");
16961 else
16962 vty_out(vty, " receive");
16963 vty_out(vty, "\n");
16964 }
16965
dd65f45e
DL
16966 /* Route reflector client. */
16967 if (peergroup_af_flag_check(peer, afi, safi,
16968 PEER_FLAG_REFLECTOR_CLIENT)) {
16969 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
16970 }
16971
16972 /* next-hop-self force */
16973 if (peergroup_af_flag_check(peer, afi, safi,
16974 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
16975 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
16976 }
16977
16978 /* next-hop-self */
16979 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
16980 vty_out(vty, " neighbor %s next-hop-self\n", addr);
16981 }
16982
16983 /* remove-private-AS */
16984 if (peergroup_af_flag_check(peer, afi, safi,
16985 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
16986 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
16987 addr);
16988 }
16989
16990 else if (peergroup_af_flag_check(peer, afi, safi,
16991 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
16992 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
16993 addr);
16994 }
16995
16996 else if (peergroup_af_flag_check(peer, afi, safi,
16997 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
16998 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
16999 }
17000
17001 else if (peergroup_af_flag_check(peer, afi, safi,
17002 PEER_FLAG_REMOVE_PRIVATE_AS)) {
17003 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
17004 }
17005
17006 /* as-override */
17007 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
17008 vty_out(vty, " neighbor %s as-override\n", addr);
17009 }
17010
17011 /* send-community print. */
17012 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
17013 PEER_FLAG_SEND_COMMUNITY);
17014 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
17015 PEER_FLAG_SEND_EXT_COMMUNITY);
17016 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
17017 PEER_FLAG_SEND_LARGE_COMMUNITY);
17018
17019 if (flag_scomm && flag_secomm && flag_slcomm) {
17020 vty_out(vty, " no neighbor %s send-community all\n", addr);
17021 } else {
17022 if (flag_scomm)
17023 vty_out(vty, " no neighbor %s send-community\n", addr);
17024 if (flag_secomm)
17025 vty_out(vty,
17026 " no neighbor %s send-community extended\n",
17027 addr);
17028
17029 if (flag_slcomm)
17030 vty_out(vty, " no neighbor %s send-community large\n",
17031 addr);
17032 }
17033
17034 /* Default information */
17035 if (peergroup_af_flag_check(peer, afi, safi,
17036 PEER_FLAG_DEFAULT_ORIGINATE)) {
17037 vty_out(vty, " neighbor %s default-originate", addr);
17038
17039 if (peer->default_rmap[afi][safi].name)
17040 vty_out(vty, " route-map %s",
17041 peer->default_rmap[afi][safi].name);
17042
17043 vty_out(vty, "\n");
17044 }
17045
17046 /* Soft reconfiguration inbound. */
17047 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
17048 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
17049 addr);
17050 }
17051
17052 /* maximum-prefix. */
17053 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
6cde4b45 17054 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
dd65f45e
DL
17055 peer->pmax[afi][safi]);
17056
17057 if (peer->pmax_threshold[afi][safi]
17058 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
17059 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
17060 if (peer_af_flag_check(peer, afi, safi,
17061 PEER_FLAG_MAX_PREFIX_WARNING))
17062 vty_out(vty, " warning-only");
17063 if (peer->pmax_restart[afi][safi])
17064 vty_out(vty, " restart %u",
17065 peer->pmax_restart[afi][safi]);
9cbd06e0
DA
17066 if (peer_af_flag_check(peer, afi, safi,
17067 PEER_FLAG_MAX_PREFIX_FORCE))
17068 vty_out(vty, " force");
dd65f45e
DL
17069
17070 vty_out(vty, "\n");
17071 }
17072
fde246e8
DA
17073 /* maximum-prefix-out */
17074 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
6cde4b45 17075 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
fde246e8
DA
17076 addr, peer->pmax_out[afi][safi]);
17077
dd65f45e
DL
17078 /* Route server client. */
17079 if (peergroup_af_flag_check(peer, afi, safi,
17080 PEER_FLAG_RSERVER_CLIENT)) {
17081 vty_out(vty, " neighbor %s route-server-client\n", addr);
17082 }
17083
17084 /* Nexthop-local unchanged. */
17085 if (peergroup_af_flag_check(peer, afi, safi,
17086 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
17087 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
17088 }
17089
17090 /* allowas-in <1-10> */
17091 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
17092 if (peer_af_flag_check(peer, afi, safi,
17093 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
17094 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
17095 } else if (peer->allowas_in[afi][safi] == 3) {
17096 vty_out(vty, " neighbor %s allowas-in\n", addr);
17097 } else {
17098 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
17099 peer->allowas_in[afi][safi]);
17100 }
17101 }
17102
17103 /* weight */
17104 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
17105 vty_out(vty, " neighbor %s weight %lu\n", addr,
17106 peer->weight[afi][safi]);
17107
17108 /* Filter. */
17109 bgp_config_write_filter(vty, peer, afi, safi);
17110
17111 /* atribute-unchanged. */
17112 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
17113 || (safi != SAFI_EVPN
17114 && peer_af_flag_check(peer, afi, safi,
17115 PEER_FLAG_NEXTHOP_UNCHANGED))
17116 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
17117
17118 if (!peer_group_active(peer)
17119 || peergroup_af_flag_check(peer, afi, safi,
17120 PEER_FLAG_AS_PATH_UNCHANGED)
17121 || peergroup_af_flag_check(peer, afi, safi,
17122 PEER_FLAG_NEXTHOP_UNCHANGED)
17123 || peergroup_af_flag_check(peer, afi, safi,
17124 PEER_FLAG_MED_UNCHANGED)) {
17125
17126 vty_out(vty,
17127 " neighbor %s attribute-unchanged%s%s%s\n",
17128 addr,
17129 peer_af_flag_check(peer, afi, safi,
17130 PEER_FLAG_AS_PATH_UNCHANGED)
17131 ? " as-path"
17132 : "",
17133 peer_af_flag_check(peer, afi, safi,
17134 PEER_FLAG_NEXTHOP_UNCHANGED)
17135 ? " next-hop"
17136 : "",
17137 peer_af_flag_check(peer, afi, safi,
17138 PEER_FLAG_MED_UNCHANGED)
17139 ? " med"
17140 : "");
17141 }
17142 }
17143}
17144
17145/* Address family based peer configuration display. */
17146static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
17147 safi_t safi)
17148{
17149 struct peer *peer;
17150 struct peer_group *group;
17151 struct listnode *node, *nnode;
17152
17153
17154 vty_frame(vty, " !\n address-family ");
17155 if (afi == AFI_IP) {
17156 if (safi == SAFI_UNICAST)
17157 vty_frame(vty, "ipv4 unicast");
17158 else if (safi == SAFI_LABELED_UNICAST)
17159 vty_frame(vty, "ipv4 labeled-unicast");
17160 else if (safi == SAFI_MULTICAST)
17161 vty_frame(vty, "ipv4 multicast");
17162 else if (safi == SAFI_MPLS_VPN)
17163 vty_frame(vty, "ipv4 vpn");
17164 else if (safi == SAFI_ENCAP)
17165 vty_frame(vty, "ipv4 encap");
17166 else if (safi == SAFI_FLOWSPEC)
17167 vty_frame(vty, "ipv4 flowspec");
17168 } else if (afi == AFI_IP6) {
17169 if (safi == SAFI_UNICAST)
17170 vty_frame(vty, "ipv6 unicast");
17171 else if (safi == SAFI_LABELED_UNICAST)
17172 vty_frame(vty, "ipv6 labeled-unicast");
17173 else if (safi == SAFI_MULTICAST)
17174 vty_frame(vty, "ipv6 multicast");
17175 else if (safi == SAFI_MPLS_VPN)
17176 vty_frame(vty, "ipv6 vpn");
17177 else if (safi == SAFI_ENCAP)
17178 vty_frame(vty, "ipv6 encap");
17179 else if (safi == SAFI_FLOWSPEC)
17180 vty_frame(vty, "ipv6 flowspec");
17181 } else if (afi == AFI_L2VPN) {
17182 if (safi == SAFI_EVPN)
17183 vty_frame(vty, "l2vpn evpn");
17184 }
17185 vty_frame(vty, "\n");
17186
17187 bgp_config_write_distance(vty, bgp, afi, safi);
17188
17189 bgp_config_write_network(vty, bgp, afi, safi);
17190
17191 bgp_config_write_redistribute(vty, bgp, afi, safi);
17192
8a4e7fe6
DA
17193 /* BGP flag dampening. */
17194 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
0221327c
DS
17195 bgp_config_write_damp(vty, bgp, afi, safi);
17196 for (ALL_LIST_ELEMENTS_RO(bgp->group, node, group))
17197 if (peer_af_flag_check(group->conf, afi, safi,
17198 PEER_FLAG_CONFIG_DAMPENING))
17199 bgp_config_write_peer_damp(vty, group->conf, afi, safi);
17200 for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer))
17201 if (peer_af_flag_check(peer, afi, safi,
17202 PEER_FLAG_CONFIG_DAMPENING))
17203 bgp_config_write_peer_damp(vty, peer, afi, safi);
8a4e7fe6 17204
dd65f45e
DL
17205 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
17206 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
17207
17208 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17209 /* Skip dynamic neighbors. */
17210 if (peer_dynamic_neighbor(peer))
17211 continue;
17212
17213 /* Do not display doppelganger peers */
17214 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17215 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
17216 }
17217
17218 bgp_config_write_maxpaths(vty, bgp, afi, safi);
17219 bgp_config_write_table_map(vty, bgp, afi, safi);
17220
17221 if (safi == SAFI_EVPN)
17222 bgp_config_write_evpn_info(vty, bgp, afi, safi);
17223
17224 if (safi == SAFI_FLOWSPEC)
17225 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
17226
17227 if (safi == SAFI_UNICAST) {
17228 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
17229 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17230 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
17231
17232 vty_out(vty, " export vpn\n");
17233 }
17234 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17235 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
17236
17237 vty_out(vty, " import vpn\n");
17238 }
17239 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17240 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
17241 char *name;
17242
17243 for (ALL_LIST_ELEMENTS_RO(
17244 bgp->vpn_policy[afi].import_vrf, node,
17245 name))
17246 vty_out(vty, " import vrf %s\n", name);
17247 }
17248 }
17249
17250 vty_endframe(vty, " exit-address-family\n");
17251}
17252
17253int bgp_config_write(struct vty *vty)
17254{
17255 struct bgp *bgp;
17256 struct peer_group *group;
17257 struct peer *peer;
17258 struct listnode *node, *nnode;
17259 struct listnode *mnode, *mnnode;
17260
17261 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
17262 vty_out(vty, "bgp route-map delay-timer %u\n",
17263 bm->rmap_update_timer);
17264
d70583f7
D
17265 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
17266 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17267 if (bm->v_update_delay != bm->v_establish_wait)
17268 vty_out(vty, " %d", bm->v_establish_wait);
17269 vty_out(vty, "\n");
17270 }
17271
9acb67cb
DS
17272 if (bm->wait_for_fib)
17273 vty_out(vty, "bgp suppress-fib-pending\n");
17274
05bd726c 17275 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17276 vty_out(vty, "bgp graceful-shutdown\n");
17277
c163f297
DS
17278 /* No-RIB (Zebra) option flag configuration */
17279 if (bgp_option_check(BGP_OPT_NO_FIB))
17280 vty_out(vty, "bgp no-rib\n");
17281
ec0acb80 17282 if (!CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
e46723a5
DS
17283 vty_out(vty, "no bgp send-extra-data zebra\n");
17284
dd65f45e
DL
17285 /* BGP configuration. */
17286 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17287
17288 /* skip all auto created vrf as they dont have user config */
17289 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17290 continue;
17291
17292 /* Router bgp ASN */
17293 vty_out(vty, "router bgp %u", bgp->as);
17294
17295 if (bgp->name)
17296 vty_out(vty, " %s %s",
17297 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17298 ? "view" : "vrf", bgp->name);
17299 vty_out(vty, "\n");
17300
17301 /* BGP fast-external-failover. */
17302 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17303 vty_out(vty, " no bgp fast-external-failover\n");
17304
17305 /* BGP router ID. */
3a6290bd 17306 if (bgp->router_id_static.s_addr != INADDR_ANY)
23d0a753
DA
17307 vty_out(vty, " bgp router-id %pI4\n",
17308 &bgp->router_id_static);
dd65f45e 17309
c208c586
S
17310 /* Suppress fib pending */
17311 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17312 vty_out(vty, " bgp suppress-fib-pending\n");
17313
dd65f45e 17314 /* BGP log-neighbor-changes. */
892fedb6 17315 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
5d5393b9 17316 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
dd65f45e 17317 vty_out(vty, " %sbgp log-neighbor-changes\n",
892fedb6
DA
17318 CHECK_FLAG(bgp->flags,
17319 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
dd65f45e
DL
17320 ? ""
17321 : "no ");
17322
17323 /* BGP configuration. */
892fedb6 17324 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
dd65f45e
DL
17325 vty_out(vty, " bgp always-compare-med\n");
17326
17327 /* RFC8212 default eBGP policy. */
1d3fdccf
DA
17328 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17329 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17330 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17331 CHECK_FLAG(bgp->flags,
17332 BGP_FLAG_EBGP_REQUIRES_POLICY)
17333 ? ""
17334 : "no ");
dd65f45e
DL
17335
17336 /* draft-ietf-idr-deprecate-as-set-confed-set */
7f972cd8 17337 if (bgp->reject_as_sets)
dd65f45e
DL
17338 vty_out(vty, " bgp reject-as-sets\n");
17339
2adac256
DA
17340 /* Suppress duplicate updates if the route actually not changed
17341 */
17342 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17343 != SAVE_BGP_SUPPRESS_DUPLICATES)
17344 vty_out(vty, " %sbgp suppress-duplicates\n",
17345 CHECK_FLAG(bgp->flags,
17346 BGP_FLAG_SUPPRESS_DUPLICATES)
17347 ? ""
17348 : "no ");
17349
dd65f45e 17350 /* BGP default ipv4-unicast. */
892fedb6 17351 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4))
dd65f45e
DL
17352 vty_out(vty, " no bgp default ipv4-unicast\n");
17353
17354 /* BGP default local-preference. */
17355 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17356 vty_out(vty, " bgp default local-preference %u\n",
17357 bgp->default_local_pref);
17358
17359 /* BGP default show-hostname */
892fedb6 17360 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
5d5393b9 17361 != SAVE_BGP_SHOW_HOSTNAME)
dd65f45e 17362 vty_out(vty, " %sbgp default show-hostname\n",
892fedb6 17363 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
dd65f45e
DL
17364 ? ""
17365 : "no ");
17366
aef999a2
DA
17367 /* BGP default show-nexthop-hostname */
17368 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17369 != SAVE_BGP_SHOW_HOSTNAME)
17370 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17371 CHECK_FLAG(bgp->flags,
17372 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17373 ? ""
17374 : "no ");
17375
dd65f45e
DL
17376 /* BGP default subgroup-pkt-queue-max. */
17377 if (bgp->default_subgroup_pkt_queue_max
17378 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
17379 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
17380 bgp->default_subgroup_pkt_queue_max);
17381
17382 /* BGP client-to-client reflection. */
892fedb6 17383 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
dd65f45e
DL
17384 vty_out(vty, " no bgp client-to-client reflection\n");
17385
17386 /* BGP cluster ID. */
17387 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
23d0a753
DA
17388 vty_out(vty, " bgp cluster-id %pI4\n",
17389 &bgp->cluster_id);
dd65f45e
DL
17390
17391 /* Disable ebgp connected nexthop check */
892fedb6 17392 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
dd65f45e
DL
17393 vty_out(vty,
17394 " bgp disable-ebgp-connected-route-check\n");
17395
17396 /* Confederation identifier*/
17397 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
17398 vty_out(vty, " bgp confederation identifier %u\n",
17399 bgp->confed_id);
17400
17401 /* Confederation peer */
17402 if (bgp->confed_peers_cnt > 0) {
17403 int i;
17404
17405 vty_out(vty, " bgp confederation peers");
17406
17407 for (i = 0; i < bgp->confed_peers_cnt; i++)
17408 vty_out(vty, " %u", bgp->confed_peers[i]);
17409
17410 vty_out(vty, "\n");
17411 }
17412
17413 /* BGP deterministic-med. */
892fedb6 17414 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
5d5393b9 17415 != SAVE_BGP_DETERMINISTIC_MED)
dd65f45e 17416 vty_out(vty, " %sbgp deterministic-med\n",
892fedb6
DA
17417 CHECK_FLAG(bgp->flags,
17418 BGP_FLAG_DETERMINISTIC_MED)
dd65f45e
DL
17419 ? ""
17420 : "no ");
17421
17422 /* BGP update-delay. */
17423 bgp_config_write_update_delay(vty, bgp);
17424
17425 if (bgp->v_maxmed_onstartup
17426 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
17427 vty_out(vty, " bgp max-med on-startup %u",
17428 bgp->v_maxmed_onstartup);
17429 if (bgp->maxmed_onstartup_value
17430 != BGP_MAXMED_VALUE_DEFAULT)
17431 vty_out(vty, " %u",
17432 bgp->maxmed_onstartup_value);
17433 vty_out(vty, "\n");
17434 }
17435 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
17436 vty_out(vty, " bgp max-med administrative");
17437 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
17438 vty_out(vty, " %u", bgp->maxmed_admin_value);
17439 vty_out(vty, "\n");
17440 }
17441
17442 /* write quanta */
17443 bgp_config_write_wpkt_quanta(vty, bgp);
17444 /* read quanta */
17445 bgp_config_write_rpkt_quanta(vty, bgp);
17446
17447 /* coalesce time */
17448 bgp_config_write_coalesce_time(vty, bgp);
17449
05bd726c 17450 /* BGP per-instance graceful-shutdown */
17451 /* BGP-wide settings and per-instance settings are mutually
17452 * exclusive.
17453 */
17454 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17455 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
17456 vty_out(vty, " bgp graceful-shutdown\n");
17457
dd65f45e
DL
17458 /* BGP graceful-restart. */
17459 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
17460 vty_out(vty,
17461 " bgp graceful-restart stalepath-time %u\n",
17462 bgp->stalepath_time);
cfd47646 17463
dd65f45e
DL
17464 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
17465 vty_out(vty, " bgp graceful-restart restart-time %u\n",
17466 bgp->restart_time);
cfd47646 17467
17468 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
17469 vty_out(vty,
17470 " bgp graceful-restart select-defer-time %u\n",
17471 bgp->select_defer_time);
17472
17473 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
dd65f45e
DL
17474 vty_out(vty, " bgp graceful-restart\n");
17475
cfd47646 17476 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
17477 vty_out(vty, " bgp graceful-restart-disable\n");
17478
dd65f45e 17479 /* BGP graceful-restart Preserve State F bit. */
892fedb6 17480 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
dd65f45e
DL
17481 vty_out(vty,
17482 " bgp graceful-restart preserve-fw-state\n");
17483
dc95985f 17484 /* Stale timer for RIB */
17485 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
17486 vty_out(vty,
17487 " bgp graceful-restart rib-stale-time %u\n",
17488 bgp->rib_stale_time);
17489
dd65f45e 17490 /* BGP bestpath method. */
892fedb6 17491 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
dd65f45e 17492 vty_out(vty, " bgp bestpath as-path ignore\n");
892fedb6 17493 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
dd65f45e
DL
17494 vty_out(vty, " bgp bestpath as-path confed\n");
17495
892fedb6
DA
17496 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
17497 if (CHECK_FLAG(bgp->flags,
17498 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
dd65f45e
DL
17499 vty_out(vty,
17500 " bgp bestpath as-path multipath-relax as-set\n");
17501 } else {
17502 vty_out(vty,
17503 " bgp bestpath as-path multipath-relax\n");
17504 }
17505 }
17506
892fedb6 17507 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
dd65f45e
DL
17508 vty_out(vty,
17509 " bgp route-reflector allow-outbound-policy\n");
17510 }
892fedb6 17511 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
dd65f45e 17512 vty_out(vty, " bgp bestpath compare-routerid\n");
892fedb6
DA
17513 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
17514 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
dd65f45e 17515 vty_out(vty, " bgp bestpath med");
892fedb6 17516 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
dd65f45e 17517 vty_out(vty, " confed");
892fedb6
DA
17518 if (CHECK_FLAG(bgp->flags,
17519 BGP_FLAG_MED_MISSING_AS_WORST))
dd65f45e
DL
17520 vty_out(vty, " missing-as-worst");
17521 vty_out(vty, "\n");
17522 }
17523
f7e1c681 17524 /* Link bandwidth handling. */
17525 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
17526 vty_out(vty, " bgp bestpath bandwidth ignore\n");
17527 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
17528 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
17529 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
17530 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
17531
dd65f45e 17532 /* BGP network import check. */
892fedb6 17533 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
5d5393b9 17534 != SAVE_BGP_IMPORT_CHECK)
dd65f45e 17535 vty_out(vty, " %sbgp network import-check\n",
892fedb6 17536 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
dd65f45e
DL
17537 ? ""
17538 : "no ");
17539
17540 /* BGP timers configuration. */
5d5393b9
DL
17541 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
17542 && bgp->default_holdtime != SAVE_BGP_HOLDTIME)
dd65f45e
DL
17543 vty_out(vty, " timers bgp %u %u\n",
17544 bgp->default_keepalive, bgp->default_holdtime);
17545
17546 /* peer-group */
17547 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
17548 bgp_config_write_peer_global(vty, bgp, group->conf);
17549 }
17550
17551 /* Normal neighbor configuration. */
17552 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17553 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17554 bgp_config_write_peer_global(vty, bgp, peer);
17555 }
17556
17557 /* listen range and limit for dynamic BGP neighbors */
17558 bgp_config_write_listen(vty, bgp);
17559
17560 /*
17561 * BGP default autoshutdown neighbors
17562 *
17563 * This must be placed after any peer and peer-group
17564 * configuration, to avoid setting all peers to shutdown after
17565 * a daemon restart, which is undesired behavior. (see #2286)
17566 */
17567 if (bgp->autoshutdown)
17568 vty_out(vty, " bgp default shutdown\n");
17569
9cf59432
DS
17570 /* BGP instance administrative shutdown */
17571 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
17572 vty_out(vty, " bgp shutdown\n");
17573
dd65f45e
DL
17574 /* IPv4 unicast configuration. */
17575 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
17576
17577 /* IPv4 multicast configuration. */
17578 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
17579
17580 /* IPv4 labeled-unicast configuration. */
17581 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
17582
17583 /* IPv4 VPN configuration. */
17584 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
17585
17586 /* ENCAPv4 configuration. */
17587 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
17588
17589 /* FLOWSPEC v4 configuration. */
17590 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
17591
17592 /* IPv6 unicast configuration. */
17593 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
17594
17595 /* IPv6 multicast configuration. */
17596 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
17597
17598 /* IPv6 labeled-unicast configuration. */
17599 bgp_config_write_family(vty, bgp, AFI_IP6,
17600 SAFI_LABELED_UNICAST);
17601
17602 /* IPv6 VPN configuration. */
17603 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
17604
17605 /* ENCAPv6 configuration. */
17606 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
17607
17608 /* FLOWSPEC v6 configuration. */
17609 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
17610
17611 /* EVPN configuration. */
17612 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
17613
17614 hook_call(bgp_inst_config_write, bgp, vty);
17615
49e5a4a0 17616#ifdef ENABLE_BGP_VNC
dd65f45e
DL
17617 bgp_rfapi_cfg_write(vty, bgp);
17618#endif
17619
17620 vty_out(vty, "!\n");
17621 }
17622 return 0;
17623}
17624
ddb5b488 17625
718e3744 17626/* BGP node structure. */
d62a17ae 17627static struct cmd_node bgp_node = {
f4b8291f 17628 .name = "bgp",
62b346ee 17629 .node = BGP_NODE,
24389580 17630 .parent_node = CONFIG_NODE,
62b346ee 17631 .prompt = "%s(config-router)# ",
612c2c15 17632 .config_write = bgp_config_write,
718e3744 17633};
17634
d62a17ae 17635static struct cmd_node bgp_ipv4_unicast_node = {
f4b8291f 17636 .name = "bgp ipv4 unicast",
62b346ee 17637 .node = BGP_IPV4_NODE,
24389580 17638 .parent_node = BGP_NODE,
62b346ee 17639 .prompt = "%s(config-router-af)# ",
718e3744 17640};
17641
d62a17ae 17642static struct cmd_node bgp_ipv4_multicast_node = {
f4b8291f 17643 .name = "bgp ipv4 multicast",
62b346ee 17644 .node = BGP_IPV4M_NODE,
24389580 17645 .parent_node = BGP_NODE,
62b346ee 17646 .prompt = "%s(config-router-af)# ",
718e3744 17647};
17648
d62a17ae 17649static struct cmd_node bgp_ipv4_labeled_unicast_node = {
f4b8291f 17650 .name = "bgp ipv4 labeled unicast",
62b346ee 17651 .node = BGP_IPV4L_NODE,
24389580 17652 .parent_node = BGP_NODE,
62b346ee 17653 .prompt = "%s(config-router-af)# ",
f51bae9c
DS
17654};
17655
d62a17ae 17656static struct cmd_node bgp_ipv6_unicast_node = {
f4b8291f 17657 .name = "bgp ipv6",
62b346ee 17658 .node = BGP_IPV6_NODE,
24389580 17659 .parent_node = BGP_NODE,
62b346ee 17660 .prompt = "%s(config-router-af)# ",
718e3744 17661};
17662
d62a17ae 17663static struct cmd_node bgp_ipv6_multicast_node = {
f4b8291f 17664 .name = "bgp ipv6 multicast",
62b346ee 17665 .node = BGP_IPV6M_NODE,
24389580 17666 .parent_node = BGP_NODE,
62b346ee 17667 .prompt = "%s(config-router-af)# ",
25ffbdc1 17668};
17669
d62a17ae 17670static struct cmd_node bgp_ipv6_labeled_unicast_node = {
f4b8291f 17671 .name = "bgp ipv6 labeled unicast",
62b346ee 17672 .node = BGP_IPV6L_NODE,
24389580 17673 .parent_node = BGP_NODE,
62b346ee 17674 .prompt = "%s(config-router-af)# ",
f51bae9c
DS
17675};
17676
62b346ee 17677static struct cmd_node bgp_vpnv4_node = {
f4b8291f 17678 .name = "bgp vpnv4",
62b346ee 17679 .node = BGP_VPNV4_NODE,
24389580 17680 .parent_node = BGP_NODE,
62b346ee 17681 .prompt = "%s(config-router-af)# ",
62b346ee 17682};
6b0655a2 17683
62b346ee 17684static struct cmd_node bgp_vpnv6_node = {
f4b8291f 17685 .name = "bgp vpnv6",
62b346ee 17686 .node = BGP_VPNV6_NODE,
24389580 17687 .parent_node = BGP_NODE,
62b346ee 17688 .prompt = "%s(config-router-af-vpnv6)# ",
62b346ee 17689};
8ecd3266 17690
62b346ee 17691static struct cmd_node bgp_evpn_node = {
f4b8291f 17692 .name = "bgp evpn",
62b346ee 17693 .node = BGP_EVPN_NODE,
24389580 17694 .parent_node = BGP_NODE,
62b346ee 17695 .prompt = "%s(config-router-evpn)# ",
62b346ee 17696};
4e0b7b6d 17697
62b346ee 17698static struct cmd_node bgp_evpn_vni_node = {
f4b8291f 17699 .name = "bgp evpn vni",
62b346ee 17700 .node = BGP_EVPN_VNI_NODE,
24389580 17701 .parent_node = BGP_EVPN_NODE,
62b346ee 17702 .prompt = "%s(config-router-af-vni)# ",
62b346ee 17703};
90e60aa7 17704
62b346ee 17705static struct cmd_node bgp_flowspecv4_node = {
f4b8291f 17706 .name = "bgp ipv4 flowspec",
62b346ee 17707 .node = BGP_FLOWSPECV4_NODE,
24389580 17708 .parent_node = BGP_NODE,
62b346ee 17709 .prompt = "%s(config-router-af)# ",
62b346ee 17710};
7c40bf39 17711
62b346ee 17712static struct cmd_node bgp_flowspecv6_node = {
f4b8291f 17713 .name = "bgp ipv6 flowspec",
62b346ee 17714 .node = BGP_FLOWSPECV6_NODE,
24389580 17715 .parent_node = BGP_NODE,
62b346ee 17716 .prompt = "%s(config-router-af-vpnv6)# ",
62b346ee 17717};
7c40bf39 17718
d62a17ae 17719static void community_list_vty(void);
1f8ae70b 17720
d62a17ae 17721static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 17722{
d62a17ae 17723 struct bgp *bgp;
17724 struct peer *peer;
d62a17ae 17725 struct listnode *lnbgp, *lnpeer;
b8a815e5 17726
d62a17ae 17727 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17728 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
17729 /* only provide suggestions on the appropriate input
17730 * token type,
17731 * they'll otherwise show up multiple times */
17732 enum cmd_token_type match_type;
17733 char *name = peer->host;
d48ed3e0 17734
d62a17ae 17735 if (peer->conf_if) {
17736 match_type = VARIABLE_TKN;
17737 name = peer->conf_if;
17738 } else if (strchr(peer->host, ':'))
17739 match_type = IPV6_TKN;
17740 else
17741 match_type = IPV4_TKN;
d48ed3e0 17742
d62a17ae 17743 if (token->type != match_type)
17744 continue;
d48ed3e0 17745
d62a17ae 17746 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
17747 }
d62a17ae 17748 }
b8a815e5
DL
17749}
17750
17751static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 17752 {.varname = "neighbor", .completions = bgp_ac_neighbor},
17753 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 17754 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 17755 {.completions = NULL}};
17756
47a306a0
DS
17757static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
17758{
17759 struct bgp *bgp;
17760 struct peer_group *group;
17761 struct listnode *lnbgp, *lnpeer;
17762
17763 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17764 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
17765 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
17766 group->name));
17767 }
17768}
17769
17770static const struct cmd_variable_handler bgp_var_peergroup[] = {
17771 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
17772 {.completions = NULL} };
17773
d62a17ae 17774void bgp_vty_init(void)
17775{
17776 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 17777 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 17778
17779 /* Install bgp top node. */
612c2c15
DL
17780 install_node(&bgp_node);
17781 install_node(&bgp_ipv4_unicast_node);
17782 install_node(&bgp_ipv4_multicast_node);
17783 install_node(&bgp_ipv4_labeled_unicast_node);
17784 install_node(&bgp_ipv6_unicast_node);
17785 install_node(&bgp_ipv6_multicast_node);
17786 install_node(&bgp_ipv6_labeled_unicast_node);
17787 install_node(&bgp_vpnv4_node);
17788 install_node(&bgp_vpnv6_node);
17789 install_node(&bgp_evpn_node);
17790 install_node(&bgp_evpn_vni_node);
17791 install_node(&bgp_flowspecv4_node);
17792 install_node(&bgp_flowspecv6_node);
d62a17ae 17793
17794 /* Install default VTY commands to new nodes. */
17795 install_default(BGP_NODE);
17796 install_default(BGP_IPV4_NODE);
17797 install_default(BGP_IPV4M_NODE);
17798 install_default(BGP_IPV4L_NODE);
17799 install_default(BGP_IPV6_NODE);
17800 install_default(BGP_IPV6M_NODE);
17801 install_default(BGP_IPV6L_NODE);
17802 install_default(BGP_VPNV4_NODE);
17803 install_default(BGP_VPNV6_NODE);
7c40bf39 17804 install_default(BGP_FLOWSPECV4_NODE);
17805 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 17806 install_default(BGP_EVPN_NODE);
17807 install_default(BGP_EVPN_VNI_NODE);
17808
8029b216
AK
17809 /* "bgp local-mac" hidden commands. */
17810 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
17811 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
17812
9acb67cb
DS
17813 /* "bgp suppress-fib-pending" global */
17814 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
17815
d62a17ae 17816 /* bgp route-map delay-timer commands. */
17817 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
17818 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17819
d70583f7
D
17820 /* global bgp update-delay command */
17821 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
17822 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
17823
05bd726c 17824 /* global bgp graceful-shutdown command */
17825 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
17826 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
17827
d62a17ae 17828 /* Dummy commands (Currently not supported) */
17829 install_element(BGP_NODE, &no_synchronization_cmd);
17830 install_element(BGP_NODE, &no_auto_summary_cmd);
17831
17832 /* "router bgp" commands. */
17833 install_element(CONFIG_NODE, &router_bgp_cmd);
17834
17835 /* "no router bgp" commands. */
17836 install_element(CONFIG_NODE, &no_router_bgp_cmd);
17837
17838 /* "bgp router-id" commands. */
17839 install_element(BGP_NODE, &bgp_router_id_cmd);
17840 install_element(BGP_NODE, &no_bgp_router_id_cmd);
17841
c208c586
S
17842 /* "bgp suppress-fib-pending" command */
17843 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
17844
d62a17ae 17845 /* "bgp cluster-id" commands. */
17846 install_element(BGP_NODE, &bgp_cluster_id_cmd);
17847 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
17848
c163f297
DS
17849 /* "bgp no-rib" commands. */
17850 install_element(CONFIG_NODE, &bgp_norib_cmd);
17851 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
17852
e46723a5
DS
17853 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
17854
d62a17ae 17855 /* "bgp confederation" commands. */
17856 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
17857 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
17858
17859 /* "bgp confederation peers" commands. */
17860 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
17861 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
17862
17863 /* bgp max-med command */
17864 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
17865 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
17866 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
17867 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
17868 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
17869
17870 /* bgp disable-ebgp-connected-nh-check */
17871 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
17872 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
17873
17874 /* bgp update-delay command */
17875 install_element(BGP_NODE, &bgp_update_delay_cmd);
17876 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
d62a17ae 17877
17878 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
555e09d4 17879 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
d62a17ae 17880
17881 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
17882 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
17883
17884 /* "maximum-paths" commands. */
17885 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
17886 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
17887 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
17888 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
17889 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
17890 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
17891 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
17892 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
17893 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
17894 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
17895 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17896 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
17897 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
17898 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17899 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
17900
39edabac
PG
17901 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
17902 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
17903 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
17904 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17905 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
d62a17ae 17906 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
17907 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
17908 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
17909 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17910 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
17911
17912 /* "timers bgp" commands. */
17913 install_element(BGP_NODE, &bgp_timers_cmd);
17914 install_element(BGP_NODE, &no_bgp_timers_cmd);
17915
17916 /* route-map delay-timer commands - per instance for backwards compat.
17917 */
17918 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
17919 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17920
17921 /* "bgp client-to-client reflection" commands */
17922 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
17923 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
17924
17925 /* "bgp always-compare-med" commands */
17926 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
17927 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
17928
9dac9fc8
DA
17929 /* bgp ebgp-requires-policy */
17930 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
17931 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
17932
2adac256
DA
17933 /* bgp suppress-duplicates */
17934 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
17935 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
17936
fb29348a
DA
17937 /* bgp reject-as-sets */
17938 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
17939 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
17940
d62a17ae 17941 /* "bgp deterministic-med" commands */
17942 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
17943 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
17944
055679e9 17945 /* "bgp graceful-restart" command */
36235319
QY
17946 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
17947 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
055679e9 17948
17949 /* "bgp graceful-restart-disable" command */
36235319
QY
17950 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
17951 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
055679e9 17952
17953 /* "neighbor a:b:c:d graceful-restart" command */
36235319
QY
17954 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
17955 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
055679e9 17956
17957 /* "neighbor a:b:c:d graceful-restart-disable" command */
17958 install_element(BGP_NODE,
17959 &bgp_neighbor_graceful_restart_disable_set_cmd);
17960 install_element(BGP_NODE,
17961 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
17962
17963 /* "neighbor a:b:c:d graceful-restart-helper" command */
17964 install_element(BGP_NODE,
17965 &bgp_neighbor_graceful_restart_helper_set_cmd);
17966 install_element(BGP_NODE,
17967 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
17968
d62a17ae 17969 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
17970 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
17971 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
17972 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
cfd47646 17973 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
f009ff26 17974 install_element(BGP_NODE,
17975 &no_bgp_graceful_restart_select_defer_time_cmd);
d62a17ae 17976 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
17977 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
17978
d6e3c15b 17979 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
17980 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
dc95985f 17981 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
17982 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
d6e3c15b 17983
7f323236
DW
17984 /* "bgp graceful-shutdown" commands */
17985 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
17986 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
17987
d62a17ae 17988 /* "bgp fast-external-failover" commands */
17989 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
17990 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
17991
d62a17ae 17992 /* "bgp bestpath compare-routerid" commands */
17993 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
17994 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
17995
17996 /* "bgp bestpath as-path ignore" commands */
17997 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
17998 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
17999
18000 /* "bgp bestpath as-path confed" commands */
18001 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
18002 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
18003
18004 /* "bgp bestpath as-path multipath-relax" commands */
18005 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
18006 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
18007
18008 /* "bgp log-neighbor-changes" commands */
18009 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
18010 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
18011
18012 /* "bgp bestpath med" commands */
18013 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
18014 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
18015
f7e1c681 18016 /* "bgp bestpath bandwidth" commands */
18017 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
ad36d216 18018 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
f7e1c681 18019
d62a17ae 18020 /* "no bgp default ipv4-unicast" commands. */
18021 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
18022 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
18023
18024 /* "bgp network import-check" commands. */
18025 install_element(BGP_NODE, &bgp_network_import_check_cmd);
18026 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
18027 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
18028
18029 /* "bgp default local-preference" commands. */
18030 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
18031 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
18032
18033 /* bgp default show-hostname */
18034 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
18035 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
18036
aef999a2
DA
18037 /* bgp default show-nexthop-hostname */
18038 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
18039 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
18040
d62a17ae 18041 /* "bgp default subgroup-pkt-queue-max" commands. */
18042 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
18043 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
18044
18045 /* bgp ibgp-allow-policy-mods command */
18046 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
18047 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
18048
18049 /* "bgp listen limit" commands. */
18050 install_element(BGP_NODE, &bgp_listen_limit_cmd);
18051 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
18052
18053 /* "bgp listen range" commands. */
18054 install_element(BGP_NODE, &bgp_listen_range_cmd);
18055 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
18056
8175f54a 18057 /* "bgp default shutdown" command */
f26845f9 18058 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
9cf59432
DS
18059
18060 /* "bgp shutdown" commands */
18061 install_element(BGP_NODE, &bgp_shutdown_cmd);
8389c83a 18062 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
9cf59432 18063 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
1b6e7a88 18064 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
f26845f9 18065
d62a17ae 18066 /* "neighbor remote-as" commands. */
18067 install_element(BGP_NODE, &neighbor_remote_as_cmd);
18068 install_element(BGP_NODE, &neighbor_interface_config_cmd);
18069 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
18070 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
18071 install_element(BGP_NODE,
18072 &neighbor_interface_v6only_config_remote_as_cmd);
18073 install_element(BGP_NODE, &no_neighbor_cmd);
18074 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
18075
18076 /* "neighbor peer-group" commands. */
18077 install_element(BGP_NODE, &neighbor_peer_group_cmd);
18078 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
18079 install_element(BGP_NODE,
18080 &no_neighbor_interface_peer_group_remote_as_cmd);
18081
18082 /* "neighbor local-as" commands. */
18083 install_element(BGP_NODE, &neighbor_local_as_cmd);
18084 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
18085 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
18086 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
18087
18088 /* "neighbor solo" commands. */
18089 install_element(BGP_NODE, &neighbor_solo_cmd);
18090 install_element(BGP_NODE, &no_neighbor_solo_cmd);
18091
18092 /* "neighbor password" commands. */
18093 install_element(BGP_NODE, &neighbor_password_cmd);
18094 install_element(BGP_NODE, &no_neighbor_password_cmd);
18095
18096 /* "neighbor activate" commands. */
18097 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
18098 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
18099 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
18100 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
18101 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
18102 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
18103 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
18104 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
18105 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 18106 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
18107 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 18108 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
18109
18110 /* "no neighbor activate" commands. */
18111 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
18112 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
18113 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
18114 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
18115 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
18116 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
18117 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
18118 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
18119 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 18120 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
18121 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 18122 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
18123
18124 /* "neighbor peer-group" set commands. */
18125 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
18126 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18127 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
18128 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18129 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
18130 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
18131 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18132 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 18133 install_element(BGP_FLOWSPECV4_NODE,
18134 &neighbor_set_peer_group_hidden_cmd);
18135 install_element(BGP_FLOWSPECV6_NODE,
18136 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 18137
18138 /* "no neighbor peer-group unset" commands. */
18139 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
18140 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18141 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18142 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18143 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18144 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18145 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18146 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 18147 install_element(BGP_FLOWSPECV4_NODE,
18148 &no_neighbor_set_peer_group_hidden_cmd);
18149 install_element(BGP_FLOWSPECV6_NODE,
18150 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 18151
18152 /* "neighbor softreconfiguration inbound" commands.*/
18153 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
18154 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
18155 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
18156 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18157 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
18158 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18159 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
18160 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18161 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
18162 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18163 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
18164 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18165 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
18166 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18167 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
18168 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18169 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
18170 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 18171 install_element(BGP_FLOWSPECV4_NODE,
18172 &neighbor_soft_reconfiguration_cmd);
18173 install_element(BGP_FLOWSPECV4_NODE,
18174 &no_neighbor_soft_reconfiguration_cmd);
18175 install_element(BGP_FLOWSPECV6_NODE,
18176 &neighbor_soft_reconfiguration_cmd);
18177 install_element(BGP_FLOWSPECV6_NODE,
18178 &no_neighbor_soft_reconfiguration_cmd);
616c6ee8
PG
18179 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
18180 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 18181
18182 /* "neighbor attribute-unchanged" commands. */
18183 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
18184 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
18185 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
18186 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
18187 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
18188 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
18189 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
18190 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
18191 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
18192 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
18193 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
18194 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
18195 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
18196 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
18197 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
18198 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
18199 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
18200 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
18201
18202 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
18203 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
18204
b8ad84d2
PG
18205 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
18206 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
18207 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
18208 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
18209
d62a17ae 18210 /* "nexthop-local unchanged" commands */
18211 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
18212 install_element(BGP_IPV6_NODE,
18213 &no_neighbor_nexthop_local_unchanged_cmd);
18214
18215 /* "neighbor next-hop-self" commands. */
18216 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
18217 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
18218 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
18219 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
18220 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
18221 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
18222 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
18223 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
18224 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
18225 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
18226 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
18227 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
18228 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
18229 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
18230 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
18231 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
18232 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
18233 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
18234 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
18235 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 18236
18237 /* "neighbor next-hop-self force" commands. */
18238 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
18239 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
1bc4e531
DA
18240 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18241 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18242 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
18243 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18244 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18245 install_element(BGP_IPV4_NODE,
18246 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18247 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
18248 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18249 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18250 install_element(BGP_IPV4M_NODE,
18251 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18252 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
18253 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18254 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18255 install_element(BGP_IPV4L_NODE,
18256 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18257 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
18258 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18259 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18260 install_element(BGP_IPV6_NODE,
18261 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18262 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
18263 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18264 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18265 install_element(BGP_IPV6M_NODE,
18266 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18267 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
18268 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18269 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18270 install_element(BGP_IPV6L_NODE,
18271 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18272 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
18273 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18274 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18275 install_element(BGP_VPNV4_NODE,
18276 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18277 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
18278 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18279 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18280 install_element(BGP_VPNV6_NODE,
18281 &no_neighbor_nexthop_self_all_hidden_cmd);
be7e1fa3
MS
18282 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
18283 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
d62a17ae 18284
18285 /* "neighbor as-override" commands. */
18286 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
18287 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
18288 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
18289 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
18290 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
18291 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
18292 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
18293 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
18294 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
18295 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
18296 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
18297 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
18298 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
18299 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
18300 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
18301 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
18302 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
18303 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
18304
18305 /* "neighbor remove-private-AS" commands. */
18306 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
18307 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
18308 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
18309 install_element(BGP_NODE,
18310 &no_neighbor_remove_private_as_all_hidden_cmd);
18311 install_element(BGP_NODE,
18312 &neighbor_remove_private_as_replace_as_hidden_cmd);
18313 install_element(BGP_NODE,
18314 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
18315 install_element(BGP_NODE,
18316 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
18317 install_element(
18318 BGP_NODE,
18319 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
18320 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
18321 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
18322 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
18323 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18324 install_element(BGP_IPV4_NODE,
18325 &neighbor_remove_private_as_replace_as_cmd);
18326 install_element(BGP_IPV4_NODE,
18327 &no_neighbor_remove_private_as_replace_as_cmd);
18328 install_element(BGP_IPV4_NODE,
18329 &neighbor_remove_private_as_all_replace_as_cmd);
18330 install_element(BGP_IPV4_NODE,
18331 &no_neighbor_remove_private_as_all_replace_as_cmd);
18332 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
18333 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
18334 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
18335 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
18336 install_element(BGP_IPV4M_NODE,
18337 &neighbor_remove_private_as_replace_as_cmd);
18338 install_element(BGP_IPV4M_NODE,
18339 &no_neighbor_remove_private_as_replace_as_cmd);
18340 install_element(BGP_IPV4M_NODE,
18341 &neighbor_remove_private_as_all_replace_as_cmd);
18342 install_element(BGP_IPV4M_NODE,
18343 &no_neighbor_remove_private_as_all_replace_as_cmd);
18344 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
18345 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
18346 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
18347 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
18348 install_element(BGP_IPV4L_NODE,
18349 &neighbor_remove_private_as_replace_as_cmd);
18350 install_element(BGP_IPV4L_NODE,
18351 &no_neighbor_remove_private_as_replace_as_cmd);
18352 install_element(BGP_IPV4L_NODE,
18353 &neighbor_remove_private_as_all_replace_as_cmd);
18354 install_element(BGP_IPV4L_NODE,
18355 &no_neighbor_remove_private_as_all_replace_as_cmd);
18356 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
18357 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
18358 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
18359 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18360 install_element(BGP_IPV6_NODE,
18361 &neighbor_remove_private_as_replace_as_cmd);
18362 install_element(BGP_IPV6_NODE,
18363 &no_neighbor_remove_private_as_replace_as_cmd);
18364 install_element(BGP_IPV6_NODE,
18365 &neighbor_remove_private_as_all_replace_as_cmd);
18366 install_element(BGP_IPV6_NODE,
18367 &no_neighbor_remove_private_as_all_replace_as_cmd);
18368 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
18369 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
18370 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
18371 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
18372 install_element(BGP_IPV6M_NODE,
18373 &neighbor_remove_private_as_replace_as_cmd);
18374 install_element(BGP_IPV6M_NODE,
18375 &no_neighbor_remove_private_as_replace_as_cmd);
18376 install_element(BGP_IPV6M_NODE,
18377 &neighbor_remove_private_as_all_replace_as_cmd);
18378 install_element(BGP_IPV6M_NODE,
18379 &no_neighbor_remove_private_as_all_replace_as_cmd);
18380 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
18381 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
18382 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
18383 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
18384 install_element(BGP_IPV6L_NODE,
18385 &neighbor_remove_private_as_replace_as_cmd);
18386 install_element(BGP_IPV6L_NODE,
18387 &no_neighbor_remove_private_as_replace_as_cmd);
18388 install_element(BGP_IPV6L_NODE,
18389 &neighbor_remove_private_as_all_replace_as_cmd);
18390 install_element(BGP_IPV6L_NODE,
18391 &no_neighbor_remove_private_as_all_replace_as_cmd);
18392 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
18393 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
18394 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
18395 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18396 install_element(BGP_VPNV4_NODE,
18397 &neighbor_remove_private_as_replace_as_cmd);
18398 install_element(BGP_VPNV4_NODE,
18399 &no_neighbor_remove_private_as_replace_as_cmd);
18400 install_element(BGP_VPNV4_NODE,
18401 &neighbor_remove_private_as_all_replace_as_cmd);
18402 install_element(BGP_VPNV4_NODE,
18403 &no_neighbor_remove_private_as_all_replace_as_cmd);
18404 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
18405 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
18406 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
18407 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18408 install_element(BGP_VPNV6_NODE,
18409 &neighbor_remove_private_as_replace_as_cmd);
18410 install_element(BGP_VPNV6_NODE,
18411 &no_neighbor_remove_private_as_replace_as_cmd);
18412 install_element(BGP_VPNV6_NODE,
18413 &neighbor_remove_private_as_all_replace_as_cmd);
18414 install_element(BGP_VPNV6_NODE,
18415 &no_neighbor_remove_private_as_all_replace_as_cmd);
18416
18417 /* "neighbor send-community" commands.*/
18418 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
18419 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
18420 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
18421 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
18422 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
18423 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
18424 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
18425 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
18426 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
18427 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
18428 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
18429 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
18430 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
18431 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
18432 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
18433 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
18434 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
18435 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
18436 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
18437 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
18438 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
18439 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
18440 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
18441 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
18442 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
18443 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
18444 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
18445 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
18446 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
18447 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
18448 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
18449 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
18450 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
18451 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
18452 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
18453 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
18454
18455 /* "neighbor route-reflector" commands.*/
18456 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
18457 install_element(BGP_NODE,
18458 &no_neighbor_route_reflector_client_hidden_cmd);
18459 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
18460 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
18461 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
18462 install_element(BGP_IPV4M_NODE,
18463 &no_neighbor_route_reflector_client_cmd);
18464 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
18465 install_element(BGP_IPV4L_NODE,
18466 &no_neighbor_route_reflector_client_cmd);
18467 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
18468 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
18469 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
18470 install_element(BGP_IPV6M_NODE,
18471 &no_neighbor_route_reflector_client_cmd);
18472 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
18473 install_element(BGP_IPV6L_NODE,
18474 &no_neighbor_route_reflector_client_cmd);
18475 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
18476 install_element(BGP_VPNV4_NODE,
18477 &no_neighbor_route_reflector_client_cmd);
18478 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
18479 install_element(BGP_VPNV6_NODE,
18480 &no_neighbor_route_reflector_client_cmd);
7c40bf39 18481 install_element(BGP_FLOWSPECV4_NODE,
18482 &neighbor_route_reflector_client_cmd);
18483 install_element(BGP_FLOWSPECV4_NODE,
18484 &no_neighbor_route_reflector_client_cmd);
18485 install_element(BGP_FLOWSPECV6_NODE,
18486 &neighbor_route_reflector_client_cmd);
18487 install_element(BGP_FLOWSPECV6_NODE,
18488 &no_neighbor_route_reflector_client_cmd);
d62a17ae 18489 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
18490 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
18491
18492 /* "neighbor route-server" commands.*/
18493 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
18494 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
18495 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
18496 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
18497 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
18498 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
18499 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
18500 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
18501 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
18502 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
18503 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
18504 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
18505 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
18506 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
18507 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
18508 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
18509 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
18510 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
18511 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
18512 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 18513 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
18514 install_element(BGP_FLOWSPECV4_NODE,
18515 &no_neighbor_route_server_client_cmd);
18516 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
18517 install_element(BGP_FLOWSPECV6_NODE,
18518 &no_neighbor_route_server_client_cmd);
d62a17ae 18519
18520 /* "neighbor addpath-tx-all-paths" commands.*/
18521 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
18522 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
18523 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18524 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18525 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18526 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18527 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18528 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18529 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18530 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18531 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18532 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18533 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18534 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18535 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18536 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18537 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18538 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18539
18540 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
18541 install_element(BGP_NODE,
18542 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18543 install_element(BGP_NODE,
18544 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18545 install_element(BGP_IPV4_NODE,
18546 &neighbor_addpath_tx_bestpath_per_as_cmd);
18547 install_element(BGP_IPV4_NODE,
18548 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18549 install_element(BGP_IPV4M_NODE,
18550 &neighbor_addpath_tx_bestpath_per_as_cmd);
18551 install_element(BGP_IPV4M_NODE,
18552 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18553 install_element(BGP_IPV4L_NODE,
18554 &neighbor_addpath_tx_bestpath_per_as_cmd);
18555 install_element(BGP_IPV4L_NODE,
18556 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18557 install_element(BGP_IPV6_NODE,
18558 &neighbor_addpath_tx_bestpath_per_as_cmd);
18559 install_element(BGP_IPV6_NODE,
18560 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18561 install_element(BGP_IPV6M_NODE,
18562 &neighbor_addpath_tx_bestpath_per_as_cmd);
18563 install_element(BGP_IPV6M_NODE,
18564 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18565 install_element(BGP_IPV6L_NODE,
18566 &neighbor_addpath_tx_bestpath_per_as_cmd);
18567 install_element(BGP_IPV6L_NODE,
18568 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18569 install_element(BGP_VPNV4_NODE,
18570 &neighbor_addpath_tx_bestpath_per_as_cmd);
18571 install_element(BGP_VPNV4_NODE,
18572 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18573 install_element(BGP_VPNV6_NODE,
18574 &neighbor_addpath_tx_bestpath_per_as_cmd);
18575 install_element(BGP_VPNV6_NODE,
18576 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18577
2b31007c
RZ
18578 /* "neighbor sender-as-path-loop-detection" commands. */
18579 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
18580 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
18581
d62a17ae 18582 /* "neighbor passive" commands. */
18583 install_element(BGP_NODE, &neighbor_passive_cmd);
18584 install_element(BGP_NODE, &no_neighbor_passive_cmd);
18585
18586
18587 /* "neighbor shutdown" commands. */
18588 install_element(BGP_NODE, &neighbor_shutdown_cmd);
18589 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
18590 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
18591 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
8336c896
DA
18592 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
18593 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
d62a17ae 18594
18595 /* "neighbor capability extended-nexthop" commands.*/
18596 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
18597 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
18598
18599 /* "neighbor capability orf prefix-list" commands.*/
18600 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
18601 install_element(BGP_NODE,
18602 &no_neighbor_capability_orf_prefix_hidden_cmd);
18603 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
18604 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
18605 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
18606 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18607 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
18608 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18609 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
18610 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
18611 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
18612 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18613 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
18614 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18615
18616 /* "neighbor capability dynamic" commands.*/
18617 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
18618 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
18619
18620 /* "neighbor dont-capability-negotiate" commands. */
18621 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
18622 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
18623
18624 /* "neighbor ebgp-multihop" commands. */
18625 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
18626 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
18627 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
18628
18629 /* "neighbor disable-connected-check" commands. */
18630 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
18631 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
18632
47cbc09b
PM
18633 /* "neighbor enforce-first-as" commands. */
18634 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
18635 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
18636
d62a17ae 18637 /* "neighbor description" commands. */
18638 install_element(BGP_NODE, &neighbor_description_cmd);
18639 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 18640 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 18641
18642 /* "neighbor update-source" commands. "*/
18643 install_element(BGP_NODE, &neighbor_update_source_cmd);
18644 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
18645
18646 /* "neighbor default-originate" commands. */
18647 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
18648 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
18649 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
18650 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
18651 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
18652 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
18653 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
18654 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
18655 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
18656 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
18657 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
18658 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
18659 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
18660 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
18661 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
18662 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
18663 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
18664 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
18665 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
18666 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
18667 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
18668
18669 /* "neighbor port" commands. */
18670 install_element(BGP_NODE, &neighbor_port_cmd);
18671 install_element(BGP_NODE, &no_neighbor_port_cmd);
18672
18673 /* "neighbor weight" commands. */
18674 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
18675 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
18676
18677 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
18678 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
18679 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
18680 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
18681 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
18682 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
18683 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
18684 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
18685 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
18686 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
18687 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
18688 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
18689 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
18690 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
18691 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
18692 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
18693
18694 /* "neighbor override-capability" commands. */
18695 install_element(BGP_NODE, &neighbor_override_capability_cmd);
18696 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
18697
18698 /* "neighbor strict-capability-match" commands. */
18699 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
18700 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
18701
18702 /* "neighbor timers" commands. */
18703 install_element(BGP_NODE, &neighbor_timers_cmd);
18704 install_element(BGP_NODE, &no_neighbor_timers_cmd);
18705
18706 /* "neighbor timers connect" commands. */
18707 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
18708 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
18709
d43114f3
DS
18710 /* "neighbor timers delayopen" commands. */
18711 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
18712 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
18713
d62a17ae 18714 /* "neighbor advertisement-interval" commands. */
18715 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
18716 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
18717
18718 /* "neighbor interface" commands. */
18719 install_element(BGP_NODE, &neighbor_interface_cmd);
18720 install_element(BGP_NODE, &no_neighbor_interface_cmd);
18721
18722 /* "neighbor distribute" commands. */
18723 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
18724 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
18725 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
18726 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
18727 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
18728 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
18729 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
18730 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
18731 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
18732 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
18733 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
18734 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
18735 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
18736 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
18737 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
18738 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
18739 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
18740 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
18741
18742 /* "neighbor prefix-list" commands. */
18743 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
d62a17ae 18744 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
d62a17ae 18745 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
d62a17ae 18746 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
d62a17ae 18747 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
d62a17ae 18748 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
d62a17ae 18749 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
d62a17ae 18750 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
d62a17ae 18751 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
7c40bf39 18752 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
7c40bf39 18753 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
d62a17ae 18754
18755 /* "neighbor filter-list" commands. */
18756 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
18757 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
18758 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
18759 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
18760 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
18761 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
18762 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
18763 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
18764 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
18765 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
18766 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
18767 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
18768 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
18769 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
18770 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
18771 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
18772 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
18773 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 18774 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
18775 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
18776 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
18777 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 18778
18779 /* "neighbor route-map" commands. */
d62a17ae 18780 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
d62a17ae 18781 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
d62a17ae 18782 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
d62a17ae 18783 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
d62a17ae 18784 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
d62a17ae 18785 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
d62a17ae 18786 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
d62a17ae 18787 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
7c40bf39 18788 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
7c40bf39 18789 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
d37ba549 18790 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
d62a17ae 18791
18792 /* "neighbor unsuppress-map" commands. */
18793 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
18794 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
18795 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
18796 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
18797 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
18798 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
18799 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
18800 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
18801 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
18802 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
18803 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
18804 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
18805 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
18806 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
18807 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
18808 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
18809 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
18810 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
18811
7f7940e6
MK
18812 /* "neighbor advertise-map" commands. */
18813 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
7f7940e6 18814 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18815 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18816 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18817 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18818 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18819 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18820 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18821 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18822
fde246e8
DA
18823 /* neighbor maximum-prefix-out commands. */
18824 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
18825 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
18826 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
18827 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18828 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
18829 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18830 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
18831 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18832 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
18833 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18834 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
18835 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18836 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
18837 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18838 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
18839 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18840 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
18841 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18842
d62a17ae 18843 /* "neighbor maximum-prefix" commands. */
18844 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
18845 install_element(BGP_NODE,
18846 &neighbor_maximum_prefix_threshold_hidden_cmd);
18847 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
18848 install_element(BGP_NODE,
18849 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
18850 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
18851 install_element(BGP_NODE,
18852 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
18853 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
18854 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
18855 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18856 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18857 install_element(BGP_IPV4_NODE,
18858 &neighbor_maximum_prefix_threshold_warning_cmd);
18859 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18860 install_element(BGP_IPV4_NODE,
18861 &neighbor_maximum_prefix_threshold_restart_cmd);
18862 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
18863 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
18864 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18865 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
18866 install_element(BGP_IPV4M_NODE,
18867 &neighbor_maximum_prefix_threshold_warning_cmd);
18868 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
18869 install_element(BGP_IPV4M_NODE,
18870 &neighbor_maximum_prefix_threshold_restart_cmd);
18871 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
18872 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
18873 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18874 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
18875 install_element(BGP_IPV4L_NODE,
18876 &neighbor_maximum_prefix_threshold_warning_cmd);
18877 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
18878 install_element(BGP_IPV4L_NODE,
18879 &neighbor_maximum_prefix_threshold_restart_cmd);
18880 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
18881 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
18882 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18883 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18884 install_element(BGP_IPV6_NODE,
18885 &neighbor_maximum_prefix_threshold_warning_cmd);
18886 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18887 install_element(BGP_IPV6_NODE,
18888 &neighbor_maximum_prefix_threshold_restart_cmd);
18889 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
18890 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
18891 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18892 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
18893 install_element(BGP_IPV6M_NODE,
18894 &neighbor_maximum_prefix_threshold_warning_cmd);
18895 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
18896 install_element(BGP_IPV6M_NODE,
18897 &neighbor_maximum_prefix_threshold_restart_cmd);
18898 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
18899 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
18900 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18901 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
18902 install_element(BGP_IPV6L_NODE,
18903 &neighbor_maximum_prefix_threshold_warning_cmd);
18904 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
18905 install_element(BGP_IPV6L_NODE,
18906 &neighbor_maximum_prefix_threshold_restart_cmd);
18907 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
18908 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
18909 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18910 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18911 install_element(BGP_VPNV4_NODE,
18912 &neighbor_maximum_prefix_threshold_warning_cmd);
18913 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18914 install_element(BGP_VPNV4_NODE,
18915 &neighbor_maximum_prefix_threshold_restart_cmd);
18916 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
18917 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
18918 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18919 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18920 install_element(BGP_VPNV6_NODE,
18921 &neighbor_maximum_prefix_threshold_warning_cmd);
18922 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18923 install_element(BGP_VPNV6_NODE,
18924 &neighbor_maximum_prefix_threshold_restart_cmd);
18925 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
18926
18927 /* "neighbor allowas-in" */
18928 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
18929 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
18930 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
18931 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
18932 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
18933 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
18934 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
18935 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
18936 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
18937 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
18938 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
18939 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
18940 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
18941 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
18942 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
18943 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
18944 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
18945 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
18946 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
18947 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
18948
0221327c
DS
18949 /* "neighbor dampening" commands. */
18950 install_element(BGP_NODE, &neighbor_damp_cmd);
18951 install_element(BGP_NODE, &no_neighbor_damp_cmd);
18952 install_element(BGP_IPV4_NODE, &neighbor_damp_cmd);
18953 install_element(BGP_IPV4_NODE, &no_neighbor_damp_cmd);
18954 install_element(BGP_IPV4M_NODE, &neighbor_damp_cmd);
18955 install_element(BGP_IPV4M_NODE, &no_neighbor_damp_cmd);
18956 install_element(BGP_IPV4L_NODE, &neighbor_damp_cmd);
18957 install_element(BGP_IPV4L_NODE, &no_neighbor_damp_cmd);
18958 install_element(BGP_IPV6_NODE, &neighbor_damp_cmd);
18959 install_element(BGP_IPV6_NODE, &no_neighbor_damp_cmd);
18960 install_element(BGP_IPV6M_NODE, &neighbor_damp_cmd);
18961 install_element(BGP_IPV6M_NODE, &no_neighbor_damp_cmd);
18962 install_element(BGP_IPV6L_NODE, &neighbor_damp_cmd);
18963 install_element(BGP_IPV6L_NODE, &no_neighbor_damp_cmd);
18964 install_element(VIEW_NODE, &show_ip_bgp_neighbor_damp_param_cmd);
18965
d62a17ae 18966 /* address-family commands. */
18967 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
18968 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 18969#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 18970 install_element(BGP_NODE, &address_family_vpnv4_cmd);
18971 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 18972#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 18973
d62a17ae 18974 install_element(BGP_NODE, &address_family_evpn_cmd);
18975
18976 /* "exit-address-family" command. */
18977 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
18978 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
18979 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
18980 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
18981 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
18982 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
18983 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
18984 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 18985 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
18986 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 18987 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
18988
18989 /* "clear ip bgp commands" */
18990 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
18991
18992 /* clear ip bgp prefix */
18993 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
18994 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
18995 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
18996
18997 /* "show [ip] bgp summary" commands. */
18998 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 18999 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 19000 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 19001 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 19002 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
19003 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 19004 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
19005
19006 /* "show [ip] bgp neighbors" commands. */
19007 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
19008
36235319 19009 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
2986cac2 19010
d62a17ae 19011 /* "show [ip] bgp peer-group" commands. */
19012 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
19013
19014 /* "show [ip] bgp paths" commands. */
19015 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
19016
19017 /* "show [ip] bgp community" commands. */
19018 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
19019
19020 /* "show ip bgp large-community" commands. */
19021 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
19022 /* "show [ip] bgp attribute-info" commands. */
19023 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 19024 /* "show [ip] bgp route-leak" command */
19025 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 19026
19027 /* "redistribute" commands. */
19028 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
19029 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
19030 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
19031 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
19032 install_element(BGP_NODE,
19033 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
19034 install_element(BGP_NODE,
19035 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
19036 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
19037 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
19038 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
19039 install_element(BGP_NODE,
19040 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
19041 install_element(BGP_NODE,
19042 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
19043 install_element(BGP_NODE,
19044 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
19045 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
19046 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
19047 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
19048 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
19049 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
19050 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
19051 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
19052 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
19053 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
19054 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
19055 install_element(BGP_IPV4_NODE,
19056 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
19057 install_element(BGP_IPV4_NODE,
19058 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
19059 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
19060 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
19061 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
19062 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
19063 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
19064 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
19065
b9c7bc5a
PZ
19066 /* import|export vpn [route-map WORD] */
19067 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
19068 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 19069
12a844a5
DS
19070 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
19071 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
19072
d62a17ae 19073 /* ttl_security commands */
19074 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
19075 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
19076
19077 /* "show [ip] bgp memory" commands. */
19078 install_element(VIEW_NODE, &show_bgp_memory_cmd);
19079
acf71666
MK
19080 /* "show bgp martian next-hop" */
19081 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
19082
48ecf8f5
DS
19083 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
19084
d62a17ae 19085 /* "show [ip] bgp views" commands. */
19086 install_element(VIEW_NODE, &show_bgp_views_cmd);
19087
19088 /* "show [ip] bgp vrfs" commands. */
19089 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
19090
19091 /* Community-list. */
19092 community_list_vty();
ddb5b488
PZ
19093
19094 /* vpn-policy commands */
b9c7bc5a
PZ
19095 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
19096 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
19097 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
19098 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
19099 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
19100 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
19101 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
19102 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
19103 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
19104 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
19105 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
19106 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 19107
301ad80a
PG
19108 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
19109 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
19110
b9c7bc5a
PZ
19111 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
19112 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
19113 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
19114 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
b9c7bc5a
PZ
19115 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
19116 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
19117 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
19118 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
19119 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
19120 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
718e3744 19121}
6b0655a2 19122
718e3744 19123#include "memory.h"
19124#include "bgp_regex.h"
19125#include "bgp_clist.h"
19126#include "bgp_ecommunity.h"
19127
19128/* VTY functions. */
19129
19130/* Direction value to string conversion. */
d62a17ae 19131static const char *community_direct_str(int direct)
19132{
19133 switch (direct) {
19134 case COMMUNITY_DENY:
19135 return "deny";
19136 case COMMUNITY_PERMIT:
19137 return "permit";
19138 default:
19139 return "unknown";
19140 }
718e3744 19141}
19142
19143/* Display error string. */
d62a17ae 19144static void community_list_perror(struct vty *vty, int ret)
19145{
19146 switch (ret) {
19147 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
19148 vty_out(vty, "%% Can't find community-list\n");
19149 break;
19150 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
19151 vty_out(vty, "%% Malformed community-list value\n");
19152 break;
19153 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
19154 vty_out(vty,
19155 "%% Community name conflict, previously defined as standard community\n");
19156 break;
19157 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
19158 vty_out(vty,
19159 "%% Community name conflict, previously defined as expanded community\n");
19160 break;
19161 }
718e3744 19162}
19163
5bf15956
DW
19164/* "community-list" keyword help string. */
19165#define COMMUNITY_LIST_STR "Add a community list entry\n"
19166
7336e101
SP
19167/*community-list standard */
19168DEFUN (community_list_standard,
19169 bgp_community_list_standard_cmd,
a08032fe 19170 "bgp community-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 19171 BGP_STR
718e3744 19172 COMMUNITY_LIST_STR
19173 "Community list number (standard)\n"
5bf15956 19174 "Add an standard community-list entry\n"
718e3744 19175 "Community list name\n"
2f8cc0e5
DA
19176 "Sequence number of an entry\n"
19177 "Sequence number\n"
718e3744 19178 "Specify community to reject\n"
19179 "Specify community to accept\n"
19180 COMMUNITY_VAL_STR)
19181{
d62a17ae 19182 char *cl_name_or_number = NULL;
2f8cc0e5 19183 char *seq = NULL;
d62a17ae 19184 int direct = 0;
19185 int style = COMMUNITY_LIST_STANDARD;
d62a17ae 19186 int idx = 0;
7336e101 19187
a08032fe 19188 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19189 if (idx)
19190 seq = argv[idx]->arg;
19191
19192 idx = 0;
d62a17ae 19193 argv_find(argv, argc, "(1-99)", &idx);
19194 argv_find(argv, argc, "WORD", &idx);
19195 cl_name_or_number = argv[idx]->arg;
19196 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19197 : COMMUNITY_DENY;
19198 argv_find(argv, argc, "AA:NN", &idx);
19199 char *str = argv_concat(argv, argc, idx);
42f914d4 19200
2f8cc0e5
DA
19201 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19202 direct, style);
42f914d4 19203
d62a17ae 19204 XFREE(MTYPE_TMP, str);
42f914d4 19205
d62a17ae 19206 if (ret < 0) {
19207 /* Display error string. */
19208 community_list_perror(vty, ret);
19209 return CMD_WARNING_CONFIG_FAILED;
19210 }
42f914d4 19211
d62a17ae 19212 return CMD_SUCCESS;
718e3744 19213}
19214
7336e101
SP
19215DEFUN (no_community_list_standard_all,
19216 no_bgp_community_list_standard_all_cmd,
a08032fe 19217 "no bgp community-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19218 NO_STR
19219 BGP_STR
19220 COMMUNITY_LIST_STR
19221 "Community list number (standard)\n"
19222 "Add an standard community-list entry\n"
19223 "Community list name\n"
2f8cc0e5
DA
19224 "Sequence number of an entry\n"
19225 "Sequence number\n"
7336e101
SP
19226 "Specify community to reject\n"
19227 "Specify community to accept\n"
19228 COMMUNITY_VAL_STR)
718e3744 19229{
d62a17ae 19230 char *cl_name_or_number = NULL;
174b5cb9 19231 char *str = NULL;
d62a17ae 19232 int direct = 0;
19233 int style = COMMUNITY_LIST_STANDARD;
2f8cc0e5 19234 char *seq = NULL;
d62a17ae 19235 int idx = 0;
7336e101 19236
a08032fe 19237 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19238 if (idx)
19239 seq = argv[idx]->arg;
19240
19241 idx = 0;
174b5cb9
DA
19242 argv_find(argv, argc, "permit", &idx);
19243 argv_find(argv, argc, "deny", &idx);
19244
19245 if (idx) {
19246 direct = argv_find(argv, argc, "permit", &idx)
19247 ? COMMUNITY_PERMIT
19248 : COMMUNITY_DENY;
19249
19250 idx = 0;
19251 argv_find(argv, argc, "AA:NN", &idx);
19252 str = argv_concat(argv, argc, idx);
19253 }
19254
19255 idx = 0;
d62a17ae 19256 argv_find(argv, argc, "(1-99)", &idx);
19257 argv_find(argv, argc, "WORD", &idx);
19258 cl_name_or_number = argv[idx]->arg;
42f914d4 19259
2f8cc0e5 19260 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 19261 direct, style);
42f914d4 19262
d62a17ae 19263 XFREE(MTYPE_TMP, str);
daf9ddbb 19264
d62a17ae 19265 if (ret < 0) {
19266 community_list_perror(vty, ret);
19267 return CMD_WARNING_CONFIG_FAILED;
19268 }
42f914d4 19269
d62a17ae 19270 return CMD_SUCCESS;
718e3744 19271}
7336e101 19272
174b5cb9
DA
19273ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
19274 "no bgp community-list <(1-99)|standard WORD>",
19275 NO_STR BGP_STR COMMUNITY_LIST_STR
19276 "Community list number (standard)\n"
19277 "Add an standard community-list entry\n"
19278 "Community list name\n")
19279
7336e101
SP
19280/*community-list expanded */
19281DEFUN (community_list_expanded_all,
19282 bgp_community_list_expanded_all_cmd,
a08032fe 19283 "bgp community-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19284 BGP_STR
19285 COMMUNITY_LIST_STR
718e3744 19286 "Community list number (expanded)\n"
5bf15956 19287 "Add an expanded community-list entry\n"
718e3744 19288 "Community list name\n"
2f8cc0e5
DA
19289 "Sequence number of an entry\n"
19290 "Sequence number\n"
718e3744 19291 "Specify community to reject\n"
19292 "Specify community to accept\n"
19293 COMMUNITY_VAL_STR)
19294{
d62a17ae 19295 char *cl_name_or_number = NULL;
2f8cc0e5 19296 char *seq = NULL;
d62a17ae 19297 int direct = 0;
19298 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 19299 int idx = 0;
7b9a4750 19300
a08032fe 19301 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19302 if (idx)
19303 seq = argv[idx]->arg;
19304
19305 idx = 0;
19306
d62a17ae 19307 argv_find(argv, argc, "(100-500)", &idx);
19308 argv_find(argv, argc, "WORD", &idx);
19309 cl_name_or_number = argv[idx]->arg;
19310 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19311 : COMMUNITY_DENY;
19312 argv_find(argv, argc, "AA:NN", &idx);
19313 char *str = argv_concat(argv, argc, idx);
42f914d4 19314
2f8cc0e5
DA
19315 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19316 direct, style);
42f914d4 19317
d62a17ae 19318 XFREE(MTYPE_TMP, str);
42f914d4 19319
d62a17ae 19320 if (ret < 0) {
19321 /* Display error string. */
19322 community_list_perror(vty, ret);
19323 return CMD_WARNING_CONFIG_FAILED;
19324 }
42f914d4 19325
d62a17ae 19326 return CMD_SUCCESS;
718e3744 19327}
19328
7336e101
SP
19329DEFUN (no_community_list_expanded_all,
19330 no_bgp_community_list_expanded_all_cmd,
a08032fe 19331 "no bgp community-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19332 NO_STR
19333 BGP_STR
19334 COMMUNITY_LIST_STR
19335 "Community list number (expanded)\n"
19336 "Add an expanded community-list entry\n"
19337 "Community list name\n"
2f8cc0e5
DA
19338 "Sequence number of an entry\n"
19339 "Sequence number\n"
7336e101
SP
19340 "Specify community to reject\n"
19341 "Specify community to accept\n"
19342 COMMUNITY_VAL_STR)
718e3744 19343{
d62a17ae 19344 char *cl_name_or_number = NULL;
2f8cc0e5 19345 char *seq = NULL;
174b5cb9 19346 char *str = NULL;
d62a17ae 19347 int direct = 0;
19348 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 19349 int idx = 0;
174b5cb9 19350
a08032fe 19351 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19352 if (idx)
19353 seq = argv[idx]->arg;
19354
19355 idx = 0;
174b5cb9
DA
19356 argv_find(argv, argc, "permit", &idx);
19357 argv_find(argv, argc, "deny", &idx);
19358
19359 if (idx) {
19360 direct = argv_find(argv, argc, "permit", &idx)
19361 ? COMMUNITY_PERMIT
19362 : COMMUNITY_DENY;
19363
19364 idx = 0;
19365 argv_find(argv, argc, "AA:NN", &idx);
19366 str = argv_concat(argv, argc, idx);
7336e101 19367 }
174b5cb9
DA
19368
19369 idx = 0;
d62a17ae 19370 argv_find(argv, argc, "(100-500)", &idx);
19371 argv_find(argv, argc, "WORD", &idx);
19372 cl_name_or_number = argv[idx]->arg;
42f914d4 19373
2f8cc0e5 19374 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 19375 direct, style);
42f914d4 19376
d62a17ae 19377 XFREE(MTYPE_TMP, str);
daf9ddbb 19378
d62a17ae 19379 if (ret < 0) {
19380 community_list_perror(vty, ret);
19381 return CMD_WARNING_CONFIG_FAILED;
19382 }
42f914d4 19383
d62a17ae 19384 return CMD_SUCCESS;
718e3744 19385}
19386
36d4bb44
EB
19387ALIAS(no_community_list_expanded_all,
19388 no_bgp_community_list_expanded_all_list_cmd,
174b5cb9 19389 "no bgp community-list <(100-500)|expanded WORD>",
36d4bb44 19390 NO_STR BGP_STR COMMUNITY_LIST_STR
174b5cb9
DA
19391 "Community list number (expanded)\n"
19392 "Add an expanded community-list entry\n"
19393 "Community list name\n")
19394
8d9b8ed9
PM
19395/* Return configuration string of community-list entry. */
19396static const char *community_list_config_str(struct community_entry *entry)
19397{
19398 const char *str;
19399
19400 if (entry->any)
19401 str = "";
19402 else {
19403 if (entry->style == COMMUNITY_LIST_STANDARD)
19404 str = community_str(entry->u.com, false);
19405 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
19406 str = lcommunity_str(entry->u.lcom, false);
19407 else
19408 str = entry->config;
19409 }
19410 return str;
19411}
19412
d62a17ae 19413static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 19414{
d62a17ae 19415 struct community_entry *entry;
718e3744 19416
d62a17ae 19417 for (entry = list->head; entry; entry = entry->next) {
19418 if (entry == list->head) {
19419 if (all_digit(list->name))
19420 vty_out(vty, "Community %s list %s\n",
19421 entry->style == COMMUNITY_LIST_STANDARD
19422 ? "standard"
19423 : "(expanded) access",
19424 list->name);
19425 else
19426 vty_out(vty, "Named Community %s list %s\n",
19427 entry->style == COMMUNITY_LIST_STANDARD
19428 ? "standard"
19429 : "expanded",
19430 list->name);
19431 }
19432 if (entry->any)
19433 vty_out(vty, " %s\n",
19434 community_direct_str(entry->direct));
19435 else
19436 vty_out(vty, " %s %s\n",
19437 community_direct_str(entry->direct),
8d9b8ed9 19438 community_list_config_str(entry));
d62a17ae 19439 }
718e3744 19440}
19441
7336e101
SP
19442DEFUN (show_community_list,
19443 show_bgp_community_list_cmd,
19444 "show bgp community-list",
718e3744 19445 SHOW_STR
7336e101 19446 BGP_STR
718e3744 19447 "List community-list\n")
19448{
d62a17ae 19449 struct community_list *list;
19450 struct community_list_master *cm;
718e3744 19451
d62a17ae 19452 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
19453 if (!cm)
19454 return CMD_SUCCESS;
718e3744 19455
d62a17ae 19456 for (list = cm->num.head; list; list = list->next)
19457 community_list_show(vty, list);
718e3744 19458
d62a17ae 19459 for (list = cm->str.head; list; list = list->next)
19460 community_list_show(vty, list);
718e3744 19461
d62a17ae 19462 return CMD_SUCCESS;
718e3744 19463}
19464
7336e101
SP
19465DEFUN (show_community_list_arg,
19466 show_bgp_community_list_arg_cmd,
960b69b9 19467 "show bgp community-list <(1-500)|WORD> detail",
7336e101
SP
19468 SHOW_STR
19469 BGP_STR
718e3744 19470 "List community-list\n"
19471 "Community-list number\n"
960b69b9 19472 "Community-list name\n"
19473 "Detailed information on community-list\n")
718e3744 19474{
d62a17ae 19475 int idx_comm_list = 3;
19476 struct community_list *list;
718e3744 19477
e237b0d2 19478 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 19479 COMMUNITY_LIST_MASTER);
19480 if (!list) {
19481 vty_out(vty, "%% Can't find community-list\n");
19482 return CMD_WARNING;
19483 }
718e3744 19484
d62a17ae 19485 community_list_show(vty, list);
718e3744 19486
d62a17ae 19487 return CMD_SUCCESS;
718e3744 19488}
6b0655a2 19489
57d187bc
JS
19490/*
19491 * Large Community code.
19492 */
d62a17ae 19493static int lcommunity_list_set_vty(struct vty *vty, int argc,
19494 struct cmd_token **argv, int style,
19495 int reject_all_digit_name)
19496{
19497 int ret;
19498 int direct;
19499 char *str;
19500 int idx = 0;
19501 char *cl_name;
2f8cc0e5
DA
19502 char *seq = NULL;
19503
a08032fe 19504 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 19505 seq = argv[idx]->arg;
d62a17ae 19506
2f8cc0e5 19507 idx = 0;
d62a17ae 19508 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19509 : COMMUNITY_DENY;
19510
19511 /* All digit name check. */
19512 idx = 0;
19513 argv_find(argv, argc, "WORD", &idx);
19514 argv_find(argv, argc, "(1-99)", &idx);
19515 argv_find(argv, argc, "(100-500)", &idx);
19516 cl_name = argv[idx]->arg;
19517 if (reject_all_digit_name && all_digit(cl_name)) {
19518 vty_out(vty, "%% Community name cannot have all digits\n");
19519 return CMD_WARNING_CONFIG_FAILED;
19520 }
19521
19522 idx = 0;
19523 argv_find(argv, argc, "AA:BB:CC", &idx);
19524 argv_find(argv, argc, "LINE", &idx);
19525 /* Concat community string argument. */
19526 if (idx)
19527 str = argv_concat(argv, argc, idx);
19528 else
19529 str = NULL;
19530
2f8cc0e5 19531 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
d62a17ae 19532
19533 /* Free temporary community list string allocated by
19534 argv_concat(). */
0a22ddfb 19535 XFREE(MTYPE_TMP, str);
d62a17ae 19536
19537 if (ret < 0) {
19538 community_list_perror(vty, ret);
19539 return CMD_WARNING_CONFIG_FAILED;
19540 }
19541 return CMD_SUCCESS;
19542}
19543
19544static int lcommunity_list_unset_vty(struct vty *vty, int argc,
19545 struct cmd_token **argv, int style)
19546{
19547 int ret;
19548 int direct = 0;
19549 char *str = NULL;
19550 int idx = 0;
2f8cc0e5 19551 char *seq = NULL;
d62a17ae 19552
a08032fe 19553 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 19554 seq = argv[idx]->arg;
d62a17ae 19555
2f8cc0e5 19556 idx = 0;
d62a17ae 19557 argv_find(argv, argc, "permit", &idx);
19558 argv_find(argv, argc, "deny", &idx);
19559
19560 if (idx) {
19561 /* Check the list direct. */
19562 if (strncmp(argv[idx]->arg, "p", 1) == 0)
19563 direct = COMMUNITY_PERMIT;
19564 else
19565 direct = COMMUNITY_DENY;
19566
19567 idx = 0;
19568 argv_find(argv, argc, "LINE", &idx);
19569 argv_find(argv, argc, "AA:AA:NN", &idx);
19570 /* Concat community string argument. */
19571 str = argv_concat(argv, argc, idx);
19572 }
19573
19574 idx = 0;
19575 argv_find(argv, argc, "(1-99)", &idx);
19576 argv_find(argv, argc, "(100-500)", &idx);
19577 argv_find(argv, argc, "WORD", &idx);
19578
19579 /* Unset community list. */
2f8cc0e5 19580 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
d62a17ae 19581 style);
19582
19583 /* Free temporary community list string allocated by
19584 argv_concat(). */
0a22ddfb 19585 XFREE(MTYPE_TMP, str);
d62a17ae 19586
19587 if (ret < 0) {
19588 community_list_perror(vty, ret);
19589 return CMD_WARNING_CONFIG_FAILED;
19590 }
19591
19592 return CMD_SUCCESS;
57d187bc
JS
19593}
19594
19595/* "large-community-list" keyword help string. */
19596#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
19597#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
19598
7336e101
SP
19599DEFUN (lcommunity_list_standard,
19600 bgp_lcommunity_list_standard_cmd,
a08032fe 19601 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
19602 BGP_STR
19603 LCOMMUNITY_LIST_STR
19604 "Large Community list number (standard)\n"
2f8cc0e5
DA
19605 "Sequence number of an entry\n"
19606 "Sequence number\n"
7336e101
SP
19607 "Specify large community to reject\n"
19608 "Specify large community to accept\n"
19609 LCOMMUNITY_VAL_STR)
52951b63 19610{
d62a17ae 19611 return lcommunity_list_set_vty(vty, argc, argv,
19612 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
19613}
19614
7336e101
SP
19615DEFUN (lcommunity_list_expanded,
19616 bgp_lcommunity_list_expanded_cmd,
a08032fe 19617 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19618 BGP_STR
19619 LCOMMUNITY_LIST_STR
19620 "Large Community list number (expanded)\n"
2f8cc0e5
DA
19621 "Sequence number of an entry\n"
19622 "Sequence number\n"
7336e101
SP
19623 "Specify large community to reject\n"
19624 "Specify large community to accept\n"
19625 "An ordered list as a regular-expression\n")
57d187bc 19626{
d62a17ae 19627 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 19628 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
19629}
19630
7336e101
SP
19631DEFUN (lcommunity_list_name_standard,
19632 bgp_lcommunity_list_name_standard_cmd,
a08032fe 19633 "bgp large-community-list standard WORD [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
19634 BGP_STR
19635 LCOMMUNITY_LIST_STR
19636 "Specify standard large-community-list\n"
19637 "Large Community list name\n"
2f8cc0e5
DA
19638 "Sequence number of an entry\n"
19639 "Sequence number\n"
7336e101
SP
19640 "Specify large community to reject\n"
19641 "Specify large community to accept\n"
19642 LCOMMUNITY_VAL_STR)
52951b63 19643{
d62a17ae 19644 return lcommunity_list_set_vty(vty, argc, argv,
19645 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
19646}
19647
7336e101
SP
19648DEFUN (lcommunity_list_name_expanded,
19649 bgp_lcommunity_list_name_expanded_cmd,
a08032fe 19650 "bgp large-community-list expanded WORD [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19651 BGP_STR
19652 LCOMMUNITY_LIST_STR
19653 "Specify expanded large-community-list\n"
19654 "Large Community list name\n"
2f8cc0e5
DA
19655 "Sequence number of an entry\n"
19656 "Sequence number\n"
7336e101
SP
19657 "Specify large community to reject\n"
19658 "Specify large community to accept\n"
19659 "An ordered list as a regular-expression\n")
57d187bc 19660{
d62a17ae 19661 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 19662 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
19663}
19664
4378f57c
DA
19665DEFUN (no_lcommunity_list_all,
19666 no_bgp_lcommunity_list_all_cmd,
7336e101
SP
19667 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
19668 NO_STR
19669 BGP_STR
19670 LCOMMUNITY_LIST_STR
19671 "Large Community list number (standard)\n"
19672 "Large Community list number (expanded)\n"
19673 "Large Community list name\n")
57d187bc 19674{
7336e101
SP
19675 return lcommunity_list_unset_vty(vty, argc, argv,
19676 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
19677}
19678
4378f57c
DA
19679DEFUN (no_lcommunity_list_name_standard_all,
19680 no_bgp_lcommunity_list_name_standard_all_cmd,
19681 "no bgp large-community-list standard WORD",
19682 NO_STR
19683 BGP_STR
19684 LCOMMUNITY_LIST_STR
19685 "Specify standard large-community-list\n"
19686 "Large Community list name\n")
19687{
19688 return lcommunity_list_unset_vty(vty, argc, argv,
19689 LARGE_COMMUNITY_LIST_STANDARD);
19690}
19691
7336e101
SP
19692DEFUN (no_lcommunity_list_name_expanded_all,
19693 no_bgp_lcommunity_list_name_expanded_all_cmd,
19694 "no bgp large-community-list expanded WORD",
19695 NO_STR
19696 BGP_STR
19697 LCOMMUNITY_LIST_STR
19698 "Specify expanded large-community-list\n"
19699 "Large Community list name\n")
57d187bc 19700{
d62a17ae 19701 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19702 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
19703}
19704
7336e101
SP
19705DEFUN (no_lcommunity_list_standard,
19706 no_bgp_lcommunity_list_standard_cmd,
a08032fe 19707 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
19708 NO_STR
19709 BGP_STR
19710 LCOMMUNITY_LIST_STR
19711 "Large Community list number (standard)\n"
2f8cc0e5
DA
19712 "Sequence number of an entry\n"
19713 "Sequence number\n"
7336e101
SP
19714 "Specify large community to reject\n"
19715 "Specify large community to accept\n"
19716 LCOMMUNITY_VAL_STR)
57d187bc 19717{
d62a17ae 19718 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19719 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
19720}
19721
7336e101
SP
19722DEFUN (no_lcommunity_list_expanded,
19723 no_bgp_lcommunity_list_expanded_cmd,
a08032fe 19724 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19725 NO_STR
19726 BGP_STR
19727 LCOMMUNITY_LIST_STR
19728 "Large Community list number (expanded)\n"
2f8cc0e5
DA
19729 "Sequence number of an entry\n"
19730 "Sequence number\n"
7336e101
SP
19731 "Specify large community to reject\n"
19732 "Specify large community to accept\n"
19733 "An ordered list as a regular-expression\n")
57d187bc 19734{
d62a17ae 19735 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19736 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
19737}
19738
7336e101
SP
19739DEFUN (no_lcommunity_list_name_standard,
19740 no_bgp_lcommunity_list_name_standard_cmd,
a08032fe 19741 "no bgp large-community-list standard WORD [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
19742 NO_STR
19743 BGP_STR
19744 LCOMMUNITY_LIST_STR
19745 "Specify standard large-community-list\n"
19746 "Large Community list name\n"
2f8cc0e5
DA
19747 "Sequence number of an entry\n"
19748 "Sequence number\n"
7336e101
SP
19749 "Specify large community to reject\n"
19750 "Specify large community to accept\n"
19751 LCOMMUNITY_VAL_STR)
57d187bc 19752{
d62a17ae 19753 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19754 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
19755}
19756
7336e101
SP
19757DEFUN (no_lcommunity_list_name_expanded,
19758 no_bgp_lcommunity_list_name_expanded_cmd,
a08032fe 19759 "no bgp large-community-list expanded WORD [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19760 NO_STR
19761 BGP_STR
19762 LCOMMUNITY_LIST_STR
19763 "Specify expanded large-community-list\n"
19764 "Large community list name\n"
2f8cc0e5
DA
19765 "Sequence number of an entry\n"
19766 "Sequence number\n"
7336e101
SP
19767 "Specify large community to reject\n"
19768 "Specify large community to accept\n"
19769 "An ordered list as a regular-expression\n")
57d187bc 19770{
d62a17ae 19771 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19772 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
19773}
19774
d62a17ae 19775static void lcommunity_list_show(struct vty *vty, struct community_list *list)
19776{
19777 struct community_entry *entry;
19778
19779 for (entry = list->head; entry; entry = entry->next) {
19780 if (entry == list->head) {
19781 if (all_digit(list->name))
19782 vty_out(vty, "Large community %s list %s\n",
169b72c8 19783 entry->style ==
19784 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 19785 ? "standard"
19786 : "(expanded) access",
19787 list->name);
19788 else
19789 vty_out(vty,
19790 "Named large community %s list %s\n",
169b72c8 19791 entry->style ==
19792 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 19793 ? "standard"
19794 : "expanded",
19795 list->name);
19796 }
19797 if (entry->any)
19798 vty_out(vty, " %s\n",
19799 community_direct_str(entry->direct));
19800 else
19801 vty_out(vty, " %s %s\n",
19802 community_direct_str(entry->direct),
8d9b8ed9 19803 community_list_config_str(entry));
d62a17ae 19804 }
57d187bc
JS
19805}
19806
7336e101
SP
19807DEFUN (show_lcommunity_list,
19808 show_bgp_lcommunity_list_cmd,
19809 "show bgp large-community-list",
57d187bc 19810 SHOW_STR
7336e101 19811 BGP_STR
57d187bc
JS
19812 "List large-community list\n")
19813{
d62a17ae 19814 struct community_list *list;
19815 struct community_list_master *cm;
57d187bc 19816
d62a17ae 19817 cm = community_list_master_lookup(bgp_clist,
19818 LARGE_COMMUNITY_LIST_MASTER);
19819 if (!cm)
19820 return CMD_SUCCESS;
57d187bc 19821
d62a17ae 19822 for (list = cm->num.head; list; list = list->next)
19823 lcommunity_list_show(vty, list);
57d187bc 19824
d62a17ae 19825 for (list = cm->str.head; list; list = list->next)
19826 lcommunity_list_show(vty, list);
57d187bc 19827
d62a17ae 19828 return CMD_SUCCESS;
57d187bc
JS
19829}
19830
7336e101
SP
19831DEFUN (show_lcommunity_list_arg,
19832 show_bgp_lcommunity_list_arg_cmd,
960b69b9 19833 "show bgp large-community-list <(1-500)|WORD> detail",
7336e101
SP
19834 SHOW_STR
19835 BGP_STR
57d187bc 19836 "List large-community list\n"
960b69b9 19837 "Large-community-list number\n"
19838 "Large-community-list name\n"
19839 "Detailed information on large-community-list\n")
57d187bc 19840{
d62a17ae 19841 struct community_list *list;
57d187bc 19842
e237b0d2 19843 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
d62a17ae 19844 LARGE_COMMUNITY_LIST_MASTER);
19845 if (!list) {
960b69b9 19846 vty_out(vty, "%% Can't find large-community-list\n");
d62a17ae 19847 return CMD_WARNING;
19848 }
57d187bc 19849
d62a17ae 19850 lcommunity_list_show(vty, list);
57d187bc 19851
d62a17ae 19852 return CMD_SUCCESS;
57d187bc
JS
19853}
19854
718e3744 19855/* "extcommunity-list" keyword help string. */
19856#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
19857#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
19858
7336e101
SP
19859DEFUN (extcommunity_list_standard,
19860 bgp_extcommunity_list_standard_cmd,
a08032fe 19861 "bgp extcommunity-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 19862 BGP_STR
718e3744 19863 EXTCOMMUNITY_LIST_STR
19864 "Extended Community list number (standard)\n"
718e3744 19865 "Specify standard extcommunity-list\n"
5bf15956 19866 "Community list name\n"
2f8cc0e5
DA
19867 "Sequence number of an entry\n"
19868 "Sequence number\n"
718e3744 19869 "Specify community to reject\n"
19870 "Specify community to accept\n"
19871 EXTCOMMUNITY_VAL_STR)
19872{
d62a17ae 19873 int style = EXTCOMMUNITY_LIST_STANDARD;
19874 int direct = 0;
19875 char *cl_number_or_name = NULL;
2f8cc0e5 19876 char *seq = NULL;
42f914d4 19877
d62a17ae 19878 int idx = 0;
7b9a4750 19879
d62a17ae 19880 argv_find(argv, argc, "(1-99)", &idx);
19881 argv_find(argv, argc, "WORD", &idx);
19882 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 19883
a08032fe 19884 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19885 seq = argv[idx]->arg;
19886
d62a17ae 19887 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19888 : COMMUNITY_DENY;
19889 argv_find(argv, argc, "AA:NN", &idx);
19890 char *str = argv_concat(argv, argc, idx);
42f914d4 19891
2f8cc0e5 19892 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 19893 direct, style);
42f914d4 19894
d62a17ae 19895 XFREE(MTYPE_TMP, str);
42f914d4 19896
d62a17ae 19897 if (ret < 0) {
19898 community_list_perror(vty, ret);
19899 return CMD_WARNING_CONFIG_FAILED;
19900 }
42f914d4 19901
d62a17ae 19902 return CMD_SUCCESS;
718e3744 19903}
19904
7336e101
SP
19905DEFUN (extcommunity_list_name_expanded,
19906 bgp_extcommunity_list_name_expanded_cmd,
a08032fe 19907 "bgp extcommunity-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19908 BGP_STR
19909 EXTCOMMUNITY_LIST_STR
5bf15956 19910 "Extended Community list number (expanded)\n"
718e3744 19911 "Specify expanded extcommunity-list\n"
19912 "Extended Community list name\n"
2f8cc0e5
DA
19913 "Sequence number of an entry\n"
19914 "Sequence number\n"
718e3744 19915 "Specify community to reject\n"
19916 "Specify community to accept\n"
19917 "An ordered list as a regular-expression\n")
19918{
d62a17ae 19919 int style = EXTCOMMUNITY_LIST_EXPANDED;
19920 int direct = 0;
19921 char *cl_number_or_name = NULL;
2f8cc0e5 19922 char *seq = NULL;
d62a17ae 19923 int idx = 0;
7336e101 19924
d62a17ae 19925 argv_find(argv, argc, "(100-500)", &idx);
19926 argv_find(argv, argc, "WORD", &idx);
19927 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 19928
a08032fe 19929 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19930 seq = argv[idx]->arg;
19931
d62a17ae 19932 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19933 : COMMUNITY_DENY;
19934 argv_find(argv, argc, "LINE", &idx);
19935 char *str = argv_concat(argv, argc, idx);
42f914d4 19936
2f8cc0e5 19937 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 19938 direct, style);
42f914d4 19939
d62a17ae 19940 XFREE(MTYPE_TMP, str);
42f914d4 19941
d62a17ae 19942 if (ret < 0) {
19943 community_list_perror(vty, ret);
19944 return CMD_WARNING_CONFIG_FAILED;
19945 }
42f914d4 19946
d62a17ae 19947 return CMD_SUCCESS;
718e3744 19948}
19949
7336e101
SP
19950DEFUN (no_extcommunity_list_standard_all,
19951 no_bgp_extcommunity_list_standard_all_cmd,
a08032fe 19952 "no bgp extcommunity-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19953 NO_STR
19954 BGP_STR
19955 EXTCOMMUNITY_LIST_STR
813d4307 19956 "Extended Community list number (standard)\n"
718e3744 19957 "Specify standard extcommunity-list\n"
5bf15956 19958 "Community list name\n"
2f8cc0e5
DA
19959 "Sequence number of an entry\n"
19960 "Sequence number\n"
718e3744 19961 "Specify community to reject\n"
19962 "Specify community to accept\n"
19963 EXTCOMMUNITY_VAL_STR)
19964{
d62a17ae 19965 int style = EXTCOMMUNITY_LIST_STANDARD;
19966 int direct = 0;
19967 char *cl_number_or_name = NULL;
d4455c89 19968 char *str = NULL;
2f8cc0e5 19969 char *seq = NULL;
d62a17ae 19970 int idx = 0;
d4455c89 19971
a08032fe 19972 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19973 seq = argv[idx]->arg;
19974
19975 idx = 0;
d4455c89
DA
19976 argv_find(argv, argc, "permit", &idx);
19977 argv_find(argv, argc, "deny", &idx);
d4455c89
DA
19978 if (idx) {
19979 direct = argv_find(argv, argc, "permit", &idx)
19980 ? COMMUNITY_PERMIT
19981 : COMMUNITY_DENY;
19982
19983 idx = 0;
19984 argv_find(argv, argc, "AA:NN", &idx);
19985 str = argv_concat(argv, argc, idx);
19986 }
19987
19988 idx = 0;
d62a17ae 19989 argv_find(argv, argc, "(1-99)", &idx);
19990 argv_find(argv, argc, "WORD", &idx);
19991 cl_number_or_name = argv[idx]->arg;
42f914d4 19992
d62a17ae 19993 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 19994 seq, direct, style);
42f914d4 19995
d62a17ae 19996 XFREE(MTYPE_TMP, str);
42f914d4 19997
d62a17ae 19998 if (ret < 0) {
19999 community_list_perror(vty, ret);
20000 return CMD_WARNING_CONFIG_FAILED;
20001 }
42f914d4 20002
d62a17ae 20003 return CMD_SUCCESS;
718e3744 20004}
20005
d4455c89
DA
20006ALIAS(no_extcommunity_list_standard_all,
20007 no_bgp_extcommunity_list_standard_all_list_cmd,
20008 "no bgp extcommunity-list <(1-99)|standard WORD>",
36d4bb44 20009 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
20010 "Extended Community list number (standard)\n"
20011 "Specify standard extcommunity-list\n"
20012 "Community list name\n")
20013
7336e101
SP
20014DEFUN (no_extcommunity_list_expanded_all,
20015 no_bgp_extcommunity_list_expanded_all_cmd,
a08032fe 20016 "no bgp extcommunity-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20017 NO_STR
20018 BGP_STR
20019 EXTCOMMUNITY_LIST_STR
718e3744 20020 "Extended Community list number (expanded)\n"
718e3744 20021 "Specify expanded extcommunity-list\n"
5bf15956 20022 "Extended Community list name\n"
2f8cc0e5
DA
20023 "Sequence number of an entry\n"
20024 "Sequence number\n"
718e3744 20025 "Specify community to reject\n"
20026 "Specify community to accept\n"
20027 "An ordered list as a regular-expression\n")
20028{
d62a17ae 20029 int style = EXTCOMMUNITY_LIST_EXPANDED;
20030 int direct = 0;
20031 char *cl_number_or_name = NULL;
d4455c89 20032 char *str = NULL;
2f8cc0e5 20033 char *seq = NULL;
d62a17ae 20034 int idx = 0;
d4455c89 20035
a08032fe 20036 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20037 seq = argv[idx]->arg;
20038
20039 idx = 0;
d4455c89
DA
20040 argv_find(argv, argc, "permit", &idx);
20041 argv_find(argv, argc, "deny", &idx);
20042
20043 if (idx) {
20044 direct = argv_find(argv, argc, "permit", &idx)
20045 ? COMMUNITY_PERMIT
20046 : COMMUNITY_DENY;
20047
20048 idx = 0;
20049 argv_find(argv, argc, "LINE", &idx);
20050 str = argv_concat(argv, argc, idx);
20051 }
20052
20053 idx = 0;
d62a17ae 20054 argv_find(argv, argc, "(100-500)", &idx);
20055 argv_find(argv, argc, "WORD", &idx);
20056 cl_number_or_name = argv[idx]->arg;
42f914d4 20057
d62a17ae 20058 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 20059 seq, direct, style);
42f914d4 20060
d62a17ae 20061 XFREE(MTYPE_TMP, str);
42f914d4 20062
d62a17ae 20063 if (ret < 0) {
20064 community_list_perror(vty, ret);
20065 return CMD_WARNING_CONFIG_FAILED;
20066 }
42f914d4 20067
d62a17ae 20068 return CMD_SUCCESS;
718e3744 20069}
20070
d4455c89
DA
20071ALIAS(no_extcommunity_list_expanded_all,
20072 no_bgp_extcommunity_list_expanded_all_list_cmd,
20073 "no bgp extcommunity-list <(100-500)|expanded WORD>",
36d4bb44 20074 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
20075 "Extended Community list number (expanded)\n"
20076 "Specify expanded extcommunity-list\n"
20077 "Extended Community list name\n")
20078
d62a17ae 20079static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 20080{
d62a17ae 20081 struct community_entry *entry;
718e3744 20082
d62a17ae 20083 for (entry = list->head; entry; entry = entry->next) {
20084 if (entry == list->head) {
20085 if (all_digit(list->name))
20086 vty_out(vty, "Extended community %s list %s\n",
20087 entry->style == EXTCOMMUNITY_LIST_STANDARD
20088 ? "standard"
20089 : "(expanded) access",
20090 list->name);
20091 else
20092 vty_out(vty,
20093 "Named extended community %s list %s\n",
20094 entry->style == EXTCOMMUNITY_LIST_STANDARD
20095 ? "standard"
20096 : "expanded",
20097 list->name);
20098 }
20099 if (entry->any)
20100 vty_out(vty, " %s\n",
20101 community_direct_str(entry->direct));
20102 else
20103 vty_out(vty, " %s %s\n",
20104 community_direct_str(entry->direct),
8d9b8ed9 20105 community_list_config_str(entry));
d62a17ae 20106 }
718e3744 20107}
20108
7336e101
SP
20109DEFUN (show_extcommunity_list,
20110 show_bgp_extcommunity_list_cmd,
20111 "show bgp extcommunity-list",
718e3744 20112 SHOW_STR
7336e101 20113 BGP_STR
718e3744 20114 "List extended-community list\n")
20115{
d62a17ae 20116 struct community_list *list;
20117 struct community_list_master *cm;
718e3744 20118
d62a17ae 20119 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20120 if (!cm)
20121 return CMD_SUCCESS;
718e3744 20122
d62a17ae 20123 for (list = cm->num.head; list; list = list->next)
20124 extcommunity_list_show(vty, list);
718e3744 20125
d62a17ae 20126 for (list = cm->str.head; list; list = list->next)
20127 extcommunity_list_show(vty, list);
718e3744 20128
d62a17ae 20129 return CMD_SUCCESS;
718e3744 20130}
20131
7336e101
SP
20132DEFUN (show_extcommunity_list_arg,
20133 show_bgp_extcommunity_list_arg_cmd,
960b69b9 20134 "show bgp extcommunity-list <(1-500)|WORD> detail",
7336e101
SP
20135 SHOW_STR
20136 BGP_STR
718e3744 20137 "List extended-community list\n"
20138 "Extcommunity-list number\n"
960b69b9 20139 "Extcommunity-list name\n"
20140 "Detailed information on extcommunity-list\n")
718e3744 20141{
d62a17ae 20142 int idx_comm_list = 3;
20143 struct community_list *list;
718e3744 20144
e237b0d2 20145 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 20146 EXTCOMMUNITY_LIST_MASTER);
20147 if (!list) {
20148 vty_out(vty, "%% Can't find extcommunity-list\n");
20149 return CMD_WARNING;
20150 }
718e3744 20151
d62a17ae 20152 extcommunity_list_show(vty, list);
718e3744 20153
d62a17ae 20154 return CMD_SUCCESS;
718e3744 20155}
6b0655a2 20156
718e3744 20157/* Display community-list and extcommunity-list configuration. */
d62a17ae 20158static int community_list_config_write(struct vty *vty)
20159{
20160 struct community_list *list;
20161 struct community_entry *entry;
20162 struct community_list_master *cm;
20163 int write = 0;
20164
20165 /* Community-list. */
20166 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20167
20168 for (list = cm->num.head; list; list = list->next)
20169 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20170 vty_out(vty,
20171 "bgp community-list %s seq %" PRId64 " %s %s\n",
20172 list->name, entry->seq,
d62a17ae 20173 community_direct_str(entry->direct),
20174 community_list_config_str(entry));
20175 write++;
20176 }
20177 for (list = cm->str.head; list; list = list->next)
20178 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20179 vty_out(vty,
20180 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
d62a17ae 20181 entry->style == COMMUNITY_LIST_STANDARD
20182 ? "standard"
20183 : "expanded",
2f8cc0e5
DA
20184 list->name, entry->seq,
20185 community_direct_str(entry->direct),
d62a17ae 20186 community_list_config_str(entry));
20187 write++;
20188 }
20189
20190 /* Extcommunity-list. */
20191 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20192
20193 for (list = cm->num.head; list; list = list->next)
20194 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20195 vty_out(vty,
20196 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
20197 list->name, entry->seq,
20198 community_direct_str(entry->direct),
d62a17ae 20199 community_list_config_str(entry));
20200 write++;
20201 }
20202 for (list = cm->str.head; list; list = list->next)
20203 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20204 vty_out(vty,
6cde4b45 20205 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
d62a17ae 20206 entry->style == EXTCOMMUNITY_LIST_STANDARD
20207 ? "standard"
20208 : "expanded",
2f8cc0e5
DA
20209 list->name, entry->seq,
20210 community_direct_str(entry->direct),
d62a17ae 20211 community_list_config_str(entry));
20212 write++;
20213 }
20214
20215
20216 /* lcommunity-list. */
20217 cm = community_list_master_lookup(bgp_clist,
20218 LARGE_COMMUNITY_LIST_MASTER);
20219
20220 for (list = cm->num.head; list; list = list->next)
20221 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20222 vty_out(vty,
6cde4b45 20223 "bgp large-community-list %s seq %" PRId64" %s %s\n",
2f8cc0e5
DA
20224 list->name, entry->seq,
20225 community_direct_str(entry->direct),
d62a17ae 20226 community_list_config_str(entry));
20227 write++;
20228 }
20229 for (list = cm->str.head; list; list = list->next)
20230 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20231 vty_out(vty,
6cde4b45 20232 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
2f8cc0e5 20233
d62a17ae 20234 entry->style == LARGE_COMMUNITY_LIST_STANDARD
20235 ? "standard"
20236 : "expanded",
2f8cc0e5 20237 list->name, entry->seq, community_direct_str(entry->direct),
d62a17ae 20238 community_list_config_str(entry));
20239 write++;
20240 }
20241
20242 return write;
20243}
20244
612c2c15 20245static int community_list_config_write(struct vty *vty);
d62a17ae 20246static struct cmd_node community_list_node = {
f4b8291f 20247 .name = "community list",
62b346ee
DL
20248 .node = COMMUNITY_LIST_NODE,
20249 .prompt = "",
612c2c15 20250 .config_write = community_list_config_write,
718e3744 20251};
20252
d62a17ae 20253static void community_list_vty(void)
20254{
612c2c15 20255 install_node(&community_list_node);
d62a17ae 20256
20257 /* Community-list. */
7336e101
SP
20258 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
20259 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
20260 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 20261 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 20262 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 20263 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
20264 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
20265 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 20266
20267 /* Extcommunity-list. */
7336e101
SP
20268 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
20269 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
20270 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
d4455c89
DA
20271 install_element(CONFIG_NODE,
20272 &no_bgp_extcommunity_list_standard_all_list_cmd);
7336e101 20273 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
d4455c89
DA
20274 install_element(CONFIG_NODE,
20275 &no_bgp_extcommunity_list_expanded_all_list_cmd);
7336e101
SP
20276 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
20277 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 20278
20279 /* Large Community List */
7336e101 20280 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
7336e101
SP
20281 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
20282 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
7336e101 20283 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
4378f57c
DA
20284 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
20285 install_element(CONFIG_NODE,
20286 &no_bgp_lcommunity_list_name_standard_all_cmd);
7336e101
SP
20287 install_element(CONFIG_NODE,
20288 &no_bgp_lcommunity_list_name_expanded_all_cmd);
20289 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
20290 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
20291 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
20292 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
20293 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
20294 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
5bf15956 20295}